コード例 #1
0
/**
* creates a link to related schema property
*
* @return none
* @param  schemaproperty $property
*/
function link_to_related_property($property)
{
    $relPropertyId = $property->getIsSubpropertyOf();
    $relPropertyUri = $property->getParentUri();
    if ($relPropertyId) {
        //get the related concept
        $relProperty = SchemaPropertyPeer::retrieveByPK($relPropertyId);
        if ($relProperty) {
            return link_to($relProperty->getLabel(), 'schemaprop/show/?id=' . $relPropertyId, ['title' => $relPropertyUri]);
        }
    }
    //if all else fails we display a truncated = 30 value
    return truncate_text($property->getParentUri(), 30);
}
コード例 #2
0
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();
                    }
                }
            }
        }
    }
}
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
         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)) {
コード例 #6
0
 /**
  * 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
 }
コード例 #7
0
    /**
     * @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;
    }
コード例 #8
0
 /**
  *
  * @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;
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
0
ファイル: _rdf.php プロジェクト: jonphipps/Metadata-Registry
/** @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>