예제 #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);
 }
예제 #2
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;
 }