/** * 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); }
/** * 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))); }
/** * 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']); } }
/** * 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; }
/** * 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()); } }