gyro/core/model/base/fields/dbfield.serialized.cls.php
Go to the documentation of this file.00001 <?php 00002 require_once dirname(__FILE__) . '/dbfield.text.cls.php'; 00003 00004 /** 00005 * A field to serialize content, can be anything, e.g. an array 00006 * 00007 * @author Gerd Riesselmann 00008 * @ingroup Model 00009 */ 00010 class DBFieldSerialized extends DBFieldText { 00011 public function __construct($name, $length = DBFieldText::BLOB_LENGTH_SMALL, $default_value = null, $policy = self::NONE) { 00012 /* @TODO Should default value be serialized here? */ 00013 parent::__construct($name, $length, serialize($default_value), $policy); 00014 } 00015 00016 /** 00017 * Returns true, if the value passed fits the fields restrictions 00018 * 00019 * @param mixed $value 00020 * @return Status 00021 */ 00022 public function validate($value) { 00023 return parent::validate(serialize($value)); 00024 } 00025 00026 /** 00027 * Format values that are not NULL 00028 * 00029 * @param mixed $value 00030 * @return string 00031 */ 00032 protected function do_format_not_null($value) { 00033 return parent::do_format_not_null(serialize($value)); 00034 } 00035 00036 /** 00037 * Transform result from SELECT to native 00038 * 00039 * @param mixed $value 00040 * @return mixed 00041 */ 00042 public function convert_result($value) { 00043 return is_null($value) ? null : unserialize($value); 00044 } 00045 00046 /** 00047 * Returns the default value for this field 00048 * 00049 * @return mixed 00050 */ 00051 public function get_field_default() { 00052 $ret = parent::get_field_default(); 00053 if ($ret) { 00054 $ret = unserialize($ret); 00055 } 00056 return $ret; 00057 } 00058 }