public function createAction() { $this->_requireAccess('editor.concepts', 'propose', self::RESPONSE_TYPE_PARTIAL_HTML); $this->_helper->_layout->setLayout('editor_central_content'); $notation = OpenSKOS_Db_Table_Notations::getNext(); $initialLanguage = Zend_Registry::get('Zend_Locale')->getLanguage(); $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor'); if (!empty($editorOptions['languages']) && !in_array($initialLanguage, $editorOptions['languages'])) { // If the browser language is supported $initialLanguage = key($editorOptions['languages']); } $concept = new Editor_Models_Concept(new Api_Models_Concept(array('prefLabel@' . $initialLanguage => array($this->getRequest()->getParam('label')), 'notation' => array($notation)))); $form = Editor_Forms_Concept::getInstance(true); $formData = $concept->toForm(); $form->getElement('conceptSchemeSelect')->setMultiOptions($formData['conceptSchemeSelect']); $form->populate($formData); $this->view->form = $form->setAction($this->getFrontController()->getRouter()->assemble(array('controller' => 'concept', 'action' => 'save'))); }
/** * Registers the notation of the document in the database, or generates one if the document does not have notation. * * @return OpenSKOS_Solr */ public function registerOrGenerateNotation() { if (isset($this->data['class']) && $this->data['class'] == 'Concept' || isset($this->data['class'][0]) && $this->data['class'][0] == 'Concept') { $currentNotation = ''; if (isset($this->data['notation']) && isset($this->data['notation'][0])) { $currentNotation = $this->data['notation'][0]; } if (empty($currentNotation)) { $this->fieldnames[] = 'notation'; $this->data['notation'] = array(OpenSKOS_Db_Table_Notations::getNext()); // Adds the notation to the xml. At the end just before </rdf:Description> $closingTag = '</rdf:Description>'; $notationTag = '<skos:notation>' . $this->data['notation'][0] . '</skos:notation>'; $xml = $this->data['xml']; $xml = str_replace($closingTag, $notationTag . $closingTag, $xml); $this->data['xml'] = $xml; } else { if (!OpenSKOS_Db_Table_Notations::isRegistered($currentNotation)) { // If we do not have the notation registered - register it. OpenSKOS_Db_Table_Notations::register($currentNotation); } } } return $this; }
/** * Check if we need to generate or not concept identifiers (notation and uri). * Validates any existing identifiers. * @param DOMNode $Description * @param DOMDocument $doc * @return boolean If an uri must be autogenerated */ protected function checkConceptIdentifiers(DOMNode $Description, DOMDocument $doc) { // We return if an uri must be autogenerated $autoGenerateUri = false; $autoGenerateIdentifiers = filter_var($this->getRequest()->getParam('autoGenerateIdentifiers', false), FILTER_VALIDATE_BOOLEAN); $xpath = new DOMXPath($doc); $notationNodes = $xpath->query('skos:notation', $Description); $uri = $Description->getAttributeNS(OpenSKOS_Rdf_Parser::$namespaces['rdf'], 'about'); if ($autoGenerateIdentifiers) { if ($uri || $notationNodes->length > 0) { throw new Zend_Controller_Action_Exception('Parameter autoGenerateIdentifiers is set to true, but the xml already contains notation (skos:notation) and/or uri (rdf:about).', 400); } $autoGenerateUri = true; } else { // Is uri missing if (!$uri) { throw new Zend_Controller_Action_Exception('Uri (rdf:about) is missing from the xml. You may consider using autoGenerateIdentifiers.', 400); } // Is notation missing if ($notationNodes->length == 0) { throw new Zend_Controller_Action_Exception('Notation (skos:notation) is missing from the xml. You may consider using autoGenerateIdentifiers.', 400); } // Is uri based on notation if (!OpenSKOS_Db_Table_Notations::isContainedInUri($uri, $notationNodes->item(0)->nodeValue)) { throw new Zend_Controller_Action_Exception('The concept uri (rdf:about) must be based on notation (must contain the notation)', 400); } $autoGenerateUri = false; } return $autoGenerateUri; }