Inheritance: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate
Example #1
0
 /**
  * Export collection object into CSV file.
  *
  * int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
  */
 public function exportCollection(BaseCollection $collection, array $intersectKeys = null)
 {
     $schema = $collection->getSchema();
     $keys = $schema->getColumnNames();
     if ($intersectKeys) {
         $keys = array_intersect_key($keys, array_flip($intersectKeys));
     }
     $php54 = version_compare(phpversion(), '5.5.0') < 0;
     if ($php54) {
         fputcsv($this->fd, $keys, $this->delimiter, $this->enclosure);
     } else {
         fputcsv($this->fd, $keys, $this->delimiter, $this->enclosure, $this->escapeChar);
     }
     foreach ($collection as $record) {
         $array = $record->toArray();
         $fields = [];
         foreach ($keys as $key) {
             $fields[] = $array[$key];
         }
         if ($php54) {
             fputcsv($this->fd, $fields, $this->delimiter, $this->enclosure);
         } else {
             fputcsv($this->fd, $fields, $this->delimiter, $this->enclosure, $this->escapeChar);
         }
     }
     return true;
 }
Example #2
0
 /**
  * @return DOMDocument
  */
 public function exportCollection(BaseCollection $collection)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $root = $dom->createElement('export');
     $dom->appendChild($root);
     // $this->appendRecord($dom, $root, $record, NULL, true);
     $schema = $collection->getSchema();
     $relations = $schema->getRelations();
     // find foreign many-to-many schema
     foreach ($relations as $rel) {
         if ($rel['type'] === Relationship::MANY_TO_MANY) {
             $junctionRel = $relations[$rel['relation_junction']];
             $junctionSchema = $junctionRel->newForeignSchema();
             $foreignRel = $junctionSchema->getRelation($rel['relation_foreign']);
             $foreignCollection = $foreignRel->newForeignCollection();
             $foreignSchema = $foreignRel->newForeignSchema();
             $collectionRoot = $dom->createElement('collection');
             $collectionRoot->setAttribute('schema', get_class($foreignSchema));
             $collectionRoot->setAttribute('class', get_class($foreignCollection));
             $root->appendChild($collectionRoot);
             foreach ($foreignCollection as $record) {
                 $this->appendRecord($dom, $collectionRoot, $record, $foreignSchema, true);
             }
         }
     }
     $collectionRoot = $dom->createElement('collection');
     $collectionRoot->setAttribute('schema', get_class($schema));
     $collectionRoot->setAttribute('class', get_class($collection));
     $root->appendChild($collectionRoot);
     foreach ($collection as $record) {
         $this->appendRecord($dom, $collectionRoot, $record, $schema, true);
     }
     $dom->formatOutput = true;
     return $dom;
 }
Example #3
0
 /**
  * Create collection pager object from collection.
  *
  * @param LazyRecord\BaseCollection collection object.
  * @return BootstrapRegionPager
  */
 protected function createCollectionPager(BaseCollection $collection)
 {
     $page = $this->getCurrentPage();
     $pageSize = $this->getCurrentPageSize();
     $count = $collection->queryCount();
     $collection->page($page, $pageSize);
     // return new RegionPager( $page, $count, $pageSize );
     return new BootstrapRegionPager($page, $count, $pageSize);
 }
Example #4
0
 /**
  * Dump Record Collection
  */
 public static function dumpCollection(BaseCollection $collection, array $options = array())
 {
     return self::dumpRows($collection->toArray(), $options);
 }
Example #5
0
 public function applyOrder(BaseCollection &$collection)
 {
     if (isset($this->data['orderBy']) && $this->data['orderBy']) {
         var_dump($this->data['orderBy']);
         foreach ($this->data['orderBy'] as $o) {
             $collection->orderBy($o[0], $o[1]);
         }
     }
 }
Example #6
0
 public function assertCollectionSize($size, BaseCollection $collection, $message = NULL)
 {
     $this->assertEquals($size, $collection->size(), $message ?: "Colletion size should match");
 }
 public function __construct(BaseCollection $collection)
 {
     $this->collection = $collection;
     $this->schema = $collection->getSchema();
 }