/**
  * create and add an individual element
  *
  * @param  SchemaProperty $schema_property
  * @param  int $userId
  * @param  int $fieldId
  * @param  int $statusId
  * @param string $language
  *
  * @param bool $isGenerated
  * @return SchemaPropertyElement
  */
 public static function createElement($schema_property, $userId, $fieldId, $statusId, $language = null, $isGenerated = false)
 {
     $element = new SchemaPropertyElement();
     $element->setCreatedUserId($userId);
     $element->setUpdatedUserId($userId);
     $element->setSchemaPropertyId($schema_property->getId());
     $element->setLanguage($language);
     $element->setStatusId($statusId);
     $element->setProfilePropertyId($fieldId);
     $element->setIsGenerated($isGenerated);
     return $element;
     //self::updateElement($schema_property, $element, $userId, $field, $con, $isSchemaProperty);
 }
예제 #2
0
 /**
  * @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;
 }
 /**
  * Declares an association between this object and a SchemaProperty object.
  *
  * @param      SchemaProperty $v
  * @return     void
  * @throws     PropelException
  */
 public function setSchemaPropertyRelatedByRelatedSchemaPropertyId($v)
 {
     if ($v === null) {
         $this->setRelatedSchemaPropertyId(NULL);
     } else {
         $this->setRelatedSchemaPropertyId($v->getId());
     }
     $this->aSchemaPropertyRelatedByRelatedSchemaPropertyId = $v;
 }
예제 #4
0
    /**
     * @param \SchemaPropertyElement | \SchemaPropertyElement[] $dbElement
     * @param                                                   $value
     * @param                                                   $rowStatus
     * @param \SchemaProperty                                   $property
     * @param \ProfileProperty                                  $profileProperty
     * @param                                                   $language
     *
     * @param                                                   $key
     *
     * @return bool
     * @throws \Exception
     * @throws \PropelException
     */
    private function upsertElementFromRow(
        &$dbElement,
        $value,
        $rowStatus,
        &$property,
        $profileProperty,
        $language,
        $key
    ) {
        if ( ! is_array($dbElement)) {
            if (empty( $dbElement ) and $value) {
                $dbElement = new \SchemaPropertyElement();
                $dbElement->setProfilePropertyId($profileProperty->getId());
                $dbElement->setSchemaPropertyId($property->getId());
                $dbElement->setLanguage($language);
                $dbElement->setCreatedUserId($this->userId);
                $property->addSchemaPropertyElementRelatedBySchemaPropertyId($dbElement);
            }
            if ($dbElement and $value !== $dbElement->getObject()) {
                if (empty( $value )) {
                    $dbElement->delete();
                } else {
                    $dbElement->setStatusId($rowStatus);
                    $dbElement->setObject($value);
                    $dbElement->setUpdatedUserId($this->userId);
                    $dbElement->importId = $this->importId;
                    $dbElement->setDeletedAt(null);
                }
                //$dbElement->save();
                if ($profileProperty->getIsInForm()) {
                    if (( $profileProperty->getHasLanguage() and $property->getLanguage() == $dbElement->getLanguage() ) or ! $profileProperty->getHasLanguage()) {
                        $this->setPropertyValue($value,
                                                $property,
                                                $profileProperty->getName(), ! $profileProperty->getIsObjectProp(),
                                                $key);
                        $dbElement->setIsSchemaProperty(true);
                    }
                }

                return true;
            }
        } else {
            $foundOne = false;
            foreach ($dbElement as &$oneElement) {
                if ( ! $foundOne) {
                    $foundOne = $this->upsertElementFromRow($oneElement,
                                                            $value,
                                                            $rowStatus,
                                                            $property,
                                                            $profileProperty,
                                                            $language,
                                                            $key);
                }
            }
        }

        return true;
    }
 /**
  * Declares an association between this object and a SchemaProperty object.
  *
  * @param      SchemaProperty $v
  * @return     void
  * @throws     PropelException
  */
 public function setSchemaPropertyRelatedByIsSubpropertyOf($v)
 {
     if ($v === null) {
         $this->setIsSubpropertyOf(NULL);
     } else {
         $this->setIsSubpropertyOf($v->getId());
     }
     $this->aSchemaPropertyRelatedByIsSubpropertyOf = $v;
 }
 /**
  * @param SchemaProperty $property
  * @param string                            $fieldName
  * @param string                            $object
  * @param int                               $objectId if the object has a related Id
  * @param int                               $userId
  * @param array                             $fieldIds
  * @param int                               $statusId
  * @param Connection                        $con
  *
  * @throws Exception
  * @throws PropelException
  * @return bool
  */
 public static function updateRelatedElements($property, $fieldName, $object, $objectId, $userId, $fieldIds, $statusId, $con)
 {
     if (isset($fieldIds[$fieldName])) {
         $profileId = $fieldIds[$fieldName]['id'];
     } else {
         return false;
     }
     $language = $fieldIds[$fieldName]['hasLang'] ? $property->getLanguage() : null;
     $element = SchemaPropertyElementPeer::lookupDetailElement($property->getId(), $profileId, $language);
     if ($element) {
         //no matter what we do, it's not generated any more
         $element->setIsGenerated(false);
         //did we make it null?
         if (0 === strlen(trim($object))) {
             //we have to make sure that it's not a subclass or subproperty
             if (('is_subproperty_of' == $fieldName || 'is_subclass_of' == $fieldName) && $property->getParentUri()) {
                 //there's a uri but it doesn't match anything registered
                 //so we have to delete just the reciprocal
                 $element->updateReciprocal('deleted', $userId, $property->getSchemaId(), $con);
             } else {
                 //delete the element
                 $element->delete($con);
             }
         } else {
             //modify it
             $element->setObject($object);
             $element->setRelatedSchemaPropertyId($objectId);
             $element->setUpdatedUserId($userId);
             $element->save();
         }
     } elseif ($profileId && $object) {
         //create one
         $element = SchemaPropertyElementPeer::createElement($property, $userId, $profileId, $statusId, $language, false);
         $element->setObject($object);
         $element->setRelatedSchemaPropertyId($objectId);
         $element->setIsSchemaProperty(TRUE);
         $element->save();
     }
     return true;
 }