Skip to content

Instantly share code, notes, and snippets.

@Da-Fecto
Created February 21, 2017 09:15
Show Gist options
  • Save Da-Fecto/719a31de06fd9ed1708f5606857d6f59 to your computer and use it in GitHub Desktop.
Save Da-Fecto/719a31de06fd9ed1708f5606857d6f59 to your computer and use it in GitHub Desktop.
<?php namespace ProcessWire;
require($config->paths->templates . 'Spout/Autoloader/autoload.php');
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
class export {
// PageArray
private $products = null;
// PageArray
private $limit = 10;
// Current
private $start = 0;
// Is new?
private $isNew = null;
private $fp = null;
private $writer = null;
public function __construct() {
$this->total = 5 * $this->limit;
}
// Create file
private function createFile() {
$base = wire('config')->paths->templates;
$path = $base . date('Ydm H:i:s') . '.xlsx';
$this->fp = fopen($path, 'a');
$this->writer = WriterFactory::create(Type::XLSX);
$this->writer->openToFile($path);
$this->isNew = false;
}
public function run() {
do {
if ($this->isNew === null) $this->createFile();
$this->products = wire('pages')->find('template=product, start=' . $this->start . ', limit=' . $this->limit);
$this->start += $this->limit;
foreach ($this->products as $p) {
$this->writer->addRow(array($p->id, $p->title));
}
} while($this->start < $this->total);
$this->writer->close();
fclose($this->fp);
}
}
$export = new export();
$export->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment