Ejemplo n.º 1
0
 /**
  * Set the defaults
  *
  * @param SchemaPropertyElement $schema_property_element
  *
  */
 public function setDefaults($schema_property_element)
 {
     $schemaObj = $this->schema_property->getSchema();
     $language = sfContext::getInstance()->getUser()->getCulture();
     $userId = sfContext::getInstance()->getUser()->getSubscriberId();
     if ("edit" == $this->getActionName() && $userId) {
         $schemaUser = $schemaObj->GetUserForSchema($userId);
         $UserLanguages = is_object($schemaUser) ? $schemaUser->getLanguages() : ['en'];
         $this->getUser()->setAttribute("languages", $UserLanguages);
         if (!in_array($language, $UserLanguages)) {
             $language = $schemaUser->getDefaultLanguage();
             //save the current culture
             $UserCulture = sfContext::getInstance()->getUser()->getCulture();
             $this->getUser()->setAttribute("UserCulture", $UserCulture);
         }
         $this->getUser()->setAttribute("CurrentLanguage", $language);
     }
     $schemaPropertyStatus = $this->schema_property->getStatusID();
     $schema_property_element->setStatusId($schemaPropertyStatus);
     parent::setDefaults($schema_property_element);
     $schemaPropertyId = $this->schema_property->getId();
     $schema_property_element->setSchemaPropertyId($schemaPropertyId);
     $schema_property_element->setCreatedUserId($userId);
     $schema_property_element->setUpdatedUserId($userId);
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
    /**
     * @param $key
     * @param $value
     * @param $propertyId
     * @param $updateTime
     * @param $rowStatusId
     * @param $cellLanguage
     * @param $cellType
     * @param $schemaId
     *
     * @return array $results
     * @throws \PropelException
     */
    private function SetPropertyElement(
        $key,
        $value,
        $propertyId,
        $updateTime,
        $rowStatusId,
        $cellLanguage,
        $cellType
    ) {
        $profilePropertyId = $this->prolog['columns'][$key]['id'];
        if (is_array($profilePropertyId)) {
            $profilePropertyId = $profilePropertyId[0];
        }

        //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 contain the identifier for the triple

        //actually there is. We look for exact matches and skip the update of an exact match,
        //but then we look at just the old properties that are left -- the ones where the property matches but the object doesn't
        //and we update those. If we have any properties left after that, we add them as new.
        //We need to add an instruction to the spreadsheet to treat an empty property cell as a skip or a delete
        //and if an empty cell means delete, then we delete those

        //get the language for this thing
        //if there's a prolog set for the language for this column, use it
        //use the default for the import (already set above)
        //fall back to the default language of the vocabulary

        //get the fqn if using curies
        if ($cellType and $this->useCuries) {
            $value = $this->getFqn($value);
        }

        $StatementCounter['status'] = 'skipped';

        /** @var \SchemaPropertyElement[] $element */
        $element = \SchemaPropertyElementPeer::lookupElement($propertyId, $profilePropertyId, $value, $cellLanguage);

        if ($element) {
            if (1 === count($element)) {
                $element = $element[0];
                //make sure we handle the special case of subproperty and subclass
                if (empty( $value ) && $element->getIsSchemaProperty() && in_array($element->getProfilePropertyId(),
                                                                                   [ 6, 9 ])
                ) {
                    return $StatementCounter;
                }
            } else {
                //it's ambiguous and we stop processing, logging an error to be dealt with later
                $error['Message']           = "Ambiguous update";
                $error['PropertyId']        = $propertyId;
                $error['ProfilePropertyId'] = $profilePropertyId;
                $error['UpdateValue']       = $value;

                $this->results['errors'][] = $error;
            }
        }

        //create a new propertyelement for each unmatched column
        //we didn't find an existing element, make a new one
        if ( ! $element && ! empty( $value )) {
            $element = new \SchemaPropertyElement;
            $element->setCreatedUserId($this->userId);
            $element->setCreatedAt($updateTime);
            $element->setProfilePropertyId($profilePropertyId);
            $element->setSchemaPropertyId($propertyId);
            $StatementCounter['status'] = 'created';
        }

        if ( ! $element) {
            return $StatementCounter;
        }

        if (( $value != $element->getObject() ) || ( $cellLanguage != $element->getLanguage() )) {
            /**
             * @todo We need a check here for objectproperties and handle differently
             *       if it's a URI, and it uses namespaces, and we have the namespace, do the substitution
             **/
            if ( ! $cellType and $cellLanguage) {
                if ($cellLanguage != $element->getLanguage()) {
                    $element->setLanguage($cellLanguage);
                }
            }
        }
        if ($value != $element->getObject()) {
            if ( ! empty( $value )) {
                $element->setObject($value);
            } else {
                $element->setDeletedAt($updateTime);
            }
        }

        if ($element->isNew() or $element->isModified()) {
            $element->setUpdatedUserId($this->userId);
            $element->setUpdatedAt($updateTime);
            $element->setStatusId($rowStatusId);
            $element->importId = $this->importId;
            $element->save();

            if ($StatementCounter['status'] != 'created') {
                $StatementCounter['status'] = 'modified';
            }

            if (is_array($element->getProfilePropertyId())) {
                $profilePropertyId = $element->getProfilePropertyId()[0];
            } else {
                $profilePropertyId = $element->getProfilePropertyId();
            }
            /** @var \ProfileProperty $profileProperty */
            $profileProperty                = $this->profileProperties[$profilePropertyId];
            $StatementCounter['column']     = $key;
            $StatementCounter['id']         = $element->getId();
            $StatementCounter['propertyId'] = $element->getProfilePropertyId();
            $StatementCounter['object']     = $element->getObject();
            $StatementCounter['type']       = $cellType;
            $StatementCounter['language']   = $cellLanguage;
        }

        unset( $element );

        return $StatementCounter;
    }