示例#1
0
 /**
  * Method to auto-populate the model state.
  *
  */
 public function populateState()
 {
     if ($filters = $this->getUserStateFromRequest($this->context() . '.filter', 'filter', array(), 'array')) {
         $filters = \Dsc\ArrayHelper::dot($filters);
         foreach ($filters as $name => $value) {
             $this->setState('filter.' . $name, $value);
         }
     }
     if ($list = $this->getUserStateFromRequest($this->context() . '.list', 'list', array(), 'array')) {
         $list = \Dsc\ArrayHelper::dot($list);
         foreach ($list as $name => $value) {
             $this->setState('list.' . $name, $value);
         }
     }
     $offset = \Dsc\Pagination::findCurrentPage();
     $this->setState('list.offset', $offset - 1 >= 0 ? $offset - 1 : 0);
     if (!is_null($this->getState('list.order')) && !is_null($this->getState('list.direction'))) {
         switch (strtolower($this->getState('list.direction'))) {
             case "-1":
             case "desc":
                 $dir = -1;
                 break;
             case "1":
             case "asc":
             default:
                 $dir = 1;
                 break;
         }
         // TODO ensure that $this->getState('list.order') is a valid sorting field
         $this->setState('list.sort', array($this->getState('list.order') => $dir));
     }
     if (is_null($this->getState('list.sort'))) {
         $this->setState('list.sort', $this->__config['default_sort']);
         if (reset($this->__config['default_sort'])) {
             list($key, $value) = each($this->__config['default_sort']);
             $this->setState('list.order', $key);
             $this->setState('list.direction', $value);
         }
     }
     return $this;
 }