gyro/core/model/base/fields/dbfield.enum.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * An enum field 00004 * 00005 * @author Gerd Riesselmann 00006 * @ingroup Model 00007 */ 00008 class DBFieldEnum extends DBField { 00009 /** 00010 * Allowed values 00011 * 00012 * @var array 00013 */ 00014 protected $allowed; 00015 00016 public function __construct($name, $allowed = array(), $default_value = null, $policy = self::NONE) { 00017 parent::__construct($name, $default_value, $policy); 00018 $this->allowed = Arr::force($allowed); 00019 } 00020 00021 /** 00022 * Returns true, if the value passed fits the fields restrictions 00023 * 00024 * @param string $value 00025 * @return Status 00026 */ 00027 public function validate($value) { 00028 $ret = parent::validate($value); 00029 if ($ret->is_ok() && !is_null($value)) { 00030 if (!in_array($value, $this->allowed)) { 00031 $ret->append(tr( 00032 'Value %val not allowed on %field', 00033 'core', 00034 array( 00035 '%field' => $this->get_field_name_translation(), 00036 '%val' => $value 00037 ) 00038 )); 00039 } 00040 } 00041 return $ret; 00042 } 00043 }