65 $this->_config = $config ?: [];
71 $this->
configure($this->_config = array_merge(
72 $this->_controller->config([
'widget',lcfirst(\
Rsi\File::basename(get_called_class()))],[]),
75 $this->
publish([
'controller',
'securityChecksIgnore']);
76 $this->
publish(
'parent',self::READWRITE);
84 $this->_config = array_merge($this->_config,$config);
93 protected function config($key,$default = null){
94 return \Rsi\Record::get($this->_config,$key,$default);
101 $config = array_merge(
102 [self::CLASS_NAME => get_called_class()],
103 $this->
get([self::DEFAULT_VALUE,self::DISPLAY,self::MIN,self::MAX,self::REQUIRED])
105 if($params = $this->
config(self::PARAMS)){
106 foreach($params as $key => $value)
if(substr($key,0,1) !=
'@') unset($params[$key]);
107 if($params) $config[self::PARAMS] = array_values($params);
109 if($this->validFunc) $config[self::VALID_FUNC] = is_array($this->validFunc)
110 ? (is_object($this->validFunc[0]) ? get_class($this->validFunc[0]) : $this->validFunc[0]) .
'::' . $this->validFunc[1]
112 if($this->trailer) $config[self::TRAILER] = $this->trans->str($this->trailer,$this->tags);
113 if($this->help) $config[self::HELP] =
true;
114 if($this->widgetHelp) $config[self::WIDGET_HELP] =
true;
117 foreach($this->widgets as $id => $widget) $widgets[$id] = array_filter($widget->clientConfig());
118 $config[self::WIDGETS] = $widgets;
124 $caption = $this->
config(self::CAPTION);
125 return $this->trans->str($caption === null ? $this->_controller->caption($id ?: $this->id) : $caption);
128 public function hint($id = null){
129 $hint = $this->
config(self::HINT);
130 return $hint === null
131 ? $this->trans->str($this->_controller->hint($id ?: $this->id),$this->tags) ?:
132 $this->trans->str($this->_controller->hint(\
Rsi\File::basename(get_called_class())),$this->tags)
133 : $this->trans->str($hint,$this->tags);
181 return $this->
format($value);
198 foreach(get_class_methods($this) as $method)
199 if((strlen($method) > 5) && (substr($method,0,5) ==
'purge') && ($method !=
'purgeBase')) $value = call_user_func([$this,$method],$value);
207 $this->_controller->expect($this->
id,$action);
216 $this->fred->externalError(
'Unknown child widget',[
'class' => get_called_class(),
'id' => $id]);
225 if(!$this->security->check($this->securityChecksIgnore,$this->_controller->expected($this->id,$action = $this->_controller->action)))
226 $this->fred->externalError(
'Suspicious widget action call',[
'class' => get_called_class()]);
227 elseif(count($id = explode(self::CHILD_ID_SEPARATOR,$this->request->widgetId)) > 1) $this->
executeChild($id);
228 elseif(!method_exists($this,$method =
'action' . ucfirst($action)))
229 $this->fred->externalError(
'Unknown widget action',[
'class' => get_called_class(),
'action' => $action]);
231 call_user_func([$this,$method]);
232 $this->
event->trigger(self::EVENT_ACTION_PREFIX . lcfirst(\
Rsi\File::basename(get_called_class())) .
':' . $action,$this,array_pop($id));
241 return \Rsi::nothing($value);
261 if($this->required === self::VALID_FUNC)
return $this->
checkValidFunc($value,$index);
262 if(is_array(
$required = $this->required)){
263 $id = explode(self::CHILD_ID_SEPARATOR,str_replace(
'*',$index,array_shift(
$required)));
264 $widget = $this->_controller->widgets[$widget_id = array_shift($id)];
265 $ref = $widget->purge($this->request->complex([
'widget',$widget_id]));
266 $ref = $this->_controller->view->convert ? $widget->convert($ref) : $widget->clientConvert($ref);
273 return $this->validFunc ? call_user_func($this->validFunc,$value,$index) :
true;
281 public function check($value,$index = null){
283 foreach(get_class_methods($this) as $method)
284 if(($method !=
'checkRequired') && (strlen($method) > 5) && (substr($method,0,5) ==
'check') && !call_user_func([$this,$method],$value,$index))
285 return lcfirst(substr($method,5));
291 switch($this->request->type){
292 case 'widget': $type = self::WIDGET_HELP;
break;
294 $this->request->result = [
295 'caption' => $this->trans->str($this->_controller->helpCaption,$this->tags),
296 'help' => $this->trans->str(($this->widgets[$this->request->id] ?? $this)->$type,$this->tags)
301 $this->_controller = $value;
306 if($this->_display === null){
309 $this->_display = $this->
config(self::DISPLAY,$this->_controller->display);
310 if(($this->_display > self::DISPLAY_READABLE) && !$this->user->authorized($this->right,
User::RIGHT_LEVEL_WRITE))
311 $this->_display = self::DISPLAY_READABLE;
312 if($this->parent) $this->_display = min($this->_display,$this->parent->display);
319 return $this->_controller->fred;
323 if($this->_id === null){
326 foreach($this->parent->widgets as $id => $widget)
if($this === $widget){
327 $this->_id = $this->parent->id . self::CHILD_ID_SEPARATOR . $id;
331 elseif($this->_controller)
foreach($this->_controller->widgets as $id => $widget)
if($this === $widget){
340 if($this->_params === null){
342 if($params = $this->
config(self::PARAMS))
foreach($params as $key => $value){
343 if(substr($key,0,1) ==
'@'){
344 $key = substr($key,1);
345 if(array_key_exists($value,$this->request->data)) $value = $this->request->data[$value];
347 $widget = $this->_controller->widgets[$value];
348 $value = $widget->clientConvert($this->request->complex([
'widget',$value]));
349 if($widget->check($value)) $value =
false;
352 $this->_params[$key] = $value;
359 return $this->display >= self::DISPLAY_READABLE;
363 if($right = $this->
config(self::RIGHT))
return $right;
364 if($right !==
false)
return $this->_controller->right;
369 if($this->_tags === null){
370 $this->_tags = $this->
config(self::TAGS,[]);
371 if($this->_config)
foreach($this->_config as $key => $value)
372 $this->_tags[$key] = is_array($value) || is_object($value) ? (bool)$value : $value;
373 if(!$this->
nothing($this->min)) $this->_tags[self::MIN] = $this->
formatTag($this->min);
374 if(!$this->
nothing($this->max)) $this->_tags[self::MAX] = $this->
formatTag($this->max);
380 if($this->_widgets === null){
381 $this->_widgets = $this->
config(self::WIDGETS,[]);
382 foreach($this->_widgets as $widget){
383 $widget->parent = $this;
395 return array_key_exists($key,$this->_config) ? $this->_config[$key] : $this->_controller->component($key);
configure($config)
Configure the object.
publish($property, $visibility=self::READABLE)
Publish a property (or hide it again).