Bouncy Melons 0.1
declarative style orm
SetField.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm;
4 
5 
14 class SetField extends Field {
15 
16  const DEFAULT_SQL_TYPE = "tinyint";
17 
18  public function __construct($name, $title = null, $options = array(), $sqlType = null) {
19  if(empty($options['set'])) {
20  throw new ERequiredFieldOptionNotSet("\bm\SetField fields option 'set' is empty, check docs for more info");
21  }
22  if(!is_array($options['set'])) {
23  throw new ERequireFieldOptionWrong("\bm\SetField field option 'set' should be one-dimentional assosiative array, check docs for more info" );
24  }
25  parent::__construct($name, $title, $options, $sqlType);
26  }
27 
28 
29  public function beforeGet($value, ISingle $single) {
30  $val = parent::beforeGet($value, $single);
31  $set = $this->getOption('set');
32  if(!empty($set[$val])){
33  return $set[$val];
34  }
35  return $val;
36  }
37 }
beforeGet($value, ISingle $single)
Definition: SetField.php:29
__construct($name, $title=null, $options=array(), $sqlType=null)
Definition: SetField.php:18