Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * @param $multiline boolean
  * @param $values    string[]
  * @return Element
  */
 protected function buildString($multiline = false, $values = null)
 {
     if ($multiline) {
         $input = new Textarea($this->getFieldName(), $this->value);
         $input->addClass('autowidth');
         $input->addClass('autoheight');
     } elseif ($values) {
         if (!isset($values[''])) {
             $values = array_merge(['' => ''], $values);
         }
         $input = new Select($this->getFieldName(), $values, $this->value);
     } else {
         $input = new Input($this->getFieldName(), $this->value);
         $input->setAttribute('autocomplete', 'off');
         $input->addClass('autowidth');
     }
     if ($this->readonly) {
         $input->setAttribute('readonly');
     }
     return $input;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }