PrimitiveMultiList.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Anton E. Lebedevich                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: PrimitiveMultiList.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class PrimitiveMultiList extends PrimitiveList
00017     {
00018         private $selected = array();
00019         
00020         public function getChoiceValue()
00021         {
00022             return $this->selected;
00023         }
00024         
00025         public function getActualChoiceValue()
00026         {
00027             if ($this->value !== null)
00028                 return $this->selected;
00029             elseif ($this->default) {
00030                 $out = array();
00031                 
00032                 foreach ($this->default as $index)
00033                     $out[] = $this->list[$index];
00034                 
00035                 return $out;
00036             }
00037             
00038             return array();
00039         }
00040         
00044         public function setDefault($default)
00045         {
00046             Assert::isArray($default);
00047             
00048             foreach ($default as $index)
00049                 Assert::isTrue(array_key_exists($index, $this->list));
00050             
00051             return parent::setDefault($default);
00052         }
00053         
00054         public function import($scope)
00055         {
00056             if (!BasePrimitive::import($scope))
00057                 return null;
00058             
00059             if (!$this->list)
00060                 throw new WrongStateException(
00061                     'list to check is not set; '
00062                     .'use PrimitiveArray in case it is intentional'
00063                 );
00064             
00065             if (is_array($scope[$this->name])) {
00066                 $values = array();
00067                 
00068                 foreach ($scope[$this->name] as $value) {
00069                     if (isset($this->list[$value])) {
00070                         $values[] = $value;
00071                         $this->selected[$value] = $this->list[$value];
00072                     }
00073                 }
00074                 
00075                 if (count($values)) {
00076                     $this->value = $values;
00077                     
00078                     return true;
00079                 }
00080             } elseif (!empty($scope[$this->name])) {
00081                 $this->value = array($scope[$this->name]);
00082                 
00083                 return true;
00084             }
00085             
00086             return false;
00087         }
00088         
00092         public function clean()
00093         {
00094             $this->selected = array();
00095             
00096             return parent::clean();
00097         }
00098     }
00099 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4