Esempio n. 1
0
 public function getNamespaces()
 {
     $criteria = new Criteria();
     $criteria->add(ConceptPeer::VOCABULARY_ID, $this->getId());
     $criteria->addJoin(ConceptPropertyPeer::CONCEPT_ID, ConceptPeer::ID);
     $criteria->addJoin(ProfilePropertyPeer::SKOS_ID, ConceptPropertyPeer::SKOS_PROPERTY_ID);
     $criteria->clearSelectColumns();
     $criteria->addSelectColumn(ProfilePropertyPeer::URI);
     $criteria->setDistinct();
     $rs = ConceptPeer::doSelectRS($criteria);
     $coreNamespaces = ['dc' => 'http://purl.org/dc/elements/1.1/', 'dcterm' => 'http://purl.org/dc/terms/', 'owl' => 'http://www.w3.org/2002/07/owl#', 'skos' => 'http://www.w3.org/2004/02/skos/core#', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', 'reg' => 'http://metadataregistry.org/uri/profile/regap/', 'rdakit' => 'http://metadataregistry.org/uri/profile/rdakit/'];
     $namespaces = [];
     foreach ($rs as $r) {
         $array = explode(":", $r[0]);
         if (isset($coreNamespaces[$array[0]])) {
             $namespaces[$array[0]] = $coreNamespaces[$array[0]];
         }
     }
     //add the required namespaces
     foreach (['dc', 'reg', 'rdf', 'skos'] as $ns) {
         $namespaces[$ns] = $coreNamespaces[$ns];
     }
     ksort($namespaces);
     return $namespaces;
 }
    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();
    }
 /**
  * Selects a collection of Concept objects filtered by history timestamp.
  *
  * @param integer $vocabularyId
  * @param date    $ts The timestamp
  * @return array Array of Concept objects.
  * @throws PropelException Any exceptions caught during processing will be
  *     rethrown wrapped into a PropelException.
  */
 public static function doSelectConceptByHistoryTimestamp($vocabularyId, $ts)
 {
     $c = new Criteria();
     $c->addJoin(ConceptPeer::ID, ConceptPropertyHistoryPeer::CONCEPT_ID);
     $c->setDistinct();
     $c->add(ConceptPeer::VOCABULARY_ID, $vocabularyId);
     $c->add(ConceptPropertyHistoryPeer::CREATED_AT, $ts, Criteria::LESS_EQUAL);
     $c->add(ConceptPropertyHistoryPeer::ACTION, 'deleted', Criteria::NOT_EQUAL);
     $results = ConceptPeer::populateObjects(ConceptPeer::doSelectRS($c));
     return $results;
 }
 /**
  * @param int $vocabularyId
  * @return array
  */
 public static function getNamespaceList($vocabularyId)
 {
     $namespaces = array();
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(ConceptPropertyPeer::OBJECT);
     $c->add(ConceptPropertyPeer::OBJECT, "http%", Criteria::LIKE);
     $c->add(ConceptPeer::VOCABULARY_ID, $vocabularyId);
     $c->addJoin(ConceptPropertyPeer::CONCEPT_ID, ConceptPeer::ID);
     $result = self::doSelectRS($c);
     self::getNamespaceUris($result, 'getObject', $namespaces);
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(ConceptPeer::URI);
     $c->add(ConceptPeer::VOCABULARY_ID, $vocabularyId);
     $result = ConceptPeer::doSelectRS($c);
     self::getNamespaceUris($result, 'getUri', $namespaces);
     return $namespaces;
 }
 /**
  * Returns the number of rows matching criteria, joining the related Status table
  *
  * @param Criteria $c
  * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
  * @param Connection $con
  * @return int Number of matching rows.
  */
 public static function doCountJoinAllExceptStatus(Criteria $criteria, $distinct = false, $con = null)
 {
     // we're going to modify criteria, so copy it first
     $criteria = clone $criteria;
     // clear out anything that might confuse the ORDER BY clause
     $criteria->clearSelectColumns()->clearOrderByColumns();
     if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
         $criteria->addSelectColumn(ConceptPeer::COUNT_DISTINCT);
     } else {
         $criteria->addSelectColumn(ConceptPeer::COUNT);
     }
     // just in case we're grouping: add those columns to the select statement
     foreach ($criteria->getGroupByColumns() as $column) {
         $criteria->addSelectColumn($column);
     }
     $criteria->addJoin(ConceptPeer::CREATED_USER_ID, UserPeer::ID);
     $criteria->addJoin(ConceptPeer::UPDATED_USER_ID, UserPeer::ID);
     $criteria->addJoin(ConceptPeer::VOCABULARY_ID, VocabularyPeer::ID);
     $criteria->addJoin(ConceptPeer::PREF_LABEL_ID, ConceptPropertyPeer::ID);
     $rs = ConceptPeer::doSelectRS($criteria, $con);
     if ($rs->next()) {
         return $rs->getInt(1);
     } else {
         // no rows returned; we infer that means 0 matches.
         return 0;
     }
 }