/**
  * 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 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);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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]);
 }
 /**
  * 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 . '}');
     }
 }
 /**
  * Adds the fields to the form
  * @param zibo\library\orm\model\Model $model Model of the data
  * @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
  *                      @
  * @return null
  */
 protected function addFieldsToForm(Model $model, array $fields = null, $skipFields = false)
 {
     $meta = $model->getMeta();
     $hiddenFields = $this->getHiddenFieldNames($model);
     $fields = $this->getModelFields($meta, $fields, $skipFields);
     $fieldFactory = FieldFactory::getInstance();
     foreach ($hiddenFields as $fieldName) {
         if (!array_key_exists($fieldName, $fields)) {
             continue;
         }
         $hiddenField = $fieldFactory->createField(FieldFactory::TYPE_HIDDEN, $fieldName, $this->data->{$fieldName});
         $this->addField($hiddenField);
         unset($fields[$fieldName]);
     }
     foreach ($fields as $fieldName => $field) {
         $value = null;
         if (isset($this->data->{$fieldName})) {
             $value = $this->data->{$fieldName};
         }
         $formField = $this->createFormField($fieldFactory, $meta, $field, $value);
         $this->addField($formField);
     }
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }