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());
 }
 /**
  * Lists all concept schemes.
  */
 public function indexAction()
 {
     $this->_requireAccess('editor.concept-schemes', 'index', self::RESPONSE_TYPE_HTML);
     // Clears the schemes cache when we start managing them.
     OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY);
     $this->view->uploadedIcons = $this->_getUploadedIcons();
     $this->view->conceptSchemes = Editor_Models_ApiClient::factory()->getConceptSchemes();
     $this->view->conceptSchemesWithDeleteJobs = $this->_getConceptSchemesWithDeleteJob();
     $user = OpenSKOS_Db_Table_Users::fromIdentity();
     $modelCollections = new OpenSKOS_Db_Table_Collections();
     $this->view->collectionsMap = $modelCollections->getIdToTitleMap($user->tenant);
 }
Esempio n. 3
0
 /**
  * Checks does a concept with the same pref label exist.
  * 
  */
 public function checkPrefLabelAction()
 {
     $prefLabel = $this->getRequest()->getPost('prefLabel');
     $count = Editor_Models_ApiClient::factory()->getConceptsCountByPrefLabel($prefLabel);
     $this->getHelper('json')->sendJson(array('status' => 'ok', 'result' => array('doExist' => $count > 0)));
 }
 /**
  * @return Editor_Forms_SearchOptions
  */
 protected function buildConceptSchemes()
 {
     $apiClient = new Editor_Models_ApiClient();
     $conceptSchemes = $apiClient->getAllConceptSchemeUriTitlesMap();
     $this->addElement('multiCheckbox', 'conceptScheme', array('label' => _('Concept schemes'), 'multiOptions' => $conceptSchemes));
     return $this;
 }
Esempio n. 5
0
 /**
  * Gets an instance of the api client. Sets the api client tenant.
  * 
  * return Editor_Models_ApiClient
  */
 protected function _getApiClientInstance()
 {
     if (null === $this->_apiClient) {
         $user = OpenSKOS_Db_Table_Users::requireById($this->get('userId'));
         $tenant = OpenSKOS_Db_Table_Tenants::fromCode($user->tenant);
         $this->_apiClient = Editor_Models_ApiClient::factory();
         $this->_apiClient->setTenant($tenant);
     }
     return $this->_apiClient;
 }
Esempio n. 6
0
 /**
  * Removes a concept uri from ConceptScheme resource fields.
  * @param string $schemeUri
  */
 public function removeFromScheme($schemeUri)
 {
     $conceptSchemesDocs = Editor_Models_ApiClient::factory()->getConceptSchemes($schemeUri, $this['tenant']);
     if (!empty($conceptSchemesDocs)) {
         $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept(array_shift($conceptSchemesDocs)));
         $conceptScheme->removeTopConcept($this['uri']);
     }
 }
Esempio n. 7
0
 /**
  * Get a relation description in a format that allows us to send it directly to the form.
  * @param string $relation
  * @param string $schemeUuid
  * @param string $schemeUri
  */
 protected function _getRelationToForm($relation, $schemeUuid, $schemeUri)
 {
     $apiClient = new Editor_Models_ApiClient();
     $relationData = array('uuid' => $schemeUuid, 'concepts' => array());
     if (in_array($relation, self::$classes['SemanticRelations'])) {
         $callback = array($this, 'getAllRelations');
     } else {
         $callback = array($this, 'getAllMappings');
     }
     $currentLanguage = Zend_Registry::get('Zend_Locale')->getLanguage();
     $concepts = $this->getRelationsByField($relation, $schemeUri, $callback, true);
     if (empty($concepts)) {
         return array();
     }
     $schemesData = $apiClient->getConceptSchemes();
     foreach ($concepts as $concept) {
         $previewLabel = $concept->getMlField('prefLabel', $currentLanguage);
         $isInternal = $this->isInternalRelation($concept['uri'], $relation);
         if (!$isInternal) {
             $previewLabel .= '*';
         }
         $shemes = array();
         foreach ($schemesData as $schemeData) {
             if (in_array($schemeData['uri'], $concept['inScheme'])) {
                 $shemes[$schemeData['uri']] = $schemeData;
             }
         }
         $relationData['concepts'][] = array('concept' => array('uuid' => $concept['uuid'], 'uri' => $concept['uri'], 'previewLabel' => $previewLabel, 'remove' => $isInternal), 'schemes' => $shemes);
     }
     return $relationData;
 }
Esempio n. 8
0
 /**
  * Updates all concepts that must be included (related) to the concept scheme.
  * For each of them the inScheme field is updated and if they are part of hasTopConcept - the topConceptOf field is updated.
  *
  * !NOTE Currently this method is not used.
  * !TODO Check for tenant.
  *
  * @param array $includeConcepts Array of uris of concepts to be included in scheme.
  */
 protected function updateRelatedConcepts($includeConcepts)
 {
     // Old related concepts will be used for removing from that scheme if not part of the $newRelatedConcepts.
     $oldRelatedConcepts = Editor_Models_ApiClient::factory()->getConceptsInScheme($this['uri']);
     // All concepts - top or regular will be added to the scheme (by updating theirs inScheme field).
     $newRelatedConceptsUris = array_unique(array_merge($this['hasTopConcept'], $includeConcepts));
     $newRelatedConcepts = Api_Models_Concepts::factory()->getEnumeratedConceptsMapByUris($newRelatedConceptsUris);
     foreach ($newRelatedConcepts as $concept) {
         $conceptData = $concept->getData();
         if (!isset($conceptData['inScheme'])) {
             $conceptData['inScheme'] = array();
         }
         if (!isset($conceptData['topConceptOf'])) {
             $conceptData['topConceptOf'] = array();
         }
         $needsUpdate = false;
         if (!in_array($this['uri'], $conceptData['inScheme'])) {
             $conceptData['inScheme'][] = $this['uri'];
             $needsUpdate = true;
         }
         if (in_array($conceptData['uri'], $this['hasTopConcept']) && !in_array($this['uri'], $conceptData['topConceptOf'])) {
             $conceptData['topConceptOf'][] = $this['uri'];
             $needsUpdate = true;
         }
         if ($needsUpdate) {
             $concept->setConceptData($conceptData);
             $concept->save($concept->getCurrentRequiredData());
         }
     }
     // Remove scheme from the inScheme field of concepts which should not be related anymore.
     $conceptsToRemove = array_udiff($oldRelatedConcepts, $newRelatedConcepts, array('Api_Models_Concept', 'compare'));
     foreach ($conceptsToRemove as $concept) {
         $conceptData = $concept->getData();
         $conceptData['inScheme'] = array_diff($conceptData['inScheme'], array($this['uri']));
         $conceptData['topConceptOf'] = array_diff($conceptData['topConceptOf'], array($this['uri']));
         $concept->setConceptData($conceptData);
         $concept->save($concept->getCurrentRequiredData());
     }
 }
