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($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));
43 return $this->multi ? parent::checkMin(count($value)) :
true;
47 return $this->multi ? parent::checkMax(count($value)) :
true;
51 foreach(\
Rsi\Record::explode($value) as $value)
if(!array_key_exists($value,$this->options))
return false;
56 $request = $this->request;
57 $options = (($popular = $request->popular) && !strcasecmp($popular,
'true') ? $this->popular :
null) ?: $this->options;
59 foreach($options as $key => $value) $keys[] = strval($key);
60 $request->result = compact(
'options',
'keys');
64 if(!array_key_exists($options_key = serialize($params = $this->params),$this->_options)){
65 $this->_options[$options_key] = $options = $this->
config(self::OPTIONS);
68 $cache_key = md5(serialize([is_callable($options) ? [get_class($options[0]),$options[1]] : $options,$params]));
69 $this->_options[$options_key] = $this->cache->fetch($cache_key);
71 if(!$this->ttl || ($this->_options[$options_key] ===
false)){
72 if(is_callable($options)) $this->_options[$options_key] = call_user_func($options,$params);
73 elseif(is_string($options)) $this->_options[$options_key] = $this->db->isSelection($options)
74 ? $this->db->record($options,$params)
75 : \Rsi\Record::explode($this->trans->str($options),
"\n",
'=');
76 if($cache_key) $this->cache->save($cache_key,$this->_options[$options_key],$this->ttl);
79 return $this->_options[$options_key];
89 if($popular = $this->
config(self::POPULAR)){
90 if(is_callable($popular)) $popular = call_user_func($popular,$this->params);
92 ($options = \
Rsi\Record::select($all = $this->options,$popular)) &&
93 ($extra = ($count = count($all)) - count($options))
94 ) $options[
$this->popularExtraKey] = $this->trans->str($this->popularExtraCaption,compact(
'count',
'extra'));