00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class PrimitiveIdentifierList extends PrimitiveIdentifier
00017 {
00018 protected $value = array();
00019
00020 public function importValue($value)
00021 {
00022 if ($value instanceof UnifiedContainer) {
00023 if ($value->isLazy())
00024 return $this->import(
00025 array($this->name => $value->getList())
00026 );
00027 elseif (
00028 $value->getParentObject()->getId()
00029 && ($list = $value->getList())
00030 ) {
00031 return $this->import(
00032 array($this->name => ArrayUtils::getIdsArray($list))
00033 );
00034 } else {
00035 return parent::importValue(null);
00036 }
00037 }
00038
00039 if (is_array($value)) {
00040 try {
00041 Assert::isInteger(current($value));
00042
00043 return $this->import(
00044 array($this->name => $value)
00045 );
00046 } catch (WrongArgumentException $e) {
00047 return $this->import(
00048 array($this->name => ArrayUtils::getIdsArray($value))
00049 );
00050 }
00051 }
00052
00053 return parent::importValue($value);
00054 }
00055
00056 public function import($scope)
00057 {
00058 if (!$this->className)
00059 throw new WrongStateException(
00060 "no class defined for PrimitiveIdentifierList '{$this->name}'"
00061 );
00062
00063 if (!BasePrimitive::import($scope))
00064 return null;
00065
00066 if (!is_array($scope[$this->name]))
00067 return false;
00068
00069 $list = array_unique($scope[$this->name]);
00070
00071 $values = array();
00072
00073 foreach ($list as $id) {
00074 if (!Assert::checkInteger($id))
00075 return false;
00076
00077 $values[] = $id;
00078 }
00079
00080 $objectList = $this->dao()->getListByIds($values);
00081
00082 if (count($objectList) == count($values)) {
00083 $this->value = $objectList;
00084 return true;
00085 }
00086
00087 return false;
00088 }
00089 }
00090 ?>