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(); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this SchemaProperty is new, it will return * an empty collection; or if this SchemaProperty has previously * been saved, it will retrieve related SchemaPropertyElementsRelatedByRelatedSchemaPropertyId from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in SchemaProperty. */ public function getSchemaPropertyElementsRelatedByRelatedSchemaPropertyIdJoinProfileProperty($criteria = null, $con = null) { // include the Peer class include_once 'lib/model/om/BaseSchemaPropertyElementPeer.php'; if ($criteria === null) { $criteria = new Criteria(); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collSchemaPropertyElementsRelatedByRelatedSchemaPropertyId === null) { if ($this->isNew()) { $this->collSchemaPropertyElementsRelatedByRelatedSchemaPropertyId = array(); } else { $criteria->add(SchemaPropertyElementPeer::RELATED_SCHEMA_PROPERTY_ID, $this->getId()); $this->collSchemaPropertyElementsRelatedByRelatedSchemaPropertyId = SchemaPropertyElementPeer::doSelectJoinProfileProperty($criteria, $con); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(SchemaPropertyElementPeer::RELATED_SCHEMA_PROPERTY_ID, $this->getId()); if (!isset($this->lastSchemaPropertyElementRelatedByRelatedSchemaPropertyIdCriteria) || !$this->lastSchemaPropertyElementRelatedByRelatedSchemaPropertyIdCriteria->equals($criteria)) { $this->collSchemaPropertyElementsRelatedByRelatedSchemaPropertyId = SchemaPropertyElementPeer::doSelectJoinProfileProperty($criteria, $con); } } $this->lastSchemaPropertyElementRelatedByRelatedSchemaPropertyIdCriteria = $criteria; return $this->collSchemaPropertyElementsRelatedByRelatedSchemaPropertyId; }