示例#1
0
 public function testCanFilterWhenGettingVisibleFields()
 {
     /* @var $field Field */
     foreach ($this->fields as $field) {
         $field->setVisible(true);
     }
     $this->assertEquals(4, count($this->fields->getVisibleFields()));
     $filter = new CallbackFilter(function (Field $field) {
         return 'visible' === $field->getId();
     });
     $this->assertEquals(1, count($this->fields->getVisibleFields($filter)));
 }
示例#2
0
 /**
  * Build a Fields object that can be used for displaying or editing
  * subscriptions.
  *
  * @todo Refactor this into a separate class.
  *
  * @param string $editUrl
  * @param Fields $componentFields
  * @return Fields
  */
 public function buildFields($editUrl, Fields $componentFields)
 {
     $fields = new Fields();
     $fields->add('recipients')->setLabel('Recipients')->setNote('Enter one or more email addresses separated by commas.')->setVisible(true)->assignHelperCallback('TableCell.Content', function (TableCellHelper $helper, array $rowData) use($editUrl) {
         return $helper->getView()->escapeHtml($this->renderRecipients($rowData['dewdrop_notification_subscription_id']));
     })->setEditable(true)->assignHelperCallback('EditControl.Control', function ($helper, View $view) {
         return $view->inputText('recipients', $this->renderRecipients($view->getRequest()->getQuery('dewdrop_notification_subscription_id')), 'form-control');
     })->assignHelperCallback('InputFilter', function ($helper) {
         $input = new Input('recipients');
         $input->setAllowEmpty(false);
         return $input;
     })->add($this->field('dewdrop_notification_frequency_id'))->add('fields')->setLabel('Which fields would you like to include in the notification emails?')->setEditable(true)->assignHelperCallback('EditControl.Control', function ($helper, View $view) use($componentFields) {
         $options = array();
         foreach ($componentFields->getVisibleFields() as $id => $field) {
             $options[$id] = $field->getLabel();
         }
         return $view->checkboxList('fields', $options, $this->getSelectedFields($view->getRequest()->getQuery('dewdrop_notification_subscription_id'), $options));
     })->assignHelperCallback('InputFilter', function ($helper) {
         $input = new Input('fields');
         $input->setAllowEmpty(false);
         return $input;
     });
     return $fields;
 }
示例#3
0
 /**
  * Given the supplied $fields and \Dewdrop\Request object, find the field
  * referenced in the query string and apply its sort callback to the query.
  *
  * @param Fields $fields
  * @param Select $select
  * @throws \Dewdrop\Fields\Exception
  * @return Select
  */
 public function modifySelect(Fields $fields, Select $select)
 {
     $this->sortedField = null;
     $this->sortedDirection = null;
     /* @var $field FieldInterface */
     foreach ($fields->getSortableFields() as $field) {
         if ($field->getQueryStringId() === urlencode($this->request->getQuery($this->prefix . 'sort'))) {
             if ('ASC' === $this->defaultDirection) {
                 $dir = 'DESC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'DESC' : 'ASC';
             } else {
                 $dir = 'ASC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'ASC' : 'DESC';
             }
             $select = call_user_func($this->getFieldAssignment($field), $select, $dir);
             if (!$select instanceof Select) {
                 throw new Exception('Your SelectSort callback must return the modified Select object.');
             }
             $this->sortedField = $field;
             $this->sortedDirection = $dir;
             return $select;
         }
     }
     // Sort by the first visible field that is also sortable, if no other sort was performed
     foreach ($fields->getVisibleFields() as $field) {
         if ($field->isSortable() && (null === $this->defaultField || $this->defaultField === $field)) {
             $this->sortedField = $field;
             $this->sortedDirection = $this->defaultDirection;
             return call_user_func($this->getFieldAssignment($field), $select, $this->defaultDirection);
         }
     }
     return $select;
 }
 /**
  * Provide a Fields object with all the available fields the user can select
  * from along with a Fields object containing only those that have been
  * selected to be displayed already.  The helper will use these two Fields
  * objects to render a modal that enables a user to check/un-check columns
  * they'd like to have displayed.
  *
  * @param Fields $available
  * @param Fields $visible
  * @param string $actionUrl
  * @param boolean $filterByUser
  * @param string $id
  * @return string
  */
 public function direct(Fields $available, Fields $visible, $actionUrl, $filterByUser = false, $id = null)
 {
     return $this->partial('bootstrap-columns-modal.phtml', array('id' => $id ?: 'adjust-columns-modal', 'actionUrl' => $actionUrl, 'visible' => $visible->getVisibleFields(), 'available' => $available->getVisibleFields(), 'filterByUser' => $filterByUser));
 }
 /**
  * Render the supplied non-grouped fields in a Bootstrap table.
  *
  * @param Fields $fields
  * @param array $data
  * @param Renderer $renderer
  * @return string
  */
 protected function renderFields(Fields $fields, array $data, Renderer $renderer)
 {
     $rowIndex = 0;
     $out = '<div class="table-responsive">';
     $out .= '<table class="table">';
     foreach ($fields->getVisibleFields() as $field) {
         $out .= '<tr>';
         $content = $renderer->getContentRenderer()->render($field, $data, $rowIndex, 1);
         $classNames = $renderer->getTdClassNamesRenderer()->render($field, $data, $rowIndex, 1);
         $header = $renderer->getHeaderRenderer()->render($field);
         if (false !== stripos($content, '<table ')) {
             $out .= $this->renderTableContentInPanel($header, $classNames, $content);
         } else {
             $out .= $this->renderHeaderAndContent($header, $classNames, $content);
         }
         $out .= '</tr>';
         $rowIndex += 1;
     }
     $out .= '</table>';
     $out .= '</div>';
     return $out;
 }