FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Lookup.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Lookup extends Table{
6 
7  const CREATOR = 'creator'; //!< Callback function to create a new record (called with value and this widget; returns the new
8  // key).
9  const OPTIONS = 'options'; //!< Options shortlist. If it is not an assoc.array, the codes from the provider will be used.
10 
11  public $creator = null;
12  public $options = null;
13 
14  protected $_checkOnly = false; //!< Set to true to prevent a creator from executing.
15 
16  protected $_downloadFormats = false;
17 
18  public function clientConfig(){
19  $config = parent::clientConfig();
20  if($this->creator) $config[self::CREATOR] = true;
21  return $config;
22  }
23 
24  protected function purgeCreator($value){
25  if(!$this->nothing($value) && $this->creator && !$this->_checkOnly && !$this->provider->exists($this->code,$value,$this->params))
26  $value = call_user_func($this->creator,$value,$this);
27  return $value;
28  }
29 
30  protected function checkRange($value,$index = null){
31  return $this->creator ? true : parent::checkRange($value,$index);
32  }
33 
34  protected function actionExists(){
35  $this->_checkOnly = true;
36  $value = $this->convert($this->purge($this->request->value));
37  $this->request->result = ['exists' => $exists = $this->checkRange($value,$this->request->index)];
38  if($exists && $this->descr) $this->request->result['descr'] = $this->provider->trans($this->descr,$this->key,$value,$this->params);
39  }
40 
41 }
const CREATOR
Callback function to create a new record (called with value and this widget; returns the new...
Definition: Lookup.php:7
checkRange($value, $index=null)
Definition: Lookup.php:30
nothing($value)
Check if a value is empty.
Definition: Widget.php:240
const OPTIONS
Options shortlist. If it is not an assoc.array, the codes from the provider will be used...
Definition: Lookup.php:9
purge($value)
Purge a value.
Definition: Widget.php:196
$_checkOnly
Set to true to prevent a creator from executing.
Definition: Lookup.php:14