protected function buildFileUpload()
 {
     $tenantFromIdentity = OpenSKOS_Db_Table_Tenants::fromIdentity();
     // We always need tenant for getting icon path.
     if (null !== $tenantFromIdentity) {
         $iconUpload = new Zend_Form_Element_File('icon');
         $iconUpload->setLabel('Upload a new icon:')->addValidator('Count', false, 1)->setRequired(true);
         $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor');
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['uploadPath'])) {
             $iconUpload->setDestination(APPLICATION_PATH . $editorOptions['schemeIcons']['uploadPath'] . '/' . $tenantFromIdentity->code);
         } else {
             $iconUpload->setDestination(APPLICATION_PATH . self::DEFAULT_UPLOAD_PATH . '/' . $tenantFromIdentity->code);
         }
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['allowedExtensions'])) {
             $iconUpload->addValidator('Extension', false, $editorOptions['schemeIcons']['allowedExtensions']);
         } else {
             $iconUpload->addValidator('Extension', false, 'jpg, jpeg, png, gif');
         }
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['maxSize'])) {
             $iconUpload->addValidator('Size', false, $editorOptions['schemeIcons']['maxSize']);
             $iconUpload->setMaxFileSize($editorOptions['schemeIcons']['maxSize']);
         } else {
             $iconUpload->addValidator('Size', false, 2097152);
             $iconUpload->setMaxFileSize(2097152);
         }
         $this->addElement($iconUpload, 'icon');
     }
     return $this;
 }
 /**
  * @see Editor_Models_ConceptValidator::validate($concept)
  */
 public function isValid(Editor_Models_Concept $concept, $extraData)
 {
     $this->_setField('prefLabel');
     $isValid = true;
     if (isset($concept['inScheme']) && !empty($concept['inScheme'])) {
         // Get all pref labels for all languages.
         $prefLabels = array();
         $languages = $concept->getConceptLanguages();
         foreach ($languages as $lang) {
             if (isset($concept['prefLabel@' . $lang])) {
                 $prefLabels = array_merge($prefLabels, $concept['prefLabel@' . $lang]);
             }
         }
         $query = 'prefLabel:("' . implode('" OR "', $prefLabels) . '")';
         $query .= ' inScheme:("' . implode('" OR "', $concept['inScheme']) . '")';
         if (isset($concept['tenant']) && !empty($concept['tenant'])) {
             $query .= ' tenant:' . $concept['tenant'];
         } elseif (null !== ($tenant = OpenSKOS_Db_Table_Tenants::fromIdentity())) {
             $query .= ' tenant:' . $tenant->code;
         }
         $query .= ' -uuid:"' . $concept['uuid'] . '"';
         $response = Api_Models_Concepts::factory()->setQueryParams(array('rows' => 0))->getConcepts($query);
         if ($response['response']['numFound'] > 0) {
             $isValid = false;
         }
     }
     if (!$isValid) {
         $this->_setErrorMessage(_('There is already a concept with same preferred label in one of the schemes.'));
     }
     return $isValid;
 }
Esempio n. 3
0
 /**
  * Sets the tenant parameter for the api requests.
  * 
  * @return OpenSKOS_Http_Client_Api
  */
 protected function assignTenant()
 {
     $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     if (null === $tenant) {
         throw new OpenSKOS_Http_Client_Api_Exception('Tenant not found. Needed for request to the api.');
     }
     $this->setParameterGet('tenant', $tenant->code);
     return $this;
 }
 public function getAction()
 {
     $model = new OpenSKOS_Db_Table_Tenants();
     $code = $this->getRequest()->getParam('id');
     $tenant = $model->find($code)->current();
     if (null === $tenant) {
         throw new Zend_Controller_Action_Exception('Insitution `' . $code . '` not found', 404);
     }
     $context = $this->_helper->contextSwitch()->getCurrentContext();
     if ($context == 'json' || $context == 'jsonp') {
         foreach ($tenant as $key => $val) {
             $this->view->assign($key, $val);
         }
         $this->view->assign('collections', $tenant->findDependentRowset('OpenSKOS_Db_Table_Collections')->toArray());
     } else {
         $this->view->assign('tenant', $tenant);
     }
 }
 public function uniqueCode($code, array $data)
 {
     //fetch the tenant:
     $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     if (null === $tenant) {
         throw new Zend_Db_Table_Exception('This method needs a valid tenant from the Zend_Auth object');
     }
     $select = $this->select()->where('tenant=?', $tenant->code)->where('code=?', $code);
     if (isset($data['id'])) {
         $select->where('NOT(id=?)', $data['id']);
     }
     return count($this->fetchAll($select)) === 0;
 }
