/** * description * * @return return_type * @param var_type $var */ public function updateFromRequest($userId, $prefLabel = null, $language = null, $statusId = null) { //upsert the preflabel concept property /** @var ConceptProperty **/ $conceptProperty = $this->getConceptProperty(); $updatedAt = time(); if (!$conceptProperty) { $conceptProperty = new ConceptProperty(); $conceptProperty->setSkosPropertyId(SkosProperty::getPrefLabelId()); $conceptProperty->setCreatedUserId($userId); $conceptProperty->setPrimaryPrefLabel(1); } $conceptProperty->setUpdatedUserId($userId); if (isset($prefLabel)) { $conceptProperty->setObject($prefLabel); $this->setPrefLabel($prefLabel); } if (isset($language)) { $conceptProperty->setLanguage($language); $this->setLanguage($language); } if (isset($statusId)) { $conceptProperty->setStatusId($statusId); $this->setStatusId($statusId); } $this->setUpdatedAt($updatedAt); $conceptProperty->setUpdatedAt($updatedAt); //now let's save the concept //if we're in create mode... if ($this->isNew()) { $this->setCreatedUserId($userId); $this->save(); $conceptProperty->setConceptRelatedByConceptId($this); $conceptProperty->save(); } else { $conceptProperty->setConceptRelatedByConceptId($this); } //update the pref_label concept property $this->setUpdatedUserId($userId); $this->setConceptProperty($conceptProperty); $this->save(); return; }
public function executeEdit() { $this->setFlash('vocabID', $this->getVocabularyId()); if ($this->getRequest()->getMethod() == sfRequest::POST) { //before the save... $concept_property = $this->getRequestParameter('concept_property'); /** * @todo the list of skos property types that require a related concept should be in a master configuration array * this applies to the template too **/ //check to see if the skosproperty requires a related concept if (!in_array($concept_property['skos_property_id'], array('3', '16', '21', '32', '33', '34', '35', '36', '37'))) { $concept_property['related_concept_id'] = null; $concept_property['scheme_id'] = null; } $conceptPropertyId = $this->getRequestParameter('id'); $userId = $this->getUser()->getSubscriberId(); //does the user have editorial rights to the reciprocal... $permission = false; if (isset($concept_property['related_concept_id']) and $concept_property['related_concept_id']) { //we want to lookup the URI of the related term $related_concept = ConceptPeer::retrieveByPK($concept_property['related_concept_id']); if ($related_concept) { if ($this->getUser()->hasCredential(array(0 => 'administrator'))) { $permission = true; } else { //get the maintainers of the reciprocal property $maintainers = $related_concept->getVocabulary()->getVocabularyHasUsers(); /** @var VocabularyHasUser $maintainer */ foreach ($maintainers as $maintainer) { if ($userId === $maintainer->getUserId() and $maintainer->getIsMaintainerFor()) { $permission = true; break; } } } } } if ($permission) { if (isset($conceptPropertyId) && $conceptPropertyId) { $this->deleteReciprocalProperty($conceptPropertyId, $concept_property['related_concept_id']); } if (isset($concept_property['related_concept_id']) and $concept_property['related_concept_id']) { //we want to lookup the URI of the related term $related_concept = ConceptPeer::retrieveByPK($concept_property['related_concept_id']); if ($related_concept) { //and overwrite whatever is in the current object TODO: move this into an javascript action in the user interface $concept_property['object'] = $related_concept->getUri(); $this->getRequest()->getParameterHolder()->set('concept_property', $concept_property); } //lookup the inverse id $InverseProfileId = ProfilePropertyPeer::retrieveBySkosID($concept_property['skos_property_id'])->getInverseProfilePropertyId(); $InverseSkosId = ProfilePropertyPeer::retrieveByPK($InverseProfileId)->getSkosId(); //then we create a new reciprocal property in the related term $newProp = new ConceptProperty(); $newProp->setConceptId($concept_property['related_concept_id']); $newProp->setSkosPropertyId($InverseSkosId); $newProp->setSchemeId($this->concept->getVocabularyId()); $newProp->setRelatedConceptId($this->concept->GetId()); $newProp->setObject($this->concept->getUri()); $newProp->setStatusId($concept_property['status_id']); $newProp->setIsGenerated(true); $newProp->setCreatedUserId($this->getUser()->getSubscriberId()); $newProp->setUpdatedUserId($this->getUser()->getSubscriberId()); //TODO: make this the user's default language (actually the language is not relevant when defining relationships) //$newProp->setLanguage($this->concept->getLanguage()); $newProp->setLanguage(''); $concept_property['language'] = ''; $newProp->save(); } } //save the array back to the request parameter $this->requestParameterHolder->set('concept_property', $concept_property); } parent::executeEdit(); }