Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class PrimitiveFormsList extends PrimitiveForm
00016 {
00017 protected $value = array();
00018
00022 public function clean()
00023 {
00024 parent::clean();
00025
00026 $this->value = array();
00027
00028 return $this;
00029 }
00030
00031 public function setComposite($composite = true)
00032 {
00033 throw new UnsupportedMethodException(
00034 'composition is not supported for lists'
00035 );
00036 }
00037
00038 public function getInnerErrors()
00039 {
00040 $result = array();
00041
00042 foreach ($this->getValue() as $id => $form) {
00043 if ($errors = $form->getInnerErrors())
00044 $result[$id] = $errors;
00045 }
00046
00047 return $result;
00048 }
00049
00050 public function import($scope)
00051 {
00052 if (!$this->proto)
00053 throw new WrongStateException(
00054 "no proto defined for PrimitiveFormsList '{$this->name}'"
00055 );
00056
00057 if (!BasePrimitive::import($scope))
00058 return null;
00059
00060 if (!is_array($scope[$this->name]))
00061 return false;
00062
00063 $error = false;
00064
00065 $this->value = array();
00066
00067 foreach ($scope[$this->name] as $id => $value) {
00068 $this->value[$id] =
00069 $this->proto->makeForm()->
00070 import($value);
00071
00072 if ($this->value[$id]->getErrors())
00073 $error = true;
00074 }
00075
00076 return !$error;
00077 }
00078
00079 public function importValue($value)
00080 {
00081 if ($value !== null)
00082 Assert::isArray($value);
00083 else
00084 return null;
00085
00086 $result = true;
00087
00088 $resultValue = array();
00089
00090 foreach ($value as $id => $form) {
00091 Assert::isInstance($form, 'Form');
00092
00093 $resultValue[$id] = $form;
00094
00095 if ($form->getErrors())
00096 $result = false;
00097 }
00098
00099 $this->value = $resultValue;
00100
00101 return $result;
00102 }
00103
00104 public function exportValue()
00105 {
00106 if (!$this->isImported())
00107 return null;
00108
00109 $result = array();
00110
00111 foreach ($this->value as $id => $form) {
00112 $result[$id] = $form->export();
00113 }
00114
00115 return $result;
00116 }
00117 }
00118 ?>