/**
  * Constructs a model detail view
  * @param zibo\library\orm\model\Model $model
  * @return null
  */
 public function __construct(Model $model, ModelFieldTable $fieldTable, ModelFieldOrderForm $orderForm = null, $editModelAction = null, $addFieldsAction = null, $editFormatAction = null, $editIndexAction = null)
 {
     parent::__construct(self::TEMPLATE);
     $meta = $model->getMeta();
     $modelTable = $meta->getModelTable();
     $modelClass = get_class($model);
     $dataClass = $meta->getDataClassName();
     $indexTable = new SimpleModelIndexTable($modelTable);
     $formatTable = new SimpleDataFormatTable($modelTable);
     $this->set('modelTable', $modelTable);
     $this->set('modelClass', $modelClass);
     $this->set('dataClass', $dataClass);
     $this->set('fieldTable', $fieldTable);
     $this->set('formatTable', $formatTable);
     $this->set('indexTable', $indexTable);
     $this->set('orderForm', $orderForm);
     $this->set('editModelAction', $editModelAction);
     $this->set('addFieldsAction', $addFieldsAction);
     $this->set('editFormatAction', $editFormatAction);
     $this->set('editIndexAction', $editIndexAction);
     $this->addJavascript(JQueryModule::SCRIPT_JQUERY_UI);
     $this->addJavascript(self::SCRIPT_TABLE);
     $this->addJavascript(self::SCRIPT_BUILDER);
     $this->addInlineJavascript('ziboOrmInitializeModelDetail();');
     $this->addStyle(self::STYLE_BUILDER);
 }
Example #2
0
 /**
  * Gets the database table definition of the provided model
  * @param zibo\library\orm\model\Model $model
  * @return zibo\library\database\definition\Table
  */
 private function getDatabaseTable(Model $model)
 {
     $meta = $model->getMeta();
     $modelTable = $meta->getModelTable();
     $databaseTable = $modelTable->getDatabaseTable();
     return $databaseTable;
 }
 /**
  * Gets the general relation information of the provided model
  * @param zibo\library\orm\model\Model $model The model to get the information from
  * @return string The general relation information of the provided model
  */
 private function getRelationInfo(Model $model)
 {
     $table = $model->getMeta()->getModelTable();
     $info = '';
     $relations = array();
     $fields = $table->getFields();
     foreach ($fields as $field) {
         if ($field instanceof PropertyField) {
             continue;
         }
         $relationModelName = $field->getRelationModelName();
         $relationModelValue = $relationModelName;
         if ($this->action) {
             $anchor = new Anchor($relationModelName, $this->action . $relationModelName);
             $relationModelValue = $anchor->getHtml();
         }
         $relations[$relationModelName] = $relationModelValue;
     }
     $numRelations = count($relations);
     if ($numRelations == 1) {
         $relation = array_pop($relations);
         $info .= $this->translator->translate('orm.label.relation.with', array('model' => $relation)) . '<br />';
     } elseif ($numRelations) {
         $last = array_pop($relations);
         $first = implode(', ', $relations);
         $info .= $this->translator->translate('orm.label.relations.with', array('first' => $first, 'last' => $last)) . '<br />';
     }
     return $info;
 }
Example #4
0
 /**
  * Gets the view of the export. This method will first add default export decorators if none were added.
  * @param string $extension extension to get the export from
  * @return zibo\libray\html\table\export\ExportView view for the export
  */
 public function getExportView($extension)
 {
     if ($this->exportColumnDecorators || $this->exportGroupDecorators) {
         return parent::getExportView($extension);
     }
     $meta = $this->model->getMeta();
     $properties = $meta->getProperties();
     foreach ($properties as $fieldName => $property) {
         $type = $property->getType();
         switch ($type) {
             case 'boolean':
                 $decorator = new BooleanDecorator($fieldName);
                 break;
             case 'date':
             case 'datetime':
                 $decorator = new DateDecorator($fieldName);
                 break;
             default:
                 $decorator = new ValueDecorator($fieldName);
                 break;
         }
         $this->addExportDecorator($decorator, new StaticDecorator(ucfirst($fieldName)));
     }
     return parent::getExportView($extension);
 }
 /**
  * Constructs a new localize decorator
  * @param zibo\library\orm\model\Model $model Model of the data
  * @param string $action URL where the locale code should point to
  * @return null
  */
 public function __construct(Model $model, $action = null)
 {
     $this->action = $action;
     $this->meta = $model->getMeta();
     $this->localizedModel = $this->meta->getLocalizedModel();
     $this->currentLocale = LocalizeController::getLocale();
     $this->locales = I18n::getInstance()->getLocaleCodeList();
     unset($this->locales[$this->currentLocale]);
 }
Example #6
0
 /**
  * Sets all the fields of the model to this query, only if the fields of this query are not yet initialized.
  * @return null
  */
 private function setModelFields()
 {
     if ($this->fields !== false) {
         return;
     }
     $this->fields = array();
     $fields = $this->model->getMeta()->getFields();
     foreach ($fields as $fieldName => $field) {
         $this->fields[] = new ModelExpression('{' . $fieldName . '}');
     }
 }
 /**
  * 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;
 }
Example #8
0
 /**
  * Gets the names of the hidden fields for this model
  * @param zibo\library\orm\model\Model $model Model of the data
  * @return array Array with the names of the hidden fields
  */
 protected function getHiddenFieldNames(Model $model)
 {
     $hiddenFields = array(ModelTable::PRIMARY_KEY);
     if ($model instanceof ExtendedModel) {
         $automaticFields = $model->getAutomaticFields();
         foreach ($automaticFields as $automaticField) {
             $hiddenFields[] = $automaticField;
         }
     }
     return $hiddenFields;
 }
