1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124:
<?php
class icms_ipf_export_Handler {
public $handler;
public $criteria;
public $fields;
public $format;
public $filename;
public $filepath;
public $options;
public $outputMethods=false;
public $notDisplayFields;
public function __construct(&$objectHandler, $criteria=null, $fields=false, $filename=false, $filepath=false, $format='csv', $options=false) {
$this->handler = $objectHandler;
$this->criteria = $criteria;
$this->fields = $fields;
$this->filename = $filename;
$this->format = $format;
$this->options = $options;
$this->notDisplayFields = array();
}
public function render($filename) {
$this->filename = $filename;
$objects = $this->handler->getObjects($this->criteria);
$rows = array();
$columnsHeaders = array();
$firstObject = true;
foreach ( $objects as $object) {
$row = array();
foreach ( $object->vars as $key=>$var) {
if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) {
if ($this->outputMethods && (isset($this->outputMethods[$key])) && (method_exists($object, $this->outputMethods[$key]))) {
$method = $this->outputMethods[$key];
$row[$key] = $object->$method();
} else {
$row[$key] = $object->getVar($key);
}
if ($firstObject) {
$columnsHeaders[$key] = $var['form_caption'];
}
}
}
$firstObject = false;
$rows[] = $row;
unset($row);
}
$data = array();
$data['rows'] = $rows;
$data['columnsHeaders'] = $columnsHeaders;
$smartExportRenderer = new icms_ipf_export_Renderer($data, $this->filename, $this->filepath, $this->format, $this->options);
$smartExportRenderer->execute();
}
public function setOuptutMethods($outputMethods) {
$this->outputMethods = $outputMethods;
}
public function setNotDisplayFields($fields) {
if (!$this->notDisplayFields) {
if (is_array($fields)) {
$this->notDisplayFields = $fields;
} else {
$this->notDisplayFields = array($fields);
}
} else {
if (is_array($fields)) {
$this->notDisplayFields = array_merge($this->notDisplayFields, $fields);
} else {
$this->notDisplayFields[] = $fields;
}
}
}
}