Beispiel #1
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 #2
0
 /**
  * Change an ISO value into a locale formatted value, knowing it's data type
  *
  * @param $type  Type
  * @param $value string
  * @return string
  */
 public function toLocale($value, Type $type = null)
 {
     if (isset($type)) {
         if ($type->isDateTime()) {
             return $this->date_format->toLocale($value);
         } elseif ($type->isFloat()) {
             return $this->number_format->floatToLocale($value);
         } elseif ($type->isInteger()) {
             return $this->number_format->integerToLocale($value);
         }
     }
     return $value;
 }
Beispiel #3
0
 /**
  * @param $report_lines Line[]
  * @param $property     Reflection_Property
  * @param $annotation   Annotation
  * @param $value        mixed
  */
 private static function checkVar(&$report_lines, Reflection_Property $property, Annotation $annotation, $value)
 {
     switch ($annotation->value) {
         case 'array':
             self::checkValue($report_lines, is_array($value), $property, $annotation, $value);
             break;
         case 'boolean':
             self::checkValue($report_lines, is_bool($value), $property, $annotation, $value);
             break;
         case 'float':
             self::checkValue($report_lines, is_float($value), $property, $annotation, $value);
             break;
         case 'integer':
             self::checkValue($report_lines, is_integer($value), $property, $annotation, $value);
             break;
         case 'string':
             self::checkValue($report_lines, is_string($value), $property, $annotation, $value);
             break;
         default:
             $type = new Type($annotation->value);
             if ($type->isClass()) {
                 self::checkValue($report_lines, is_a($value, $type->asString(), true), $property, $annotation, $value);
             }
     }
 }
 /**
  * Gets the type of the property, as defined by its var annotation
  *
  * @return Type
  * @throws Exception
  */
 public function getType()
 {
     $type = new Type($this->getAnnotation('var')->value);
     if ($type->isNull()) {
         throw new Exception($this->class . '::$' . $this->name . ' type not set using @var annotation', E_USER_ERROR);
     }
     return $type;
 }