Ejemplo n.º 1
0
/**
 * creates a link to related SchemaProperty
 *
 * @return none
 *
 * @param  SchemaPropertyElement $property
 */
function link_to_related($property)
{
    $relSchemaPropertyId = $property->getRelatedSchemaPropertyId();
    if ($relSchemaPropertyId) {
        //get the related SchemaProperty
        $relSchemaProperty = $property->getSchemaPropertyRelatedByRelatedSchemaPropertyId();
        if ($relSchemaProperty) {
            $link = 'schemaprop/show/?id=' . $relSchemaPropertyId;
            return link_to($property->getObject(), $link, ["title" => $relSchemaProperty]);
        }
    }
    //If the skosProperty.objectType is resource then we display a truncated URI with a complete link_to
    if (strpos(0 === $property->getObject(), sfConfig::get('app_base_domain'))) {
        return link_to(truncate_text($property->getObject(), 30), $property->getObject());
    }
    //if it's a status code, we resolve the status
    if (14 == $property->getProfilePropertyId()) {
        return $property->getStatus();
    }
    //if it's a URI we return a link, but if it's not we just return the object
    //return preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[A-Z0-9+&@#\/%=~_|]/i', '<a href="\0">\0</a>', $property->getObject());
    //if all else fails we display a truncated = 30 value
    return $property->getObject();
}
Ejemplo n.º 2
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;
    }