Elgg  Version 6.1
ColumnFactory.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Views\TableColumn;
4 
5 use Elgg\Values;
7 
49 
59  public function fromView($name, $heading = null, $vars = []) {
60  $view = "page/components/column/$name";
61 
62  if (!is_string($heading)) {
63  if (elgg_language_key_exists("table_columns:fromView:$name")) {
64  $heading = elgg_echo("table_columns:fromView:$name");
65  } else {
66  $title = str_replace('_', ' ', $name);
67  $heading = elgg_ucwords($title);
68  }
69  }
70 
71  return new ViewColumn($view, $heading, $vars);
72  }
73 
82  public function fromProperty($name, $heading = null) {
83  if (!is_string($heading)) {
84  if (elgg_language_key_exists("table_columns:fromProperty:$name")) {
85  $heading = elgg_echo("table_columns:fromProperty:$name");
86  } else {
87  $title = str_replace('_', ' ', $name);
88  $heading = elgg_ucwords($title);
89  }
90  }
91 
92  $renderer = function ($item) use ($name) {
93  return $item->{$name};
94  };
95 
96  return new CallableColumn($renderer, $heading);
97  }
98 
108  public function fromMethod($name, $heading = null, $args = []) {
109  if (!is_string($heading)) {
110  if (elgg_language_key_exists("table_columns:fromMethod:$name")) {
111  $heading = elgg_echo("table_columns:fromMethod:$name");
112  } else {
113  $title = str_replace('_', ' ', $name);
114  $heading = elgg_ucwords($title);
115  }
116  }
117 
118  $renderer = function ($item) use ($name, $args) {
119  return call_user_func_array([$item, $name], $args);
120  };
121 
122  return new CallableColumn($renderer, $heading);
123  }
124 
143  public function __call($name, $arguments) {
144  // allow event to hijack magic methods
145  $column = _elgg_services()->events->triggerResults('table_columns:call', $name, [
146  'arguments' => $arguments,
147  ]);
148  if ($column instanceof TableColumn) {
149  return $column;
150  }
151 
152  if (elgg_language_key_exists("table_columns:fromView:$name")) {
153  array_unshift($arguments, $name);
154  return call_user_func_array([$this, 'fromView'], $arguments);
155  }
156 
157  if (elgg_language_key_exists("table_columns:fromProperty:$name")) {
158  array_unshift($arguments, $name);
159  return call_user_func_array([$this, 'fromProperty'], $arguments);
160  }
161 
162  if (elgg_language_key_exists("table_columns:fromMethod:$name")) {
163  array_unshift($arguments, $name);
164  return call_user_func_array([$this, 'fromMethod'], $arguments);
165  }
166 
167  // empty column and error
168  _elgg_services()->logger->error(__CLASS__ . ": No method defined '$name'");
169  return new CallableColumn([Values::class, 'getNull'], '');
170  }
171 }
if(!$items) $item
Definition: delete.php:13
fromView($name, $heading=null, $vars=[])
Make a column from one of the page/components/column/* views.
Saves user notification settings.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
fromProperty($name, $heading=null)
Make a column by reading a property of the item.
$title
Definition: generic.php:50
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$column
Definition: add.php:10
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
Table column rendered by a view.
Definition: ViewColumn.php:10
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
Table column rendered by a function.
__call($name, $arguments)
Provide additional methods via events and specified language keys.
fromMethod($name, $heading=null, $args=[])
Make a column by calling a method on the item.
Factory for table column objects.
$vars
Definition: theme.php:5
A renderer for a column of table cells and a header.
Definition: TableColumn.php:7
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_ucwords($str)
Wrapper for mb_convert_case($str, MB_CASE_TITLE)
Definition: mb_wrapper.php:160