bebeboutik/modules/exports/CronExport.php

60 lines
1.3 KiB
PHP
Raw Normal View History

2016-01-04 12:49:26 +01:00
<?php
include_once(dirname(__FILE__).'/../../config/config.inc.php');
include_once(dirname(__FILE__).'/config.php');
class CronExportCore {
protected $self;
protected $file;
public $filename;
protected $dest_path = '';
protected $postfix = '';
protected $sep = ';';
protected $headers = array();
protected $params = array();
public function __construct($self, $params=array()) {
$this->self = $self;
$keys = array(
'sep',
'headers',
'dest_path',
'postfix',
'params',
);
global $config;
for($i=0, $l=count($keys); $i<$l; $i++) {
if(isset($params[$keys[$i]])) {
$this->{$keys[$i]} = $params[$keys[$i]];
} elseif(isset($config[$this->self][$keys[$i]])) {
$this->{$keys[$i]} = $config[$this->self][$keys[$i]];
}
}
}
protected function preProcess() {}
protected function process() {
// Do stuff here
}
protected function postProcess() {}
protected function w($line=array()) {
fputcsv($this->file, array_values($line), $this->sep);
}
public function run() {
$this->preProcess();
$this->filename = _PS_ROOT_DIR_.$this->dest_path.'/'.date('Y-m-d', mktime()).$this->postfix.'.csv';
touch($this->filename);
$this->filename = realpath($this->filename);
$this->file = fopen($this->filename, 'w');
$this->w($this->headers);
$this->process();
fclose($this->file);
$this->postProcess();
}
}