/** * Constructs a new scaffold form * @param string $action URL where this form will point to * @param zibo\library\orm\model\Model $model Model of the data on the form * @param mixed $data Data object of the model to preset the form * @param array $fields Array with the names of the fields which need to be added to the form. If not provided, all the fields of the model will be added * @param boolean $skipFields Set to true to skip the provided fields instead of adding them * @return null */ public function __construct($action, Model $model, $data = null, array $fields = null, $skipFields = false) { if ($data == null) { $data = $model->createData(); } $this->isConstructing = true; parent::__construct($action, self::NAME . $model->getName(), $data); $this->isConstructing = false; $this->dataFieldNames = array(); $this->addFieldsToForm($model, $fields, $skipFields); }
/** * Gets the model detail vieiw * @param zibo\library\orm\model\Model $model * @param zibo\orm\builder\table\ModelFieldTable $fieldTable * @param zibo\orm\builder\form\ModelFieldOrderForm $orderForm * @return zibo\orm\builder\view\ModelDetailView */ public function getModelDetailView(Model $model, ModelFieldTable $fieldTable, ModelFieldOrderForm $orderForm = null, $editAction = null) { $basePath = $this->request->getBasePath(); $modelName = $model->getName(); if (!$this->isReadOnly && $editAction) { $editModelAction = $editAction . '/' . WizardController::ACTION_LIMIT . '/' . BuilderWizard::LIMIT_MODEL; $addFieldsAction = $editAction . '/' . WizardController::ACTION_FIELD; $editFormatAction = $editAction . '/' . WizardController::ACTION_LIMIT . '/' . BuilderWizard::LIMIT_DATA_FORMAT; $editIndexAction = $editAction . '/' . WizardController::ACTION_LIMIT . '/' . BuilderWizard::LIMIT_INDEX; } else { $editModelAction = null; $addFieldsAction = null; $editFormatAction = null; $editIndexAction = null; } $view = new ModelDetailView($model, $fieldTable, $orderForm, $editModelAction, $addFieldsAction, $editFormatAction, $editIndexAction); $sidebar = $view->getSidebar(); if (!$this->isReadOnly) { $editAction = $this->request->getBaseUrl() . '/' . Module::ROUTE_WIZARD . '/' . WizardController::ACTION_MODEL . '/' . $modelName; $scaffoldAction = $basePath . '/' . self::ACTION_SCAFFOLD . '/' . $modelName; $exportAction = $basePath . '/' . self::ACTION_EXPORT . '/' . $modelName . '/1'; $sidebar->addAction($editAction, self::TRANSLATION_EDIT, true); $sidebar->addAction($scaffoldAction, self::TRANSLATION_SCAFFOLD_MODEL, true); $sidebar->addAction($exportAction, self::TRANSLATION_EXPORT_MODEL, true); } $sidebar->addAction($basePath, self::TRANSLATION_BACK, true); $sidebar->setInformation(self::TRANSLATION_INFORMATION_MODEL, true); return $view; }
/** * Gets the primary keys of the has many values * @param Model $model Model of the has many field * @param string $foreignKey Name of the foreign key to this model * @param integer $id Value for the foreign key * @return array Array with the primary key of the has many value as key and value */ private function findOldHasManyAndBelongsTo($model, $foreignKey, $id) { $condition = new SimpleCondition(new FieldExpression($foreignKey), new ScalarExpression($id), Condition::OPERATOR_EQUALS); $statement = new SelectStatement(); $statement->addTable(new TableExpression($model->getName())); $statement->addField(new FieldExpression(ModelTable::PRIMARY_KEY)); $statement->addCondition($condition); $result = $this->executeStatement($statement); $model->clearCache(); $oldHasMany = array(); foreach ($result as $record) { $oldHasMany[$record[ModelTable::PRIMARY_KEY]] = $record[ModelTable::PRIMARY_KEY]; } return $oldHasMany; }
/** * Constructs a new model table * @param zibo\library\orm\model\Model $model * @param string $formAction URL where the form will point to */ public function __construct(Model $model, $formAction) { $this->model = $model; $this->query = $model->createQuery(); parent::__construct(array(), $formAction, self::FORM_NAME . $this->model->getName()); }
/** * Adds a model to the manager * @param zibo\library\orm\model\Model $model * @return null */ public function addModel(Model $model) { $this->models[$model->getName()] = $model; }
/** * Registeres a link model for a many to many relation * @param zibo\library\orm\definition\field\HasField $field1 * @param zibo\library\orm\definition\field\HasField $field2 * @return zibo\library\orm\model\Model The registered model */ private function registerManyToManyLinkModel(Model $model, $fieldName, HasField $field2) { $modelName = $model->getName(); $modelMeta = $model->getMeta(); $field1 = $modelMeta->getField($fieldName); $linkModelName = $this->getManyToManyLinkModelName($field1, $field2, $modelMeta, $fieldName); $field1->setLinkModelName($linkModelName); $field2->setLinkModelName($linkModelName); $field1->setForeignKeyName($field2->getName()); $field2->setForeignKeyName($field1->getName()); if ($this->hasModel($linkModelName)) { return; } return $this->createAndRegisterLinkModel($linkModelName, $field1->getRelationModelName(), $field2->getRelationModelName()); }
/** * Registers a new model, taking into account the models defined by modules * @param zibo\library\orm\model\Model $model * @param boolean $defineModels * @return null */ public function registerModel(Model $model, $defineModels = true) { $modelName = $model->getName(); $moduleModel = $this->getModuleModel($modelName); if ($moduleModel) { $this->checkModuleModel($moduleModel, $model); } $builderModels = $this->getBuilderModels(); $builderModels[$modelName] = $model; $this->writeBuilderModels($builderModels); $this->defineModels($defineModels); }
/** * Sets a model to the cache * @param zibo\library\orm\model\Model $model Model to cache * @return null */ public function setModel(Model $model) { $modelName = $model->getName(); $this->cache->set(self::CACHE_TYPE_MODEL, $modelName, $model); $this->indexModel[$modelName] = $modelName; $this->cache->set(self::CACHE_TYPE_INDEX, self::CACHE_TYPE_MODEL, $this->indexModel); }