public function isValid($data)
 {
     // If the user is disabled to change search profile he can not change any search settings.
     if (OpenSKOS_Db_Table_Users::requireFromIdentity()->disableSearchProfileChanging) {
         $this->addError(_('You are not allowed to change your detailed search options.'));
     }
     return parent::isValid($data);
 }
 public function indexAction()
 {
     $user = OpenSKOS_Db_Table_Users::requireFromIdentity();
     $apiClient = new Editor_Models_ApiClient();
     $this->view->assign('conceptSchemes', $apiClient->getAllConceptSchemeUriTitlesMap());
     $this->view->assign('conceptSchemesId', $apiClient->getConceptSchemeMap('uri', 'uuid'));
     $this->view->assign('disableSearchProfileChanging', $user->disableSearchProfileChanging);
     $this->view->assign('exportForm', Editor_Forms_Export::getInstance());
     $this->view->assign('deleteForm', Editor_Forms_Delete::getInstance());
     $this->view->assign('changeStatusForm', Editor_Forms_ChangeStatus::getInstance());
     $this->view->assign('historyData', $user->getUserHistory());
     $this->view->assign('searchForm', Editor_Forms_Search::getInstance());
 }
Example #3
0
 /**
  * @return Editor_Forms_Search
  */
 public static function factory()
 {
     // Gets the user which should be used for getting search options.
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if (null !== $request->getPost('user')) {
         $model = new OpenSKOS_Db_Table_Users();
         $userForSearch = $model->find($request->getPost('user'))->current();
         if (null === $userForSearch) {
             throw new Zend_Controller_Action_Exception('User not found', 404);
         }
     } else {
         $userForSearch = OpenSKOS_Db_Table_Users::requireFromIdentity();
     }
     return new Editor_Forms_Search(array('UserForSearch' => $userForSearch));
 }
 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');
     }
 }