Example #1
0
 public function validateModelObject(Model $object, array &$data, $process = null, $isStrict = false)
 {
     $filter = $object->getFilter();
     $shadow = [];
     $columns = $object->getColumns($process);
     //		$groupColumns = $object->getGroupColumns();
     if ($isStrict) {
         if ($process === Model::ON_UPDATE) {
             $shadow = $object->getShadowData();
         }
     }
     foreach (array_keys($data) as $field) {
         $column = isset($columns[$field]) ? $columns[$field] : [];
         // 过滤值,同时必须更新$data
         $object[$field] = $data[$field] = $filter->filterColumn($data[$field], $column);
         $isRemove = false;
         if ($isStrict) {
             if (!empty($column['dummy'])) {
                 $isRemove = true;
             }
             //				if (!isset($groupColumns['default'][$field]))
             //					$isRemove = true;
             if ($process === Model::ON_UPDATE) {
                 if (isset($shadow[$field]) && equals($shadow[$field], $data[$field])) {
                     $isRemove = true;
                 }
             }
         }
         if ($isRemove) {
             unset($data[$field]);
             continue;
         }
         $error = $this->validateColumn($field, $data[$field], $column, $object, $process, $isStrict);
         if ($error !== false) {
             $object->setError($field, $error, false);
             // 不要覆盖已经存在的错误
         }
     }
     return $this;
 }
Example #2
0
 /**
  * Prepares this model for any other existing Model.
  *
  * The original does not have to use the FluentBuilderTrait.
  *
  * @param Model $model
  *
  * @return DynamicFluentModel
  */
 public function withModel(Model $model)
 {
     return $this->withTable($model->getTableName(), $model->getPrimaryKeyName(), $model->getColumns());
 }
Example #3
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;
 }
 /** !Route GET, class/$class */
 public function classInfo($class)
 {
     $this->checkTables();
     $result = $this->indexClass($class, '');
     if ($result === false) {
         return new NotFoundResponse($this->request);
     }
     $this->reflector = $result;
     $className = Library::getClassName($class);
     $reflection = new RecessReflectionClass($className);
     $this->reflection = $reflection;
     $this->className = $className;
     if ($reflection->isSubclassOf('Model')) {
         $this->relationships = Model::getRelationships($className);
         $this->columns = Model::getColumns($className);
         $this->table = Model::tableFor($className);
         $this->source = Model::sourceNameFor($className);
     }
 }