Example #1
0
File: form.php Project: ateliee/pmp
 /**
  * @param Model $model
  * @return $this
  */
 public function createFormModel(Model &$model, $multi_form = false)
 {
     $table_name = $model->getTablename();
     $prex = "";
     if ($multi_form) {
         $prex = $table_name . "-";
     }
     $fields = $model->getColumns();
     foreach ($fields as $key => $column) {
         if (!$column->getFormenable()) {
             continue;
         }
         $type = $this->convertColumnsToFormType($column);
         $elm = new FormElement($type, $prex);
         $elm->setIsArray($column->getType() == ModelColumn::$TYPE_ARRAY && $column->getChoices() > 0);
         $elm->setAttr($this->makeAttr($key, $type, array()));
         $elm->setAttrValue(FormElement::$ATTR_FORMAT, $column->getFormat());
         $elm->setAttrValue(FormElement::$ATTR_CHOICES, $column->getChoices());
         $elm->setAttrValue(FormElement::$ATTR_LABEL, $column->getComment());
         if ($column->getType() == ModelColumn::$TYPE_BOOLEAN) {
             $elm->setAttrValue(FormElement::$ATTR_VALUE, 1);
         }
         if ($column->getLength() > 0) {
             $elm->setAttrValue(FormElement::$ATTR_MAXLENGTH, $column->getLength());
         }
         if ($column->getType() == ModelColumn::$TYPE_DATE || $column->getType() == ModelColumn::$TYPE_DATETIME) {
             if ($column->getNullable() == false) {
                 $elm->setAttrValue(FormElement::$ATTR_REQUIRED, true);
             }
         }
         $this->addElement($key, $elm);
         $this->setValue($key, $model->get($key));
     }
     $this->models[$table_name] = $model;
     return $this;
 }