Elgg  Version 6.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 
17  protected array $options;
18 
25  public function __construct(public string $name, array $options = []) {
26  $defaults = [
27  'label' => null,
28  'default_on' => true,
29  'priority' => 500,
30  ];
31 
32  $this->options = array_merge($defaults, $options);
33  }
34 
38  public function __get($name) {
39  switch ($name) {
40  case 'label':
41  return $this->getLabel();
42 
43  case 'default_on':
44  return $this->isEnabledByDefault();
45  }
46 
47  return elgg_extract($name, $this->options);
48  }
49 
53  public function __set($name, $value) {
54  $this->options[$name] = $value;
55  }
56 
60  public function getID() {
61  return $this->name;
62  }
63 
67  public function getPriority() {
68  return $this->priority;
69  }
70 
76  public function getLabel(): string {
77  $label = elgg_extract('label', $this->options);
78  if (isset($label)) {
79  return $label;
80  }
81 
82  return elgg_echo("groups:tool:{$this->name}");
83  }
84 
90  public function getDescription(): ?string {
91  $lan_key = "groups:tool:{$this->name}:description";
93  return null;
94  }
95 
96  return elgg_echo($lan_key);
97  }
98 
104  public function isEnabledByDefault(): bool {
105  $default_on = elgg_extract('default_on', $this->options, true);
106 
107  if ($default_on === true || $default_on === 'yes') {
108  return true;
109  }
110 
111  return false;
112  }
113 
119  public function mapMetadataName(): string {
120  return "{$this->name}_enable";
121  }
122 
131  public function mapMetadataValue($value = null): string {
132  if (!isset($value)) {
133  $value = $this->default_on;
134  }
135 
136  if ($value === 'yes' || $value === true) {
137  return 'yes';
138  }
139 
140  return 'no';
141  }
142 }
__get($name)
{}
Definition: Tool.php:38
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
getLabel()
Get tool label.
Definition: Tool.php:76
$defaults
Generic entity header upload helper.
Definition: header.php:6
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
isEnabledByDefault()
Is the tool enabled by default?
Definition: Tool.php:104
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:131
$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:256
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:60
if(!$annotation instanceof ElggAnnotation) if(!$annotation->canEdit()) if(!$annotation->delete()) $lan_key
Definition: delete.php:33
getDescription()
Get tool description.
Definition: Tool.php:90
getPriority()
{Get priority (weight) of the item within a collection.int}
Definition: Tool.php:67
__set($name, $value)
{}
Definition: Tool.php:53
mapMetadataName()
Get metadata name for DB storage.
Definition: Tool.php:119
array $options
Definition: Tool.php:17
__construct(public string $name, array $options=[])
Constructor.
Definition: Tool.php:25
$priority