Example #9
0
 /**
  * Deletes the old has many values which are not saved
  * @param Model $model Model of the has many field
  * @param string $foreignKey Name of the foreign key to this model
  * @param array $oldHasMany Array with the primary key of the has many value as key and value
  * @param boolean $idDependant Flag to see whether the has many value is dependant on this model
  * @return null
  */
 private function deleteOldHasManyAndBelongsTo($model, $foreignKey, $oldHasMany, $isDependant)
 {
     if ($isDependant) {
         $model->delete($oldHasMany);
         return;
     }
     foreach ($oldHasMany as $id) {
         $model->saveField(null, $foreignKey, $id);
     }
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * 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());
 }
Example #12
0
 /**
  * Constructs a new result parser
  * @param zibo\library\orm\model\Model $model Model of this result
  * @return null
  */
 public function __construct(Model $model)
 {
     $this->meta = $model->getMeta();
     $this->data = $model->createData(false);
 }
Example #13
0
 /**
  * Create a xml element with the definition of a model
  * @param zibo\library\xml\dom\Document $dom
  * @param zibo\library\orm\Model $model
  * @return DOMElement an xml element which defines the model
  */
 protected function getElementFromModel(Document $dom, Model $model)
 {
     $meta = $model->getMeta();
     $modelTable = $meta->getModelTable();
     $modelClass = get_class($model);
     $dataClass = $meta->getDataClassName();
     $group = $modelTable->getGroup();
     $modelElement = $dom->createElement(self::TAG_MODEL);
     $modelElement->setAttribute(self::ATTRIBUTE_NAME, $model->getName());
     if ($meta->isLogged()) {
         $modelElement->setAttribute(self::ATTRIBUTE_LOG, 'true');
     }
     $modelElement->setAttribute(self::ATTRIBUTE_MODEL_CLASS, $modelClass);
     $modelElement->setAttribute(self::ATTRIBUTE_DATA_CLASS, $dataClass);
     if ($meta->willBlockDeleteWhenUsed()) {
         $modelElement->setAttribute(self::ATTRIBUTE_WILL_BLOCK_DELETE, 'true');
     }
     if ($group) {
         $modelElement->setAttribute(self::ATTRIBUTE_GROUP, $group);
     }
     $fields = $modelTable->getFields();
     foreach ($fields as $fieldName => $field) {
         if ($fieldName == ModelTable::PRIMARY_KEY) {
             continue;
         }
         $fieldElement = $this->getElementFromField($dom, $field);
         $importedFieldElement = $dom->importNode($fieldElement, true);
         $modelElement->appendChild($importedFieldElement);
     }
     $indexes = $modelTable->getIndexes();
     foreach ($indexes as $index) {
         $indexElement = $this->getElementFromIndex($dom, $index);
         $modelElement->appendChild($indexElement);
     }
     $dataFormats = $modelTable->getDataFormats(false);
     foreach ($dataFormats as $dataFormat) {
         $formatElement = $dom->createElement(self::TAG_FORMAT, $dataFormat->getFormat());
         $formatElement->setAttribute(self::ATTRIBUTE_NAME, $dataFormat->getName());
         $modelElement->appendChild($formatElement);
     }
     return $modelElement;
 }
Example #14
0
 /**
  * Updates the group of the link model according to the groups of the references models
  * @param zibo\library\orm\model\Model $model Model of the link field
  * @param zibo\library\orm\model\Model $relationModel Model referenced by the link field
  * @param zibo\library\orm\model\Model $linkModel Model used to link the model and the relation model
  * @return null
  */
 private function updateLinkModelGroup(Model $model, Model $relationModel, Model $linkModel = null)
 {
     if (!$linkModel) {
         return;
     }
     $modelGroup = $model->getMeta()->getModelTable()->getGroup();
     $relationGroup = $model->getMeta()->getModelTable()->getGroup();
     if ($modelGroup == $relationGroup) {
         $linkModel->getMeta()->getModelTable()->setGroup($modelGroup);
     }
 }
Example #15
0
 /**
  * Checks if all the necessairy information from the module model is in the builder model
  * @param zibo\library\orm\model\Model $moduleModel
  * @param zibo\library\orm\model\Model $builderModel
  * @return null
  * @throws zibo\library\orm\exception\ModelIncompleteException when the model misses information defined in the module model
  */
 private function checkModuleModel(Model $moduleModel, Model $builderModel)
 {
     $moduleTable = $moduleModel->getMeta()->getModelTable();
     $builderTable = $builderModel->getMeta()->getModelTable();
     $moduleFields = $moduleTable->getFields();
     foreach ($moduleFields as $fieldName => $moduleField) {
         if (!$builderTable->hasField($fieldName)) {
             throw new ModelIncompleteException('Field ' . $fieldName . ' not found while it\'s defined in the module model');
         }
         $builderField = $builderTable->getField($fieldName);
         $this->checkModuleField($fieldName, $moduleField, $builderField);
     }
 }
 /**
  * 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);
 }