5 class Options extends \Rsi\Fred\Controller\Widget{
29 $config = array_merge(parent::clientConfig(),$this->
get([self::ESCAPE,self::MULTI,self::TTL]));
30 if(!$this->trailer && $this->multi && ($this->min || $this->max) && $this->multiTrailer && ($this->display >= self::DISPLAY_WRITEABLE))
31 $config[self::TRAILER] = $this->trans->str($this->multiTrailer,$this->tags);
32 if($this->display < self::DISPLAY_READABLE) $config[self::OPTIONS] = $this->options;
34 if($this->popular || array_key_exists(self::PARAMS,$config)) $config[
'groupDelimiter'] =
$this->groupDelimiter;
39 return $this->
nothing($value) ? null : ($this->multi ? array_values(\
Rsi\Record::explode($value)) : (is_scalar($value) ? $value : null));
42 protected function checkMin($value,$index = null){
43 return $this->multi ? parent::checkMin(count($value),$index) :
true;
46 protected function checkMax($value,$index = null){
47 return $this->multi ? parent::checkMax(count($value),$index) :
true;
51 foreach(\
Rsi\Record::explode($value) as $value)
52 if(!array_key_exists($value,$this->options))
return false;
57 $request = $this->request;
59 foreach(($options = (strcasecmp($request->popular,
'true') ? null : $this->popular) ?: $this->options) as $key => $value) $keys[] = strval($key);
60 $request->result = compact(
'options',
'keys');
64 if($this->_options === null){
65 $this->_options = $options = $this->
config(self::OPTIONS);
68 $cache_key = md5(serialize([is_callable($options) ? [get_class($options[0]),$options[1]] : $options,$this->params]));
69 $this->_options = $this->cache->fetch($cache_key);
71 if(!$this->ttl || ($this->_options ===
false)){
72 if(is_callable($options)) $this->_options = call_user_func($options,$this->params);
73 elseif(is_string($options)) $this->_options = $this->db->isSelection($options)
74 ? $this->db->record($options,$this->params)
75 : \Rsi\Record::explode($this->trans->str($options),
"\n",
'=');
76 if($cache_key) $this->cache->save($cache_key,$this->_options,$this->ttl);
83 $this->_options = null;
84 $this->_config[self::OPTIONS] = $value;
89 if($popular = $this->
config(self::POPULAR)){
90 if(is_callable($popular)) $popular = call_user_func($popular,$this->params);
92 ($options = \
Rsi\Record::select($this->options,$popular)) &&
93 ($extra = ($count = count($this->options)) - count($options))
94 ) $options[
$this->popularExtraKey] = $this->trans->str($this->popularExtraCaption,compact(
'count',
'extra'));