gyro/core/model/base/fields/dbfield.bool.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A boolean field im DB 00004 * 00005 * A Boolean field is an Enum with Values 'TRUE' and 'FALSE'. 00006 * 00007 * @author Gerd Riesselmann 00008 * @ingroup Model 00009 */ 00010 class DBFieldBool extends DBField { 00011 /** 00012 * Constructor 00013 * 00014 * @param string $name field name 00015 * @param bool $default_value Default Value 00016 * @param int $policy 00017 * @return void 00018 */ 00019 public function __construct($name, $default_value = false, $policy = self::NONE) { 00020 parent::__construct($name, $default_value, $policy); 00021 } 00022 00023 /** 00024 * Format values that are not NULL 00025 * 00026 * @param mixed $value 00027 * @return string 00028 */ 00029 protected function do_format_not_null($value) { 00030 if ($value) { 00031 return $this->quote('TRUE'); 00032 } else { 00033 return $this->quote('FALSE'); 00034 } 00035 } 00036 00037 /** 00038 * Allow replacements for field in select from clause 00039 */ 00040 public function format_select() { 00041 return '(' . parent::format_select() . " = 'TRUE')"; 00042 } 00043 00044 /** 00045 * Transform result from SELECT to native 00046 * 00047 * @param mixed $value 00048 * @return mixed 00049 */ 00050 public function convert_result($value) { 00051 if (is_string($value)) { 00052 return in_array(strtoupper($value), array('TRUE', '1')); 00053 } 00054 return !empty($value); 00055 } 00056 00057 /** 00058 * Reads value from array (e.g $_POST) and converts it into something meaningfull 00059 */ 00060 public function read_from_array($arr) { 00061 $ret = Arr::get_item($arr, $this->get_field_name(), null); 00062 if (!$this->is_null($ret)) { 00063 $ret = !empty($ret); 00064 } 00065 return $ret; 00066 } 00067 }