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