/** * description * * @return string */ public function getRelatedConcept() { $concept = ConceptPeer::retrieveByPK($this->getRelatedConceptId()); if ($concept) { return $concept->getPrefLabel(); } }
/** * creates a link to related concept * * @return none * @param conceptproperty $property */ function link_to_related($property) { $relConceptId = $property->getRelatedConceptId(); if ($relConceptId) { //get the related concept $relConcept = ConceptPeer::retrieveByPK($relConceptId); if ($relConcept) { return link_to($relConcept->getPrefLabel(), 'concept/show/?id=' . $relConceptId); } } //If the skosProperty.objectType is resource then we display a truncated URI with a complete link_to if ($property->getProfileProperty()->getIsObjectProp()) { return link_to(truncate_text($property->getObject(), 30), $property->getObject()); } //if all else fails we display a truncated = 30 value return truncate_text($property->getObject(), 30); }
/** * Set the defaults * * @param ConceptProperty $concept_property */ public function setDefaults($discuss) { $action = $this->getRequest()->getParameter('action'); if ('create' == strtolower($action)) { $filter = $this->getUser()->getAttributeHolder()->getAll('sf_admin/discuss/filters'); //we need to get all the numbers if ($filter && is_array($filter)) { $filterKey = array_keys($filter); try { switch ($filterKey[0]) { case "property": $property = ConceptPropertyPeer::retrieveByPK($filter[$filterKey[0]]); $concept = $property->getConceptRelatedByConceptId(); $vocabId = $concept->getVocabularyId(); $vocabulary = myActionTools::findCurrentVocabulary(); /** @var Discuss **/ $discuss->setConceptProperty($property); $discuss->setConcept($concept); $discuss->setVocabularyId($vocabId); break; case "concept_id": $concept = ConceptPeer::retrieveByPK($filter[$filterKey[0]]); $vocabId = $concept->getVocabularyId(); /** @var Discuss **/ $discuss->setConcept($concept); $discuss->setVocabularyId($vocabId); case "vocabulary_id": $vocabId = VocabularyPeer::retrieveByPK($filter[$filterKey[0]]); /** @var Discuss **/ $discuss->setVocabularyId($vocabId); break; default: } } catch (Exception $e) { } } } else { } parent::setDefaults($discuss); }
/** * Get the associated Concept object * * @param Connection Optional Connection object. * @return Concept The associated Concept object. * @throws PropelException */ public function getConceptRelatedByRelatedConceptId($con = null) { if ($this->aConceptRelatedByRelatedConceptId === null && $this->related_concept_id !== null) { // include the related Peer class include_once 'lib/model/om/BaseConceptPeer.php'; $this->aConceptRelatedByRelatedConceptId = ConceptPeer::retrieveByPK($this->related_concept_id, $con); /* The following can be used instead of the line above to guarantee the related object contains a reference to this object, but this level of coupling may be undesirable in many circumstances. As it can lead to a db query with many results that may never be used. $obj = ConceptPeer::retrieveByPK($this->related_concept_id, $con); $obj->addConceptsRelatedByRelatedConceptId($this); */ } return $this->aConceptRelatedByRelatedConceptId; }
} } $objectId = $vocabulary_has_user->getID(); if (!isset($vocabulary)) { $vocabulary = $vocabulary_has_user->getVocabulary(); } $tab = false; break; case 'concept': $showBc = true; $showVocabularyBc = true; $showConceptBc = true; if (!isset($concept)) { $id = 'show' == $action ? $sf_params->get('id') : $paramId; if ($id) { $concept = ConceptPeer::retrieveByPK($id); } } if (!isset($vocabulary)) { if ($concept) { $vocabulary = $concept->getVocabulary(); } } $objectId = $concept->getID(); break; case 'conceptprop': $showBc = true; $showVocabularyBc = true; $showConceptBc = true; $showconceptpropBc = true; if (!isset($concept_property)) {
public function testGetConceptPropertiesArray(FunctionalTester $I) { $concept = ConceptPeer::retrieveByPK(727); $propertyArray = jsonldService::getConceptPropertyArray($concept); $I->assertEquals(json_encode($propertyArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), '{ "@id": "http://rdaregistry.info/termList/AspectRatio/1001", "@type": "Concept", "api": "http://api.metadataregistry.org/concepts/727", "inScheme": "http://rdaregistry.info/termList/AspectRatio/", "status": "Published", "prefLabel": { "en": "full screen", "de": "Vollbild", "fr": "plein écran", "es": "pantalla completa", "zh": "全屏" }, "scopeNote": { "en": "Use for standard format, i.e., 1.33:1 or 4:3." }, "definition": { "en": "Aspect ratio for a moving image resource of less than 1.5:1.", "de": "Bildformat einer Bewegtbildressource von weniger als 1.5:1.", "fr": "Format de l’image d’une ressource d’images animées inférieur à 1,5:1.", "es": "Proporción dimensional de un recurso de imagen en movimiento menor que 1.5:1.", "zh": "动态图像资源的宽高比小于1.5:1。" }, "ToolkitLabel": { "en": "full screen", "fr": "plein écran", "de": "Vollbild", "es": "pantalla completa", "zh": "全屏" }, "ToolkitDefinition": { "en": "Aspect ratio for a moving image resource of less than 1.5:1.", "fr": "Format de l’image d’une ressource d’images animées inférieur à 1,5:1.", "de": "Bildformat einer Bewegtbildressource von weniger als 1.5:1.", "es": "Proporción dimensional de un recurso de imagen en movimiento menor que 1.5:1.", "zh": "动态图像资源的宽高比小于1.5:1。" }, "altLabel": { "en": [ "full-screen", "full-screen", "fullscreen", "full-screen" ] } }'); }
public function executeShowConcept() { //build the complete URI $rootUri = $this->getRequest()->getUriPrefix() . '/'; $conceptUri = $rootUri . 'uri/' . $this->getRequestParameter('scheme', '') . '/' . $this->getRequestParameter('concept', ''); $type = $this->getRequestParameter('type'); $ts = strtotime($this->getRequestParameter('ts')); $this->timestamp = $ts; //$_SERVER['HTTP_ACCEPT'] = ''; //$_SERVER['HTTP_USER_AGENT'] = ''; switch ($type) { case 'rdf': //this URI HAS an 'id', HAS an 'rdf' suffix, and does NOT have a 'uri' action $id = $this->getRequestParameter('id'); $concept = ConceptPeer::retrieveByPK($id); $this->getContext()->getResponse()->setStatusCode(200); break; case 'html': //this URI does NOT have an 'id', HAS an 'html' suffix, and HAS a 'uri' action //redirect to the base registry using the correct id for the scheme: // http://metadataregistry.org/concept/list/vocabulary_id/16.html $concept = ConceptPeer::getConceptByUri($conceptUri); $this->forward404Unless($concept); //redirect $this->getContext()->getResponse()->setStatusCode(303); $this->redirect($this->getRequest()->getUriPrefix() . '/concept/show/id/' . $concept->getId() . '.html'); break; case 'uri': //this URI does NOT have an 'id', HAS an 'rdf' suffix, and HAS a 'uri' action $concept = ConceptPeer::getConceptByUri($conceptUri); break; case 'api_uri': //this URI does NOT have an 'id', does NOT have an 'rdf' suffix, and comes from the API $uri = $this->getRequestParameter('uri', ''); $concept = ConceptPeer::getConceptByUri($uri); break; default: //covers case of 'unknown' too //this URI does NOT have an 'id', does NOT have a suffix, and HAS a 'uri' action //do content negotiation if (true === strpos($_SERVER['HTTP_ACCEPT'], 'text/html') || true === strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') || 0 === strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla')) { //we redirect to html $concept = ConceptPeer::getConceptByUri($conceptUri); $this->forward404Unless($concept); //redirect $this->getContext()->getResponse()->setStatusCode(303); $this->redirect($this->getRequest()->getUriPrefix() . '/concept/show/id/' . $concept->getId() . '.html'); } else { $concept = ConceptPeer::getConceptByUri($conceptUri); $this->forward404Unless($concept); //we redirect to rdf $redirectUri = $_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_SERVER['REQUEST_URI']; $this->redirect($this->getRequest()->getUriPrefix() . $redirectUri . '.rdf'); } break; } $this->forward404Unless($concept); $vocabulary = $concept->getVocabulary(); //get the property data $properties = $concept->getConceptPropertysRelatedByConceptId(); $this->properties = $properties; $this->vocabulary = $vocabulary; $this->concept = $concept; // get the list of skos properties that reference resources $this->skosProps = SkosPropertyPeer::getResourceProperties(); $this->namespaces = $vocabulary->getNamespaces(); //get top concepts for vocabulary $this->getTopConcepts($vocabulary); }
/** * @return \Ddeboer\DataImport\Result * @throws \Ddeboer\DataImport\Exception\ExceptionInterface * @throws \Exception */ public function processData() { $workflow = new Workflow($this->reader); $output = new ConsoleOutput(); // Don’t import the non-metadata $filter = new Filter\CallbackFilter(function ($row) { if (is_numeric($row['reg_id'])) { return true; } if ( ! trim($row['reg_id'])) { foreach ($row as $item) { if ( ! is_array($item)) { if (trim($item)) { return true; } } else { foreach ($item as $foo) { if (trim($foo)) { return true; } } } } } return false; }); $trimConverter = new CallbackItemConverter(function ($row) { foreach ($row as $key => $value) { $row[$key] = trim($row[$key]); } return $row; }); $lexicalConverter = new CallbackItemConverter(function ($row) { foreach ($row as $key => $value) { if (isset( $this->prolog['columns'][$key]['id'] ) and $this->prolog['columns'][$key]['id'] == 27) { $lang = $this->prolog['columns'][$key]['lang']; //check for existing language suffix if ($value and ! preg_match("/\\." . $lang . "$/u", $value)) { $row[$key] = $value . "." . $lang; } } } return $row; }); $typeConverter = new MappingValueConverter([ 'rdfs:class' => 'class', 'rdfs:property' => 'property', 'class' => 'class', 'property' => 'property', 'Class' => 'class', 'Property' => 'property', 'subclass' => 'class', 'subproperty' => 'property', '' => '', ]); $vocabWriter = new Writer\CallbackWriter(function ($row) { $this->setPrologColumns(); //todo: $row[59] (status) and $row[62] (uri) sre hardcoded but the array key should be set somewhere globally if ( ! isset( $row[59] )) { $row[59] = $this->prolog['defaults']['statusId']; } $rowStatus = $row[59]; $language = $this->prolog['defaults']['lang']; foreach ($row as $key => &$element) { $this->updateRowUris($key, $element); } $uri = $this->getFqn($row[62]); $property = null; if ( ! empty( $row['reg_id'] )) { $property = \ConceptPeer::retrieveByPK($row['reg_id']); } else { //check for an existing property by uri /** @var \Concept $property */ $property = \ConceptPeer::getConceptByUri($uri); } //even if we found a property, we kill it if it's in a different schema than we're populating if ($property and $property->getVocabularyId() !== $this->vocabId) { //todo: we should log this event unset( $property ); } if (empty( $property )) { //it's a new property $property = new \Concept(); $property->setVocabularyId($this->vocabId); $property->setCreatedUserId($this->userId); $property->setUpdatedUserId($this->userId); $property->setStatusId($rowStatus); $property->setLanguage($language); $property->setUri($uri); $property->save(); } unset( $row['reg_id'] ); if ($property) { // if (8 == $rowStatus) { // //it's been deprecated and we don't do anything else // $property->setStatusId($rowStatus); // $this->updateElement($element, $dbElement, $property); // } else { $dbElements = $property->getElementsForImport($this->profileProperties); foreach ($dbElements as $key => $dbElement) { /** @var string | array $rowElement */ $rowElement = isset( $row[$key] ) ? $row[$key] : null; if (is_array($rowElement)) { foreach ($rowElement as $elementKey => &$element) { if ($this->updateConceptProperty($element, $dbElement, $property)) { unset( $rowElement[$elementKey] ); } } } else { if ($this->updateConceptProperty($rowElement, $dbElement, $property)) { unset( $row[$key] ); } } } foreach ($row as $key => $value) { $dbElement = isset( $dbElements[$key] ) ? $dbElements[$key] : null; if ( ! empty( $this->prolog['columns'][$key]['property'] )) { $profileProperty = $this->prolog['columns'][$key]['property']; if (is_array($value)) { foreach ($value as &$oneValue) { $language = $this->prolog['columns'][$key]['lang'][0]; $this->upsertConceptFromRow($dbElement, $oneValue, $rowStatus, $property, $profileProperty, $language, $key); } } else { $language = $this->prolog['columns'][$key]['lang']; $this->upsertConceptFromRow($dbElement, $value, $rowStatus, $property, $profileProperty, $language, $key); } } } } $property->setUri($uri); $property->setStatusId($rowStatus); $affectedRows = $property->save(); if (empty( $property->getPrefLabel() )) { $prefLabel = \ConceptPropertyPeer::lookupProperty($property->getId(), 19, $this->prolog['defaults']['lang']); if ( ! empty( $prefLabel )) { $property->setPrefLabel($prefLabel->getObject()); $property->setPrefLabelId($prefLabel->getId()); $property->setLanguage($this->prolog['defaults']['lang']); $property->save(); } } return; //************** // CRUFT ALERT // The rest of this is never run!! //************** //build an array of references $newElements = [ ]; $newElements2 = [ ]; if ( ! isset( $row['status'] )) { $row[14] = $this->prolog['defaults']['statusId']; } foreach ($row as $key => $element) { //skip it there's no property id $columnKey = $this->prolog['columns'][$key]; if ( ! $columnKey['id']) { continue; } if ( ! empty( $columnKey['type'] ) and $this->useCuries) { $element = $this->getFqn($element); } $key2 = md5(strval($columnKey['id']) . strval($columnKey['lang']) . $element); $newElements[$key2] = [ ]; $newElements[$key2] += $columnKey; $newElements[$key2]['val'] = $element; /** @var \ProfileProperty $profileProperty */ if (isset( $columnKey['property'] )) { $profileProperty = $columnKey['property']; $var = [ 'matchkey' => $key2, 'val' => $newElements[$key2], ]; if (isset( $profileProperty ) and $profileProperty->getHasLanguage()) { $newElements2[$columnKey['id']][$columnKey['lang']][] = $var; } else { $newElements2[$columnKey['id']][] = $var; } } } if ( ! empty( $row['reg_id'] )) { $property = \SchemaPropertyPeer::retrieveByPK($row['reg_id']); if ($property) { $dbElements = $property->getSchemaPropertyElementsRelatedBySchemaPropertyIdJoinProfileProperty(); $dbElements2 = [ ]; /** @var \SchemaPropertyElement $dbElement */ foreach ($dbElements as $dbElement) { if ($dbElement->getProfileProperty()->getHasLanguage()) { $dbElements2[$dbElement->getProfilePropertyId()][$dbElement->getLanguage()][] = &$dbElement; } else { $dbElements2[$dbElement->getProfilePropertyId()][] = &$dbElement; } } /** @var \SchemaPropertyElement $element */ foreach ($dbElements as $element) { $language = $element->getLanguage(); $profilePropertyId = $element->getProfilePropertyId(); $key = md5(strval($profilePropertyId) . strval($language) . $element->getObject()); //if the newelement key matches then if (isset( $newElements[$key] )) { if ($element->getProfileProperty()->getHasLanguage()) { $newElements2Array = $newElements2[$profilePropertyId][$language]; } else { $newElements2Array = $newElements2[$profilePropertyId]; } $count = count($newElements2Array); for ($I = 0; $I < $count; $I++) { if ($newElements2Array[$I]['matchkey'] == $key) { unset( $newElements2Array[$I] ); } } unset( $newElements[$key] ); $element->importStatus = 'match'; continue; } else { if ($element->getProfileProperty()->getHasLanguage()) { if (isset( $newElements2[$profilePropertyId][$language] )) { $count = count($newElements2[$profilePropertyId][$language]); for ($I = 0; $I < $count; $I++) { if ($newElements2[$profilePropertyId][$language][$I]['val']['val'] == $element->getObject()) { unset( $newElements2[$profilePropertyId][$language][$I] ); $element->importStatus = 'match'; if ( ! count($newElements2[$profilePropertyId][$language])) { unset( $newElements2[$profilePropertyId][$language] ); } continue; } } } } else { //compare the old values with the new with the same key $count = count($newElements2[$profilePropertyId]); for ($I = 0; $I < $count; $I++) { if (isset( $newElements2[$profilePropertyId][$I] )) { if ($newElements2[$profilePropertyId][$I]['val']['val'] == $element->getObject()) { unset( $newElements2[$profilePropertyId][$I] ); $element->importStatus = 'match'; continue; } } } } //if the key matches then //if the value matches //delete the newElement //else the value doesn't match //if the newElement value is empty //delete the dbElement } $element->matchKey = $key; } //update the property values $property->save(); } else { //there's no existing property an we have to create a new one $property = new \SchemaProperty(); } foreach ($newElements as $key => $newElement) { if ( ! empty( $newElement['id'] ) and ! isset( $oldElements[$key] )) { $profileProperty = $newElement['property']; //walk the old elements looking for a match on predicate + language /** @var \SchemaPropertyElement[] $oldElement */ foreach ($dbElements as $oldElement) { /** @var \SchemaPropertyElement $oldOne */ $oldOne = &$oldElement['element']; if ($newElement['id'] == $oldOne->getProfilePropertyId()) { /** @var \ProfileProperty $profileProperty */ if (( $profileProperty->getHasLanguage() and $newElement['lang'] == $oldOne->getLanguage() ) or ! $profileProperty->getHasLanguage()) { if ( ! empty( $newElement['val'] )) { $oldOne->setObject($newElement['val']); $oldOne->setUpdatedUserId($this->userId); $oldOne->setStatusId($row['status']); //$oldOne->save(); $oldElement['status'] = "updated"; } else { $oldOne->delete(); $oldElement['status'] = "deleted"; } //update the property value if ($profileProperty->getIsInForm()) { $this->setPropertyValue($newElement['val'], $property, $profileProperty->getName(), ! $profileProperty->getIsObjectProp()); } break; } } } //we looked through them all, add a new one if ( ! empty( $newElement['val'] )) { $addMe = new \SchemaPropertyElement(); $addMe->setObject($newElement['val']); //$addMe->setSchemaPropertyRelatedBySchemaPropertyId($property); $addMe->setCreatedUserId($this->userId); $addMe->setUpdatedUserId($this->userId); $addMe->setLanguage($newElement['lang']); $addMe->setProfilePropertyId($newElement['id']); $addMe->setStatusId($row['status']); $addMe->importId = $this->importId; //$addMe->save(); $property->addSchemaPropertyElementRelatedBySchemaPropertyId($addMe); //update the property value if ($profileProperty->getIsInForm()) { $this->setPropertyValue($newElement['val'], $property, $profileProperty->getName(), ! $profileProperty->getIsObjectProp()); } } } } //update the property if ($property) { $property->setStatusId($row['status']); $property->save(); } } //var_dump($row); }); $schemaWriter = new Writer\CallbackWriter(function ($row) { $this->setPrologColumns(); if ( ! isset( $row[14] )) { $row[14] = $this->prolog['defaults']['statusId']; } $rowStatus = $row[14]; $language = $this->prolog['defaults']['lang']; foreach ($row as $key => &$element) { $this->updateRowUris($key, $element); } $uri = $row[13]; $property = null; $schemaId = $this->vocabId; if ( ! empty( $row['reg_id'] )) { $property = \SchemaPropertyPeer::retrieveByPK($row['reg_id']); } else { //check for an existing property by uri /** @var \SchemaProperty $property */ $property = \SchemaPropertyPeer::retrieveByUri($uri); if ($property) { $schemaId = $property->getSchemaId(); } } //even if we found a property, we kill it if it's in a different schema than we're populating if ($property and $schemaId !== $this->vocabId) { //todo: we should log this event unset( $property ); } if (empty( $property )) { //it's a new property $property = new \SchemaProperty(); $property->setSchemaId($this->vocabId); $property->setCreatedUserId($this->userId); $property->setUpdatedUserId($this->userId); $property->setStatusId($rowStatus); $property->setLanguage($language); $property->save(); } unset( $row['reg_id'] ); if ($property) { // if (8 == $rowStatus) { // //it's been deprecated and we don't do anything else // $property->setStatusId($rowStatus); // $this->updateElement($element, $dbElement, $property); // } else { $dbElements = $property->getElementsForImport($this->profileProperties); foreach ($dbElements as $key => $dbElement) { /** @var string | array $rowElement */ $rowElement = isset( $row[$key] ) ? $row[$key] : null; if (is_array($rowElement)) { foreach ($rowElement as $elementKey => &$element) { if ($this->updateElement($element, $dbElement, $property)) { unset( $rowElement[$elementKey] ); } } } else { if ($this->updateElement($rowElement, $dbElement, $property)) { unset( $row[$key] ); } } } foreach ($row as $key => $value) { $dbElement = isset( $dbElements[$key] ) ? $dbElements[$key] : null; if ( ! empty( $this->prolog['columns'][$key]['property'] )) { $profileProperty = $this->prolog['columns'][$key]['property']; if (is_array($value)) { foreach ($value as &$oneValue) { $language = $this->prolog['columns'][$key]['lang'][0]; $this->upsertElementFromRow($dbElement, $oneValue, $rowStatus, $property, $profileProperty, $language, $key); } } else { $language = $this->prolog['columns'][$key]['lang']; $this->upsertElementFromRow($dbElement, $value, $rowStatus, $property, $profileProperty, $language, $key); } if ($key == 'parent_class' and strtolower($property->getType()) == 'class' and $row[$key] != $property->getParentUri()) { $property->setParentUri($row[$key]); //we'll set this later $property->setIsSubpropertyOf(null); } if ($key == 'parent_property' and strtolower($property->getType()) == 'property' and $row[$key] != $property->getParentUri()) { $property->setParentUri($row[$key]); //we'll set this later $property->setIsSubpropertyOf(null); } } } } $affectedRows = $property->save(); // } return; //build an array of references $newElements = [ ]; $newElements2 = [ ]; if ( ! isset( $row['status'] )) { $row[14] = $this->prolog['defaults']['statusId']; } foreach ($row as $key => $element) { //skip it there's no property id $columnKey = $this->prolog['columns'][$key]; if ( ! $columnKey['id']) { continue; } if ( ! empty( $columnKey['type'] ) and $this->useCuries) { $element = $this->getFqn($element); } $key2 = md5(strval($columnKey['id']) . strval($columnKey['lang']) . $element); $newElements[$key2] = [ ]; $newElements[$key2] += $columnKey; $newElements[$key2]['val'] = $element; /** @var \ProfileProperty $profileProperty */ if (isset( $columnKey['property'] )) { $profileProperty = $columnKey['property']; $var = [ 'matchkey' => $key2, 'val' => $newElements[$key2], ]; if (isset( $profileProperty ) and $profileProperty->getHasLanguage()) { $newElements2[$columnKey['id']][$columnKey['lang']][] = $var; } else { $newElements2[$columnKey['id']][] = $var; } } } if ( ! empty( $row['reg_id'] )) { $property = \SchemaPropertyPeer::retrieveByPK($row['reg_id']); if ($property) { $dbElements = $property->getSchemaPropertyElementsRelatedBySchemaPropertyIdJoinProfileProperty(); $dbElements2 = [ ]; /** @var \SchemaPropertyElement $dbElement */ foreach ($dbElements as $dbElement) { if ($dbElement->getProfileProperty()->getHasLanguage()) { $dbElements2[$dbElement->getProfilePropertyId()][$dbElement->getLanguage()][] = &$dbElement; } else { $dbElements2[$dbElement->getProfilePropertyId()][] = &$dbElement; } } /** @var \SchemaPropertyElement $element */ foreach ($dbElements as $element) { $language = $element->getLanguage(); $profilePropertyId = $element->getProfilePropertyId(); $key = md5(strval($profilePropertyId) . strval($language) . $element->getObject()); //if the newelement key matches then if (isset( $newElements[$key] )) { if ($element->getProfileProperty()->getHasLanguage()) { $newElements2Array = $newElements2[$profilePropertyId][$language]; } else { $newElements2Array = $newElements2[$profilePropertyId]; } $count = count($newElements2Array); for ($I = 0; $I < $count; $I++) { if ($newElements2Array[$I]['matchkey'] == $key) { unset( $newElements2Array[$I] ); } } unset( $newElements[$key] ); $element->importStatus = 'match'; continue; } else { if ($element->getProfileProperty()->getHasLanguage()) { if (isset( $newElements2[$profilePropertyId][$language] )) { $count = count($newElements2[$profilePropertyId][$language]); for ($I = 0; $I < $count; $I++) { if ($newElements2[$profilePropertyId][$language][$I]['val']['val'] == $element->getObject()) { unset( $newElements2[$profilePropertyId][$language][$I] ); $element->importStatus = 'match'; if ( ! count($newElements2[$profilePropertyId][$language])) { unset( $newElements2[$profilePropertyId][$language] ); } continue; } } } } else { //compare the old values with the new with the same key $count = count($newElements2[$profilePropertyId]); for ($I = 0; $I < $count; $I++) { if (isset( $newElements2[$profilePropertyId][$I] )) { if ($newElements2[$profilePropertyId][$I]['val']['val'] == $element->getObject()) { unset( $newElements2[$profilePropertyId][$I] ); $element->importStatus = 'match'; continue; } } } } //if the key matches then //if the value matches //delete the newElement //else the value doesn't match //if the newElement value is empty //delete the dbElement } $element->matchKey = $key; } //update the property values $property->save(); } else { //there's no existing property an we have to create a new one $property = new \SchemaProperty(); } foreach ($newElements as $key => $newElement) { if ( ! empty( $newElement['id'] ) and ! isset( $oldElements[$key] )) { $profileProperty = $newElement['property']; //walk the old elements looking for a match on predicate + language /** @var \SchemaPropertyElement[] $oldElement */ foreach ($dbElements as $oldElement) { /** @var \SchemaPropertyElement $oldOne */ $oldOne = &$oldElement['element']; if ($newElement['id'] == $oldOne->getProfilePropertyId()) { /** @var \ProfileProperty $profileProperty */ if (( $profileProperty->getHasLanguage() and $newElement['lang'] == $oldOne->getLanguage() ) or ! $profileProperty->getHasLanguage()) { if ( ! empty( $newElement['val'] )) { $oldOne->setObject($newElement['val']); $oldOne->setUpdatedUserId($this->userId); $oldOne->setStatusId($row['status']); //$oldOne->save(); $oldElement['status'] = "updated"; } else { $oldOne->delete(); $oldElement['status'] = "deleted"; } //update the property value if ($profileProperty->getIsInForm()) { $this->setPropertyValue($newElement['val'], $property, $profileProperty->getName(), ! $profileProperty->getIsObjectProp()); } break; } } } //we looked through them all, add a new one if ( ! empty( $newElement['val'] )) { $addMe = new \SchemaPropertyElement(); $addMe->setObject($newElement['val']); //$addMe->setSchemaPropertyRelatedBySchemaPropertyId($property); $addMe->setCreatedUserId($this->userId); $addMe->setUpdatedUserId($this->userId); $addMe->setLanguage($newElement['lang']); $addMe->setProfilePropertyId($newElement['id']); $addMe->setStatusId($row['status']); $addMe->importId = $this->importId; //$addMe->save(); $property->addSchemaPropertyElementRelatedBySchemaPropertyId($addMe); //update the property value if ($profileProperty->getIsInForm()) { $this->setPropertyValue($newElement['val'], $property, $profileProperty->getName(), ! $profileProperty->getIsObjectProp()); } } } } //update the property if ($property) { $property->setStatusId($row['status']); $property->save(); } } //var_dump($row); }); $workflow->addItemConverter($this->mapping); $workflow->addFilter($filter); $workflow->addItemConverter($trimConverter); $workflow->addItemConverter($lexicalConverter); $workflow->addWriter(new Writer\ConsoleProgressWriter($output, $this->reader)); $workflow->addValueConverter("4", $typeConverter); //add a database writer if ('schema' == $this->type) { $workflow->addWriter($schemaWriter); } else { $workflow->addWriter($vocabWriter); } /** @todo we need to make a second pass through to delete missing rows * for each schemaproperty in the database * match to a row in the csv * if the row value is empty and $this->deleteMissing * delete the entire schemaproperty */ $workResults = $workflow->process(); $this->DataWorkflowResults = $workResults; /** @TODO need to make a second pass through to lookup and set $element->related_schema_property_id */ $this->processParents($this->vocabId); //use the prolog to configure namespaces, look up correct resources in the database //store the row number of the first non-meta line return $workResults; }
/** * Gets the related vocabulary object * * @return Vocabulary */ public function getRelatedConcept() { return ConceptPeer::retrieveByPK($this->related_concept_id); }
/** * description * * @return Concept Current concept object * @param integer $vocabId */ public static function setLatestConcept($vocabId) { $vocabObj = ConceptPeer::retrieveByPK($vocabId); sfContext::getInstance()->getUser()->setCurrentConcept($vocabObj); return $vocabObj; }
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(); }