public function setOptionsAction() { $form = Editor_Forms_SearchOptions::getInstance(); $request = $this->getRequest(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return $this->_forward('show-form'); } $user = OpenSKOS_Db_Table_Users::requireFromIdentity(); // Reset defaults if ((bool) $this->getRequest()->getParam('resetDefaults', false)) { $defaultProfile = $user->getFirstDefaultSearchProfile(); if ($defaultProfile !== null) { return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => $defaultProfile->id)); } else { return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => '')); } } // Switch profile. if ((bool) $this->getRequest()->getParam('switchProfile', false)) { return $this->_forward('show-form', 'search', 'editor'); } // Save options or profile $options = Editor_Forms_SearchOptions::formValues2Options($this->getRequest()->getPost()); $profilesModel = new OpenSKOS_Db_Table_SearchProfiles(); // Save profile as new one. if ((bool) $this->getRequest()->getParam('saveAs', false)) { $profileName = $this->getRequest()->getParam('searchProfileNameSaveAs', ''); if (empty($profileName)) { $form->getElement('searchProfileNameSaveAs')->addError(_('Please fill a profile name.')); return $this->_forward('show-form'); } $newProfileId = $profilesModel->addNew($profileName, $options, $user->id, $user->tenant); // Switch the form to the new profile return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => $newProfileId, 'switchProfile' => true, 'reInitForm' => true)); } // Save or delete existing profile. $profileId = intval($this->getRequest()->getParam('searchProfileId', '')); $profile = $profilesModel->find($profileId)->current(); if (((bool) $this->getRequest()->getParam('save', false) || (bool) $this->getRequest()->getParam('delete', false)) && !empty($profileId)) { if (!($user->isAllowed('editor.manage-search-profiles', null) || $user->id == $profile->creatorUserId)) { $form->addError(_('You are not allowed to edit that search profile.')); return $this->_forward('show-form'); } if ((bool) $this->getRequest()->getParam('save', false)) { $profileName = $this->getRequest()->getParam('searchProfileName', ''); if (empty($profileName)) { $form->getElement('searchProfileName')->addError(_('Please fill a profile name.')); return $this->_forward('show-form'); } $profile->name = $profileName; $profile->setSearchOptions($options); $profile->save(); return $this->_forward('show-form', 'search', 'editor', array('switchProfile' => true, 'reInitForm' => true)); } if ((bool) $this->getRequest()->getParam('delete', false)) { $profile->delete(); return $this->_forward('show-form', 'search', 'editor', array('reInitForm' => true)); } } // Save options for the user if ((bool) $this->getRequest()->getParam('ok', false)) { if (null !== $profile) { $originalOptions = $profile->getSearchOptions(); $originalOptions = Editor_Forms_SearchOptions::formValues2Options($originalOptions); // Make sure that there are no any old or unneeded options in the profile. $originalOptions['searchProfileId'] = $profile->id; } else { $originalOptions = Editor_Forms_SearchOptions::getDefaultSearchOptions(); } $checkOptions = array_merge(Editor_Forms_SearchOptions::getDefaultSearchOptions(), $options); if ($checkOptions != $originalOptions) { $options['searchProfileId'] = 'custom'; } $user->setSearchOptions($options); return $this->_forward('set-options-success'); } }