.

DBFieldSet Class Reference
[Model]

A SET datatype as supported by MySQL. More...

Inheritance diagram for DBFieldSet:
DBFieldEnum DBField IDBField IPolicyHolder

List of all members.

Public Member Functions

  convert_result ($value)
  Transform result from SELECT to native.
  format_select ()
  Allow replacements for field in select from clause.
  validate ($value)
  Returns true, if the value passed fits the fields restrictions.

Static Public Member Functions

static  set_clear_value (&$set, $value)
  Clear value on given set.
static  set_has_value ($set, $value)
  Returns wether value is in given set or not.
static  set_set_value (&$set, $value)
  Set value on given set.

Protected Member Functions

  do_format_not_null ($value)
  Format values that are not NULL.

Detailed Description

A SET datatype as supported by MySQL.

Actually a couple of bit flags

The SET datatype is an array that is saved into DB as integer

Author:
Gerd Riesselmann

Definition at line 12 of file dbfield.set.cls.php.


Member Function Documentation

DBFieldSet::convert_result ( value  ) 

Transform result from SELECT to native.

Parameters:
mixed  $value
Returns:
mixed

Reimplemented from DBField.

Definition at line 62 of file dbfield.set.cls.php.

00062                                                {
00063                 $ret = array();
00064                 $cnt = count($this->allowed);
00065                 for ($i = 0; $i < $cnt; $i++) {
00066                         $test = pow(2, $i);
00067                         if ($value & $test) {
00068                                 $ret[] = $this->allowed[$i];
00069                         }
00070                 }
00071                 return $ret;
00072         }
DBFieldSet::do_format_not_null ( value  )  [protected]

Format values that are not NULL.

Parameters:
mixed  $value
Returns:
string

Reimplemented from DBField.

Definition at line 36 of file dbfield.set.cls.php.

00036                                                       {
00037                 $value = Arr::force($value);
00038                 $ret = 0;
00039                 $cnt = count($this->allowed);
00040                 for ($i = 0; $i < $cnt; $i++) {
00041                         $test = $this->allowed[$i];
00042                         if (in_array($test, $value)) {
00043                                 $ret = $ret | pow(2, $i);
00044                         }
00045                 }
00046                 return $ret;            
00047         }
DBFieldSet::format_select (  ) 

Allow replacements for field in select from clause.

Reimplemented from DBField.

Definition at line 52 of file dbfield.set.cls.php.

00052                                         {
00053                 return $this->get_field_name() . '+0';
00054         }       
static DBFieldSet::set_clear_value ( &$  set,
value  
) [static]

Clear value on given set.

Parameters:
array  $set The set to modify
string  $value The value to set

Definition at line 97 of file dbfield.set.cls.php.

00097                                                               {
00098                 $new_set = array();
00099                 self::set_force_array($set);
00100                 foreach($set as $v) {
00101                         if ($v !== $value) {
00102                                 $new_set[] = $v;
00103                         }
00104                 } 
00105                 $set = $new_set;
00106         }
static DBFieldSet::set_has_value ( set,
value  
) [static]

Returns wether value is in given set or not.

Parameters:
array  $set The set to modify
string  $value The value to set
Returns:
bool

Definition at line 115 of file dbfield.set.cls.php.

00115                                                            {
00116                 $ret = false;
00117                 if (!is_null($set) && !$set instanceof DBNull) {
00118                         $ret = in_array($value, $set);
00119                 }
00120                 return $ret;
00121         }
static DBFieldSet::set_set_value ( &$  set,
value  
) [static]

Set value on given set.

Parameters:
array  $set The set to modify
string  $value The value to set

Definition at line 84 of file dbfield.set.cls.php.

00084                                                             {
00085                 if (!self::set_has_value($set, $value)) {
00086                         self::set_force_array($set);
00087                         $set[] = $value;
00088                 }
00089         }
DBFieldSet::validate ( value  ) 

Returns true, if the value passed fits the fields restrictions.

Parameters:
mixed  $value
Returns:
Status

Reimplemented from DBFieldEnum.

Definition at line 19 of file dbfield.set.cls.php.

00019                                          {
00020                 $ret = new Status();
00021                 $arr_value = Arr::force($value, false);
00022                 foreach($arr_value as $val) {
00023 //                      if ($val !== '') {
00024                                 $ret->merge(parent::validate($val));
00025 //                      }
00026                 }
00027                 return $ret;
00028         }

The documentation for this class was generated from the following file: