/** * Assign icon to a scheme. * */ public function assignIconAction() { $this->_requireAccess('editor.concept-schemes', 'manage-icons', self::RESPONSE_TYPE_JSON); $schemeUuid = $this->getRequest()->getParam('schemeUuid'); $iconToAssign = $this->getRequest()->getParam('iconFile'); $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor'); if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['uploadPath'])) { $iconsUploadPath = APPLICATION_PATH . $editorOptions['schemeIcons']['uploadPath'] . '/' . $this->_tenant->code; } else { $iconsUploadPath = APPLICATION_PATH . Editor_Forms_UploadIcon::DEFAULT_UPLOAD_PATH . '/' . $this->_tenant->code; } if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['assignPath'])) { $iconsAssignPath = APPLICATION_PATH . $editorOptions['schemeIcons']['assignPath'] . '/' . $this->_tenant->code; } else { $iconsAssignPath = APPLICATION_PATH . Editor_Forms_UploadIcon::DEFAULT_ASSIGN_PATH . '/' . $this->_tenant->code; } if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['extension'])) { $iconsExtension = $editorOptions['schemeIcons']['extension']; } else { $iconsExtension = 'png'; } copy($iconsUploadPath . '/' . $iconToAssign, $iconsAssignPath . '/' . $schemeUuid . '.' . $iconsExtension); // Clears the schemes cache after a scheme icon is changed. OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY); $this->getHelper('json')->sendJson(array('status' => 'ok', 'result' => array('newIconPath' => Editor_Models_ConceptScheme::buildIconPath($schemeUuid)))); }
/** * 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']); } }
$model = new OpenSKOS_Db_Table_Jobs(); // Gets new DB object to prevent connection time out. $job = $model->find($job->id)->current(); // Gets new DB object to prevent connection time out. fwrite(STDERR, $job->id . ': ' . $e->getMessage() . "\n"); $job->error($e->getMessage())->finish()->save(); } break; case OpenSKOS_Db_Table_Row_Job::JOB_TASK_DELETE_CONCEPT_SCHEME: $job->start()->save(); try { $response = Api_Models_Concepts::factory()->getConcepts('uuid:' . $job->getParam('uuid')); if (!isset($response['response']['docs']) || 1 !== count($response['response']['docs'])) { throw new Zend_Exception('The requested concept scheme was not found'); } $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept(array_shift($response['response']['docs']))); $conceptScheme->delete(true, $job['user']); // Clears the schemes cache after the scheme is removed. OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY); $model = new OpenSKOS_Db_Table_Jobs(); // Gets new DB object to prevent connection time out. $job = $model->find($job->id)->current(); // Gets new DB object to prevent connection time out. $job->finish()->save(); } catch (Zend_Exception $e) { $model = new OpenSKOS_Db_Table_Jobs(); // Gets new DB object to prevent connection time out. $job = $model->find($job->id)->current(); // Gets new DB object to prevent connection time out. fwrite(STDERR, $job->id . ': ' . $e->getMessage() . "\n"); $job->error($e->getMessage())->finish()->save();
/** * Get all ConceptScheme documents for the current tenant. * The result is once cached in Zend_Registry and retrieved from there when search again. * * @param string $uri, optional If specified - selects the specified concept scheme * @param string $tenant, optional If specified concept schemes for this tenant will be returned. If not - concept schemes for current tenant. * @return array An array of concept scheme documents data, or the single concept scheme data if uri is specified. */ public function getConceptSchemes($uri = null, $tenant = null, $inCollections = array()) { if (null === $tenant) { $tenant = $this->_getCurrentTenant()->code; } if (null === $inCollections) { $inCollections = array(); } $conceptSchemes = OpenSKOS_Cache::getCache()->load(self::CONCEPT_SCHEMES_CACHE_KEY); if ($conceptSchemes === false) { $conceptSchemes = array(); } $schemesCacheKey = $tenant . implode('', $inCollections); if (!isset($conceptSchemes[$schemesCacheKey])) { $query = 'class:ConceptScheme tenant:' . $tenant; if (!empty($inCollections)) { if (count($inCollections) == 1) { $query .= sprintf(' collection:%s', $inCollections[0]); } else { $query .= sprintf(' collection:(%s)', implode(' OR ', $inCollections)); } } $response = Api_Models_Concepts::factory()->setQueryParams(array('rows' => self::DEFAULT_MAX_ROWS_LIMIT))->getConcepts($query); $response = $response['response']; $conceptSchemes[$schemesCacheKey] = array(); if ($response['numFound'] > 0) { foreach ($response['docs'] as $doc) { $doc['iconPath'] = Editor_Models_ConceptScheme::buildIconPath($doc['uuid'], $this->_tenant); $conceptSchemes[$schemesCacheKey][] = $doc; } } usort($conceptSchemes[$schemesCacheKey], array('Editor_Models_ConceptScheme', 'compareDocs')); OpenSKOS_Cache::getCache()->save($conceptSchemes, self::CONCEPT_SCHEMES_CACHE_KEY); } if (null !== $uri) { if (!is_array($uri)) { $uri = array($uri); } $schemes = array(); foreach ($conceptSchemes[$schemesCacheKey] as $schemeLine) { if (isset($schemeLine['uri']) && in_array($schemeLine['uri'], $uri)) { $schemes[$schemeLine['uri']] = $schemeLine; } } return $schemes; } return $conceptSchemes[$schemesCacheKey]; }
/** * Parses all the form data and prepares it for loading into the model. * * @param array $formData * @return $sextraData */ public function transformFormData(array &$formData) { $formMapping = $this->_getFormMapping(); $extraData = array(); $apiClient = new Editor_Models_ApiClient(); $apiModelConcepts = Api_Models_Concepts::factory(); foreach ($formData as $key => $value) { if (in_array($key, $formMapping['languageFields'])) { foreach ($value as $languageCode => $perLanguageValues) { if (!empty($languageCode)) { $formData[$key][$languageCode] = $perLanguageValues[0]; // These fields always contain array of one element because the multitext fields are used. } else { unset($formData[$key][$languageCode]); } } } else { if (in_array($key, $formMapping['uuid2uri'])) { if (is_array($formData[$key]) && array_filter($formData[$key])) { foreach ($formData[$key] as $position => $value) { if (!empty($value)) { $concept = $apiModelConcepts->getConcept($value); if (null !== $concept) { $formData[$key][$position] = $concept['uri']; } else { unset($formData[$key][$position]); } } else { unset($formData[$key][$position]); } } } else { unset($formData[$key]); } } } } foreach ($formData as $key => $value) { if (in_array($key, $formMapping['extraFields'])) { if ($key == 'uriCode' || $key == 'uriBase') { $extraData['uri'] = Editor_Models_ConceptScheme::buildUri($formData['uriCode'], $formData['uriBase']); unset($formData['uriCode']); unset($formData['uriBase']); continue; } $extraData[$key] = $formData[$key]; unset($formData[$key]); } } return $extraData; }
/** * Validate if the scheme is unique in the given tenant. * If not - checks if it should be perged. If not adds it to the _duplicateConceptSchemes and return false. * * @param OpenSKOS_Solr_Document $schemeDoc * @param int $byUserId, optional * @return bool If the document can be inserted */ protected function handleUniqueConceptScheme(OpenSKOS_Solr_Document $schemeDoc, $byUserId = null) { $canInsertDocument = true; $schemeUri = $schemeDoc->offsetGet('uri'); $schemesCheck = $this->_solr()->limit(1)->search('uri:"' . $schemeUri[0] . '" ' . 'AND tenant:"' . $this->getOpt('tenant') . '" ' . 'AND deleted:false ' . 'AND collection:' . $this->getCollection()->id); if ($schemesCheck['response']['numFound'] > 0) { if (!$this->getOpt('purge')) { $this->_duplicateConceptSchemes[] = $schemeUri[0]; $canInsertDocument = false; } else { $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept(array_shift($schemesCheck['response']['docs']))); $conceptScheme->delete(true, $byUserId); } } return $canInsertDocument; }