예제 #1
0
 /**
  * Remove a field from this group and the GroupedFields container.
  *
  * @param string $id
  * @return Group
  */
 public function remove($id)
 {
     // This check ensures we don't enter an infinite loop because the set will try to remove from the group as well
     if ($this->groupedFields->has($id)) {
         $this->groupedFields->remove($id);
     }
     return parent::remove($id);
 }
 /**
  * Render the supplied GroupedFields object in a Bootstrap tab view.
  *
  * @param GroupedFields $fields
  * @param array $data
  * @param Renderer $renderer
  * @param integer $viewIndex
  * @return string
  */
 protected function renderGroups(GroupedFields $fields, array $data, Renderer $renderer, $viewIndex = null)
 {
     static $globalGroupedViewCount = 0;
     $output = '<ul class="nav nav-tabs">';
     foreach ($fields->getGroups() as $index => $group) {
         if (count($group)) {
             $output .= sprintf('<li%s><a href="#details_%d_group_%d" data-toggle="tab">%s</a></li>', 0 === $index ? ' class="active"' : '', $this->view->escapeHtmlAttr(null !== $viewIndex ? $viewIndex : $globalGroupedViewCount), $index, $this->view->escapeHtml($group->getTitle()));
         }
     }
     $output .= '</ul>';
     $output .= '<div class="tab-content">';
     foreach ($fields->getGroups() as $index => $group) {
         if (count($group)) {
             $output .= sprintf('<div class="tab-pane-edit tab-pane fade%s" id="details_%d_group_%d">', 0 === $index ? ' in active' : '', $this->view->escapeHtmlAttr(null !== $viewIndex ? $viewIndex : $globalGroupedViewCount), $index);
             $output .= $this->renderFields($group, $data, $renderer);
             $output .= '</div>';
         }
     }
     $output .= '</div>';
     $globalGroupedViewCount += 1;
     return $output;
 }
예제 #3
0
 /**
  * Render a GroupedFields object using a Bootstrap tab view.
  *
  * @param GroupedFields $groupedFields
  * @param InputFilter $inputFilter
  * @param Renderer $renderer
  * @return string
  */
 public function renderGroupedFields(GroupedFields $groupedFields, InputFilter $inputFilter, Renderer $renderer)
 {
     $output = '<ul class="nav nav-tabs">';
     /* @var $group Group */
     foreach ($groupedFields->getGroups() as $index => $group) {
         if (count($group)) {
             $output .= sprintf('<li%s><a href="#group_%d" data-toggle="tab">%s</a></li>', 0 === $index ? ' class="active"' : '', $index, $this->view->escapeHtml($group->getTitle()));
         }
     }
     $output .= '</ul>';
     $output .= '<div class="tab-content">';
     $fieldPosition = 0;
     foreach ($groupedFields->getGroups() as $index => $group) {
         if (count($group)) {
             $output .= sprintf('<div class="tab-pane-edit tab-pane fade%s" id="group_%d">', 0 === $index ? ' in active' : '', $index);
             $output .= $this->renderFields($group, $inputFilter, $renderer, $fieldPosition);
             $output .= '</div>';
             $fieldPosition += count($group);
         }
     }
     $output .= '</div>';
     return $output;
 }
예제 #4
0
 /**
  * Apply the filter to the supplied set of fields.  In return, you'll end
  * up with a \Dewdrop\Fields\GroupedFields object that reflects the sort
  * order and grouping preferences contained in this filter.  You can use
  * that object either as a normal \Dewdrop\Fields object or you can call
  * getGroups() on it to get the fields back in their assigned groups.
  *
  * @param Fields $currentFields
  * @return GroupedFields
  */
 public function apply(Fields $currentFields)
 {
     if (!$this->loadedDbData) {
         $this->loadedDbData = $this->load();
     }
     $groupedFields = new GroupedFields([], $currentFields->getUser());
     foreach ($this->loadedDbData as $fieldConfig) {
         // Ungrouped fields come after grouped fields
         if (!$fieldConfig['group_id']) {
             continue;
         }
         $fieldId = $fieldConfig['field_id'];
         $groupId = $fieldConfig['group_id'];
         if ($currentFields->has($fieldId)) {
             if (!$groupedFields->hasGroup($groupId)) {
                 $group = $groupedFields->addGroup($groupId);
                 $group->setTitle($fieldConfig['group_title']);
             }
             $groupedFields->getGroup($groupId)->add($currentFields->get($fieldId));
         }
     }
     $ungrouped = $groupedFields->addGroup('ungrouped');
     $ungrouped->setTitle('Other');
     foreach ($this->loadedDbData as $fieldConfig) {
         if (!$fieldConfig['group_id']) {
             $id = $fieldConfig['field_id'];
             if ($currentFields->has($id)) {
                 $ungrouped->add($currentFields->get($id));
             }
         }
     }
     foreach ($currentFields as $field) {
         if (!$groupedFields->has($field->getId())) {
             $ungrouped->add($field);
         }
     }
     return $groupedFields;
 }