Beispiel #1
0
 /**
  * Using the Listing's fetchData() method, grab an array of IDs.  Depending upon
  * the selection mode the user has chosen, we may or may not paginate the result
  * set.
  *
  * @param bool $usePagination
  * @return array
  */
 private function fetchIdsFromListing($usePagination)
 {
     $out = [];
     if (!$usePagination) {
         $pagination = $this->listing->getSelectModifierByName('SelectPaginate');
         $this->listing->removeSelectModifierByName('SelectPaginate');
     }
     foreach ($this->listing->fetchData($this->fields) as $row) {
         $out[] = $row[$this->listing->getPrimaryKey()->getName()];
     }
     if (!$usePagination && isset($pagination)) {
         $this->listing->registerSelectModifier($pagination);
     }
     return $out;
 }
Beispiel #2
0
 /**
  * This is the core of the Counter class.  The overall logic implemented in
  * this method is explained in detail in the primary docblock for this class.
  * The array returned from this method will contain one associative array
  * for each distinct value of the $groupField found: the content for that
  * field as generated by the supplied $renderer and the count of records
  * that had that value.
  *
  * @param CellRendererInterface $renderer
  * @return array
  */
 public function fetchData(CellRendererInterface $renderer)
 {
     /* @var $sorter \Dewdrop\Fields\Helper\SelectSort */
     $sorter = $this->listing->getSelectModifierByName('SelectSort');
     $sorter->setDefaultField($this->groupField)->setDefaultDirection('asc');
     $this->listing->removeSelectModifierByName('SelectPaginate');
     $data = $this->listing->fetchData($this->fields);
     $counts = [];
     $content = [];
     $out = [];
     foreach ($data as $row) {
         $cellContent = $renderer->getContentRenderer()->render($this->groupField, $row, 0, 0);
         $contentHash = md5(strtoupper($cellContent));
         if (!array_key_exists($contentHash, $counts)) {
             $counts[$contentHash] = 0;
         }
         $counts[$contentHash] += 1;
         $content[$contentHash] = $cellContent;
     }
     foreach ($counts as $hash => $count) {
         $out[] = ['content' => $content[$hash], 'count' => $count];
     }
     return $out;
 }