Beispiel #1
0
 /**
  * Creates a new or modifies an exisitng specification field (according to a passed parameters)
  *
  * @return JSONResponse Status and errors list if status was equal to failure
  */
 private function save(FilterGroup $filterGroup)
 {
     $this->getConfig();
     $errors = $this->validate($this->request->getValueArray(array('name', 'filters', 'specFieldID', 'ID')), $this->filtersConfig['languageCodes']);
     if (!$errors) {
         $filters = $this->request->get('filters', false);
         $filterGroup->loadRequestData($this->request);
         $filterGroup->specField->set(SpecField::getInstanceByID((int) $this->request->get('specFieldID')));
         $filterGroup->save();
         $specField = $filterGroup->specField->get();
         $specField->load();
         $specFieldType = $specField->type->get();
         $newIDs = array();
         if (!empty($filters) && !$specField->isSelector()) {
             $newIDs = $filterGroup->saveFilters($filters, $specFieldType, $this->filtersConfig['languageCodes']);
         }
         return new JSONResponse(array('id' => $filterGroup->getID(), 'newIDs' => $newIDs), 'success');
     } else {
         return new JSONResponse(array('errors' => $this->translateArray($errors)));
     }
 }
 private function getFiltersByGroup($array, FilterGroup $group)
 {
     $res = array();
     foreach ($array as $index => $filter) {
         if ($filter instanceof SpecificationFilterInterface) {
             if ($filter->getFilterGroup()->getID() === $group->getID()) {
                 $res[$index] = $filter;
             }
         }
     }
     return $res;
 }