Esempio n. 6
0
 protected function _uniqueFieldValue($fieldname, $value, $data)
 {
     //fetch the tenant:
     $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     if (null === $tenant) {
         throw new Zend_Db_Table_Exception('This method needs a valid tenant from the Zend_Auth object');
     }
     $select = $this->select()->where('tenant=?', $tenant->code)->where($fieldname . '=?', $value);
     if (isset($data['id'])) {
         $select->where('NOT(id=?)', $data['id']);
     }
     return count($this->fetchAll($select)) === 0;
 }
 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);
     }
 }
 /**
  * @see Editor_Models_ConceptValidator::validate($concept)
  */
 public function isValid(Editor_Models_Concept $concept, $extraData)
 {
     $this->_setField('notation');
     $isValid = true;
     if (!isset($concept['notation']) || empty($concept['notation'])) {
         $this->_setErrorMessage(_('Notation not specified.'));
         $isValid = false;
     } else {
         $query = 'notation:"' . $concept['notation'] . '"';
         $query .= ' tenant:"' . OpenSKOS_Db_Table_Tenants::fromIdentity()->code . '"';
         $query .= ' -uuid:"' . $concept['uuid'] . '"';
         $response = Api_Models_Concepts::factory()->setQueryParams(array('rows' => 0))->getConcepts($query);
         if ($response['response']['numFound'] > 0) {
             $this->_setErrorMessage(_('System error. The notation of this concept is already used.'));
             $isValid = false;
         }
     }
     return $isValid;
 }
Esempio n. 9
0
 public function init()
 {
     if (false === OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor', 'view')) {
         $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Your access level does not allow you to use the Editor.'));
         $this->_helper->redirector('index', 'index', 'website');
     }
     if ($this->getRequest()->isPost()) {
         if (null !== $this->getRequest()->getParam('cancel')) {
             $this->_helper->redirector('index');
         }
     }
     $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     if (null === $tenant) {
         throw new Zend_Controller_Action_Exception('Tenant not found', 404);
     }
     $tenant->getForm()->setAction($this->getFrontController()->getRouter()->assemble(array('action' => 'save')));
     $this->_tenant = $tenant;
     $this->_helper->_layout->setLayout('editor');
     $this->view->navigation()->setAcl(Zend_Registry::get(OpenSKOS_Application_Resource_Acl::REGISTRY_KEY))->setRole(OpenSKOS_Db_Table_Users::fromIdentity()->role)->setContainer($this->_getNavigationContainer());
 }
Esempio n. 10
0
 public function getClasses(OpenSKOS_Db_Table_Row_Tenant $tenant = null)
 {
     if (null === $tenant) {
         $tenant = OpenSKOS_Db_Table_Tenants::fromCode($this->tenant);
     }
     if (null === $tenant) {
         $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     }
     return $this->getTable()->getClasses($tenant, $this);
 }
Esempio n. 11
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. 12
0
 public function getInstitution()
 {
     $model = new OpenSKOS_Db_Table_Tenants();
     return $model->find($this->data['tenant'])->current();
 }
Esempio n. 13
0
    exit(0);
}
$args = $OPTS->getRemainingArgs();
if (!$args || count($args) != 1) {
    echo str_replace('[ options ]', '[ options ] action', $OPTS->getUsageMessage());
    fwrite(STDERR, "Expected an actions (create|delete)\n");
    exit(1);
}
$action = $args[0];
$query = $OPTS->query;
if (null === $OPTS->code) {
    fwrite(STDERR, "missing required `code` argument\n");
    exit(1);
}
include 'bootstrap.inc.php';
$model = new OpenSKOS_Db_Table_Tenants();
switch ($action) {
    case 'create':
        if (null === $OPTS->name) {
            fwrite(STDERR, "missing required `name` argument\n");
            exit(1);
        }
        if (null === $OPTS->email) {
            fwrite(STDERR, "missing required `email` argument\n");
            exit(1);
        }
        if (null === $OPTS->password) {
            $password = OpenSKOS_Db_Table_Users::pwgen(8);
        } else {
            $password = $OPTS->password;
        }
Esempio n. 14
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;
 }
Esempio n. 15
0
 /**
  * @return OpenSKOS_Db_Table_Row_Tenant
  */
 protected function _getTenant()
 {
     static $tenant;
     if (null === $tenant) {
         //need a tenant and a collection:
         $tenantCode = $this->getRequest()->getParam('tenant');
         if (!$tenantCode) {
             throw new Zend_Controller_Action_Exception('No tenant specified', 412);
         }
         $model = new OpenSKOS_Db_Table_Tenants();
         $tenant = $model->find($tenantCode)->current();
         if (null === $tenant) {
             throw new Zend_Controller_Action_Exception('No such tenant: `' . $tenantCode . '`', 404);
         }
     }
     return $tenant;
 }
