Elgg  Version 5.1
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 
86  public function getLabel() {
87  $label = elgg_extract('label', $this->options);
88  if (isset($label)) {
89  return $label;
90  }
91 
92  return elgg_echo("groups:tool:{$this->name}");
93  }
94 
100  public function getDescription(): ?string {
101  $lan_key = "groups:tool:{$this->name}:description";
103  return null;
104  }
105 
106  return elgg_echo($lan_key);
107  }
108 
113  public function isEnabledByDefault() {
114  $default_on = elgg_extract('default_on', $this->options, true);
115 
116  if ($default_on === true || $default_on === 'yes') {
117  return true;
118  }
119 
120  return false;
121  }
122 
127  public function mapMetadataName() {
128  return "{$this->name}_enable";
129  }
130 
139  public function mapMetadataValue($value = null) {
140  if (!isset($value)) {
141  $value = $this->default_on;
142  }
143 
144  if ($value === 'yes' || $value === true) {
145  return 'yes';
146  }
147 
148  return 'no';
149  }
150 }
__get($name)
{}
Definition: Tool.php:48
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
getLabel()
Get tool label.
Definition: Tool.php:86
$defaults
Generic entity header upload helper.
Definition: header.php:6
isEnabledByDefault()
Is the tool enabled by default?
Definition: Tool.php:113
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
mapMetadataValue($value=null)
Get metadata value for DB storage.
Definition: Tool.php:139
$value
Definition: generic.php:51
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
__construct($name, array $options=[])
Constructor.
Definition: Tool.php:33
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
getID()
{Get unique item identifier within a collection.string|int}
Definition: Tool.php:70
if(!$annotation instanceof ElggAnnotation) if(!$annotation->canEdit()) if(!$annotation->delete()) $lan_key
Definition: delete.php:33
getDescription()
Get tool description.
Definition: Tool.php:100
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:127
$site name
Definition: settings.php:15
$priority