Esempio n. 9
0
 protected function buildAllowedConceptScheme()
 {
     $loggedUser = OpenSKOS_Db_Table_Users::requireFromIdentity();
     $userForSearch = $this->getUserForSearch();
     $userOptions = $userForSearch->getSearchOptions($loggedUser['id'] != $userForSearch['id']);
     $allowedConceptSchemes = array();
     if (isset($userOptions['searchProfileId'])) {
         $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
         $profile = $profilesModel->find($userOptions['searchProfileId'])->current();
         if (null !== $profile) {
             $profileOptions = $profile->getSearchOptions();
             $apiClient = new Editor_Models_ApiClient();
             $inCollections = array();
             if (isset($profileOptions['collections'])) {
                 $inCollections = $profileOptions['collections'];
             }
             $conceptSchemesInCollections = $apiClient->getAllConceptSchemeUriTitlesMap(null, $inCollections);
             if (!empty($profileOptions['conceptScheme'])) {
                 foreach ($profileOptions['conceptScheme'] as $allowedConceptSchemeUri) {
                     $allowedConceptSchemes[$allowedConceptSchemeUri] = $conceptSchemesInCollections[$allowedConceptSchemeUri];
                 }
             } else {
                 // If we don't have concept schemes checked - then all concept schemes in the collections are allowed.
                 $allowedConceptSchemes = $conceptSchemesInCollections;
             }
         }
     }
     $this->addElement('multiCheckbox', 'allowedConceptScheme', array('label' => _('Concept scheme'), 'multiOptions' => $allowedConceptSchemes));
     return $this;
 }
 public function showFormAction()
 {
     $this->_helper->_layout->setLayout('editor_modal_box');
     $user = OpenSKOS_Db_Table_Users::requireFromIdentity();
     if ((bool) $this->getRequest()->getParam('reInitForm', false)) {
         $this->view->form = new Editor_Forms_SearchOptions();
     } else {
         $this->view->form = Editor_Forms_SearchOptions::getInstance();
     }
     $this->view->form->setAction($this->getFrontController()->getRouter()->assemble(array('controller' => 'search', 'action' => 'set-options')));
     $profilesModel = new OpenSKOS_Db_Table_SearchProfiles();
     if ((bool) $this->getRequest()->getParam('resetDefaults', false) || (bool) $this->getRequest()->getParam('switchProfile', false)) {
         // If param searchProfileId is set - loads the form for that profile.
         $profileId = $this->getRequest()->getParam('searchProfileId', '');
         if (!empty($profileId)) {
             $profile = $profilesModel->find($profileId);
             if ($profile->count() > 0) {
                 $profileSearchOptions = $profile->current()->getSearchOptions();
                 $profileSearchOptions = array_merge($profileSearchOptions, array('searchProfileId' => $profileId, 'switchProfile' => false));
                 $this->view->form->populate($profileSearchOptions);
             }
         } else {
             $this->view->form->populate(Editor_Forms_SearchOptions::getDefaultSearchOptions());
         }
     } else {
         // If the form is opened (not submited with errors) populate it with the data from the user session.
         if (!$this->getRequest()->isPost()) {
             $options = $user->getSearchOptions();
             if (empty($options)) {
                 $options = Editor_Forms_SearchOptions::getDefaultSearchOptions();
             }
             $this->view->form->populate($options);
         }
     }
     // Switch profile is set to true only from js
     $this->view->form->getElement('switchProfile')->setValue(0);
     // Check is editing and deleting of the selected profile allowed for the current user.
     $profile = $profilesModel->find($this->view->form->getElement('searchProfileId')->getValue());
     if ($profile->count() > 0) {
         if (!($user->isAllowed('editor.manage-search-profiles', null) || $user->id == $profile->current()->creatorUserId)) {
             $this->view->form->getElement('save')->setAttrib('class', 'do-not-show');
             $this->view->form->getElement('delete')->setAttrib('class', 'do-not-show');
         }
     } else {
         $this->view->form->getElement('save')->setAttrib('class', 'do-not-show');
         $this->view->form->getElement('delete')->setAttrib('class', 'do-not-show');
     }
     // Send profiles options to refresh the search profile selector.
     $this->view->assign('conceptSchemeOptions', $this->_getConceptSchemeOptions());
     $this->view->assign('profilesOptions', $this->_getProfilesSelectOptions());
     // Set concept scheme - collections map.
     $apiClient = new Editor_Models_ApiClient();
     $conceptSchemes = $apiClient->getConceptSchemeMap('uri', 'collection');
     $collectionsConceptSchemesMap = array_fill_keys(array_values($conceptSchemes), array());
     foreach ($conceptSchemes as $conceptSchemeUri => $conceptSchemeCollection) {
         $collectionsConceptSchemesMap[$conceptSchemeCollection][] = $conceptSchemeUri;
     }
     $this->view->assign('collectionsConceptSchemesMap', $collectionsConceptSchemesMap);
 }