/**
  * Method to auto-populate the model state.
  *
  * This method will only called in constructor. Using `ignore_request` to ignore this method.
  *
  * @param   string  $ordering   An optional ordering field.
  * @param   string  $direction  An optional direction (asc|desc).
  *
  * @return  void
  */
 protected function populateState($ordering = null, $direction = null)
 {
     $config = $this->getContainer()->get('joomla.config');
     // Set default ordering
     $this->state->set('list.direction', $direction);
     $this->state->set('list.ordering', $ordering);
     // If the context is set, assume that stateful lists are used.
     if ($this->context) {
         $app = $this->container->get('app');
         // Receive & set filters
         if ($filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array')) {
             $this->state->set('filter', $filters);
         }
         // Receive & set searches
         if ($searches = $app->getUserStateFromRequest($this->context . '.search', 'search', array(), 'array')) {
             $searches = AdminListHelper::handleSearches($searches, $this->getSearchFields());
             $this->state->set('search', $searches);
         }
         $limit = 0;
         // Receive & set list options
         if ($list = $app->getUserStateFromRequest($this->context . '.list', 'list', array(), 'array')) {
             foreach ($list as $name => $value) {
                 // Extra validations
                 switch ($name) {
                     case 'fullordering':
                         $orderConfig = array('ordering' => $ordering, 'direction' => $direction);
                         $orderConfig = AdminListHelper::handleFullordering($value, $orderConfig, $this);
                         $this->state->set('list.direction', $orderConfig['direction']);
                         $this->state->set('list.ordering', $orderConfig['ordering']);
                         break;
                         //						case 'ordering':
                         //							$value = $this->filterField($value);
                         //							break;
                     //						case 'ordering':
                     //							$value = $this->filterField($value);
                     //							break;
                     case 'direction':
                         if (!in_array(strtoupper($value), array('ASC', 'DESC', ''))) {
                             $value = $direction;
                         }
                         break;
                     case 'limit':
                         $limit = $value;
                         break;
                         // Just to keep the default case
                     // Just to keep the default case
                     default:
                         $value = $value;
                         break;
                 }
                 $this->state->set('list.' . $name, $value);
             }
         }
         // Fill the limits and start
         if (!$limit) {
             $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $config->get('list_limit'), 'uint');
             $this->state->set('list.limit', $limit);
         }
         $value = $app->getUserStateFromRequest($this->context . '.limitstart', 'limitstart', 0);
         $limitstart = $limit != 0 ? floor($value / $limit) * $limit : 0;
         $this->state->set('list.start', $limitstart);
     } else {
         $this->state->set('list.start', 0);
         $this->state->set('list.limit', 0);
     }
 }
 /**
  * Method to test handleFullordering().
  *
  * @return void
  *
  * @covers Windwalker\Model\Helper\AdminListHelper::handleFullordering
  *
  * @dataProvider handleFullorderingProvider
  */
 public function testHandleFullordering($value, $orderConfig, $filterFields, $expected)
 {
     $model = new ListModel(array('allow_fields' => $filterFields));
     $this->assertEquals($expected, AdminListHelper::handleFullordering($value, $orderConfig, $model));
 }