Example #1
0
 /**
  * Sort the listing in both ascending and descending order for the
  * supplied field, catching any exceptions if the sorted query causes
  * a problem.
  *
  * @param FieldInterface $field
  * @return array
  */
 public function runOnSingleField(FieldInterface $field)
 {
     $directions = ['ASC', 'DESC'];
     $results = [];
     foreach ($directions as $direction) {
         $results[$direction] = array('success' => false, 'message' => null, 'sql' => '');
         $request = new Request(array(), array($this->listing->getPrefix() . 'sort' => urldecode($field->getQueryStringId()), $this->listing->getPrefix() . 'dir' => $direction));
         $this->sortHelper->setRequest($request);
         try {
             // Don't need much data here, just need to run the query.
             $select = $this->listing->getModifiedSelect($this->fields)->limit(1);
             $results[$direction]['sql'] = (string) $select->reset(Select::LIMIT_COUNT);
             $select->getAdapter()->fetchAll($select);
             $results[$direction]['success'] = true;
         } catch (CorePhpException $e) {
             $results[$direction]['message'] = $e->getMessage();
         }
     }
     return $results;
 }