Beispiel #1
0
 /**
  * @param $class_name                 string
  * @param $property_path              string[]
  * @param $object_not_found_behaviour string create_new_value, do_nothing, tell_it_and_stop_import
  */
 public function __construct($class_name = null, $property_path = null, $object_not_found_behaviour = null)
 {
     if (isset($class_name)) {
         $this->class_name = $class_name;
         $this->name = Names::classToDisplay($class_name);
     }
     if (isset($object_not_found_behaviour)) {
         $this->object_not_found_behaviour = $object_not_found_behaviour;
     }
     if (isset($property_path)) {
         $this->property_path = $property_path;
     }
 }
 /**
  * @param $list_settings Data_List_Settings
  * @return string
  */
 public function getSearchSummary(Data_List_Settings $list_settings)
 {
     if ($list_settings->search) {
         if (Locale::current()) {
             $t = '|';
             $i = '¦';
         } else {
             $t = $i = '';
         }
         $class_display = Names::classToDisplay((new Reflection_Class($list_settings->class_name))->getAnnotation('set')->value);
         $summary = $t . $i . ucfirst($class_display) . $i . ' filtered by' . $t;
         $first = true;
         foreach ($list_settings->search as $property_path => $value) {
             if ($first) {
                 $first = false;
             } else {
                 $summary .= ',';
             }
             $summary .= SP . $t . $property_path . $t . ' = ' . DQ . $value . DQ;
         }
         return $summary;
     }
     return null;
 }
Beispiel #3
0
 /**
  * Gets annotation name (the displayable root of the annotation class name, when set)
  *
  * @return string
  */
 public function getAnnotationName()
 {
     return Names::classToDisplay(lLastParse(Namespaces::shortClassName(get_class($this)), '_Annotation'));
 }
Beispiel #4
0
 /**
  * @param $conditions string[] the key is the name of the condition, the value is the name of the
  *   value that enables the condition
  * @param $filters string[] the key is the name of the filter, the value is the name of the form
  *   element containing its value
  * @return string
  */
 public function buildObject($conditions = null, $filters = null)
 {
     $class_name = $this->type->asString();
     // visible input
     $input = new Input(null, strval($this->value));
     $input->setAttribute('autocomplete', 'off');
     $input->setAttribute('data-combo-class', Names::classToSet($class_name));
     if (!$this->readonly) {
         if ($filters) {
             $html_filters = [];
             $old_name = $this->name;
             foreach ($filters as $filter_name => $filter_value) {
                 $this->name = $filter_value;
                 $name = $this->getFieldName('', false);
                 $html_filters[] = $filter_name . '=' . $name;
             }
             $this->name = $old_name;
             $input->setAttribute('data-combo-filters', join(',', $html_filters));
         }
         if ($conditions) {
             $html_conditions = [];
             $old_name = $this->name;
             foreach ($conditions as $condition_name => $condition_value) {
                 $this->name = $condition_name;
                 $name = $this->getFieldName('', false);
                 $html_conditions[] = $name . '=' . $condition_value;
             }
             $this->name = $old_name;
             $input->setAttribute('data-conditions', join(';', $html_conditions));
         }
         $input->addClass('autowidth');
         $input->addClass('combo');
         // id input
         $id_input = new Input($this->getFieldName('id_'), $this->value ? Dao::getObjectIdentifier($this->value) : '');
         $id_input->setAttribute('type', 'hidden');
         $id_input->addClass('id');
         // 'add' / 'edit' anchor
         $fill_combo = isset($this->template) ? ['fill_combo' => $this->template->getFormId() . DOT . $this->getFieldName('id_', false)] : '';
         $edit = new Anchor(View::current()->link($this->value ? get_class($this->value) : $class_name, Feature::F_ADD, null, $fill_combo), 'edit');
         $edit->addClass('edit');
         $edit->setAttribute('target', Target::BLANK);
         $edit->setAttribute('title', '|Edit ¦' . Names::classToDisplay($class_name) . '¦|');
         // 'more' button
         $more = new Button('more');
         $more->addClass('more');
         $more->setAttribute('tabindex', -1);
         $this->setOnChangeAttribute($id_input);
         return $id_input . $input . $more . $edit;
     }
     return $input;
 }
Beispiel #5
0
 /**
  * @return string
  */
 private function getDefaultTitle()
 {
     return ucfirst(Names::classToDisplay((new Reflection_Class($this->class_name))->getAnnotation('set')));
 }
Beispiel #6
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;
 }