Beispiel #1
0
 protected function addSortCriteria($criteria)
 {
     if ($this->getRequestParameter('sort') == '') {
         return;
     }
     $column = EtvaNodePeer::translateFieldName(sfInflector::camelize($this->getRequestParameter('sort')), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
     if ('asc' == strtolower($this->getRequestParameter('dir'))) {
         $criteria->addAscendingOrderByColumn($column);
     } else {
         $criteria->addDescendingOrderByColumn($column);
     }
     $criteria->setIgnoreCase(true);
 }
Beispiel #2
0
 /**
  * Adds sort criteria
  * request object is like this;
  *
  * <code>
  * $request['sort'] = json encoded([{field: 'node_name',direction: 'ASC'},{field: 'name',direction: 'ASC'}])
  * or
  * $request['sort'] = $field_name; // file name to sort
  * $request['dir'] = $dir; // direction ASC or DESC
  * </code>
  *
  * @param Criteria $criteria
  *     
  *
  */
 protected function addSortCriteria(Criteria $criteria)
 {
     $sort = $this->getRequestParameter('sort');
     $sort_array = json_decode($sort, true);
     if (gettype($sort_array) == 'array') {
         $sort = $sort_array;
     }
     if ($sort == '') {
         return;
     }
     $sort_els = $sort;
     if (!is_array($sort)) {
         $sort_els = array(array('field' => $sort, 'direction' => $this->getRequestParameter('dir')));
     }
     foreach ($sort_els as $sort_info) {
         $field = $sort_info['field'];
         if (preg_match('/^node_(.*)/', $field, $matches)) {
             $field = $matches[1];
             $column = EtvaNodePeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
         } else {
             $column = EtvaServerPeer::translateFieldName(sfInflector::camelize($field), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
         }
         if ('asc' == strtolower($sort_info['direction'])) {
             $criteria->addAscendingOrderByColumn($column);
         } else {
             $criteria->addDescendingOrderByColumn($column);
         }
         $criteria->setIgnoreCase(true);
     }
 }