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;
 }
示例#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;
 }
示例#4
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 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;
 }
 /**
  * @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;
 }
示例#7
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());
 }
 /**
  * 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;
 }
示例#9
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 '';
     }
 }
示例#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);
 }
示例#11
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;
 }