/**
  * Creates the model query from the provided properties
  * @param \ride\library\orm\model\Model $model
  * @param \ride\library\orm\model\ContentProperties $contentProperties
  * @param string $locale Code of the locale
  * @param integer $page Page number
  * @param array $arguments Arguments for the condition
  * @return \ride\library\orm\query\ModelQuery
  */
 public function getModelQuery(ContentProperties $contentProperties, $locale, $page = 1, array $arguments, &$isFiltered = null)
 {
     $isFiltered = false;
     // create query
     $query = $this->model->createQuery($locale);
     $query->setRecursiveDepth($contentProperties->getRecursiveDepth());
     $query->setFetchUnlocalized($contentProperties->getIncludeUnlocalized());
     // select fields
     $modelFields = $contentProperties->getModelFields();
     if ($modelFields) {
         foreach ($modelFields as $fieldName) {
             $query->addFields('{' . $fieldName . '}');
         }
     }
     // apply condition
     $condition = $contentProperties->getCondition();
     if ($condition) {
         $arguments = $this->parseContextVariables($condition, $arguments);
         if ($arguments) {
             $isFiltered = true;
             $query->addConditionWithVariables($condition, $arguments);
         } else {
             $query->addCondition($condition);
         }
     }
     // apply search
     if ($contentProperties->hasSearch()) {
         $searchQuery = $this->request->getQueryParameter('query');
         if ($searchQuery) {
             $conditions = array();
             $fields = $this->model->getMeta()->getProperties();
             foreach ($fields as $fieldName => $field) {
                 if ($field->getOption('scaffold.search')) {
                     $conditions[] = '{' . $fieldName . '} LIKE %1%';
                 }
             }
             if ($conditions) {
                 $condition = implode(' OR ', $conditions);
                 $searchQuery = '%' . $searchQuery . '%';
                 $query->addCondition($condition, $searchQuery);
             }
         }
     }
     // apply filters
     $this->filters = array();
     $filters = $contentProperties->getFilters();
     foreach ($filters as $filter) {
         $filterValue = $this->request->getQueryParameter($filter['name']);
         if ($filterValue) {
             $isFiltered = true;
         }
         $this->filters[$filter['name']] = array('type' => $filter['type'], 'field' => $filter['field'], 'filter' => $this->dependencyInjector->get('ride\\web\\cms\\orm\\filter\\ContentOverviewFilter', $filter['type']));
         $this->filters[$filter['name']]['value'] = $this->filters[$filter['name']]['filter']->applyQuery($this->model, $query, $filter['field'], $filterValue);
     }
     // apply order
     $order = $contentProperties->getOrder();
     if ($order) {
         $query->addOrderBy($order);
     }
     // apply pagination
     if ($contentProperties->isPaginationEnabled()) {
         $paginationOffset = $contentProperties->getPaginationOffset();
         $rows = $contentProperties->getPaginationRows();
         $offset = ($page - 1) * $rows;
         if ($paginationOffset) {
             $offset += $paginationOffset;
         }
         $query->setLimit((int) $rows, (int) $offset);
     }
     return $query;
 }