/** * @return Zend_Form */ public function getUploadForm() { static $form; if (null === $form) { $form = new Zend_Form(); $form->setAttrib('enctype', 'multipart/form-data')->addElement('file', 'xml', array('label' => _('File'), 'required' => true, 'validators' => array('NotEmpty' => array()))); $statusOptions = ['label' => 'Status for imported concepts']; if ($this->getTenant()['enableStatusesSystem']) { $statusOptions['multiOptions'] = OpenSKOS_Concept_Status::statusesToOptions(); } else { $statusOptions['multiOptions'] = [OpenSKOS_Concept_Status::APPROVED]; $statusOptions['disabled'] = true; } $form->addElement('select', 'status', $statusOptions); $form->addElement('checkbox', 'ignoreIncomingStatus', array('label' => 'Ignore incoming status')); $editorOptions = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('editor'); $form->addElement('select', 'lang', array('label' => 'The default language to use if no "xml:lang" attribute is found', 'multiOptions' => $editorOptions['languages'])); $form->addElement('checkbox', 'toBeChecked', array('label' => 'Sets the toBeCheked status of imported concepts')); $form->addElement('checkbox', 'purge', array('label' => 'Purge. Delete all concept schemes found in the file. (will also delete concepts inside them)')); $form->addElement('checkbox', 'delete-before-import', array('label' => _('Delete concepts in this collection before import'))); $form->addElement('checkbox', 'onlyNewConcepts', array('label' => _('Import contains only new concepts. Do not update any concepts if they match by notation (or uri if useUriAsIdentifier is used).'))); $form->addElement('checkbox', 'useUriAsIdentifier', array('label' => _('Use uri as identifier if concept notation does not exist in the importing concept.'))); $form->addElement('submit', 'submit', array('label' => 'Submit')); } return $form; }
/** * @see Editor_Models_ConceptValidator::validate($concept) */ public function isValid(Editor_Models_Concept $concept, $extraData) { $this->_setField('status'); $isValid = true; $oldConcept = null; $response = Api_Models_Concepts::factory()->getConcepts('uuid:' . $concept['uuid']); if (isset($response['response']['docs']) && 1 === count($response['response']['docs'])) { $oldConcept = new Editor_Models_Concept(new Api_Models_Concept(array_shift($response['response']['docs']))); } if (null !== $oldConcept) { $isValid = OpenSKOS_Concept_Status::isTransitionAllowed($oldConcept['status'], $concept['status']); } if (!$isValid) { $this->_setErrorMessage(sprintf(_('The status transition from "%s" to "%s" is not allowed.'), $oldConcept['status'], $concept['status'])); } return $isValid; }
/** * Gets an array of the available search options. * * @return array */ public static function getAvailableSearchOptions() { $options['labels']['prefLabel'] = _('preferred'); $options['labels']['altLabel'] = _('alternative'); $options['labels']['hiddenLabel'] = _('hidden'); $options['statuses']['none'] = _('none'); // We can not filter by status deleted. Those concepts are not shown. $statuses = array_diff(OpenSKOS_Concept_Status::getStatuses(), [OpenSKOS_Concept_Status::DELETED]); foreach ($statuses as $status) { $options['statuses'][$status] = _($status); } $options['docproperties']['definition'] = _('definition'); $options['docproperties']['example'] = _('example'); $options['docproperties']['changeNote'] = _('change note'); $options['docproperties']['editorialNote'] = _('editorial note'); $options['docproperties']['historyNote'] = _('history note'); $options['docproperties']['scopeNote'] = _('scope note'); $options['interactiontypes']['created'] = _('created'); $options['interactiontypes']['modified'] = _('modified'); $options['interactiontypes']['approved'] = _('approved'); return $options; }
public function saveAction() { $concept = $this->_getConcept(); $form = Editor_Forms_Concept::getInstance($concept); $formData = $this->getRequest()->getParams(); if (!$this->getRequest()->isPost()) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('No POST data recieved')); $this->_helper->redirector('edit'); } $this->_checkConceptTenantForEdit($concept); if (!$form->isValid($formData)) { return $this->_forward('edit'); } else { //@FIXME should upgrade multi hidden fields to allow easy submission (change name to template something) array_shift($formData['inScheme']); $form->populate($formData); if (null === $concept) { $this->_requireAccess('editor.concepts', 'propose', self::RESPONSE_TYPE_PARTIAL_HTML); $concept = new Editor_Models_Concept(new Api_Models_Concept()); } else { $this->_requireAccess('editor.concepts', 'edit', self::RESPONSE_TYPE_PARTIAL_HTML); } $formData = $form->getValues(); $oldData = $concept->getData(); //by reference. $extraData = $concept->transformFormData($formData); $concept->setConceptData($formData, $extraData); try { $user = OpenSKOS_Db_Table_Users::fromIdentity(); $extraData = array_merge($extraData, array('tenant' => $user->tenant, 'modified_by' => (int) $user->id, 'modified_timestamp' => date("Y-m-d\\TH:i:s\\Z"), 'toBeChecked' => isset($extraData['toBeChecked']) ? (bool) $extraData['toBeChecked'] : false)); if (!isset($extraData['uuid']) || empty($extraData['uuid'])) { $extraData['uuid'] = $concept['uuid']; $extraData['created_by'] = $extraData['modified_by']; $extraData['created_timestamp'] = $extraData['modified_timestamp']; } else { if (isset($oldData['created_by'])) { $extraData['created_by'] = $oldData['created_by']; } if (isset($oldData['created_timestamp'])) { $extraData['created_timestamp'] = $oldData['created_timestamp']; } if (isset($oldData['collection'])) { $extraData['collection'] = $oldData['collection']; } if (isset($oldData['approved_by'])) { $extraData['approved_by'] = $oldData['approved_by']; } if (isset($oldData['approved_timestamp'])) { $extraData['approved_timestamp'] = $oldData['approved_timestamp']; } if (isset($oldData['deleted_by'])) { $extraData['deleted_by'] = $oldData['deleted_by']; } if (isset($oldData['deleted_timestamp'])) { $extraData['deleted_timestamp'] = $oldData['deleted_timestamp']; } } if ($extraData['status'] === OpenSKOS_Concept_Status::APPROVED && (!isset($oldData['status']) || $oldData['status'] !== OpenSKOS_Concept_Status::APPROVED)) { $extraData['approved_timestamp'] = $extraData['modified_timestamp']; $extraData['approved_by'] = $extraData['modified_by']; } if ($extraData['status'] !== OpenSKOS_Concept_Status::APPROVED) { $formData['approved_by'] = ''; $formData['approved_timestamp'] = ''; $extraData['approved_by'] = ''; $extraData['approved_timestamp'] = ''; } if (OpenSKOS_Concept_Status::isStatusLikeDeleted($extraData['status'])) { $formData['deleted_by'] = ''; $formData['deleted_timestamp'] = ''; $extraData['deleted_by'] = ''; $extraData['deleted_timestamp'] = ''; } if (!isset($extraData['collection'])) { if (isset($concept['inScheme']) && isset($concept['inScheme'][0])) { $firstConceptScheme = Editor_Models_ApiClient::factory()->getConceptSchemes($concept['inScheme'][0]); $firstConceptScheme = array_shift($firstConceptScheme); if (!empty($firstConceptScheme) && isset($firstConceptScheme['collection'])) { $extraData['collection'] = $firstConceptScheme['collection']; } } } $this->_handleStatusAutomatedActions($concept, $formData, $extraData); $concept->setConceptData($formData, $extraData); if ($concept->save($extraData)) { if (!isset($concept['inScheme'])) { $newSchemes = array(); } else { $newSchemes = $concept['inScheme']; } if (!isset($oldData['inScheme'])) { $oldSchemes = array(); } else { $oldSchemes = $oldData['inScheme']; } $concept->updateConceptSchemes($newSchemes, $oldSchemes); } else { return $this->_forward('edit', 'concept', 'editor', array('errors' => $concept->getErrors())); } } catch (Zend_Exception $e) { return $this->_forward('edit', 'concept', 'editor', array('errors' => array(new Editor_Models_ConceptValidator_Error('unknown', $e->getMessage())))); } $this->_helper->redirector('view', 'concept', 'editor', array('uuid' => $extraData['uuid'])); } }
/** * Build the statuses dropdown. */ protected function buildStatuses() { if ($this->getEnableStatusesSystem()) { if ($this->_isProposalOnly) { $availableStatuses = [OpenSKOS_Concept_Status::CANDIDATE]; } else { $availableStatuses = OpenSKOS_Concept_Status::getAvailableStatuses($this->getCurrentStatus()); } // Fallback for expired status for beg //!TODO Can be removed when conversion ready if ($this->getCurrentStatus() == OpenSKOS_Concept_Status::_EXPIRED) { $availableStatuses[] = OpenSKOS_Concept_Status::OBSOLETE; } $this->addElement('select', 'status', array('label' => 'Status:', 'multiOptions' => OpenSKOS_Concept_Status::statusesToOptions($availableStatuses), 'value' => 'candidate', 'decorators' => array('ViewHelper', 'Label', array('HtmlTag', array('tag' => 'span', 'id' => 'concept-edit-status'))))); if ($this->_isProposalOnly) { $this->getElement('status')->setValue(OpenSKOS_Concept_Status::CANDIDATE); } // Fallback for expired status for beg //!TODO Can be removed when conversion ready if ($this->getCurrentStatus() == OpenSKOS_Concept_Status::_EXPIRED) { $this->getElement('status')->setValue(OpenSKOS_Concept_Status::OBSOLETE); } } else { $this->addElement('hidden', 'status', array('decorators' => array('ViewHelper'), 'value' => OpenSKOS_Concept_Status::APPROVED)); } $this->addElement('hidden', 'statusOtherConcept', array('decorators' => array('ViewHelper'))); $this->addElement('hidden', 'statusOtherConceptLabelToFill', array('decorators' => array('ViewHelper'))); }
/** * Tries to perform real update over the concept without loosing any old data and properly chaning the update data. * * @param array $updateData Leave empty array if no normal data is updated. * @param array $updateExtraData Leave empty array if no extra data is updated. * @param bool $commit, optional, Default: true * @param bool $ignoreValidation, optional, Default: false If set to true the validation on save will not be performed. * @return bool True if the save is successfull. False otherwise. You can see errors by calling getErrors(); */ public function update($updateData, $updateExtraData = [], $commit = true, $ignoreValidation = false) { $data = $this->getData(); $extraData = $this->getCurrentRequiredData(); // Fix for preventing multiplying of the notation. unset($extraData['notation']); //!TODO The fallowing should be added to required data or all the process of editing concept should be refactored so that old data is not lost. // Data which will be lost on update if not remembered... if (isset($data['deleted'])) { $extraData['deleted'] = $data['deleted']; } if (isset($data['toBeChecked'])) { $extraData['toBeChecked'] = $data['toBeChecked']; } if (isset($data['created_by'])) { $extraData['created_by'] = $data['created_by']; } if (isset($data['created_timestamp'])) { $extraData['created_timestamp'] = $data['created_timestamp']; } if (isset($data['modified_by'])) { $extraData['modified_by'] = $data['modified_by']; } if (isset($data['modified_timestamp'])) { $extraData['modified_timestamp'] = $data['modified_timestamp']; } if (isset($data['approved_by'])) { $extraData['approved_by'] = $data['approved_by']; } if (isset($data['approved_timestamp'])) { $extraData['approved_timestamp'] = $data['approved_timestamp']; } if (isset($data['deleted_by'])) { $extraData['deleted_by'] = $data['deleted_by']; } if (isset($data['deleted_timestamp'])) { $extraData['deleted_timestamp'] = $data['deleted_timestamp']; } if (isset($data['status'])) { $extraData['status'] = $data['status']; } $data = array_merge($data, $updateData); $extraData = array_merge($extraData, $updateExtraData); if (isset($extraData['status'])) { if ($extraData['status'] !== OpenSKOS_Concept_Status::APPROVED) { $data['approved_by'] = ''; $data['approved_timestamp'] = ''; $extraData['approved_by'] = ''; $extraData['approved_timestamp'] = ''; } if ($extraData['status'] !== OpenSKOS_Concept_Status::isStatusLikeDeleted($extraData['status'])) { $data['deleted_by'] = ''; $data['deleted_timestamp'] = ''; $extraData['deleted_by'] = ''; $extraData['deleted_timestamp'] = ''; } } // The actual update... $this->setConceptData($data, $extraData); return $this->save($extraData, $commit, $ignoreValidation); }
protected function buildStatus() { $this->addElement('select', 'status', array('label' => 'Status:', 'separator' => '', 'multiOptions' => OpenSKOS_Concept_Status::statusesToOptions(), 'decorators' => array('ViewHelper', 'Label'))); return $this; }
/** * * @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) { $statuses = OpenSKOS_Concept_Status::getStatuses(); if (!in_array($opts->status, $statuses)) { throw new OpenSKOS_Rdf_Parser_Exception('Illegal `status` value, must be one of `' . implode('|', $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; }