* - beforeInsert($request,$roo) - before insert - jerr() will stop insert..
*
* AFTER
- * - onUpdate($old, $request,$roo) - after update // return value ignored
- * - onInsert($request,$roo) - after insert
+ * - onUpdate($old, $request,$roo, $event) - after update // return value ignored
+ * - onInsert($request,$roo, $event) - after insert
* - onDelete($req, $roo) - after delete
* - onUpload($roo)
*
var $debugEnabled = true; // disable this for public versions of this code.
+ var $do = false; // the dataobject being worked on..
+
function getAuth()
{
parent::getAuth(); // load company!
return true;
}
/**
- * GET method Roo/TABLENAME.php
+ * GET method Roo/TABLENAME
*
* Generally for SELECT or Single SELECT
*
* toRooArray($request) : array
* - called if singleArray is unavailable on single fetch.
* - always tried for mutiple results.
- * toArray() - the default method if none of the others are found.
+ * toArray() - the default method if none of the others are found.
+ * toSimpleExcelColumn($col) - see toCSV - this enables special columns to be created for exported data.
*
* autoJoin($request)
* - standard DataObject feature - causes all results to show all
$this->sessionState(0);
$res = $x->find();
$this->sessionState(1);
-
+
if (false === $res) {
$this->jerr($x->_lastError->toString());
$this->toCsv($ret, $_REQUEST['csvCols'], $_REQUEST['csvTitles'],
- empty($_REQUEST['csvFilename']) ? '' : $_REQUEST['csvFilename']
- );
+ empty($_REQUEST['csvFilename']) ? '' : $_REQUEST['csvFilename'] );
function toCsv($data, $cols, $titles, $filename, $addDate = true)
{
-
+ // die('here');
$this->sessionState(0); // turn off sessions - no locking..
require_once 'Pman/Core/SimpleExcel.php';
$rooar = method_exists($data, 'toRooArray');
while($data->fetch()) {
$x = $rooar ? $data->toRooArray($q) : $data->toArray();
-
-
+
if ($cols == '*') { /// did we get cols sent to us?
$cols = array_keys($x);
}
+
+ if(!is_array($cols)) {
+ $cols = explode(',', $cols);
+ }
if ($titles !== false) {
if ($titles== '*') {
$titles= array_keys($x);
}
+ if(!is_array($titles)) {
+ $titles = explode(',', $titles);
+ }
foreach($cols as $i=>$col) {
- $se_config['cols'][] = array(
+ $add = array(
'header'=> isset($titles[$i]) ? $titles[$i] : $col,
'dataIndex'=> $col,
'width'=> 100,
// 'color' => 'yellow', // set color for the cell which is a header element
// 'fillBlank' => 'gray', // set
);
- $se = new Pman_Core_SimpleExcel(array(), $se_config);
+ //die('here');
+ if (method_exists($data, 'toSimpleExcelColumn')) {
+ $add = $data->toSimpleExcelColumn($add);
+ }
+
+ $se_config['cols'][] = $add;
+
}
+ $se = new Pman_Core_SimpleExcel(array(), $se_config);
$titles = false;
}
}
-
- foreach($data as $x) {
+ foreach($data as $x) {
//echo "<PRE>"; print_r(array($_REQUEST['csvCols'], $x->toArray())); exit;
$line = array();
- if ($titles== '*') {
- $titles= array_keys($x);
- }
+
if ($cols== '*') {
$cols= array_keys($x);
}
+
+ if(!is_array($cols)) {
+ $cols = explode(',', $cols);
+ }
+
if ($titles !== false) {
+ if ($titles== '*') {
+ $titles= array_keys($x);
+ }
+
+ if(!is_array($titles)) {
+ $titles = explode(',', $titles);
+ }
+
foreach($cols as $i=>$col) {
- $se_config['cols'][] = array(
+ $add = array(
'header'=> isset($titles[$i]) ? $titles[$i] : $col,
'dataIndex'=> $col,
'width'=> 100,
// 'color' => 'yellow', // set color for the cell which is a header element
// 'fillBlank' => 'gray', // set
);
- $se = new Pman_Core_SimpleExcel(array(),$se_config);
+ //die('here');
+ if (method_exists($this->do, 'toSimpleExcelColumn')) {
+ $add = $this->do->toSimpleExcelColumn($add);
+ }
+
+ $se_config['cols'][] = $add;
+
}
-
+ $se = new Pman_Core_SimpleExcel(array(),$se_config);
+
//fputcsv($fh, $titles);
$titles = false;
}
-
-
$se->addLine($se_config['workbook'], $x);
}
+
if(!$se){
$this->jerr('no data found');
}
+
$se->send($fn .'.xls');
exit;
-
-
}
} else if (method_exists($x, 'applyFilters')) {
// always call apply filters even after update/insert...
// however arguments are not passed.
- $x->applyFilters(array(), $this->authUser, $this);
+ $x->applyFilters(array('_is_update_request' => true), $this->authUser, $this);
}
// DB_DataObject::DebugLevel(1);
if ($res === false) {
$this->jerr($x->_lastError->toString());
}
+ $ev = $this->addEvent("ADD", $x);
if (method_exists($x, 'onInsert')) {
- $x->onInsert($_REQUEST, $this);
+ $x->onInsert($_REQUEST, $this, $ev);
}
- $ev = $this->addEvent("ADD", $x);
+
if ($ev) {
$ev->audit($x);
}
if ($res === false) {
$this->jerr($x->_lastError->toString());
}
-
+ $ev = $this->addEvent("EDIT", $x);
+
if (method_exists($x, 'onUpdate')) {
- $x->onUpdate($old, $req, $this);
+ $x->onUpdate($old, $req, $this, $ev);
}
- $ev = $this->addEvent("EDIT", $x);
if ($ev) {
$ev->audit($x, $old);
}
}
- echo $key; exit;
+
switch($key) {
$x->whereAdd("(on_id = $oid OR
on_id IN ( SELECT distinct(id) FROM Documents WHERE original = $o )
)");
- continue;
+ continue 2;
}
$x->on_id = $val;
// the aobve rule for !strlen non-joined cols should apply to joined ones.
if (!strlen($val)) {
- continue;
+ continue 2;
}
}
- continue;
+ continue 2;
}
}
if (!empty($q_filtered)) {
if (!is_a($x, 'DB_DataObject') && !is_a($x, 'PDO_DataObject')) {
$this->jerr('invalid url - no dataobject');
}
-
+ $this->do = $x;
return $x;
}