Esempio n. 1
0
 /**
  * Build the order part from the query.
  *
  * The first arg is the field to be ordered and the $order
  * arg is the correspondent order (ASC|DESC)
  *
  * If the $reset is set to true, all previous order should be removed
  *
  * @param string $field
  * @param string $order
  * @param bool $reset
  * @return Bvb_Grid_Source_Doctrine
  */
 public function buildQueryOrder($field, $order, $reset = false)
 {
     if ($reset) {
         $this->_query->removeDqlQueryPart('orderby');
     }
     $this->_query->addOrderBy($field . ' ' . $order);
     return $this;
 }
 protected function tryToSortWithForeignColumn(Doctrine_Query $query, array $sort)
 {
     $table = $this->getDmModule()->getTable();
     if ('integer' === dmArray::get($table->getColumnDefinition($sort[0]), 'type')) {
         if ($table->isI18nColumn($sort[0])) {
             $query->addOrderBy(sprintf('%s.%s %s', $query->getJoinAliasForRelationAlias($table->getComponentName(), 'Translation'), $sort[0], $sort[1]));
             // Success, skip default sorting by local column
             return;
         } elseif ($relation = $table->getRelationHolder()->getLocalByColumnName($sort[0])) {
             if ($relation instanceof Doctrine_Relation_LocalKey && ($foreignTable = $relation->getTable()) instanceof dmDoctrineTable) {
                 if (($foreignColumn = $foreignTable->getIdentifierColumnName()) != 'id') {
                     if (!($joinAlias = $query->getJoinAliasForRelationAlias($table->getComponentName(), $relation->getAlias()))) {
                         $query->leftJoin(sprintf('%s.%s %s', $query->getRootAlias(), $relation->getAlias(), $relation->getAlias()));
                         $joinAlias = $relation->getAlias();
                         if ($foreignTable->isI18nColumn($foreignColumn)) {
                             $query->leftJoin(sprintf('%s.%s %s', $joinAlias, 'Translation', $joinAlias . 'Translation'));
                         }
                     }
                     if ($foreignTable->isI18nColumn($foreignColumn)) {
                         $query->addOrderBy(sprintf('%s.%s %s', $joinAlias . 'Translation', $foreignColumn, $sort[1]));
                     } else {
                         $query->addOrderBy(sprintf('%s.%s %s', $joinAlias, $foreignColumn, $sort[1]));
                     }
                     // Success, skip default sorting by local column
                     return;
                 }
             }
         }
     } elseif ($table->isI18nColumn($sort[0])) {
         $query->addOrderBy(sprintf('%s.%s %s', $query->getJoinAliasForRelationAlias($table->getComponentName(), 'Translation'), $sort[0], $sort[1]));
         // Success, skip default sorting by local column
         return;
     }
     if ($table->hasField($sort[0])) {
         $query->addOrderBy($sort[0] . ' ' . $sort[1]);
     }
 }
 /**
  * hookOrderBy
  * builds DQL query orderby part from given parameter array
  *
  * @param array $params         an array containing all fields which the built query
  *                              should be ordered by
  * @return boolean              whether or not the hooking was successful
  */
 public function hookOrderby($params)
 {
     if (!is_array($params)) {
         return false;
     }
     foreach ($params as $name) {
         $e = explode(' ', $name);
         $order = 'ASC';
         if (count($e) > 1) {
             $order = $e[1] == 'DESC' ? 'DESC' : 'ASC';
         }
         $e = explode('.', $e[0]);
         if (count($e) == 2) {
             list($alias, $column) = $e;
             $map = $this->query->getAliasDeclaration($alias);
             $table = $map['table'];
             if ($def = $table->getDefinitionOf($column)) {
                 $this->query->addOrderBy($alias . '.' . $column . ' ' . $order);
             }
         }
     }
     return true;
 }
 /**
  * Add sort to Doctrine_Query.
  *
  * @param Doctrine_Query $q
  * @param string $fld
  * @param string $dir
  */
 protected function rec_query_add_sort(Doctrine_Query $q, $fld, $dir)
 {
     $q->addOrderBy("{$fld} {$dir}");
 }
Esempio n. 5
0
 /**
  * Adds orderby option to the query on the <field_name>
  *
  * @param Doctrine_Query $q
  */
 private function addOrderByPositionOption(Doctrine_Query $q, $table_alias = 't', $filed_name = 'position')
 {
     $q->addOrderBy($table_alias . '.' . $filed_name);
 }
Esempio n. 6
0
 protected function addSortQuery(Doctrine_Query $query)
 {
     $sort = $this->getSort();
     if ($sort) {
         $query->addOrderBy(sprintf("%s %s", $sort[0], $sort[1]));
     }
 }
 /**
  * Handle custom sorters
  *
  * @param Doctrine_Query $q
  * @param string $fld
  * @param string $dir
  */
 protected function rec_query_add_sort(Doctrine_Query $q, $fld, $dir)
 {
     if ($fld == 'cre_username') {
         $q->addOrderBy("cu.user_username {$dir}");
     } elseif ($fld == 'upd_username') {
         $q->addOrderBy("uu.user_username {$dir}");
     } else {
         parent::rec_query_add_sort($q, $fld, $dir);
     }
 }
Esempio n. 8
0
 /**
  * Add sort query
  * 
  * @param   Doctrine_Query  $q
  * @return  void
  */
 protected function addSortQuery($q)
 {
     $q->addOrderBy('root_id, lft');
 }