Esempio n. 1
0
 /**
  * @param $property Reflection_Property
  * @param $value    boolean|integer|float|string|array
  */
 public function beforeObjectBuilderArrayBuildBasicValue(Reflection_Property $property, &$value)
 {
     if (isset($value)) {
         if (is_array($value) && !empty($value)) {
             if ($property->getAnnotation('link')->value == Link_Annotation::COLLECTION) {
                 $class = new Reflection_Class($property->getType()->getElementTypeAsString());
                 $properties = $class->accessProperties();
                 reset($value);
                 if (!is_numeric(key($value))) {
                     $value = arrayFormRevert($value);
                 }
                 foreach ($value as $key => $element) {
                     foreach ($element as $property_name => $property_value) {
                         if (isset($property_value) && isset($properties[$property_name])) {
                             $value[$key][$property_name] = self::propertyToIso($properties[$property_name], $property_value);
                         }
                     }
                 }
             }
         } else {
             $value = self::propertyToIso($property, $value);
         }
     }
 }
Esempio n. 2
0
 /**
  * Accepted arrays :
  * $array[$object_number][$property_name] = $value
  * $array[$property_name][$object_number] = $value
  * $array[0][$column_number] = 'property_name' then $array[$object_number][$column_number] = $value
  *
  * @param $class_name    string
  * @param $array         array
  * @param $null_if_empty boolean
  * @param $parent        object the parent object, if linked
  * @return object[]
  */
 public function buildCollection($class_name, $array, $null_if_empty = false, $parent = null)
 {
     $collection = [];
     if ($array) {
         $builder = new Object_Builder_Array($class_name, $this->from_form);
         /** @var $link Class_\Link_Annotation */
         $link = $builder->class->getAnnotation('link');
         if ($link->value && isset($parent->id)) {
             $composite_properties = call_user_func([$builder->class->name, 'getCompositeProperties'], $this->class->name);
             $id_property_name = 'id_' . reset($composite_properties);
         } else {
             $id_property_name = null;
         }
         // replace $array[$property_name][$object_number] with $array[$object_number][$property_name]
         reset($array);
         if ($this->from_form && !is_numeric(key($array))) {
             $array = arrayFormRevert($array);
         }
         // check if the first row contains column names
         $first_row = reset($array);
         reset($first_row);
         if ($combine = is_numeric(key($first_row))) {
             unset($array[key($array)]);
         }
         foreach ($array as $key => $element) {
             if ($combine) {
                 $element = array_combine($first_row, $element);
             }
             if ($id_property_name && !isset($element[$id_property_name])) {
                 $element[$id_property_name] = $parent->id;
             }
             $object = $builder->build($element, null, $this->null_if_empty_sub_objects || $null_if_empty, $id_property_name);
             if (isset($object)) {
                 $collection[$key] = $object;
             }
         }
     }
     return $collection;
 }