Esempio n. 1
0
 /**
  * Tests for acceptance of fields with dots in
  * CSort::attributes.
  *
  * @return void
  */
 function testGetDirectionsWithDots()
 {
     $_GET['sort'] = 'comments.id';
     $criteria = new CDbCriteria();
     $criteria->with = 'comments';
     $sort = new CSort('TestPost');
     $sort->attributes = array('id', 'comments.id' => array('asc' => 'comments.id', 'desc' => 'comments.id desc'));
     $sort->applyOrder($criteria);
     $directions = $sort->getDirections();
     $this->assertTrue(isset($directions['comments.id']));
 }
Esempio n. 2
0
 /**
  * Tests for acceptance of arrays for asc/desc keys in
  * CSort::attributes.
  *
  * @return void
  */
 function testGetDirectionsWithArrays()
 {
     $_GET['sort'] = 'comments.id';
     $criteria = new CDbCriteria();
     $criteria->with = 'comments';
     $sort = new CSort('TestPost');
     $sort->attributes = array('id', 'comments.id' => array('asc' => array('comments.id', 'id'), 'desc' => array('comments.id desc', 'id desc')));
     $sort->applyOrder($criteria);
     $directions = $sort->getDirections();
     $this->assertEquals($criteria->order, 'comments.id, id');
 }
Esempio n. 3
0
 /**
  * Override the default method to read from model in case attribute is not present in request
  * @return array sort directions indexed by attribute names.
  * Sort direction can be either CSort::SORT_ASC for ascending order or
  * CSort::SORT_DESC for descending order.
  */
 public function getDirections()
 {
     $directions = parent::getDirections();
     if (empty($directions)) {
         $attributes = explode($this->separators[0], $this->sortAttribute . $this->sortDescending);
         foreach ($attributes as $attribute) {
             if (($pos = strrpos($attribute, $this->separators[1])) !== false) {
                 $descending = substr($attribute, $pos + 1) === $this->descTag;
                 if ($descending) {
                     $attribute = substr($attribute, 0, $pos);
                 }
             } else {
                 $descending = false;
             }
             if ($this->resolveAttribute($attribute) !== false) {
                 $directions[$attribute] = $descending;
                 if (!$this->multiSort) {
                     return $directions;
                 }
             }
         }
         if ($directions === array() && is_array($this->defaultOrder)) {
             $directions = $this->defaultOrder;
         }
     }
     return $directions;
 }