/**
  * 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);
 }
 public function getAction()
 {
     $modelTenant = new OpenSKOS_Db_Table_Tenants();
     $id = $this->getRequest()->getParam('id');
     list($tenantCode, $collectionCode) = explode(':', $id);
     $tenant = $modelTenant->find($tenantCode)->current();
     if (null === $tenant) {
         throw new Zend_Controller_Action_Exception('Insitution `' . $tenantCode . '` not found', 404);
     }
     $modelCollections = new OpenSKOS_Db_Table_Collections();
     $collection = $tenant->findDependentRowset('OpenSKOS_Db_Table_Collections', null, $modelCollections->select()->where('code=?', $collectionCode))->current();
     if (null === $collection) {
         throw new Zend_Controller_Action_Exception('Collection `' . $id . '` not found', 404);
     }
     $context = $this->_helper->contextSwitch()->getCurrentContext();
     if ($context == 'json' || $context == 'jsonp') {
         foreach ($collection as $key => $val) {
             $this->view->assign($key, $val);
         }
     } else {
         $this->view->assign('tenant', $tenant);
         $this->view->assign('collection', $collection);
     }
 }
 /**
  * @return Editor_Forms_SearchOptions
  */
 protected function buildCollections()
 {
     $modelCollections = new OpenSKOS_Db_Table_Collections();
     $collections = $modelCollections->fetchAll($modelCollections->select()->where('tenant = ?', $this->_getCurrentTenant()->code));
     $collectionsOptions = array();
     foreach ($collections as $collection) {
         $collectionsOptions[$collection->id] = $collection->dc_title;
     }
     $this->addElement('multiselect', 'collections', array('label' => _('Collections'), 'multiOptions' => $collectionsOptions));
     return $this;
 }
Beispiel #4
0
 */
