Elgg  Version 2.3
ColumnFactory.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Views\TableColumn;
3 
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_trigger_plugin_hook('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:133
$view
Definition: crop.php:34
fromView($name, $heading=null, $vars=[])
Make a column from one of the page/components/column/* views.
if(!$items) $item
Definition: delete.php:17
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
fromProperty($name, $heading=null)
Make a column by reading a property of the item.
$column
Definition: add.php:13
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
$vars['entity']
$title
Definition: save.php:22
Table column rendered by a view.
Definition: ViewColumn.php:9
Table column rendered by a function.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:826
__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.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
Factory for table column objects.
class
Definition: placeholder.php:21
A renderer for a column of table cells and a header.
Definition: TableColumn.php:7
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5
elgg_ucwords($str)
Wrapper for mb_convert_case($str, MB_CASE_TITLE)
Definition: mb_wrapper.php:206