public function executePropertylist() { $c = new Criteria(); $c->add(SchemaPropertyPeer::SCHEMA_ID, $this->schemaId); // $c->addDescendingOrderByColumn(ConceptPropertyPeer::SKOS_PROPERTY_ID); $this->properties = SchemaPropertyPeer::doSelect($c); }
public function execute(&$value, &$error) { $propertyId = $this->getContext()->getRequest()->getParameter('id'); $c = new Criteria(); $c->add(SchemaPropertyPeer::URI, $value); $object = SchemaPropertyPeer::doSelectOne($c); if ($object) { //check to see if the retrieved object has the same id if ($propertyId && $object->getId() == $propertyId) { return true; } else { $error = $this->getParameter('unique_error'); return false; } } return true; }
public function execute(&$value, &$error) { $schemaId = $this->getContext()->getRequest()->getParameter('schema_id'); $propertyId = $this->getContext()->getRequest()->getParameter('id'); $c = new Criteria(); $c->add(SchemaPropertyPeer::NAME, $value); $c->add(SchemaPropertyPeer::SCHEMA_ID, $schemaId); $object = SchemaPropertyPeer::doSelectOne($c); if ($object) { //it's ok to use if the status is deprecated if ($object->getStatusId() == 8) { return true; } //check to see if the retrieved object has the same id if ($propertyId && $object->getId() == $propertyId) { return true; } else { $error = $this->getParameter('unique_error'); return false; } } return true; }
/** * @param int $schemaId * @return array */ public static function getNamespaceList($schemaId) { $namespaces = array(); $c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(SchemaPropertyElementPeer::OBJECT); $c->add(SchemaPropertyElementPeer::OBJECT, "http%", Criteria::LIKE); $c->add(SchemaPropertyPeer::SCHEMA_ID, $schemaId); $c->addJoin(SchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $result = self::doSelectRS($c); self::getNamespaceUris($result, 'getObject', $namespaces); $c = new Criteria(); $c->clearSelectColumns(); $c->addSelectColumn(SchemaPropertyPeer::URI); $c->add(SchemaPropertyPeer::SCHEMA_ID, $schemaId); $result = SchemaPropertyPeer::doSelectRS($c); self::getNamespaceUris($result, 'getUri', $namespaces); return $namespaces; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param Connection $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(SchemaPropertyPeer::ID, $pks, Criteria::IN); $objs = SchemaPropertyPeer::doSelect($criteria, $con); } return $objs; }
function run_import_repair($task, $args) { //xdebug_break(); if (count($args) < 1) { throw new Exception('You must provide a batch ID.'); } $batchId = $args[0]; //get the import history for the batchid $criteria = new Criteria(); $criteria->add(\FileImportHistoryPeer::BATCH_ID, $batchId); $batch = \FileImportHistoryPeer::doSelect($criteria); if (empty($batch)) { throw new Exception('Not a valid batch ID.'); } $criteria = new \Criteria(); $criteria->add(\ProfilePropertyPeer::NAME, "isSameAs"); /** @var $profileProperty \ProfileProperty */ $profileProperty = \ProfilePropertyPeer::doSelectOne($criteria); $sameasId = $profileProperty->getId(); //for each one in the list /** @var $history FileImportHistory */ foreach ($batch as $history) { //get result array $results = $history->getResults(); $rows = $results['success']['rows']; $userId = $history->getUserId(); //for each row foreach ($rows as $row) { //get the references /** @var $property \SchemaProperty */ $property = \SchemaPropertyPeer::retrieveByPK($row['id']); /** @var $ref \SchemaProperty */ $ref = \SchemaPropertyPeer::retrieveByUri($property->getParentUri()); if ($property and $ref) { $property->setIsSubpropertyOf($ref->getId()); $property->saveSchemaProperty($userId); } //update the parent property if (isset($row['statements'])) { //for each statement foreach ($row['statements'] as $statement) { //get the references if ($sameasId != $statement['propertyId']) { /** @var $ref \SchemaProperty */ $ref = \SchemaPropertyPeer::retrieveByUri($statement['object']); } else { //ref = the parent $ref = $property; } /** @var $propertyElement \SchemaPropertyElement */ $propertyElement = \SchemaPropertyElementPeer::retrieveByPK($statement['id']); if ($propertyElement and $ref) { $propertyElement->setSchemaPropertyRelatedByRelatedSchemaPropertyId($ref); $propertyElement->save(); } } } } } }
/** * @return string * @throws sfError404Exception */ public function executeGet() { /** @var myWebRequest $request **/ $request = $this->getRequest(); $redir = $this->getRequestParameter('redir', false); $uri = $this->getRequestParameter('uri'); if (!$uri) { $uri = "http://" . $request->getPathInfoParam('HTTP_HOST') . $request->getPathInfoParam('REQUEST_URI'); //strip trailing type $uri = preg_replace('/\\.\\w+$/U', '', $uri); //strip _dev script if it's part of the URI' $uri = preg_replace('%\\w+\\_dev.php/%', '', $uri); } $module = $this->getRequestParameter('type'); if ('unknown' == $module) { $accept = $request->getPathInfoParam('HTTP_ACCEPT'); $agent = $request->getPathInfoParam('HTTP_USER_AGENT'); //any of these will return html /*RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml) RewriteCond %{HTTP_ACCEPT} text/html [OR] RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.* RewriteRule ^(.*)$ rdtest.php?type=html&uri=$1 [QSA,L] */ if (!preg_match('%application/rdf\\+xml.*(text/html|application/xhtml\\+xml)%im', $accept) && (preg_match('%text/html%im', $accept) || preg_match('%application/xhtml\\+xml%im', $accept) || preg_match('%^Mozilla/.*%im', $agent) && preg_match('%\\*/\\*%im', $accept))) { $module = 'html'; } elseif (preg_match('%application/rdf\\+xml%im', $accept)) { $module = 'rdf'; } elseif (preg_match('%text/rdf+n3%im', $accept)) { $module = 'n3'; } else { $module = sfConfig::get('default_conneg_type'); } } $class = strtolower($this->getRequestParameter('class')); switch ($class) { case 'concept': switch ($module) { case 'html': /** @var Concept $concept **/ $concept = ConceptPeer::getConceptByUri($uri); $this->forward404Unless($concept); $uri = $request->getUriPrefix() . "/concept/show/id/" . $concept->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showConcept'); break; } break; case 'concept_scheme': case 'conceptscheme': switch ($module) { case 'html': /** @var Vocabulary $vocabulary **/ $vocabulary = VocabularyPeer::retrieveByUri($uri); $this->forward404Unless($vocabulary); $uri = $request->getUriPrefix() . "/vocabulary/show/id/" . $vocabulary->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showScheme'); break; case 'xsd': //reset the type $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'xml', 'showScheme'); break; } break; case 'schema': /** @var Schema $schema **/ $schema = SchemaPeer::retrieveByUri($uri); $this->forward404Unless($schema); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schema/show/id/" . $schema->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $schema->getId()); $this->forwardIf($uri, 'schema', 'showRdf'); break; } break; case 'schema_property': case 'schemaproperty': /** @var SchemaProperty $property **/ $property = SchemaPropertyPeer::retrieveByUri($uri); $this->forward404Unless($property); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schemaprop/show/id/" . $property->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $property->getId()); $this->forwardIf($uri, 'schemaprop', 'showRdf'); break; } break; default: $this->forward404(); } return sfView::NONE; }
/** * updates/creates/deletes the reciprocal property * * @param string $action * @param int $userId * @param int $schemaId * @param Connection $con * * @throws \PropelException */ public function updateReciprocal($action, $userId, $schemaId, $con = null) { $inverseProfilePropertyId = $this->getProfileProperty()->getInverseProfilePropertyId(); if (empty($inverseProfilePropertyId) and $this->getProfileProperty()->getIsReciprocal()) { $inverseProfilePropertyId = $this->getProfileProperty()->getId(); } if (!$inverseProfilePropertyId) { //there's no reciprocal or inverse to process return; } $relatedPropertyId = $this->getRelatedSchemaPropertyId(); if (!$relatedPropertyId) { $relatedProperty = SchemaPropertyPeer::retrieveByUri($this->getObject()); if (!$relatedProperty) { //there's no related property in the registry return; } else { $relatedPropertyId = $relatedProperty->getId(); $this->setRelatedSchemaPropertyId($relatedPropertyId); $this->save(); } } $schemaPropertyID = $this->getSchemaPropertyId(); $property = $this->getSchemaPropertyRelatedBySchemaPropertyId(); //does the user have editorial rights to the reciprocal... $permission = false; //get the maintainers of the reciprocal property $maintainers = $property->getSchema()->getMaintainerIds(); foreach ($maintainers as $maintainerId) { if ($userId == $maintainerId) { $permission = true; break; } } if (false === $permission) { return; } $c = new Criteria(); $c->add(SchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, $relatedPropertyId); $c->add(SchemaPropertyElementPeer::PROFILE_PROPERTY_ID, $inverseProfilePropertyId); $c->add(SchemaPropertyElementPeer::OBJECT, $property->getUri()); $recipElement = SchemaPropertyElementPeer::doSelectOne($c, $con); $recipSchemaProperty = SchemaPropertyPeer::retrieveByPK($relatedPropertyId, $con); $recipProfileProperty = ProfilePropertyPeer::retrieveByPK($inverseProfilePropertyId, $con); $statusId = $this->getStatusId(); $language = ''; if ($recipProfileProperty) { $recipField = $recipProfileProperty->getName(); if ($recipProfileProperty->getHasLanguage()) { $language = $this->getLanguage(); } } //if action == deleted then if ('deleted' == $action && $recipElement) { //delete the reciprocal $recipElement->delete($con); return; } //undelete the element if it's deleted and we get this far if (isset($recipElement)) { $recipElement->setDeletedAt(null); } //if action == added, and reciprocal doesn't exist if ('added' == $action && !$recipElement) { //add the reciprocal $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true); } //if action == updated if ('updated' == $action) { //check to see if there's a reciprocal if (!$recipElement) { //create a new one $recipElement = SchemaPropertyElementPeer::createElement($recipSchemaProperty, $userId, $inverseProfilePropertyId, $statusId, $language, false, true); } } if ($recipElement) { if (isset($this->importId)) { $recipElement->importId = $this->importId; } $recipElement->setUpdatedUserId($userId); $recipElement->setRelatedSchemaPropertyId($schemaPropertyID); $recipElement->setObject($this->getSchemaPropertyRelatedBySchemaPropertyId()->getUri()); $recipElement->save($con); } return; }
<?php $c = new Criteria(); $c->add(SchemaPropertyElementPeer::PROFILE_PROPERTY_ID, 12); /** @var SchemaProperty $schema_property */ $result = $schema_property->getSchemaPropertyElementsRelatedBySchemaPropertyId($c); if (count($result)) { /** @var SchemaPropertyElement $range */ $range = $result[0]; //get the related property $relProperty = $range->getSchemaPropertyRelatedByRelatedSchemaPropertyId(); if ($relProperty) { echo link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relProperty->getId(), ['title' => $relProperty->getUri()]); } else { $relProperty = SchemaPropertyPeer::retrieveByUri($range->getObject()); if ($relProperty) { //the id was broken, let's fix it... $range->setRelatedSchemaPropertyId($relProperty->getId()); $range->save(); echo link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relProperty->getId(), ['title' => $relProperty->getUri()]); } else { echo $range->getObject(); } } }
if ($id) { $schema = SchemaPeer::retrieveByPK($id); } } if (!empty($schema)) { $objectId = $schema->getID(); } break; case 'schemaprop': $showBc = true; $showSchemaBc = true; $showSchemaPropBc = true; if (!isset($schema_property)) { $id = 'show' == $action ? $sf_params->get('id') : $paramId; if ($id) { $schema_property = SchemaPropertyPeer::retrieveByPK($id); } } if (!isset($schema)) { if ($schema_property) { $objectId = $schema_property->getId(); $schema = $schema_property->getSchema(); } } break; case 'schemapropel': $showBc = true; $showSchemaBc = true; $showSchemaPropBc = true; $showSchemaPropelBc = true; if (!isset($schema_property_element)) {
/** * overload schemaSave * * @return mixed * * @param integer $userId * * @throws Exception * @throws PropelException */ public function saveSchemaProperty($userId) { //if the property is modified then if ($this->isModified() || $this->isNew()) { $fields = Schema::getProfileArray(); /** @var $field ProfileProperty */ foreach ($fields as $field) { $fieldIds[sfInflector::underscore($field->getName())] = ["id" => $field->getId(), "hasLang" => $field->getHasLanguage()]; } $statusId = $this->getStatusId(); $con = Propel::getConnection(SchemaPropertyPeer::DATABASE_NAME); try { //start a transaction $con->begin(); $this->setUpdatedUserId($userId); //if the property is new then if ($this->isNew()) { //set the created user $this->setCreatedUserId($userId); } //FIXME if the status is modified we have to update all of the existing statement statuses -- IF THEY MATCH THE OLD STATUS $columns = $this->modifiedColumns; //save it last $affectedRows = $this->save($con); $skipArray = ["is_subproperty_of", "is_subclass_of"]; foreach ($columns as $column) { $fieldName = SchemaPropertyPeer::translateFieldName($column, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME); if (in_array($fieldName, $skipArray)) { $object = $this->getParentUri(); if ("class" == $this->getType()) { $fieldName = "is_subclass_of"; $objectId = $this->getIsSubclassOf(); } else { $fieldName = "is_subproperty_of"; $objectId = $this->getIsSubpropertyOf(); } } else { $object = $this->getByName($column, BasePeer::TYPE_COLNAME); $objectId = null; } SchemaPropertyPeer::updateRelatedElements($this, $fieldName, $object, $objectId, $userId, $fieldIds, $statusId, $con); } //commit the transaction $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollback(); throw $e; } } }
/** * description * * @return SchemaProperty Current property property object * @param integer $propertyId */ public static function setLatestSchemaProperty($propertyId) { $propertyObj = SchemaPropertyPeer::retrieveByPK($propertyId); sfContext::getInstance()->getUser()->setCurrentSchemaProperty($propertyObj); return $propertyObj; }
/** * Builds a multi-dimensional array of Schemas[SchemaProperties] * Optionally returns a script tag * * @param integer $userId * * @param bool $makeScript * @param string $var * * @return array */ function schema_for_user_select_array($userId, $makeScript = FALSE, $var = '') { //get the schemas for a user $schemasArray = SchemaHasUserPeer::getSchemasForUser($userId); $schemas = array(); /** @var $schema Schema */ foreach ($schemasArray as $schema) { //select schema properties to add to array $schemaId = $schema->getId(); $schemas[$schemaId] = array('name' => $schema->getName(), 'uri' => $schema->getUri(), 'properties' => array()); $schemaPropArray = SchemaPropertyPeer::getElementsForSchema($schemaId); /** @var $element SchemaProperty */ foreach ($schemaPropArray as $schemaProp) { $schemaPropId = $schemaProp->getId(); $schemas[$schemaId]['properties'][$schemaPropId] = array('name' => $schemaProp->getLabel(), 'uri' => $schemaProp->getUri(), 'type' => $schemaProp->getType()); } } if ($makeScript) { $var = $var ? $var : "data"; $content = "var {$var} = " . json_encode($schemas); return javascript_tag($content); } return $schemas; }
/** @var SchemaPropertyElement $element */ foreach ($elements as $element) { if ($element->getIsGenerated()) { if ($excludeGenerated) { continue; } } /** @var ProfileProperty $property */ $property = $element->getProfileProperty(); $object = $element->getObject(); $related = $element->getRelatedSchemaPropertyId(); $uri = $property->getUri(); if ('type' == $property->getName()) { $object = $typeArray[$object]; } if ($object) { if ($property->getIsObjectProp()) { echo ' <' . $uri . ' rdf:resource="' . rtrim($object) . '" />' . PHP_EOL; } else { echo " <" . $uri . ' xml:lang="' . $element->getLanguage() . '">' . htmlspecialchars(html_entity_decode($object, ENT_QUOTES | ENT_HTML5, 'UTF-8'), ENT_NOQUOTES, "UTF-8", false) . '</' . $uri . '>' . PHP_EOL; } } if ($related && empty($object)) { $relatedProperty = SchemaPropertyPeer::retrieveByPK($related); echo '<' . $uri . ' rdf:resource="' . $relatedProperty->getUri() . '" />' . PHP_EOL; } } ?> </rdf:Description>
public function executeGetSchemaPropertyList() { $schemaId = $this->getRequestParameter('selectedSchemaId'); $schemapropId = sfContext::getInstance()->getUser()->getAttribute('schemaprop')->getId(); $results = SchemaPropertyPeer::getSchemaPropertysByVocabID($schemaId, $schemapropId); foreach ($results as $myCschemaprop) { $options[$myCschemaprop->getId()] = $myCschemaprop->getPrefLabel(); } if (!isset($options)) { $options[''] = 'There are no related schemaprops to select'; } $this->schemaprops = $options; }
function run_import_marc_vocabulary($task, $args) { //check the argument counts if (count($args) < 1) { throw new Exception('You must provide a vocabulary type.'); } if (count($args) < 2) { throw new Exception('You must provide a file name.'); } if (count($args) < 3) { throw new Exception('You must provide a vocabulary id.'); } //set the arguments $type = strtolower($args[0]); $filePath = $args[1]; $id = $args[2]; $deleteMissing = (isset($args[3]) && ("-d" == $args[3])); //do some basic validity checks if (! in_array($type, array("schema", "vocab", "vocabulary"))) { throw new Exception('You must import into a schema or a vocab'); } if ("vocabulary" == $type) { $type = "vocab"; } if (! is_numeric($id)) { throw new Exception('You must provide a valid ID'); } //does the file exist? if (! file_exists($filePath)) { throw new Exception('You must supply a valid file to import: ' . $filePath); } //is the file a valid type? if (preg_match('/^.+\.([[:alpha:]]{2,4})$/', $filePath, $matches)) { if (! in_array(strtolower($matches[1]), array("json", "rdf", "csv", "xml"))) { throw new Exception('You must provide a valid file type based on the extension'); } } else { throw new Exception("File type cannot be determined from the file extension"); } $fileType = $matches[1]; //is the object a valid object? if ('vocab' == $type) { $vocabObj = VocabularyPeer::retrieveByPK($id); if (is_null($vocabObj)) { throw new Exception('Invalid vocabulary ID'); } //set some defaults $baseDomain = $vocabObj->getBaseDomain(); $language = $vocabObj->getLanguage(); $statusId = $vocabObj->getStatusId(); //get a skos property id map $skosMap = SkosPropertyPeer::getPropertyNames(); //there has to be a hash or a slash $tSlash = preg_match('@(/$)@i', $vocabObj->getUri()) ? '' : '/'; $tSlash = preg_match('/#$/', $vocabObj->getUri()) ? '' : $tSlash; } else { $schemaObj = SchemaPeer::retrieveByPK($id); if (is_null($schemaObj)) { throw new Exception('Invalid schema ID'); } //set some defaults $baseDomain = $schemaObj->getUri(); $language = $schemaObj->getLanguage(); $statusId = $schemaObj->getStatusId(); //get a element set property id map $profileId = 1; $profile = ProfilePeer::retrieveByPK($profileId); $elementMap = $profile->getAllProperties(); //there has to be a hash or a slash $tSlash = preg_match('@(/$)@i', $baseDomain) ? '' : '/'; $tSlash = preg_match('/#$/', $baseDomain) ? '' : $tSlash; } // insert jon's user id $userId = 36; /* From here on the process is the same regardless of UI */ //execute // parse file to get the fields/columns and data $file = fopen($filePath, "r"); if (! $file) { throw new Exception("Can't read supplied file"); } // check to see if file has been uploaded before // check import history for file name $importHistory = FileImportHistoryPeer::retrieveByLastFilePath($filePath); // if reimport // get last import history for filename // unserialize column map // match column names to AP based on map // look for matches in unmatched field/column names to AP (ideal) // csv table of data -- // row1: parsed field names/column headers // row2: select dropdown with available fields from object AP (pre-select known matches) // each select identified by column number // row3: display datatype of selected field (updated dynamically when field selected) // row4-13: first 10 rows of parsed data from file // require a column that can match to 'URI' (maybe we'll allow an algorithm later) // require columns that are required by AP // on reimport there should be a flag to 'delete missing properties' from the current data // note: at some point there will be a reimport process that allows URI changing // this will require that there be an OMR identifier embedded in the incoming data switch ($fileType) { case "csv": try { $reader = new aCsvReader($filePath); } catch(Exception $e) { throw new Exception("Not a happy CSV file!"); } if ('vocab' == $type) { // Get array of heading names found $headings = $reader->getHeadings(); $fields = ConceptPeer::getFieldNames(); //set the map // $map[] = array("property" => "Uri", "column" => "URILocal"); // $map[] = array("property" => "prefLabel", "column" => "skos:prefLabel"); // $map[] = array("property" => "definition", "column" => "skos:definition"); // $map[] = array("property" => "notation", "column" => "skos:notation"); // $map[] = array("property" => "scopeNote", "column" => "skos:scopeNote"); $map = array( "uri" => "URILocal", "prefLabel" => "skos:prefLabel", "definition" => "skos:definition", "notation" => "skos:notation", "scopeNote" => "skos:scopeNote" ); $rows = 0; //executeImport: // serialize the column map try { while ($row = $reader->getRow()) { $rows ++; // lookup the URI (or the OMR ID if available) for a match $uri = $baseDomain . $row[$map["uri"]]; $concept = ConceptPeer::getConceptByUri($uri); $updateTime = time(); $language = (isset($map['language'])) ? $row[$map['language']] : $vocabObj->getLanguage(); if (! $concept) { // create a new concept or element $concept = new Concept(); $concept->setVocabulary($vocabObj); $concept->setUri($uri); /** * @todo Need to handle updates for topconcept here, just like language **/ $concept->setIsTopConcept(false); $concept->updateFromRequest( $userId, fixMarcEncoding(rtrim($row[$map['prefLabel']])), $language, $statusId ); } //don't update the concept if the preflabel matches else if ($row[$map['prefLabel']] != $concept->getPrefLabel()) { $concept->updateFromRequest($userId, fixMarcEncoding(rtrim($row[$map['prefLabel']]))); } //there needs to be a language to lookup the properties unless it's an objectProperty $rowLanguage = (isset($map['language'])) ? $row[$map['language']] : $concept->getLanguage(); foreach ($map as $key => $value) { //we skip because we already did them if (! in_array($key, array('uri', 'prefLabel', 'language'))) { $skosId = $skosMap[$key]; //check to see if the property already exists $property = ConceptPropertyPeer::lookupProperty($concept->getId(), $skosId, $rowLanguage); //create a new property for each unmatched column if (! empty($row[$value])) { if (! $property) { $property = new ConceptProperty(); $property->setCreatedUserId($userId); $property->setConceptId($concept->getId()); $property->setCreatedAt($updateTime); $property->setSkosPropertyId($skosId); } if (($row[$value] != $property->getObject()) || ($rowLanguage != $property->getLanguage()) ) { /** * @todo We need a check here for skos objectproperties and handle differently **/ if ($rowLanguage != $property->getLanguage()) { $property->setLanguage($rowLanguage); } if ($row[$value] != $property->getObject()) { $property->setObject(fixMarcEncoding(rtrim($row[$value]))); } $property->setUpdatedUserId($userId); $property->setUpdatedAt($updateTime); $property->save(); } } //the row value is empty else if ($deleteMissing && $property) { $property->delete(); } } } // else // lookup and update concept or element // lookup and update each property // update the history for each property, action is 'import', should be a single timestamp for all (this should be automatic) // if 'delete missing properties' is true // delete each existing, non-required property that wasn't updated by the import } } catch(Exception $e) { // catch // if there's an error of any kind, write to error log and continue echo "Error on row: " . $rows . ", " . $uri . "\n" . $e . "\n"; continue; } $objects = $vocabObj->countConcepts(); } else //it's an element set { $map = array( "uri" => "uriLocalPart", "name" => "reg:name", "definition" => "skos:definition", "label" => "rdfs:label", "note" => array("tag" => "tagCap", "ind1" => "ind1Cap", "ind2" => "ind2Cap", "sub" => "subCap") ); $rows = 0; //executeImport: // serialize the column map try { while ($row = $reader->getRow()) { // lookup the URI (or the OMR ID if available) for a match //There always has to be a URI on either update or create if (! isset($row[$map["uri"]])) { throw new Exception('Missing URI for row: ' . $reader->getRowCount()); continue; } $rows ++; $uri = $baseDomain . $tSlash . $row[$map["uri"]]; $property = SchemaPropertyPeer::retrieveByUri($uri); $updateTime = time(); $rowLanguage = (isset($map['language'])) ? $row[$map['language']] : $language; $rowStatusId = (isset($map['status'])) ? $row[$map['status']] : $statusId; if (! $property) { // create a new property /** @var SchemaProperty * */ $property = new SchemaProperty(); $property->setSchema($schemaObj); $property->setUri($uri); $property->setCreatedUserId($userId); $property->setCreatedAt($updateTime); } $property->setLanguage($rowLanguage); $property->setStatusId($rowStatusId); $property->setUpdatedUserId($userId); $property->setUpdatedAt($updateTime); if (isset($row[$map["label"]])) { $property->setLabel($row[$map["label"]]); } if (isset($row[$map["name"]])) { $property->setName($row[$map["name"]]); } if (isset($row[$map["definition"]])) { $property->setDefinition($row[$map["definition"]]); } if (is_array($map["note"])) { $note = ''; foreach ($map["note"] as $key => $value) { $caption = ! empty($row[$value]) ? " (" . $row[$value] . ")" : ' (no caption)'; $note .= ! empty($row[$key]) ? $key . ": " . $row[$key] . $caption . "<br />" : ""; } $property->setNote($note); } else { if (isset($row[$map["note"]])) { $property->setNote($row[$map["note"]]); } } $property->saveSchemaProperty($userId); /** * @todo Need to handle domain and range **/ foreach ($map as $key => $value) { //we skip because we already did them if (! in_array( $key, array('uri', 'status', 'language', 'label', 'name', 'definition', 'comment', 'note') ) ) { $elementId = $elementMap[$key]; //check to see if the property already exists //note that this also checks the object value as well, so there's no way to update or delete an existing triple //the sheet would have to conatin the identifier for the triple $element = SchemaPropertyElementPeer::lookupElement( $schemaObj->getId(), $elementId, $map[$value] ); //create a new property for each unmatched column if (! empty($row[$value])) { if (! $element) { $element = new SchemaPropertyElement(); $element->setCreatedUserId($userId); $element->setCreatedAt($updateTime); $element->setProfilePropertyId($elementId); } if (($row[$value] != $element->getObject()) || ($rowLanguage != $element->getLanguage()) ) { /** * @todo We need a check here for objectproperties and handle differently **/ if ($rowLanguage != $element->getLanguage()) { $element->setLanguage($rowLanguage); } if ($row[$value] != $element->getObject()) { $element->setObject($row[$value]); } $element->setUpdatedUserId($userId); $element->setUpdatedAt($updateTime); $element->save(); } } //the row value is empty else if ($deleteMissing && $element) { $element->delete(); } } } // else // lookup and update concept or element // lookup and update each property // update the history for each property, action is 'import', should be a single timestamp for all (this should be automatic) // if 'delete missing properties' is true // delete each existing, non-required property that wasn't updated by the import } } catch(Exception $e) { // catch // if there's an error of any kind, write to error log and continue echo "Error on row: " . $rows . ", " . $uri . "\n" . $e . "\n"; continue; } $objects = $schemaObj->countSchemaPropertys(); } // save the import history file (match timestamp to history entries) break; case "json": break; case "rdf": break; case "xml": break; default: } /* output to stdout*/ // number of objects imported (link to history, filtered on timestamp of import) echo "File:" . $filePath . ";\n Objects imported: " . $objects . "; Rows read: " . $rows . "\n"; // number of errors (link to error log) }
/** * * @return Schema */ private static function getSchema() { $currentPropertyId = sfContext::getInstance()->getRequest()->getParameter('schema_property_id', ''); if ($currentPropertyId) { $schema = SchemaPropertyPeer::retrieveByPK($currentPropertyId)->getSchema(); } else { $schema = sfContext::getInstance()->getUser()->getAttribute('schema'); } if (!$schema) { $id = sfContext::getInstance()->getRequest()->getParameter('id', ''); if ($id) { if ("schemapropel" == sfContext::getInstance()->getModuleName()) { $schema = SchemaPropertyElementPeer::retrieveByPK($id)->getSchemaPropertyRelatedBySchemaPropertyId()->getSchema(); } else { $schema = self::retrieveByPK($id)->getSchema(); } } } return $schema; }
/** * Get the associated SchemaProperty object * * @param Connection Optional Connection object. * @return SchemaProperty The associated SchemaProperty object. * @throws PropelException */ public function getSchemaPropertyRelatedByRelatedSchemaPropertyId($con = null) { if ($this->aSchemaPropertyRelatedByRelatedSchemaPropertyId === null && $this->related_schema_property_id !== null) { // include the related Peer class include_once 'lib/model/om/BaseSchemaPropertyPeer.php'; $this->aSchemaPropertyRelatedByRelatedSchemaPropertyId = SchemaPropertyPeer::retrieveByPK($this->related_schema_property_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 = SchemaPropertyPeer::retrieveByPK($this->related_schema_property_id, $con); $obj->addSchemaPropertysRelatedByRelatedSchemaPropertyId($this); */ } return $this->aSchemaPropertyRelatedByRelatedSchemaPropertyId; }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this SchemaProperty is new, it will return * an empty collection; or if this SchemaProperty has previously * been saved, it will retrieve related SchemaPropertysRelatedByIsSubpropertyOf from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in SchemaProperty. */ public function getSchemaPropertysRelatedByIsSubpropertyOfJoinStatus($criteria = null, $con = null) { // include the Peer class include_once 'lib/model/om/BaseSchemaPropertyPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collSchemaPropertysRelatedByIsSubpropertyOf === null) { if ($this->isNew()) { $this->collSchemaPropertysRelatedByIsSubpropertyOf = array(); } else { $criteria->add(SchemaPropertyPeer::IS_SUBPROPERTY_OF, $this->getId()); $this->collSchemaPropertysRelatedByIsSubpropertyOf = SchemaPropertyPeer::doSelectJoinStatus($criteria, $con); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(SchemaPropertyPeer::IS_SUBPROPERTY_OF, $this->getId()); if (!isset($this->lastSchemaPropertyRelatedByIsSubpropertyOfCriteria) || !$this->lastSchemaPropertyRelatedByIsSubpropertyOfCriteria->equals($criteria)) { $this->collSchemaPropertysRelatedByIsSubpropertyOf = SchemaPropertyPeer::doSelectJoinStatus($criteria, $con); } } $this->lastSchemaPropertyRelatedByIsSubpropertyOfCriteria = $criteria; return $this->collSchemaPropertysRelatedByIsSubpropertyOf; }
/** * Selects a collection of SchemaPropertyElementHistory objects pre-filled with all related objects except FileImportHistory. * * @return array Array of SchemaPropertyElementHistory objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptFileImportHistory(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } SchemaPropertyElementHistoryPeer::addSelectColumns($c); $startcol2 = SchemaPropertyElementHistoryPeer::NUM_COLUMNS - SchemaPropertyElementHistoryPeer::NUM_LAZY_LOAD_COLUMNS + 1; UserPeer::addSelectColumns($c); $startcol3 = $startcol2 + UserPeer::NUM_COLUMNS; SchemaPropertyElementPeer::addSelectColumns($c); $startcol4 = $startcol3 + SchemaPropertyElementPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol5 = $startcol4 + SchemaPropertyPeer::NUM_COLUMNS; SchemaPeer::addSelectColumns($c); $startcol6 = $startcol5 + SchemaPeer::NUM_COLUMNS; ProfilePropertyPeer::addSelectColumns($c); $startcol7 = $startcol6 + ProfilePropertyPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol8 = $startcol7 + SchemaPropertyPeer::NUM_COLUMNS; StatusPeer::addSelectColumns($c); $startcol9 = $startcol8 + StatusPeer::NUM_COLUMNS; $c->addJoin(SchemaPropertyElementHistoryPeer::CREATED_USER_ID, UserPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_PROPERTY_ELEMENT_ID, SchemaPropertyElementPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::SCHEMA_ID, SchemaPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::PROFILE_PROPERTY_ID, ProfilePropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::RELATED_SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(SchemaPropertyElementHistoryPeer::STATUS_ID, StatusPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = SchemaPropertyElementHistoryPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getUser(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj2->initSchemaPropertyElementHistorys(); $obj2->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyElementPeer::getOMClass(); $cls = Propel::import($omClass); $obj3 = new $cls(); $obj3->hydrate($rs, $startcol3); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj3 = $temp_obj1->getSchemaPropertyElement(); //CHECKME if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) { $newObject = false; $temp_obj3->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj3->initSchemaPropertyElementHistorys(); $obj3->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj4 = new $cls(); $obj4->hydrate($rs, $startcol4); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj4 = $temp_obj1->getSchemaPropertyRelatedBySchemaPropertyId(); //CHECKME if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) { $newObject = false; $temp_obj4->addSchemaPropertyElementHistoryRelatedBySchemaPropertyId($obj1); break; } } if ($newObject) { $obj4->initSchemaPropertyElementHistorysRelatedBySchemaPropertyId(); $obj4->addSchemaPropertyElementHistoryRelatedBySchemaPropertyId($obj1); } $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj5 = new $cls(); $obj5->hydrate($rs, $startcol5); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj5 = $temp_obj1->getSchema(); //CHECKME if ($temp_obj5->getPrimaryKey() === $obj5->getPrimaryKey()) { $newObject = false; $temp_obj5->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj5->initSchemaPropertyElementHistorys(); $obj5->addSchemaPropertyElementHistory($obj1); } $omClass = ProfilePropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj6 = new $cls(); $obj6->hydrate($rs, $startcol6); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj6 = $temp_obj1->getProfileProperty(); //CHECKME if ($temp_obj6->getPrimaryKey() === $obj6->getPrimaryKey()) { $newObject = false; $temp_obj6->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj6->initSchemaPropertyElementHistorys(); $obj6->addSchemaPropertyElementHistory($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj7 = new $cls(); $obj7->hydrate($rs, $startcol7); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj7 = $temp_obj1->getSchemaPropertyRelatedByRelatedSchemaPropertyId(); //CHECKME if ($temp_obj7->getPrimaryKey() === $obj7->getPrimaryKey()) { $newObject = false; $temp_obj7->addSchemaPropertyElementHistoryRelatedByRelatedSchemaPropertyId($obj1); break; } } if ($newObject) { $obj7->initSchemaPropertyElementHistorysRelatedByRelatedSchemaPropertyId(); $obj7->addSchemaPropertyElementHistoryRelatedByRelatedSchemaPropertyId($obj1); } $omClass = StatusPeer::getOMClass(); $cls = Propel::import($omClass); $obj8 = new $cls(); $obj8->hydrate($rs, $startcol8); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj8 = $temp_obj1->getStatus(); //CHECKME if ($temp_obj8->getPrimaryKey() === $obj8->getPrimaryKey()) { $newObject = false; $temp_obj8->addSchemaPropertyElementHistory($obj1); break; } } if ($newObject) { $obj8->initSchemaPropertyElementHistorys(); $obj8->addSchemaPropertyElementHistory($obj1); } $results[] = $obj1; } return $results; }
/** * @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; }
public function write() { $adapter = new Adapter("/"); $filesystem = new Filesystem($adapter); if ( ! $filesystem->has($this->path)) { $filesystem->createDir($this->path); } $filename = $this->path . $this->getFileName(); $writer = new CsvWriter( "," ); $writer->setStream( fopen( $filename, 'w' ) ); $header = $this->getPrologHeader(); if ($this->includeProlog) { $header[ 1 ][ 0 ] = 'uri'; ksort($header[1]); $header[ 2 ][ 0 ] = 'lang'; $header[ 2 ][ 1 ] = $this->getSchema()->getLanguage(); //default language ksort($header[2]); $header[ 3 ][ 0 ] = 'type'; $header[ 3 ][ 1 ] = 'uri'; //default type ksort($header[3]); } foreach ( $header as $line ) { $writer->writeItem( $line ); } if ($this->includeProlog) { $metadata = $this->getMetadata(); foreach ($metadata as $line) { $writer->writeItem($line); } $prefixRows = $this->getPrefixRows(); foreach ($prefixRows as $line) { $writer->writeItem($line); } } //get the data if ( $this->populate ) { $prefixes = $this->getPrefixes(); $prefixPattern = array(); $prefixReplacement = array(); foreach ( $prefixes as $prefix => $namespace ) { if (trim($prefix)) { if ( ! is_int($prefix)) { $prefixPattern[] = "|" . $namespace . "|"; $prefixReplacement[] = $prefix . ":"; } } } $map = $this->getHeaderMap(); $c = new \Criteria(); $c->clearSelectColumns(); if ('schema' === $this->type) { $c->addSelectColumn(\SchemaPropertyPeer::ID); $c->add(\SchemaPropertyPeer::SCHEMA_ID, $this->schema->getId()); if ($this->excludeDeprecated) { $c->add(\SchemaPropertyPeer::STATUS_ID, 8, \Criteria::NOT_EQUAL); } $c->addAscendingOrderByColumn(\SchemaPropertyPeer::URI); $properties = \SchemaPropertyPeer::doSelectRS($c); } else { $c->addSelectColumn(\ConceptPeer::ID); $c->addSelectColumn(\ConceptPeer::URI); $c->addSelectColumn(\ConceptPeer::STATUS_ID); $c->add(\ConceptPeer::VOCABULARY_ID, $this->schema->getId()); if ($this->excludeDeprecated) { $c->add(\ConceptPeer::STATUS_ID, 8, \Criteria::NOT_EQUAL); } $c->addAscendingOrderByColumn(\ConceptPeer::URI); $properties = \ConceptPeer::doSelectRS($c); } foreach ( $properties as $property ) { $line = array_fill( 0, $this->getHeaderCount(), '' ); $line[0] = $property[0]; $map = $this->getHeaderMap(); $ce = new \Criteria(); if ('schema' === $this->type) { $ce->add(\BaseSchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, $property[0]); if (!$this->includeDeleted) { $ce->add(\BaseSchemaPropertyElementPeer::DELETED_AT, null); } if ($this->includeDeleted) { $ce->addAscendingOrderByColumn(\SchemaPropertyElementPeer::UPDATED_AT); } $elements = \SchemaPropertyElementPeer::doSelectJoinProfileProperty($ce); } else { $ce->add(\ConceptPropertyPeer::CONCEPT_ID, $property[0]); if (!$this->includeDeleted) { $ce->add(\ConceptPropertyPeer::DELETED_AT, null); } if ($this->includeDeleted) { $ce->addAscendingOrderByColumn(\ConceptPropertyPeer::UPDATED_AT); } $elements = \ConceptPropertyPeer::doSelectJoinProfilePropertyRelatedBySkosPropertyId($ce); $line[array_search('uri', $header[0])] = $property[1]; $line[array_search('status', $header[0])] = $property[2]; } /** @var \SchemaPropertyElement $element */ foreach ($elements as $element ) { if ($this->excludeGenerated and $element->getIsGenerated()) { continue; } /** @var \ProfileProperty $profileProperty */ $profileProperty = $element->getProfileProperty(); $propertyId = $profileProperty->getId(); if ('schema' === $this->type and in_array( $propertyId, [ 6, 9, ] ) and $element->getIsSchemaProperty() ) { $language = 'parent'; } else { $language = $profileProperty->getHasLanguage() ? $element->getLanguage() : ''; } $index = $propertyId . $language; if (isset($map[ $index ])) { foreach ($map[ $index ] as &$column) { if (false !== $column) { $line[ $column ] = $element->getObject(); $column = false; break; } } } } $writer->writeItem( preg_replace( $prefixPattern, $prefixReplacement, $line )); unset($line, $elements); } } //add an empty line at the end $line = array_fill( 0, $this->getHeaderCount(), '' ); $writer->writeItem( $line ); $writer->finish(); }
protected function deleteSchemaPropertyElement($schema_property_element) { $con = Propel::getConnection(SchemaPropertyElementPeer::DATABASE_NAME); /** * @todo at some point we need to refuse to delete a required field **/ try { //start a transaction $con->begin(); //update the property page if ($schema_property_element->getIsSchemaProperty()) { $fieldName = $schema_property_element->getProfileProperty($con)->getName(); $fields = SchemaPropertyPeer::getFieldNames(BasePeer::TYPE_FIELDNAME); //get the property page $property = $schema_property_element->getSchemaPropertyRelatedBySchemaPropertyId($con); $property->setByName($fieldName, '', BasePeer::TYPE_FIELDNAME); $property->setUpdatedUserId($schema_property_element->getUpdatedUserId()); if ('is_subproperty_of' == $fieldName) { $property->setRelatedPropertyId(null); } $property->save($con); } $schema_property_element->delete(); //commit the transaction $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } }
/** * @param SchemaProperty $property * @param Criteria $cLang * @param ProfileProperty[] $propArray * @param Status[] $statusArray * @param bool $languageArray * @param $languageDefault * * @return array * */ public function getResourceArray(SchemaProperty $property, Criteria $cLang, $propArray, $statusArray, $languageArray, $languageDefault) { //todo: this should be based on a constant rather than hard-coded; $lexicalAliasProperty = 27; //todo: remove hard coded registry URLs $resourceArray = []; $resourceArray["@id"] = $property->getUri(); $resourceArray["isDefinedBy"] = array("@id" => $this->getUri(), "url" => "http://metadataregistry.org/schema/show/id/" . $this->getId() . ".html", "label" => $this->getName()); $typeArray = array('property' => "Property", 'class' => "Class", 'subproperty' => "Property", 'subclass' => "Class"); $resourceArray["url"] = "http://metadataregistry.org/schemaprop/show/id/" . $property->getId() . ".html"; $elements = $property->getSchemaPropertyElementsRelatedBySchemaPropertyId($cLang); /** @var SchemaPropertyElement $element */ foreach ($elements as $element) { /** @var string $ppi */ $pproperty = $propArray[$element->getProfilePropertyId()]; $ppi = $pproperty->getLabel(); //id if (!$pproperty->getIsObjectProp()) { if ($pproperty->getHasLanguage() && $languageArray) { //we're putting language related elements in a language specific array self::addToGraph($resourceArray[$ppi][$element->getLanguage()], $element->getObject(), $pproperty->getIsSingleton()); } else { self::addToGraph($resourceArray[$ppi], $element->getObject(), $pproperty->getIsSingleton()); } } else { $array = array(); if ("status" !== $ppi) { if (!in_array($statusArray[$element->getStatusId()][2], ["Deprecated", "Not Approved"])) { $object = $element->getSchemaPropertyRelatedByRelatedSchemaPropertyId(); if (!$object) { //there wasn't an ID so we look it up by the URI $object = SchemaPropertyPeer::retrieveByUri($element->getObject()); if ($object) { //we now have an ID //todo: log that we did this $element->setRelatedSchemaPropertyId($object->getId()); $element->save(); } } if ($object) { //we got an object somehow //todo: refactor this to build a language array for lexicalalias and label if uselanguagearray is true //we'll need to get the array of available languages for the schema and do a for/next //todo: we removed the language filter from the query, so we need to check for a language match here $object->setLanguage($languageDefault); if ($lexicalAliasProperty == $pproperty->getId()) { $array = $object->getLexicalAlias(); $this->setLexicalArray($element->getObject(), $resourceArray["@id"], 308); } else { $array = array("@id" => $object->getUri(), "lexicalAlias" => $object->getLexicalAlias(), "url" => "http://metadataregistry.org/schemaprop/show/id/" . $object->getId() . ".html", "label" => $object->getLabel()); if (empty($array['lexicalAlias'])) { unset($array['lexicalAlias']); } } } else { if ('@type' == $ppi and isset($typeArray[$element->getObject()])) { $array = $typeArray[$element->getObject()]; } else { $array = array("@id" => $element->getObject()); } } } } else { //it's a status $status = $statusArray[$element->getObject()]; $array = array("@id" => $status[3], "lexicalAlias" => "http://metadataregistry.org/uri/RegStatus/" . $status[2] . ".en", "url" => "http://metadataregistry.org/concept/show/id/{$status['4']}.html", "label" => $status[2]); //$resourceArray[ $ppi ] = self::addToGraph($array, $pproperty->getIsSingleton()); } self::addToGraph($resourceArray[$ppi], $array, $pproperty->getIsSingleton()); } } ksort($resourceArray, SORT_FLAG_CASE | SORT_NATURAL); return $resourceArray; }
<?php $c = new Criteria(); $c->add(SchemaPropertyElementPeer::PROFILE_PROPERTY_ID, 11); /** @var SchemaProperty $schema_property */ $result = $schema_property->getSchemaPropertyElementsRelatedBySchemaPropertyId($c); if (count($result)) { /** @var SchemaPropertyElement $domain */ $domain = $result[0]; //get the related property $relProperty = $domain->getSchemaPropertyRelatedByRelatedSchemaPropertyId(); if ($relProperty) { echo link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relProperty->getId(), ['title' => $relProperty->getUri()]); } else { $relProperty = SchemaPropertyPeer::retrieveByUri($domain->getObject()); if ($relProperty) { //the id was broken, let's fix it... $domain->setRelatedSchemaPropertyId($relProperty->getId()); $domain->save(); echo link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relProperty->getId(), ['title' => $relProperty->getUri()]); } else { echo $domain->getObject(); } } }
/** * gets repeatable or unused profile properties for a resource property element * * @return array * @param criteria $criteria */ public static function getProfilePropertiesForCreate($criteria = null) { if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } //get the current property ID //create should always have a property id $propertyId = sfContext::getInstance()->getRequest()->getParameter('schema_property_id'); //get the current property if ($propertyId) { $schemaProperty = SchemaPropertyPeer::retrieveByPK($propertyId); if ('class' == $schemaProperty->getType() || 'subclass' == $schemaProperty->getType()) { $criteria->add(ProfilePropertyPeer::IS_IN_CLASS_PICKLIST, 1); } else { $criteria->add(ProfilePropertyPeer::IS_IN_PROPERTY_PICKLIST, 1); } } //properties for the metadata registry schema are currently related to profile '1' $criteria->add(ProfilePropertyPeer::PROFILE_ID, 1); $criteria->add(ProfilePropertyPeer::IS_IN_PICKLIST, 1); $criteria->addAscendingOrderByColumn(ProfilePropertyPeer::URI); //get the list of all properties for this profile/namespace //at some point this should look at the property or schema namespace $profileProperties = self::doSelect($criteria); $propertyList = array(); $pickList = array(); foreach ($profileProperties as $key => $property) { $propertyList[$property->getId()] = $property; $pickList[$property->getId()] = $property->getLabel(); } //get the property elements already in use for this property $c = new Criteria(); $c->add(SchemaPropertyElementPeer::SCHEMA_PROPERTY_ID, $propertyId); $c->add(SchemaPropertyElementPeer::IS_SCHEMA_PROPERTY, true); $elements = SchemaPropertyElementPeer::doSelect($c); foreach ($elements as $key => $element) { $propertyId = $element->getProfilePropertyId(); //if the property is in the list and not repeatable /** @var ProfileProperty **/ if (isset($propertyList[$propertyId]) && $propertyList[$propertyId]->getIsSingleton()) { //remove it from the list of all properties unset($pickList[$propertyId]); unset($propertyList[$propertyId]); } } return $propertyList; //whatever remains in the list }
/** * Selects a collection of Discuss objects pre-filled with all related objects except DiscussRelatedByParentId. * * @return array Array of Discuss objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptDiscussRelatedByParentId(Criteria $c, $con = null) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } DiscussPeer::addSelectColumns($c); $startcol2 = DiscussPeer::NUM_COLUMNS - DiscussPeer::NUM_LAZY_LOAD_COLUMNS + 1; UserPeer::addSelectColumns($c); $startcol3 = $startcol2 + UserPeer::NUM_COLUMNS; UserPeer::addSelectColumns($c); $startcol4 = $startcol3 + UserPeer::NUM_COLUMNS; SchemaPeer::addSelectColumns($c); $startcol5 = $startcol4 + SchemaPeer::NUM_COLUMNS; SchemaPropertyPeer::addSelectColumns($c); $startcol6 = $startcol5 + SchemaPropertyPeer::NUM_COLUMNS; SchemaPropertyElementPeer::addSelectColumns($c); $startcol7 = $startcol6 + SchemaPropertyElementPeer::NUM_COLUMNS; VocabularyPeer::addSelectColumns($c); $startcol8 = $startcol7 + VocabularyPeer::NUM_COLUMNS; ConceptPeer::addSelectColumns($c); $startcol9 = $startcol8 + ConceptPeer::NUM_COLUMNS; ConceptPropertyPeer::addSelectColumns($c); $startcol10 = $startcol9 + ConceptPropertyPeer::NUM_COLUMNS; $c->addJoin(DiscussPeer::CREATED_USER_ID, UserPeer::ID); $c->addJoin(DiscussPeer::DELETED_USER_ID, UserPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_ID, SchemaPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_PROPERTY_ID, SchemaPropertyPeer::ID); $c->addJoin(DiscussPeer::SCHEMA_PROPERTY_ELEMENT_ID, SchemaPropertyElementPeer::ID); $c->addJoin(DiscussPeer::VOCABULARY_ID, VocabularyPeer::ID); $c->addJoin(DiscussPeer::CONCEPT_ID, ConceptPeer::ID); $c->addJoin(DiscussPeer::CONCEPT_PROPERTY_ID, ConceptPropertyPeer::ID); $rs = BasePeer::doSelect($c, $con); $results = array(); while ($rs->next()) { $omClass = DiscussPeer::getOMClass(); $cls = Propel::import($omClass); $obj1 = new $cls(); $obj1->hydrate($rs); $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj2 = new $cls(); $obj2->hydrate($rs, $startcol2); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj2 = $temp_obj1->getUserRelatedByCreatedUserId(); //CHECKME if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { $newObject = false; $temp_obj2->addDiscussRelatedByCreatedUserId($obj1); break; } } if ($newObject) { $obj2->initDiscusssRelatedByCreatedUserId(); $obj2->addDiscussRelatedByCreatedUserId($obj1); } $omClass = UserPeer::getOMClass(); $cls = Propel::import($omClass); $obj3 = new $cls(); $obj3->hydrate($rs, $startcol3); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj3 = $temp_obj1->getUserRelatedByDeletedUserId(); //CHECKME if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) { $newObject = false; $temp_obj3->addDiscussRelatedByDeletedUserId($obj1); break; } } if ($newObject) { $obj3->initDiscusssRelatedByDeletedUserId(); $obj3->addDiscussRelatedByDeletedUserId($obj1); } $omClass = SchemaPeer::getOMClass(); $cls = Propel::import($omClass); $obj4 = new $cls(); $obj4->hydrate($rs, $startcol4); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj4 = $temp_obj1->getSchema(); //CHECKME if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) { $newObject = false; $temp_obj4->addDiscuss($obj1); break; } } if ($newObject) { $obj4->initDiscusss(); $obj4->addDiscuss($obj1); } $omClass = SchemaPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj5 = new $cls(); $obj5->hydrate($rs, $startcol5); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj5 = $temp_obj1->getSchemaProperty(); //CHECKME if ($temp_obj5->getPrimaryKey() === $obj5->getPrimaryKey()) { $newObject = false; $temp_obj5->addDiscuss($obj1); break; } } if ($newObject) { $obj5->initDiscusss(); $obj5->addDiscuss($obj1); } $omClass = SchemaPropertyElementPeer::getOMClass(); $cls = Propel::import($omClass); $obj6 = new $cls(); $obj6->hydrate($rs, $startcol6); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj6 = $temp_obj1->getSchemaPropertyElement(); //CHECKME if ($temp_obj6->getPrimaryKey() === $obj6->getPrimaryKey()) { $newObject = false; $temp_obj6->addDiscuss($obj1); break; } } if ($newObject) { $obj6->initDiscusss(); $obj6->addDiscuss($obj1); } $omClass = VocabularyPeer::getOMClass(); $cls = Propel::import($omClass); $obj7 = new $cls(); $obj7->hydrate($rs, $startcol7); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj7 = $temp_obj1->getVocabulary(); //CHECKME if ($temp_obj7->getPrimaryKey() === $obj7->getPrimaryKey()) { $newObject = false; $temp_obj7->addDiscuss($obj1); break; } } if ($newObject) { $obj7->initDiscusss(); $obj7->addDiscuss($obj1); } $omClass = ConceptPeer::getOMClass(); $cls = Propel::import($omClass); $obj8 = new $cls(); $obj8->hydrate($rs, $startcol8); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj8 = $temp_obj1->getConcept(); //CHECKME if ($temp_obj8->getPrimaryKey() === $obj8->getPrimaryKey()) { $newObject = false; $temp_obj8->addDiscuss($obj1); break; } } if ($newObject) { $obj8->initDiscusss(); $obj8->addDiscuss($obj1); } $omClass = ConceptPropertyPeer::getOMClass(); $cls = Propel::import($omClass); $obj9 = new $cls(); $obj9->hydrate($rs, $startcol9); $newObject = true; for ($j = 0, $resCount = count($results); $j < $resCount; $j++) { $temp_obj1 = $results[$j]; $temp_obj9 = $temp_obj1->getConceptProperty(); //CHECKME if ($temp_obj9->getPrimaryKey() === $obj9->getPrimaryKey()) { $newObject = false; $temp_obj9->addDiscuss($obj1); break; } } if ($newObject) { $obj9->initDiscusss(); $obj9->addDiscuss($obj1); } $results[] = $obj1; } return $results; }