FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Controller.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi\Fred;
4 
5 class Controller extends Component{
6 
7  const TOTAL_COUNT = 'count';
8  const TOTAL_SUM = 'sum';
9  const TOTAL_AVG = 'avg';
10  const TOTAL_STD = 'std';
11  const TOTAL_MAX = 'max';
12  const TOTAL_MIN = 'min';
13  const TOTAL_UNIQUE = 'unique';
14  const TOTAL_NULL = 'null';
15  const TOTAL_NOT_NULL = 'not_null';
16 
17  public $domainRedir = []; //!< Prefered domain notation (key = domain mask regex, value = prefered domain, incl. protocol).
18  public $domainRedirPermanent = false; //!< True to make a redirection permanent (HTTP status code = 301; defaults to 302).
19  public $defaultWidgetNamespace = __CLASS__ . '\\Widget';
20  public $defaultViewNamespace = __CLASS__ . '\\View';
21  public $defaultViewType = 'html';
22  public $viewClassName = null; //!< Fix the view to a certain View or Controller class (empty = same as called class).
23  public $fragmentId = null;
24 
25  public $display = Controller\Widget::DISPLAY_WRITEABLE; //!< Default display mode for widgets.
26  public $defaultCaption = null; //!< An asterisk will be replaced with widget ID.
27  public $defaultHint = null; //!< An asterisk will be replaced with the widget ID or type.
28  public $helpCaption = 'Help';
29  public $errorStr = '[caption]{[!caption]{[id]}}: [error]';
30 
31  public $inactiveMessage = '[@inactiveMessage]'; //!< Message for inactive user who is redirected to login controller.
32 
33  public $clientErrorPrio = null; //!< Log client errors with this prio (empty = do not log).
34  public $clientErrorBanDelay = 10; //!< Ban delay for the first error in a new session (prevent flooding via multiple
35  // sessions).
36  public $clientErrorMax = 25; //!< Maximum number of client errors to log in one session.
37 
38  protected $_securityChecksIgnore = []; //!< Security checks to ignore (key = action, null = default; value = array with
39  // checks to ignore, true = all).
40  protected $_authSets = []; //!< Possible sets of necessary authentication (array of arrays of authentication checks).
41  protected $_rights = []; //!< Necessary right needed per action (key = action, null = default; value = right, optionally
42  // completed with a minimal level in 'right:level' notation, or only a level relative to the default right in ':level'
43  // notation).
44  protected $_checkWidgets = ['default' => false,'fragment' => false,'pingAlive' => false,'clientError' => false,'featureHint' => false,'requestSocket' => false];
45  //!< Widgets to check per action (key = action; value = array with ID's of widget to check; null = default, otherwise all).
46 
47  protected $_action = null;
48  protected $_widgets = null;
49  protected $_constraints = null;
50  protected $_view = null;
51 
52  protected function init(){
53  parent::init();
54  $this->publish('authSets',self::READWRITE);
55  if($this->action == 'default') $this->domainRedir();
56  }
57 
58  protected function domainRedir(){
59  if($this->domainRedir && !in_array($domain = \Rsi\Http::host(true),$this->domainRedir))
60  foreach($this->domainRedir as $mask => $redir) if(preg_match($mask,$domain)){
61  \Rsi\Http::redirHeader($redir . \Rsi\Record::get($_SERVER,'REQUEST_URI'),$this->domainRedirPermanent);
62  $this->_fred->halt();
63  }
64  }
65 
66  public function clientConfig(){
67  $widgets = $constraints = [];
68  foreach($this->widgets as $id => $widget) $widgets[$id] = array_filter($widget->clientConfig(),function($value){
69  return $value !== null;
70  });
71  foreach($this->constraints as $constraint) $constraints[] = array_filter($constraint);
72  return array_merge(parent::clientConfig(),[
73  'route' => $this->route('*'),
74  'widgets' => $widgets,
75  'checkWidgets' => $this->_checkWidgets,
76  'constraints' => $constraints
77  ]);
78  }
79  /**
80  * Add an authentication check to all sets, or create a new one if none exists.
81  * @param string $name Authentication check name.
82  */
83  protected function addAuth($name){
84  if(!$this->_authSets) $this->_authSets[] = [$name];
85  else foreach($this->_authSets as &$set) if(!in_array($name,$set)) $set[] = $name;
86  unset($set);
87  }
88  /**
89  * Remove an authentication check from all sets.
90  * @param string $name Authentication check name.
91  */
92  protected function removeAuth($name){
93  $sets = [];
94  foreach($this->_authSets as $key => $set) $sets[$key] = array_diff($set,[$name]);
95  $this->_authSets = array_filter($sets);
96  }
97  /**
98  * Add a single widget.
99  * @param string $id Widget ID.
100  * @param Rsi\Fred\Controller\Widget $widget
101  */
102  protected function addWidget($id,$widget){
103  $widget->controller = $this;
104  $this->_widgets[$id] = $widget;
105  }
106  /**
107  * Add multiple widgets.
108  * @param array $widgets Key = ID, value = widget.
109  */
110  protected function addWidgets($widgets){
111  foreach($widgets as $id => $widget) $this->addWidget($id,$widget);
112  }
113  /**
114  * Create a widget by type.
115  * @param string $type Widget type (class name).
116  * @param string $config Configuration.
117  * @return Widget
118  */
119  protected function widgetByType($type,$config){
120  $class_name = (substr($type,0,1) == '\\' ? '' : $this->defaultWidgetNamespace . '\\') . ucfirst($type);
121  return new $class_name($config);
122  }
123  /**
124  * Add a widget by type.
125  * @param string $id Widget ID.
126  * @param string $type Widget type (class name).
127  * @param string $config Configuration.
128  */
129  protected function addByType($id,$type,$config){
130  $this->addWidget($id,$this->widgetByType($type,$config));
131  }
132  /**
133  * Create a widget from a database definition.
134  * @param string $table Name of the table.
135  * @param string $column Column name.
136  * @param array $extra Extra configuration to add to the definition.
137  * @return Widget
138  */
139  protected function widgetFromDef($table,$column,$extra = null){
140  $def = $this->component('def')->column($table,$column,$extra);
141  return $this->widgetByType($def['type'],$def);
142  }
143  /**
144  * Add widgets from a database definition.
145  * @param string $table Name of the table.
146  * @param string|array $columns One or more column names (all table columns when empty).
147  * @param array $extra Extra configuration to add to the definition.
148  * @param string $prefix Prefix to add to the column name for the widget ID.
149  */
150  protected function addFromDef($table,$columns = null,$extra = null,$prefix = null){
151  if(!$columns) $columns = array_keys($this->component('def')->table($table));
152  elseif(!is_array($columns)) $columns = [$columns];
153  foreach($columns as $column) $this->addWidget($prefix . $column,$this->widgetFromDef($table,$column,$extra));
154  }
155  /**
156  * Add widgets from a definition record.
157  * @param Rsi\Fred\Def\Record $record Definition record.
158  * @param string $prefix Prefix to add to the column name for the widget ID.
159  */
160  protected function addFromRecord($record,$prefix = null){
161  foreach($record->columns as $column => $config) $this->addByType($prefix . $column,$config['type'],$config);
162  }
163  /**
164  * Copy data from a definition record to the request.
165  * @param Rsi\Fred\Def\Record $record Definition record.
166  * @param string $prefix Prefix to add to the column name for the widget ID.
167  */
168  protected function dataFromRecord($record,$prefix = null){
169  $request = $this->component('request');
170  foreach($record->columns as $column => $config) $request->data[$prefix . $column] = $record->get($column);
171  }
172  /**
173  * Copy data from the request to a definition record.
174  * @param Rsi\Fred\Def\Record $record Definition record.
175  * @param string $prefix Prefix to add to the column name for the widget ID.
176  */
177  protected function dataToRecord($record,$prefix = null){
178  $request = $this->component('request');
179  foreach($record->columns as $column => $config) $record->set($column,$request->data[$prefix . $column]);
180  }
181  /**
182  * Remove one or more widget(s).
183  * @param string $ids,... Widget ID('s).
184  */
185  protected function deleteWidget(...$ids){
186  $this->getWidgets();
187  foreach($ids as $id) unset($this->_widgets[$id]);
188  }
189  /**
190  * Add a constraint.
191  * @param array $ids Widgets involved (an asterisk will be replaced with the current index during checking, '*--' with the
192  * previous index, '*++' with the next). Widgets that are empty (nothing) are ignored.
193  * @param string $operator Like used with \\Rsi\\Str::operator().
194  * @param string $group Group widget values (use TOTAL_* constants), rather than checking them one-by-one.
195  * @param number $total Grouping reference value. Set to true to make this equal to the number of values.
196  */
197  protected function addConstraint($ids,$operator,$group = null,$total = null){
198  $this->_constraints[] = compact('ids','operator','group','total');
199  }
200  /**
201  * Initialize the widgets.
202  * Called by the widget getter.
203  */
204  protected function initWidgets(){
205  }
206  /**
207  * Reset the controller.
208  * Called when the same controller is used for both the handling of the request ('post') and the view. Use this to perform
209  * actions between those two events.
210  */
211  public function reset(){
212  $this->_action = null;
213  }
214  /**
215  * Note if an action is expected.
216  * @param string $id Widget ID.
217  * @param string $action
218  */
219  public function expect($id,$action){
220  $expected = $this->session->expected ?: [];
221  \Rsi\Record::set($expected,[$id,$action],true);
222  $this->session->expected = $expected;
223  }
224  /**
225  * Was the action expected?
226  * @param string $id Widget ID.
227  * @param string $action
228  * @return bool
229  */
230  public function expected($id,$action){
231  if($result = \Rsi\Record::get($expected = $this->session->expected,[$id,$action = $this->action])){
232  unset($expected[$id][$action]);
233  $this->session->expected = $expected;
234  }
235  return $result;
236  }
237  /**
238  * Parameters for the route to this controller.
239  * @return array
240  */
241  public function routeParams(){
242  return [];
243  }
244  /**
245  * Route to this controller.
246  * @param string $type
247  * @param array $params Extra params.
248  * @return string
249  */
250  public function route($type = null,$params = null){
251  $router = $this->component('router');
252  if(($type === null) && (($type = $router->viewType) == $this->defaultViewType)) $type = null;
253  return $router->reverse($this->name,$type,($params ?: []) + $this->routeParams());
254  }
255  /**
256  * Navigate to another controller.
257  * @param int $levels Number of levels to go up.
258  * @param string $suffix Suffix to add.
259  * @param bool|array $params Parameters for the controller (set to false to only change the view controller name).
260  */
261  public function redir($levels = 1,$suffix = null,$params = null){
262  $request = $this->component('request');
263  $name = \Rsi\File::dirname($this->name,$levels) . $suffix;
264  if($params === false) $request->viewControllerName = $name;
265  else $request->redir = $this->component('router')->reverse($name,null,$params);
266  }
267  /**
268  * Default caption for a widget.
269  * @param string $id Widget ID.
270  * @return string
271  */
272  public function caption($id){
273  return str_replace('*',$id,$this->defaultCaption);
274  }
275  /**
276  * Default hint for a widget.
277  * @param string $id Widget ID or type.
278  * @return string
279  */
280  public function hint($id){
281  return str_replace('*',$id,$this->defaultHint);
282  }
283  /**
284  * Unknwon action called.
285  */
286  protected function unkownAction(){
287  $this->_fred->externalError('Unknown controller action',['class' => get_called_class(),'action' => $this->action]);
288  }
289  /**
290  * Default action (if no action specified).
291  */
292  protected function actionDefault(){
293  }
294  /**
295  * Return a fragment from the view.
296  */
297  protected function actionFragment(){
298  $this->fragmentId = $this->_fred->request->fragmentId;
299  }
300  /**
301  * Ping to keep the session alive.
302  */
303  protected function actionPingAlive(){
304  $alive = $this->component('alive');
305  if($this->component('request')->redir = $alive->ping()){
306  $message = $this->component('message');
307  $local = $this->component('local');
308  $message->warning($this->inactiveMessage,[
309  'maxSessionTime' => $alive->maxSessionTime ? $local->formatNumber($alive->maxSessionTime,1,0) : null,
310  'maxInactiveTime' => $alive->maxInactiveTime ? $local->formatNumber($alive->maxInactiveTime,1,0) : null,
311  'sessionStart' => $local->formatDateTime($alive->session->start),
312  'sessionAlive' => $local->formatDateTime($alive->session->alive)
313  ]);
314  }
315  }
316  /**
317  * Log client-side errors.
318  */
319  protected function actionClientError(){
320  if($this->clientErrorPrio){
321  $security = $this->component('security');
322  $request = $this->component('request');
323  if(
324  (count($errors = $security->session->clientErrors ?: []) < $this->clientErrorMax) &&
325  !in_array($hash = md5($request->message . $request->url . $request->lineNo),$errors)
326  ){
327  $this->component('log')->add(
328  $this->clientErrorPrio,
329  'Client error: ' . $request->message,
330  $request->url,
331  $request->lineNo,
332  array_filter(['column' => $request->column,'trace' => $request->trace,'journal' => $request->journal])
333  );
334  if(!$errors) $security->addBan('clientError',$this->clientErrorBanDelay);
335  $errors[] = $hash;
336  $security->session->clientErrors = $errors;
337  }
338  }
339  }
340  /**
341  * Return a feature hint translation.
342  */
343  protected function actionFeatureHint(){
344  $request = $this->component('request');
345  $request->result = $this->component('hint')->trans($request->id,$request->count);
346  }
347  /**
348  * Request a socket.
349  */
350  protected function actionRequestSocket(){
351  $socket = $this->component('socket');
352  $this->component('request')->result = [
353  'host' => $socket->clientHost,
354  'port' => $socket->clientPort,
355  'prefix' => $socket->clientPrefix,
356  'token' => $socket->token()
357  ];
358  }
359  /**
360  * Add an error to the request.
361  * @param string $id ID of the widget involved.
362  * @param string $error Error type.
363  */
364  protected function addError($id,$error){
365  $this->component('request')->errors[$id] = $this->component('trans')->str($this->errorStr,[
366  'id' => $id,
367  'error' => $error,
368  'caption' => strip_tags($this->widgets[$id]->caption($id))
369  ]);
370  }
371  /**
372  * Calculate the total for an array.
373  * @param array $values Array with values (string or numeric).
374  * @param string $type Type of total (see TOTAL_* constants).
375  * @return mixed Calculated value for array.
376  */
377  public function arrayTotal($values,$type){
378  if($values) switch($type){
379  case self::TOTAL_SUM: return array_sum($values);
380  case self::TOTAL_COUNT: return count($values);
381  case self::TOTAL_AVG: return array_sum($values) / count($values);
382  case self::TOTAL_MAX: return max($values);
383  case self::TOTAL_MIN: return min($values);
384  case self::TOTAL_UNIQUE: return count(array_unique($values));
385  }
386  return null;
387  }
388  /**
389  * Check a constraint.
390  * @param array $widget_ids Widgets in the action.
391  * @param array $ids Widgets involved.
392  * @param string $operator Like used with \\Rsi\\Str::operator().
393  * @param string $group Group widget values (use TOTAL_* constants), rather than checking them one-by-one.
394  * @param number $total Grouping reference value.
395  */
396  protected function checkConstraint($widget_ids,$ids,$operator,$group = null,$total = null){
397  $request = $this->component('request');
398  $indexes = null;
399  $sub_ids = [];
400  foreach($ids as $id){
401  $id = explode(Controller\Widget::CHILD_ID_SEPARATOR,$id);
402  if(
403  in_array($widget_id = array_shift($id),$widget_ids) &&
404  !$this->widgets[$widget_id]->nothing($value = $request->data[$widget_id])
405  ){
406  $sub_ids[] = [$widget_id,$id];
407  if($indexes === null) while($id) switch($sub = array_shift($id)){
408  case '*':
409  $indexes = $value ? array_keys($value) : [];
410  break 2; //exit while
411  default:
412  $value = \Rsi\Record::get($value,$sub);
413  }
414  }
415  }
416  if($indexes === null) $indexes = [null];
417  foreach($indexes as $i => $index){
418  $init = $prev = false;
419  $values = [];
420  foreach($sub_ids as list($widget_id,$id)){
421  $value = $request->data[$widget_id];
422  while($id){
423  switch($sub = array_shift($id)){
424  case '*':
425  $sub = $index;
426  break;
427  case '*--':
428  if(!$i) break 3; //exit sub_ids, next index
429  $sub = $indexes[$i - 1];
430  break;
431  case '*++':
432  if($i + 1 >= count($indexes)) break 3; //exit sub_ids, next index
433  $sub = $indexes[$i + 1];
434  break;
435  }
436  $value = \Rsi\Record::get($value,$sub);
437  if(!is_numeric($sub) && $this->widgets[$widget_id]->widgets[$sub]->nothing($value)) continue 2; //next sub_id
438  }
439  if($group) $values[] = $value;
440  elseif(!$init) $init = true;
441  elseif(!\Rsi\Str::operator($prev,$operator,$value)) $this->addError($widget_id,'constraint');
442  $prev = $value;
443  }
444  if($group && $values && !\Rsi\Str::operator(
445  $this->arrayTotal($values,$group),
446  $operator,
447  $total === true ? count($values) : $total
448  )) foreach($sub_ids as list($widget_id,$id)) $this->addError($widget_id,'group');
449  }
450  }
451  /**
452  * Check widget values.
453  * Widget data is taken from the request data array. Errors are added to the request.
454  * @param array $ids Widgets to check (empty = all).
455  * @return bool True if everything is OK.
456  */
457  protected function checkWidgets($ids = null){
458  $request = $this->component('request');
459  if(!$ids) $ids = array_keys($this->widgets);
460  foreach($ids as $id){
461  $widget = $this->widgets[$id];
462  if($widget->writeable && ($error = $widget->check($request->data[$id] ?? null))) $this->addError($id,$error);
463  }
464  if(!$request->errors) foreach($this->constraints as $constraint)
465  $this->checkConstraint($ids,$constraint['ids'],$constraint['operator'],$constraint['group'],$constraint['total']);
466  return !$request->errors;
467  }
468  /**
469  * Execute the action (if specified) on the controller.
470  * Security checks are executed before. All input and output is handled through the request component. An action can only
471  * trust the values from the data array. If the value is not present, the user is not authorized to modify it. All other
472  * values must be checked.
473  */
474  public function execute(){
475  $request = $this->component('request');
476  if(($id = $request->widgetId) && ($id = explode(Controller\Widget::CHILD_ID_SEPARATOR,$id)) && ($widget_id = array_shift($id))){
477  if(!array_key_exists($widget_id,$this->widgets))
478  $this->_fred->externalError('Unknown widget',['class' => get_called_class(),'id' => $widget_id]);
479  else{
480  $widget = $this->widgets[$widget_id];
481  if(!$widget->readable) $this->_fred->externalError(
482  'User not authorized for widget',
483  ['class' => get_called_class(),'id' => $widget_id,'action' => $this->action]
484  );
485  else $widget->execute($id);
486  }
487  }
488  elseif(!method_exists($this,$method = 'action' . ucfirst($this->action))) $this->unkownAction();
489  else{ //action on this controller
490  if(!$this->component('security')->check($this->securityChecksIgnore))
491  $this->_fred->externalError('Suspicious controller call',['class' => get_called_class()]);
492  $convert = $this->view->convert;
493  if(($widgets = $this->widgets) && ($ids = array_key_exists($this->action,$this->_checkWidgets) && ($this->_checkWidgets[$this->action] !== null)
494  ? $this->_checkWidgets[$this->action]
495  : (array_key_exists(null,$this->_checkWidgets) ? $this->_checkWidgets[null] : array_keys($widgets))
496  )){
497  foreach($ids as $id){
498  $widget = $widgets[$id];
499  if($widget->writeable){
500  $value = $widget->purge($request->complex(['widget',$id]));
501  $value = $convert ? $widget->convert($value) : $widget->clientConvert($value);
502  if($error = $widget->check($value)){
503  $request->data[$id] = null;
504  $this->addError($id,$error);
505  }
506  else $request->data[$id] = $widget->dataConvert($value);
507  }
508  }
509  if(!$request->errors) foreach($this->constraints as $constraint)
510  $this->checkConstraint($ids,$constraint['ids'],$constraint['operator'],$constraint['group'],$constraint['total']);
511  }
512  foreach($widgets as $id => $widget) if(!$ids || !in_array($id,$ids)) $request->data[$id] = $widget->defaultValue;
513  if(!$request->errors) call_user_func([$this,$method]);
514  }
515  }
516  /**
517  * Necessary right for an action.
518  * @param string $action
519  * @return string Necessary right.
520  */
521  public function actionRight($action = null){
522  $right = null;
523  if(array_key_exists($action ?: null,$this->_rights)){
524  $right = $this->_rights[$action];
525  if(substr($right,0,1) == User::RIGHT_LEVEL_SEPARATOR)
526  $right = \Rsi\Str::part($this->_rights[null],User::RIGHT_LEVEL_SEPARATOR) . $right;
527  }
528  elseif(array_key_exists(null,$this->_rights)) $right = $this->_rights[null];
529  return $right;
530  }
531  /**
532  * Available actions for current user.
533  * @param string $prefix Prefix where the action name has to start with.
534  * @return array Array with action names.
535  */
536  public function actions($prefix = null){
537  $actions = [];
538  $prefix = 'action' . ucfirst($prefix);
539  foreach(get_class_methods($this) as $method) if(
540  \Rsi\Str::startsWith($method,$prefix) &&
541  $this->component('user')->authorized($this->actionRight($action = lcfirst(substr($method,6))))
542  ) $actions[] = $action;
543  return $actions;
544  }
545 
546  protected function getAction(){
547  if($this->_action === null) $this->_action = $this->component('request')->action ?: 'default';
548  return $this->_action;
549  }
550 
551  protected function setCheckWidgets($check_widgets){
552  foreach($check_widgets as $action => $ids) $this->_checkWidgets[$action] = $ids ? array_values($ids) : $ids;
553  }
554 
555  protected function getConstraints(){
556  if($this->_constraints === null) $this->getWidgets();
557  return $this->_constraints;
558  }
559 
560  protected function getName(){
561  foreach($this->component('front')->controllerNamespaces + [null => null] as $namespace => $prefix)
562  if(\Rsi\Str::startsWith(get_called_class(),$namespace)) break;
563  return str_replace('\\','/',$prefix . substr(get_called_class(),strlen($namespace) + ($prefix ? 0 : 1)));
564  }
565 
566  protected function getRight(){
567  return $this->actionRight($this->action);
568  }
569 
570  protected function setRights($rights){
571  $this->_rights = array_merge($this->_rights,$rights);
572  }
573 
574  protected function getSecurityChecksIgnore(){
575  if($this->action && array_key_exists($this->action,$this->_securityChecksIgnore)) return $this->_securityChecksIgnore[$this->action];
576  if(array_key_exists(null,$this->_securityChecksIgnore)) return $this->_securityChecksIgnore[null];
577  return null;
578  }
579 
580  protected function setSecurityChecksIgnore($security_checks_ignore){
581  $this->_securityChecksIgnore = array_merge($this->_securityChecksIgnore,$security_checks_ignore);
582  }
583 
584  protected function getView(){
585  if($this->_view === null){
586  $type = $this->component('router')->viewType ?: $this->defaultViewType;
587  if(
588  !class_exists($class_name = str_replace('Controller','View',$this->viewClassName ?: get_called_class()) . '\\' . ucfirst($type)) && //specific view for this type
589  !class_exists($class_name = $this->defaultViewNamespace . '\\' . ucfirst($type)) && //general view for this type
590  !class_exists($class_name = str_replace('Controller','View',$this->viewClassName ?: get_called_class()) . '\\' . ucfirst($type = $this->defaultViewType)) //specific view for default type
591  ) $class_name = $this->defaultViewNamespace . '\\' . ucfirst($type); //default view for default type
592  $this->_view = new $class_name($this->_fred,array_replace_recursive(
593  $this->config('view',[]),
594  $this->config(['view',$type],[]),
595  ['controller' => $this]
596  ));
597  }
598  return $this->_view;
599  }
600 
601  protected function getWidgets(){
602  if($this->_widgets === null){
603  $this->_widgets = $this->_constraints = [];
604  $this->initWidgets();
605  }
606  return $this->_widgets;
607  }
608 
609  protected function setWidgets($value){
610  if($value === false) $this->_widgets = [];
611  else $this->addWidgets($value);
612  }
613 
614  protected function _get($key){
615  return $this->widgets[$key];
616  }
617 
618  protected function _set($key,$value){
619  $this->addWidget($key,$value);
620  }
621 
622 }
Rsi\Fred\Controller\checkWidgets
checkWidgets($ids=null)
Check widget values.
Definition: Controller.php:457
Rsi\Fred\Controller\deleteWidget
deleteWidget(... $ids)
Remove one or more widget(s).
Definition: Controller.php:185
Rsi\Fred\Controller\$_securityChecksIgnore
$_securityChecksIgnore
Security checks to ignore (key = action, null = default; value = array with.
Definition: Controller.php:38
Rsi\Fred\Controller\$_constraints
$_constraints
Definition: Controller.php:49
Rsi\Fred\Controller\setRights
setRights($rights)
Definition: Controller.php:570
Rsi
Rsi\Fred\Controller\actionRight
actionRight($action=null)
Necessary right for an action.
Definition: Controller.php:521
Rsi\Fred\Controller\TOTAL_MIN
const TOTAL_MIN
Definition: Controller.php:12
Rsi\Fred\Controller\$defaultCaption
$defaultCaption
An asterisk will be replaced with widget ID.
Definition: Controller.php:26
Rsi\Fred\Controller\$defaultWidgetNamespace
$defaultWidgetNamespace
Definition: Controller.php:19
Rsi\Fred\Controller\TOTAL_NULL
const TOTAL_NULL
Definition: Controller.php:14
Rsi\Fred\Controller\actionRequestSocket
actionRequestSocket()
Request a socket.
Definition: Controller.php:350
Rsi\Fred\Controller\_get
_get($key)
Default getter if no specific setter is defined, and the property is also not published (readable).
Definition: Controller.php:614
Rsi\Fred\Controller\$defaultHint
$defaultHint
An asterisk will be replaced with the widget ID or type.
Definition: Controller.php:27
Rsi\Fred\Controller\getName
getName()
Definition: Controller.php:560
Rsi\Fred\Controller\addConstraint
addConstraint($ids, $operator,$group=null, $total=null)
Add a constraint.
Definition: Controller.php:197
Rsi\Fred\Controller\$viewClassName
$viewClassName
Fix the view to a certain View or Controller class (empty = same as called class).
Definition: Controller.php:22
Rsi\Fred\Controller\init
init()
Definition: Controller.php:52
Rsi\Fred\Controller\setWidgets
setWidgets($value)
Definition: Controller.php:609
Rsi\Fred\Controller\$fragmentId
$fragmentId
Definition: Controller.php:23
Rsi\Fred\Controller\TOTAL_MAX
const TOTAL_MAX
Definition: Controller.php:11
Rsi\Fred\Controller\$display
$display
Default display mode for widgets.
Definition: Controller.php:25
Rsi\Fred\Controller\getConstraints
getConstraints()
Definition: Controller.php:555
Rsi\Fred\Controller\initWidgets
initWidgets()
Initialize the widgets.
Definition: Controller.php:204
Rsi\Fred\Controller\expected
expected($id, $action)
Was the action expected?
Definition: Controller.php:230
Rsi\Fred\Controller\$domainRedirPermanent
$domainRedirPermanent
True to make a redirection permanent (HTTP status code = 301; defaults to 302).
Definition: Controller.php:18
Rsi\Fred\Controller\dataFromRecord
dataFromRecord($record, $prefix=null)
Copy data from a definition record to the request.
Definition: Controller.php:168
Rsi\Fred\Controller\hint
hint($id)
Default hint for a widget.
Definition: Controller.php:280
Rsi\Fred\Controller\Widget\DISPLAY_WRITEABLE
const DISPLAY_WRITEABLE
Show editable input element(s).
Definition: Widget.php:41
Rsi\Fred\Controller\$clientErrorPrio
$clientErrorPrio
Log client errors with this prio (empty = do not log).
Definition: Controller.php:33
Rsi\Fred\Controller\reset
reset()
Reset the controller.
Definition: Controller.php:211
Rsi\Fred\Controller\actionPingAlive
actionPingAlive()
Ping to keep the session alive.
Definition: Controller.php:303
Rsi\Fred\Controller\TOTAL_AVG
const TOTAL_AVG
Definition: Controller.php:9
Rsi\Fred\Controller\actions
actions($prefix=null)
Available actions for current user.
Definition: Controller.php:536
Rsi\Fred\Controller\setCheckWidgets
setCheckWidgets($check_widgets)
Definition: Controller.php:551
Rsi\Fred\Controller\removeAuth
removeAuth($name)
Remove an authentication check from all sets.
Definition: Controller.php:92
Rsi\Fred\Controller\clientConfig
clientConfig()
Public configuration.
Definition: Controller.php:66
Rsi\Fred\Controller\getRight
getRight()
Definition: Controller.php:566
Rsi\Fred\Controller\TOTAL_SUM
const TOTAL_SUM
Definition: Controller.php:8
Rsi\Fred\Controller\arrayTotal
arrayTotal($values, $type)
Calculate the total for an array.
Definition: Controller.php:377
Rsi\Fred\Controller
Definition: Controller.php:5
Rsi\Fred\Component
Basic component class.
Definition: Component.php:8
Rsi\Fred\Controller\Widget\CHILD_ID_SEPARATOR
const CHILD_ID_SEPARATOR
Definition: Widget.php:9
Rsi\Fred\Controller\actionFragment
actionFragment()
Return a fragment from the view.
Definition: Controller.php:297
Rsi\Fred\Controller\TOTAL_UNIQUE
const TOTAL_UNIQUE
Definition: Controller.php:13
Rsi\Fred\Controller\$clientErrorBanDelay
$clientErrorBanDelay
Ban delay for the first error in a new session (prevent flooding via multiple.
Definition: Controller.php:34
Rsi\Fred\Controller\addWidgets
addWidgets($widgets)
Add multiple widgets.
Definition: Controller.php:110
Rsi\Fred\Controller\addWidget
addWidget($id, $widget)
Add a single widget.
Definition: Controller.php:102
Rsi\Fred\Controller\$domainRedir
$domainRedir
Prefered domain notation (key = domain mask regex, value = prefered domain, incl. protocol).
Definition: Controller.php:17
Rsi\Fred\Controller\getSecurityChecksIgnore
getSecurityChecksIgnore()
Definition: Controller.php:574
Rsi\Fred\Component\component
component($name)
Get a component (local or default).
Definition: Component.php:81
Rsi\Fred\Controller\addAuth
addAuth($name)
Add an authentication check to all sets, or create a new one if none exists.
Definition: Controller.php:83
Rsi\Fred\Controller\dataToRecord
dataToRecord($record, $prefix=null)
Copy data from the request to a definition record.
Definition: Controller.php:177
Rsi\Fred\Controller\route
route($type=null, $params=null)
Route to this controller.
Definition: Controller.php:250
Rsi\Fred\Component\config
config($key, $default=null)
Retrieve a config value.
Definition: Component.php:53
Rsi\Fred\Controller\$_authSets
$_authSets
Possible sets of necessary authentication (array of arrays of authentication checks).
Definition: Controller.php:40
Rsi\Fred\Controller\redir
redir($levels=1, $suffix=null, $params=null)
Navigate to another controller.
Definition: Controller.php:261
Rsi\Fred\Controller\widgetFromDef
widgetFromDef($table, $column, $extra=null)
Create a widget from a database definition.
Definition: Controller.php:139
Rsi\Fred\Controller\addError
addError($id, $error)
Add an error to the request.
Definition: Controller.php:364
Rsi\Fred\Controller\$_rights
$_rights
Necessary right needed per action (key = action, null = default; value = right, optionally.
Definition: Controller.php:41
Rsi\Fred\Controller\execute
execute()
Execute the action (if specified) on the controller.
Definition: Controller.php:474
Rsi\Fred\Controller\setSecurityChecksIgnore
setSecurityChecksIgnore($security_checks_ignore)
Definition: Controller.php:580
Rsi\Fred\Controller\$inactiveMessage
$inactiveMessage
Message for inactive user who is redirected to login controller.
Definition: Controller.php:31
Rsi\Fred\Controller\$helpCaption
$helpCaption
Definition: Controller.php:28
Rsi\Fred\Controller\expect
expect($id, $action)
Note if an action is expected.
Definition: Controller.php:219
Rsi\Fred\Controller\getView
getView()
Definition: Controller.php:584
Rsi\Fred\Controller\TOTAL_COUNT
const TOTAL_COUNT
Definition: Controller.php:7
Rsi\Fred\Controller\caption
caption($id)
Default caption for a widget.
Definition: Controller.php:272
Rsi\Thing\publish
publish($property, $visibility=self::READABLE)
Publish a property (or hide it again).
Definition: Thing.php:28
Rsi\Fred\Controller\addFromRecord
addFromRecord($record, $prefix=null)
Add widgets from a definition record.
Definition: Controller.php:160
Rsi\Fred\Controller\$_view
$_view
Definition: Controller.php:50
Rsi\Fred\Controller\addByType
addByType($id, $type, $config)
Add a widget by type.
Definition: Controller.php:129
Rsi\Fred\Controller\addFromDef
addFromDef($table, $columns=null, $extra=null, $prefix=null)
Add widgets from a database definition.
Definition: Controller.php:150
Rsi\Fred\Controller\$_checkWidgets
$_checkWidgets
Widgets to check per action (key = action; value = array with ID's of widget to check; null = default...
Definition: Controller.php:44
Rsi\Fred\Controller\$_action
$_action
Definition: Controller.php:47
Rsi\Fred\Controller\$errorStr
$errorStr
Definition: Controller.php:29
Rsi\Fred\Controller\routeParams
routeParams()
Parameters for the route to this controller.
Definition: Controller.php:241
Rsi\Fred\Controller\unkownAction
unkownAction()
Unknwon action called.
Definition: Controller.php:286
Rsi\Fred\Controller\checkConstraint
checkConstraint($widget_ids, $ids, $operator,$group=null, $total=null)
Check a constraint.
Definition: Controller.php:396
Rsi\Fred\Controller\domainRedir
domainRedir()
Definition: Controller.php:58
Rsi\Fred\Controller\$_widgets
$_widgets
Definition: Controller.php:48
Rsi\Fred\Controller\getWidgets
getWidgets()
Definition: Controller.php:601
Rsi\Fred\Controller\actionDefault
actionDefault()
Default action (if no action specified).
Definition: Controller.php:292
Rsi\Fred\Controller\$defaultViewType
$defaultViewType
Definition: Controller.php:21
Rsi\Fred\Controller\$defaultViewNamespace
$defaultViewNamespace
Definition: Controller.php:20
Rsi\Fred\Controller\TOTAL_STD
const TOTAL_STD
Definition: Controller.php:10
Rsi\Fred\Controller\actionClientError
actionClientError()
Log client-side errors.
Definition: Controller.php:319
Rsi\Fred\Controller\$clientErrorMax
$clientErrorMax
Maximum number of client errors to log in one session.
Definition: Controller.php:36
Rsi\Fred\Controller\actionFeatureHint
actionFeatureHint()
Return a feature hint translation.
Definition: Controller.php:343
Rsi\Fred\Controller\widgetByType
widgetByType($type, $config)
Create a widget by type.
Definition: Controller.php:119
Rsi\Fred\Controller\_set
_set($key, $value)
Default setter if no specific setter is defined, and the property is also not published (writeable).
Definition: Controller.php:618
Rsi\Fred\Controller\getAction
getAction()
Definition: Controller.php:546
Rsi\Fred\Controller\TOTAL_NOT_NULL
const TOTAL_NOT_NULL
Definition: Controller.php:15
Rsi\Fred\User\RIGHT_LEVEL_SEPARATOR
const RIGHT_LEVEL_SEPARATOR
Separator between right and level in a single string notation.
Definition: User.php:10
Rsi\Fred
Definition: Alive.php:3