/** * @param $object object * @param $property Reflection_Property * @return Standard_Cell */ protected function buildCell($object, Reflection_Property $property) { if (!isset($this->template)) { $this->template = new Html_Template(); } $value = $property->getValue($object); $preprop = $this->preprop ? $this->preprop . '[' . $this->property->name . ']' : $this->property->name; $builder = new Html_Builder_Property($property, $value, $preprop . '[]'); $input = $builder->setTemplate($this->template)->build(); if ($property->name == reset($this->properties)->name && !(new Reflection_Class($this->class_name))->getAnnotation('link')->value) { $property_builder = new Html_Builder_Property(); $property_builder->setTemplate($this->template); $id_input = new Input($preprop . '[id][' . $property_builder->template->nextCounter($preprop . '[id][]') . ']', isset($object->id) ? $object->id : null); $id_input->setAttribute('type', 'hidden'); $input = $id_input . $input; } return new Standard_Cell($input); }
/** * @param $object object * @param $property Reflection_Property * @param $map object[] */ private function writeMap($object, Reflection_Property $property, $map) { // old map $class = new Link_Class(get_class($object)); $composite_property_name = $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null; $old_object = Search_Object::create(Link_Class::linkedClassNameOf($object)); $this->setObjectIdentifier($old_object, $this->getObjectIdentifier($object, $composite_property_name)); $aop_getter_ignore = Getter::$ignore; Getter::$ignore = false; $old_map = $property->getValue($old_object); Getter::$ignore = $aop_getter_ignore; // map properties : write each of them $insert_builder = new Map_Insert($property); $id_set = []; foreach ($map as $element) { $id = $this->getObjectIdentifier($element) ?: $this->getObjectIdentifier($this->write($element)); if (!isset($old_map[$id])) { $query = $insert_builder->buildQuery($object, $element); $this->connection->query($query); } else { $id_set[$id] = true; } } // remove old unused elements $delete_builder = new Map_Delete($property); foreach ($old_map as $old_element) { $id = $this->getObjectIdentifier($old_element); if (!isset($id_set[$id])) { $query = $delete_builder->buildQuery($object, $old_element); $this->connection->query($query); } } }
/** * Format the property value, taken from the input object, depending on it's type * * @param $object object|mixed * @param $final_value boolean * @return string */ public function getFormattedValue($object, $final_value = false) { return $this->formatValue($final_value ? $object : $this->property->getValue($object)); }
/** * Returns an HTML edit widget for current property or List_Data property * * @param $template Template * @param $name string * @param $ignore_user boolean ignore @user annotation, to disable invisible and read-only * @param $can_always_be_null boolean ignore @null annotation and consider this can always be null * @return string */ public function getEdit(Template $template, $name = null, $ignore_user = false, $can_always_be_null = false) { if (isset($name)) { $name = str_replace(DOT, '>', $name); } $object = reset($template->objects); // find the first next object if (!$object instanceof Reflection_Property) { $object = next($template->objects); $property_name = reset($template->var_names); while ($object !== false && !is_object($object)) { $object = next($template->objects); $property_name = next($template->var_names); } } if ($object instanceof Default_List_Data) { $class_name = $object->element_class_name; $property_name = prev($template->var_names); list($property, $property_path, $value) = $this->toEditPropertyExtra($class_name, $property_name); $property_edit = new Html_Builder_Property($property, $value); $property_edit->name = $name ?: $property_path; $property_edit->preprop = null; if ($ignore_user) { $property_edit->readonly = false; } if ($can_always_be_null) { $property_edit->null = true; } return $property_edit->build(); } if ($object instanceof Reflection_Property_Value) { $property_edit = new Html_Builder_Property($object, $object->value()); $property_edit->name = $name ?: $object->path; $property_edit->preprop = null; if ($ignore_user) { $property_edit->readonly = false; } if ($can_always_be_null) { $property_edit->null = true; } return $property_edit->build(); } if ($object instanceof Reflection_Property) { $property_edit = new Html_Builder_Property($object); $property_edit->name = $name ?: $object->path; $property_edit->preprop = null; if ($ignore_user) { $property_edit->readonly = false; } return $property_edit->build(); } if (is_object($object) && isset($property_name) && is_string($property_name)) { $property = new Reflection_Property(get_class($object), $property_name); if (isset($property)) { if ($template->preprops && !$name) { $preprop = isset($preprop) ? $preprop . '[' . reset($template->preprops) . ']' : reset($template->preprops); while ($next = next($template->preprops)) { if (strpos($next, BS) !== false && class_exists($next)) { $next = Names::classToDisplay($next); } else { $next = str_replace(DOT, '>', $next); } $preprop .= '[' . $next . ']'; } $property_edit = new Html_Builder_Property($property, $property->getValue($object), $preprop); } else { $property_edit = new Html_Builder_Property($property, $property->getValue($object)); $property_edit->name = $name ?: $property_name; } if ($ignore_user) { $property_edit->readonly = false; } if ($can_always_be_null) { $property_edit->null = true; } return $property_edit->build(); } } // default html input widget $input = new Input(); $input->setAttribute('name', reset($template->objects)); return $input; }