/**
  * @expectedException \Dewdrop\Fields\Exception
  */
 public function testExceptionIsThrownWhenModifierDoesNotReturnASelectObject()
 {
     $modifier = $this->getMock('\\Dewdrop\\Fields\\Helper\\SelectModifierInterface', array('modifySelect', 'setPrefix', 'getPrefix', 'matchesName'), array());
     $select = $this->model->select()->from('dewdrop_test_fruits');
     $modifier->expects($this->any())->method('modifySelect')->will($this->returnValue(null));
     $this->listing->registerSelectModifier($modifier);
     $this->listing->getModifiedSelect($this->getFields());
 }
Exemple #2
0
 /**
  * Get a \Dewdrop\Fields\Listing object that allows the component to
  * retrieve records for viewing.  The Listing handles applying user sorts
  * and filters.
  *
  * @return Listing
  */
 public function getListing()
 {
     if (!$this->listing) {
         $this->listing = new Listing($this->getPrimaryModel()->selectAdminListing(), $this->getPrimaryModel()->field('user_id'));
         $model = $this->getPrimaryModel();
         $columns = $model->getMetadata('columns');
         if (array_key_exists('deleted', $columns)) {
             $deletedRecordsModifier = new DeletedRecordsModifier($this->getRequest(), $model->field('deleted'));
             $this->listing->registerSelectModifier($deletedRecordsModifier);
         }
     }
     return $this->listing;
 }
 /**
  * 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;
 }
Exemple #4
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;
 }
Exemple #5
0
 /**
  * @param Fields $fields
  * @param Listing $listing
  * @param CsvCell $csvCellRenderer
  * @return void
  */
 public function renderWithGenerator(Fields $fields, Listing $listing, CsvCell $csvCellRenderer)
 {
     // Output CSV data
     $outputHandle = fopen('php://output', 'w');
     // Get the visible component fields
     $fields = $fields->getVisibleFields();
     // Render header
     fputcsv($outputHandle, $this->renderHeader($fields, $csvCellRenderer));
     // Render content
     $rowIndex = 0;
     foreach ($listing->fetchDataWithGenerator($fields) as $row) {
         $csvRow = [];
         $columnIndex = 0;
         foreach ($fields as $field) {
             $csvRow[] = $csvCellRenderer->getContentRenderer()->render($field, $row, $rowIndex, $columnIndex);
             $columnIndex++;
         }
         fputcsv($outputHandle, $csvRow);
         $rowIndex++;
     }
     // Close output handle
     fclose($outputHandle);
 }