/**
  * Gets the model query
  * @param joppa\content\model\ContentProperties $contentProperties
  * @param zibo\library\orm\model\Model $model
  * @param string $locale Code of the locale
  * @param string $id The id of the record to fetch
  * @return zibo\library\orm\query\ModelQuery
  */
 private function getModelQuery(ContentProperties $contentProperties, $model, $locale, $id)
 {
     $includeUnlocalizedData = $contentProperties->getIncludeUnlocalized();
     $query = $model->createQuery($contentProperties->getRecursiveDepth(), $locale, $includeUnlocalizedData);
     $modelFields = $contentProperties->getModelFields();
     if ($modelFields) {
         foreach ($modelFields as $fieldName) {
             $query->addFields('{' . $fieldName . '}');
         }
     }
     $idField = $contentProperties->getParameterId();
     $query->addCondition('{' . $idField . '} = %1%', $id);
     $condition = $contentProperties->getCondition();
     if ($condition) {
         $query->addCondition($condition);
     }
     $order = $contentProperties->getOrder();
     if ($order) {
         $query->addOrderBy($order);
     }
     return $query;
 }
 /**
  * Constructs a new properties form
  * @param string $action URL where this form will point to
  * @param joppa\model\Node $node
  * @param joppa\content\model\ContentProperties $properties
  * @return null
  */
 public function __construct($action, Node $node, ContentProperties $properties)
 {
     parent::__construct($action, self::NAME, self::TRANSLATION_SAVE);
     $translator = I18n::getInstance()->getTranslator();
     $modelManager = ModelManager::getInstance();
     $fieldFactory = FieldFactory::getInstance();
     $model = $properties->getModelName();
     $fields = $properties->getModelFields();
     $recursiveDepth = $properties->getRecursiveDepth();
     $includeUnlocalized = $properties->getIncludeUnlocalized();
     $view = $properties->getView();
     $modelField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_MODEL, $model);
     $modelField->setOptions($this->getModelOptions($modelManager));
     $modelField->addEmpty();
     $fieldsField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_FIELDS, $fields);
     $fieldsField->setOptions(self::getModelFieldOptions($modelManager, $model));
     $fieldsField->setIsMultiple(true);
     $recursiveDepthField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_RECURSIVE_DEPTH, $recursiveDepth);
     $recursiveDepthField->setOptions($this->getNumericOptions(0, 5));
     $includeUnlocalizedField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_INCLUDE_UNLOCALIZED, $includeUnlocalized);
     $includeUnlocalizedField->setOptions($this->getIncludeUnlocalizedOptions($translator));
     $viewField = $fieldFactory->createField(FieldFactory::TYPE_LIST, self::FIELD_VIEW, $view);
     $viewField->setOptions($this->getViewOptions($translator));
     $this->addField($modelField);
     $this->addField($fieldsField);
     $this->addField($recursiveDepthField);
     $this->addField($includeUnlocalizedField);
     $this->addField($viewField);
 }
 /**
  * Gets the model query
  * @param zibo\library\orm\model\Model $model
  * @param joppa\content\model\ContentProperties $contentProperties
  * @param string $locale Code of the locale
  * @param integer $page Page number
  * @return zibo\library\orm\query\ModelQuery
  */
 public function getModelQuery($model, ContentProperties $contentProperties, $locale, $page = 1)
 {
     $includeUnlocalizedData = $contentProperties->getIncludeUnlocalized();
     $query = $model->createQuery($contentProperties->getRecursiveDepth(), $locale, $includeUnlocalizedData);
     $modelFields = $contentProperties->getModelFields();
     if ($modelFields) {
         foreach ($modelFields as $fieldName) {
             $query->addFields('{' . $fieldName . '}');
         }
     }
     $condition = $contentProperties->getCondition();
     if ($condition) {
         $query->addCondition($condition);
     }
     $order = $contentProperties->getOrder();
     if ($order) {
         $query->addOrderBy($order);
     }
     if ($contentProperties->isPaginationEnabled()) {
         $paginationOffset = $contentProperties->getPaginationOffset();
         $rows = $contentProperties->getPaginationRows();
         $offset = ($page - 1) * $rows;
         if ($paginationOffset) {
             $offset += $paginationOffset;
         }
         $query->setLimit($rows, $offset);
     }
     return $query;
 }