require_once 'Zend/Console/Getopt.php';
$opts = array('help|?' => 'Print this usage message', 'env|e=s' => 'The environment to use (defaults to "production")', 'collection|c=s' => 'Collection id or code (required)', 'tenant|t=s' => 'Tenant code (required if a collection code is used)', 'metadataPrefix=s' => 'The OAI `metadataPrefix` argument (defaults to `oai_rdf`)', 'set=s' => 'The OAI `set` argument', 'from=s' => 'The OAI `from` argument (defaults to the last date from Solr, use null to harvest all records)', 'until=s' => 'The OAI `until` argument (defaults to null)', 'query|q=s' => 'Optional Solr query', 'rows|r' => 'Optional maximum number of records to harvest per page', 'verbose|v' => 'Show debug information');
try {
    $OPTS = new Zend_Console_Getopt($opts);
} catch (Zend_Console_Getopt_Exception $e) {
    fwrite(STDERR, $e->getMessage() . "\n");
    echo str_replace('[ options ]', '[ options ] action', $OPTS->getUsageMessage());
    exit(1);
}
if ($OPTS->help) {
    echo str_replace('[ options ]', '[ options ] action', $OPTS->getUsageMessage());
    exit(0);
}
include 'bootstrap.inc.php';
$model = new OpenSKOS_Db_Table_Collections();
if (null !== $OPTS->collection) {
    if (preg_match('/^\\d+$/', $OPTS->collection)) {
        $collection = $model->find($OPTS->collection)->current();
    } else {
        $tenant = $OPTS->tenant;
        if (null === $tenant) {
            fwrite(STDERR, "if you want to select a collection by it's code, a tenant code is required\n");
            exit(1);
        }
        $collection = $model->fetchRow($model->select()->where('code=?', $OPTS->collection)->where('tenant=?', $tenant));
        if (null === $collection) {
            fwrite(STDERR, "collection `{$OPTS->collection}` not found\n");
            exit(2);
        }
        if (!$collection->OAI_baseURL) {
 /**
  * @return OpenSKOS_Db_Table_Row_Collection
  */
 protected function _getCollection()
 {
     $model = new OpenSKOS_Db_Table_Collections();
     if (null === ($code = $this->getRequest()->getParam('collection'))) {
         //create a new collection:
         $collection = $model->createRow(array('tenant' => $this->_tenant->code));
     } else {
         $collection = $model->findByCode($code, $this->_tenant->code);
         if (null === $collection) {
             $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(sprintf(_('Collection `%s` not found', $code)));
             $this->_helper->redirector('index');
         }
     }
     return $collection;
 }
 public function getCollection()
 {
     $model = new OpenSKOS_Db_Table_Collections();
     return $model->find($this->data['collection'])->current();
 }
 /**
  * This builds the buttons for the form.
  *
  * @return Editor_Forms_ConceptScheme
  */
 protected function buildHeader()
 {
     $this->addElement('hidden', 'uuid', array('decorators' => array()));
     // Collections
     $modelCollections = new OpenSKOS_Db_Table_Collections();
     $collectionOptions = $modelCollections->getIdToTitleMap($this->_getCurrentTenant()->code);
     $this->addElement('select', 'collection', array('label' => _('Collection:'), 'multiOptions' => $collectionOptions, 'decorators' => array('ViewHelper', 'Label', array('HtmlTag', array('tag' => 'br', 'placement' => Zend_Form_Decorator_HtmlTag::APPEND)))));
     // Uri code
     $this->addElement('text', 'uriBase', array('label' => 'URI: ', 'decorators' => array('ViewHelper', 'Label'), 'filters' => array('StringTrim')));
     $this->getElement('uriBase')->setRequired(true);
     $this->addElement('text', 'uriCode', array('decorators' => array('ViewHelper'), 'filters' => array('StringTrim')));
     $this->getElement('uriCode')->setRequired(true);
     $this->addElement('submit', 'conceptSchemeSave', array('label' => _('Ok'), 'class' => 'concept-edit-submit', 'decorators' => array('ViewHelper', array('HtmlTag', array('tag' => 'span', 'id' => 'concept-edit-action')))));
     $this->addDisplayGroup(array('collection', 'uriBase', 'uriCode', 'conceptSchemeSave'), 'concept-header', array('legend' => 'header', 'disableDefaultDecorators' => true, 'decorators' => array('FormElements', array('HtmlTag', array('tag' => 'div', 'id' => 'concept-edit-header')))));
     return $this;
 }
 /**
  * @return OpenSKOS_Db_Table_Row_Collection
  */
 protected function _getCollection()
 {
     $collectionCode = $this->getRequest()->getParam('collection');
     if (!$collectionCode) {
         throw new Zend_Controller_Action_Exception('No collection specified', 412);
     }
     $model = new OpenSKOS_Db_Table_Collections();
     $collection = $model->findByCode($collectionCode, $this->_getTenant());
     if (null === $collection) {
         throw new Zend_Controller_Action_Exception('No such collection: `' . $collectionCode . '`', 404);
     }
     return $collection;
 }
 /**
  * Parses the part of the query for searching for specified collections.
  * By default the search is performed for all collections.
  *
  * @return OpenSKOS_Solr_Queryparser_Editor
  */
 protected function _parseSearchForCollections()
 {
     $modelCollections = new OpenSKOS_Db_Table_Collections();
     $allCollections = $modelCollections->fetchAll($modelCollections->select()->where('tenant = ?', $this->_tenant->code));
     $searchInCollections = array();
     if (isset($this->_searchOptions['collections'])) {
         $searchInCollections = $this->_searchOptions['collections'];
     }
     if (!empty($searchInCollections) && count($searchInCollections) != count($allCollections)) {
         $query = '';
         foreach ($searchInCollections as $collectionId) {
             $query .= !empty($query) ? ' OR ' : '';
             $query .= 'collection:' . $collectionId;
         }
         if (!empty($query) && count($searchInCollections) > 1) {
             $query = '(' . $query . ')';
         }
         if (!empty($query)) {
             $this->_addDefaultQuerySeparator();
             $this->_query .= $query;
         }
     }
     return $this;
 }
Beispiel #10
0
 /**
  * 
  * @param Zend_Console_Getopt $opts
  * @return OpenSKOS_Rdf_Parser
  */
 public function setOpts(Zend_Console_Getopt $opts)
 {
     try {
         $opts->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo str_replace('[ options ]', '[ options ] file', $e->getUsageMessage());
         throw new OpenSKOS_Rdf_Parser_Exception($e->getMessage());
     }
     if (null !== $opts->help) {
         echo str_replace('[ options ]', '[ options ] file', $opts->getUsageMessage());
         throw new OpenSKOS_Rdf_Parser_Exception('', 0);
     }
     if ($opts->status) {
         if (!in_array($opts->status, self::$statuses)) {
             throw new OpenSKOS_Rdf_Parser_Exception('Illegal `status` value, must be one of `' . implode('|', self::$statuses) . '`', 0);
         }
     }
     foreach (self::$required as $opt) {
         if (null === $this->_opts->{$opt}) {
             throw new OpenSKOS_Rdf_Parser_Exception("missing required parameter `{$opt}`");
         }
     }
     $this->_opts = $opts;
     if (null !== $this->_opts->help) {
         $this->printUsageMessageAndExit();
     }
     if (null !== $opts->limit) {
         $this->setLimit((int) $opts->limit);
     }
     if (null !== $opts->from) {
         $this->setFrom((int) $opts->from);
     }
     $this->_bootstrap();
     $files = $this->_opts->getRemainingArgs();
     if (count($files) !== 1) {
         throw new OpenSKOS_Rdf_Parser_Exception(str_replace('[ options ]', '[ options ] file', $this->_opts->getUsageMessage()));
     }
     $this->setFiles($files);
     $model = new OpenSKOS_Db_Table_Tenants();
     $tenant = $model->find($opts->tenant)->current();
     if (null === $tenant) {
         throw new OpenSKOS_Rdf_Parser_Exception("No such tenant: `{$opts->tenant}`");
     }
     $model = new OpenSKOS_Db_Table_Collections();
     if (preg_match('/^\\d+$/', $opts->collection)) {
         $collection = $model->find($opts->collection)->current();
     } else {
         $collection = $model->findByCode($opts->collection, $opts->tenant);
     }
     if (null === $collection) {
         throw new OpenSKOS_Rdf_Parser_Exception("No such collection: `{$opts->collection}`");
     } else {
         $this->_collection = $collection;
     }
     return $this;
 }
Beispiel #11
0
 public function getSet($set)
 {
     @(list($tenantCode, $collectionCode, $conceptSchemaUuid) = explode(':', $set));
     if (null === $tenantCode) {
         return;
     }
     $model = new OpenSKOS_Db_Table_Tenants();
     if (null === ($tenant = $model->find($tenantCode)->current())) {
         return;
     }
     if (null !== $collectionCode) {
         $model = new OpenSKOS_Db_Table_Collections();
         $collection = $model->fetchRow($model->select()->where('code=?', $collectionCode)->where('tenant=?', $tenantCode));
         if (null === $collection) {
             return;
         }
         if (null !== $conceptSchemaUuid) {
             $params = array('limit' => 1, 'fl' => 'uuid');
             $response = new OpenSKOS_SKOS_ConceptSchemes(OpenSKOS_Solr::getInstance()->search("class:ConceptScheme AND tenant:{$tenant->code} AND collection:{$collection->id} AND uuid:{$conceptSchemaUuid}"));
             if (count($response) == 0) {
                 return;
             } else {
                 return $response->current();
             }
         } else {
             return $collection;
         }
     } else {
         return $tenant;
     }
 }