Esempio n. 16
0
 /**
  * Merge search options
  * @param array $formOptions
  * @param array $profileOptions
  * @return array
  */
 public static function mergeSearchOptions($formOptions, $profileOptions)
 {
     // Merge concept schemes options.
     if (isset($formOptions['allowedConceptScheme']) && !empty($formOptions['allowedConceptScheme'])) {
         $profileOptions['conceptScheme'] = $formOptions['allowedConceptScheme'];
         unset($formOptions['allowedConceptScheme']);
     }
     $options = array_merge($formOptions, $profileOptions);
     // Remove any status options if status system is disabled.
     if (!OpenSKOS_Db_Table_Tenants::fromIdentity()['enableStatusesSystem']) {
         $options['status'] = [];
     } elseif (!empty($options['status'])) {
         // We can not search for status deleted.
         $options['status'] = array_diff($options['status'], [OpenSKOS_Concept_Status::DELETED]);
     }
     return $options;
 }
 /**
  * Gets the currently logged user's tenant.
  *
  * @return OpenSKOS_Db_Table_Row_Tenant
  */
 protected function _getCurrentTenant()
 {
     if (!$this->_currentTenant) {
         $this->_currentTenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
         if (null === $this->_currentTenant) {
             throw new Zend_Exception('Tenant not found. Needed for request to the api.');
         }
     }
     return $this->_currentTenant;
 }
Esempio n. 18
0
 /**
  * Parses the part of the query for searching for specified tenants.
  * By default the search is performed for the current tenant.
  *
  * @return OpenSKOS_Solr_Queryparser_Editor
  */
 protected function _parseSearchForTenants()
 {
     $modelTenants = new OpenSKOS_Db_Table_Tenants();
     $allTenants = $modelTenants->fetchAll();
     $searchInTenants = array();
     if (isset($this->_searchOptions['tenants']) && !empty($this->_searchOptions['tenants'])) {
         $searchInTenants = $this->_searchOptions['tenants'];
     } else {
         $searchInTenants[] = $this->_tenant->code;
     }
     if (!empty($searchInTenants) && count($allTenants) != count($searchInTenants)) {
         $query = '';
         foreach ($searchInTenants as $tenantCode) {
             $query .= !empty($query) ? ' OR ' : '';
             $query .= 'tenant:' . $tenantCode;
         }
         if (!empty($query) && count($searchInTenants) > 1) {
             $query = '(' . $query . ')';
         }
         if (!empty($query)) {
             $this->_addDefaultQuerySeparator();
             $this->_query .= $query;
         }
     }
     return $this;
 }
Esempio n. 19
0
 /**
  * Builds the path to the concept scheme icon.
  * Returns empty string if the file does not exist. 
  * 
  * @param srtring $uuid
  * @param OpenSKOS_Db_Table_Row_Tenant $tenant optional, Default null. If not set the currently logged one will be used.
  * @return string
  */
 public static function buildIconPath($uuid, $tenant = null)
 {
     $editorOptions = OpenSKOS_Application_BootstrapAccess::getBootstrap()->getOption('editor');
     if (null === $tenant) {
         $tenant = OpenSKOS_Db_Table_Tenants::fromIdentity();
     }
     // We always need tenant for getting icon path.
     if (null !== $tenant) {
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['assignPath'])) {
             $iconsAssignPath = APPLICATION_PATH . $editorOptions['schemeIcons']['assignPath'] . '/' . $tenant->code;
         } else {
             $iconsAssignPath = APPLICATION_PATH . Editor_Forms_UploadIcon::DEFAULT_ASSIGN_PATH . '/' . $tenant->code;
         }
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['assignHttpPath'])) {
             $iconsAssignHttpPath = $editorOptions['schemeIcons']['assignHttpPath'] . '/' . $tenant->code;
         } else {
             $iconsAssignHttpPath = Editor_Forms_UploadIcon::DEFAULT_ASSIGN_HTTP_PATH . '/' . $tenant->code;
         }
         if (isset($editorOptions['schemeIcons']) && isset($editorOptions['schemeIcons']['extension'])) {
             $iconsExtension = $editorOptions['schemeIcons']['extension'];
         } else {
             $iconsExtension = 'png';
         }
         if (is_file($iconsAssignPath . '/' . $uuid . '.' . $iconsExtension)) {
             return $iconsAssignHttpPath . '/' . $uuid . '.' . $iconsExtension . '?nocache=' . time();
         } else {
             return '';
         }
     } else {
         return '';
     }
 }
Esempio n. 20
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;
     }
 }