public function indexAction()
 {
     $this->view->searchForm = Editor_Forms_Search::getInstance();
     $request = $this->getRequest();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$this->view->searchForm->isValid($this->getRequest()->getPost())) {
         return;
     }
     $userForSearch = $this->view->searchForm->getUserForSearch();
     $loggedUser = OpenSKOS_Db_Table_Users::requireFromIdentity();
     $this->view->disableSearchProfileChanging = $loggedUser->disableSearchProfileChanging;
     $searchOptions = $this->view->searchForm->getValues();
     $detailedSearchOptions = $userForSearch->getSearchOptions(true);
     // Change search profile if needed and allowed. Change concept schemes if needed.
     //!TODO Refactor. That code evolved little ugly.
     if ($loggedUser['id'] == $userForSearch['id']) {
         $profileId = $this->getRequest()->getParam('searchProfileId', '');
         if ($detailedSearchOptions['searchProfileId'] != $profileId || !isset($detailedSearchOptions['searchProfileId'])) {
             $this->_switchUserToSearchProfile($loggedUser, $profileId);
             $detailedSearchOptions = $loggedUser->getSearchOptions();
             // Reset allowedConceptScheme
             if ($loggedUser->disableSearchProfileChanging) {
                 $searchOptions['allowedConceptScheme'] = array();
             }
         } elseif (!isset($searchOptions['conceptScheme']) || !isset($detailedSearchOptions['conceptScheme']) || $searchOptions['conceptScheme'] != $detailedSearchOptions['conceptScheme']) {
             if ($loggedUser->isAllowedToUseSearchProfile('custom')) {
                 // Change concept schemes selection
                 $detailedSearchOptions['searchProfileId'] = 'custom';
                 if (isset($searchOptions['conceptScheme'])) {
                     $detailedSearchOptions['conceptScheme'] = $searchOptions['conceptScheme'];
                 } else {
                     $detailedSearchOptions['conceptScheme'] = array();
                 }
                 $loggedUser->setSearchOptions($detailedSearchOptions);
             }
         }
     }
     // Select the concepts
     $apiClient = new Editor_Models_ApiClient();
     try {
         $conceptsRaw = $apiClient->searchConcepts(Editor_Forms_Search::mergeSearchOptions($searchOptions, $detailedSearchOptions));
     } catch (Exception $ex) {
         $this->getHelper('json')->sendJson(array('status' => 'error', 'message' => 'Bad query syntax.'));
     }
     $concepts = array();
     foreach ($conceptsRaw['data'] as $concept) {
         $concepts[] = $concept->toArray(array('uuid', 'uri', 'status', 'schemes', 'previewLabel', 'previewScopeNote'));
     }
     $this->getHelper('json')->sendJson(array('status' => 'ok', 'numFound' => $conceptsRaw['numFound'], 'concepts' => $concepts, 'conceptSchemeOptions' => $this->_getConceptSchemeOptions($searchOptions), 'profileOptions' => $this->_getProfilesSelectOptions()));
 }
 public function exportAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->_forward('index', 'index');
     }
     $user = $this->getCurrentUser();
     $export = new Editor_Models_Export();
     $export->set('userId', $user['id']);
     $export->set('format', $this->getRequest()->getPost('format'));
     $export->set('type', $this->getRequest()->getPost('type'));
     $export->set('maxDepth', $this->getRequest()->getPost('maxDepth'));
     // Currently this applies only for rtf export.
     $outputFileName = $this->getRequest()->getPost('fileName');
     if (empty($outputFileName)) {
         $export->set('outputFileName', uniqid());
     } else {
         $export->set('outputFileName', $outputFileName);
     }
     $fieldsToExport = $this->getRequest()->getPost('fieldsToExport');
     if (empty($fieldsToExport)) {
         $export->set('fieldsToExport', array());
     } else {
         $export->set('fieldsToExport', explode(',', $this->getRequest()->getPost('fieldsToExport')));
     }
     switch ($export->get('type')) {
         case 'concept':
             $export->set('conceptUuid', $this->getRequest()->getPost('additionalData'));
             // We have the uuid in additionalData.
             break;
         case 'search':
             $searchFormData = Zend_Json::decode($this->getRequest()->getPost('additionalData'), Zend_Json::TYPE_ARRAY);
             // We have the json encoded search form data in additionalData.
             $searchFormData = $this->_fixJsSerializedArrayData('conceptScheme', $searchFormData);
             $searchFormData = $this->_fixJsSerializedArrayData('allowedConceptScheme', $searchFormData);
             $userForSearch = OpenSKOS_Db_Table_Users::requireById($searchFormData['user']);
             $userSearchOptions = $userForSearch->getSearchOptions($user['id'] != $userForSearch['id']);
             $export->set('searchOptions', Editor_Forms_Search::mergeSearchOptions($searchFormData, $userSearchOptions));
             break;
     }
     if ($export->isTimeConsumingExport()) {
         $export->exportWithBackgroundJob();
         $this->_redirect($this->getRequest()->getPost('currentUrl'));
     } else {
         $fileContent = $export->exportToString();
         $fileDetails = $export->getExportFileDetails();
         $this->getHelper('file')->sendFileContent($fileDetails['fileName'], $fileContent, $fileDetails['mimeType']);
     }
 }