Elgg  Version 3.0
ColumnFactory.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Views\TableColumn;
3 
4 use Elgg\Values;
6 
43 
53  public function fromView($name, $heading = null, $vars = []) {
54  $view = "page/components/column/$name";
55 
56  if (!is_string($heading)) {
57  if (elgg_language_key_exists("table_columns:fromView:$name")) {
58  $heading = elgg_echo("table_columns:fromView:$name");
59  } else {
60  $title = str_replace('_', ' ', $name);
61  $heading = elgg_ucwords($title);
62  }
63  }
64 
65  return new ViewColumn($view, $heading, $vars);
66  }
67 
76  public function fromProperty($name, $heading = null) {
77  if (!is_string($heading)) {
78  if (elgg_language_key_exists("table_columns:fromProperty:$name")) {
79  $heading = elgg_echo("table_columns:fromProperty:$name");
80  } else {
81  $title = str_replace('_', ' ', $name);
82  $heading = elgg_ucwords($title);
83  }
84  }
85 
86  $renderer = function ($item) use ($name) {
87  return $item->{$name};
88  };
89 
90  return new CallableColumn($renderer, $heading);
91  }
92 
102  public function fromMethod($name, $heading = null, $args = []) {
103  if (!is_string($heading)) {
104  if (elgg_language_key_exists("table_columns:fromMethod:$name")) {
105  $heading = elgg_echo("table_columns:fromMethod:$name");
106  } else {
107  $title = str_replace('_', ' ', $name);
108  $heading = elgg_ucwords($title);
109  }
110  }
111 
112  $renderer = function ($item) use ($name, $args) {
113  return call_user_func_array([$item, $name], $args);
114  };
115 
116  return new CallableColumn($renderer, $heading);
117  }
118 
137  public function __call($name, $arguments) {
138  // allow hook to hijack magic methods
139  $column = _elgg_services()->hooks->trigger('table_columns:call', $name, [
140  'arguments' => $arguments,
141  ]);
142  if ($column instanceof TableColumn) {
143  return $column;
144  }
145 
146  if (elgg_language_key_exists("table_columns:fromView:$name")) {
147  array_unshift($arguments, $name);
148  return call_user_func_array([$this, 'fromView'], $arguments);
149  }
150 
151  if (elgg_language_key_exists("table_columns:fromProperty:$name")) {
152  array_unshift($arguments, $name);
153  return call_user_func_array([$this, 'fromProperty'], $arguments);
154  }
155 
156  if (elgg_language_key_exists("table_columns:fromMethod:$name")) {
157  array_unshift($arguments, $name);
158  return call_user_func_array([$this, 'fromMethod'], $arguments);
159  }
160 
161  // empty column and error
162  _elgg_services()->logger->error(__CLASS__ . ": No method defined '$name'");
163  return new CallableColumn([Values::class, 'getNull'], '');
164  }
165 }
elgg_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:96
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
fromView($name, $heading=null, $vars=[])
Make a column from one of the page/components/column/* views.
if(!$items) $item
Definition: delete.php:13
fromProperty($name, $heading=null)
Make a column by reading a property of the item.
$column
Definition: add.php:10
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
Table column rendered by a view.
Definition: ViewColumn.php:9
if(!$owner||!$owner->canEdit()) if(!$owner->hasIcon('master')) if(!$owner->saveIconFromElggFile($owner->getIcon('master'), 'icon', $coords)) $view
Definition: crop.php:30
$title
Definition: user.php:20
Table column rendered by a function.
__call($name, $arguments)
Provide additional methods via hook 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['type']
Definition: save.php:11
class
Definition: placeholder.php:21
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:1292
elgg_ucwords($str)
Wrapper for mb_convert_case($str, MB_CASE_TITLE)
Definition: mb_wrapper.php:206