Elgg  Version 3.0
Tool.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Groups;
4 
6 
15 class Tool implements CollectionItemInterface {
16 
20  public $name;
21 
25  protected $options;
26 
33  public function __construct($name, array $options = []) {
34  $this->name = $name;
35 
36  $defaults = [
37  'label' => null,
38  'default_on' => true,
39  'priority' => 500,
40  ];
41 
42  $this->options = array_merge($defaults, $options);
43  }
44 
48  public function __get($name) {
49  switch ($name) {
50  case 'label' :
51  return $this->getLabel();
52 
53  case 'default_on' :
54  return $this->isEnabledByDefault();
55  }
56 
57  return elgg_extract($name, $this->options);
58  }
59 
63  public function __set($name, $value) {
64  $this->options[$name] = $value;
65  }
66 
70  public function getId() {
71  return $this->name;
72  }
73 
77  public function getPriority() {
78  return $this->priority;
79  }
80 
85  public function getLabel() {
86  $label = elgg_extract('label', $this->options);
87  if (isset($label)) {
88  return $label;
89  }
90 
91  return elgg_echo("groups:tool:{$this->name}");
92  }
93 
98  public function isEnabledByDefault() {
99  $default_on = elgg_extract('default_on', $this->options, true);
100 
101  if ($default_on === true || $default_on === 'yes') {
102  return true;
103  }
104 
105  return false;
106  }
107 
112  public function mapMetadataName() {
113  return "{$this->name}_enable";
114  }
115 
124  public function mapMetadataValue($value = null) {
125  if (!isset($value)) {
126  $value = $this->default_on;
127  }
128 
129  if ($value === 'yes' || $value === true) {
130  return 'yes';
131  }
132 
133  return 'no';
134  }
135 }
__get($name)
{}
Definition: Tool.php:48
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
getLabel()
Get module title.
Definition: Tool.php:85
getId()
{Get unique item identifier within a collection.string|int}
Definition: Tool.php:70
$defaults
isEnabledByDefault()
Is the tool enabled by default?
Definition: Tool.php:98
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
mapMetadataValue($value=null)
Get metadata value for DB storage.
Definition: Tool.php:124
__construct($name, array $options=[])
Constructor.
Definition: Tool.php:33
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
$value
Definition: debugging.php:7
$site name
getPriority()
{Get priority (weight) of the item within a collection.int}
Definition: Tool.php:77
__set($name, $value)
Definition: Tool.php:63
mapMetadataName()
Get metadata name for DB storage.
Definition: Tool.php:112
$priority