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)];
38  if($exists && $this->descr) $this->request->result['descr'] = $this->provider->trans($this->descr,$this->key,$value,$this->params);
39  }
40 
41 }
Rsi\Fred\Controller\Widget\Lookup\$creator
$creator
Definition: Lookup.php:11
Rsi\Fred\Controller\Widget\Lookup\actionExists
actionExists()
Definition: Lookup.php:34
Rsi\Fred\Controller\Widget\Table
Definition: Table.php:8
Rsi\Fred\Controller\Widget\Table\convert
convert($value)
Convert a value from user format to standard, internal format.
Definition: Table.php:108
Rsi\Fred\Controller\Widget\nothing
nothing($value)
Check if a value is empty.
Definition: Widget.php:274
Rsi\Fred\Controller\Widget\Lookup\CREATOR
const CREATOR
Callback function to create a new record (called with value and this widget; returns the new.
Definition: Lookup.php:7
Rsi\Fred\Controller\Widget\Lookup\$_downloadFormats
$_downloadFormats
Definition: Lookup.php:16
Rsi\Fred\Controller\Widget\Lookup\checkRange
checkRange($value, $index=null)
Definition: Lookup.php:30
Rsi\Fred\Controller\Widget\Lookup\$options
$options
Definition: Lookup.php:12
Rsi\Fred\Controller\Widget\Lookup\clientConfig
clientConfig()
Public configuration.
Definition: Lookup.php:18
Rsi\Fred\Controller\Widget\Lookup\$_checkOnly
$_checkOnly
Set to true to prevent a creator from executing.
Definition: Lookup.php:14
Rsi\Fred\Controller\Widget\Lookup\OPTIONS
const OPTIONS
Options shortlist. If it is not an assoc.array, the codes from the provider will be used.
Definition: Lookup.php:9
Rsi\Fred\Controller\Widget\Lookup\purgeCreator
purgeCreator($value)
Definition: Lookup.php:24
Rsi\Fred\Controller\Widget\purge
purge($value)
Purge a value.
Definition: Widget.php:217
Rsi\Fred\Controller\Widget
Definition: Char.php:3
Rsi\Fred\Controller\Widget\Lookup
Definition: Lookup.php:5