// ------------ROO HOOKS------------------------------------
- function applyFilters($q, $au)
+ function applyFilters($q, $au ,$roo)
{
$tn = $this->tableName();
if (!empty($q['query']['from'])) {
if (isset($q['_related_on_id']) && isset($q['_related_on_table'])) {
// example: sales order - has invoices,
+ ///DB_DataObject::DebugLevel(1);
$ev =$this->factory('Events');
$ev->setFrom(array(
'on_id' => $q['_related_on_id'],
));
$obj = $ev->object();
+ if (!$obj) {
+ $roo->jerr("ontable is invalid");
+ }
+ if (!method_exists($obj,'relatedWhere')) {
+ $roo->jerr( $q['_related_on_table'] . " Does not have method relatedWhere :" .
+ implode(',', get_class_methods($obj)));
+ }
if ($obj && method_exists($obj,'relatedWhere')) {
$ar = $obj->relatedWhere();
$tn = $this->tableName();
}
// since roo does not support autojoin yet..
- $this->autoJoinExtra();
-
+ if (!isset($q['_distinct'])) {
+ $this->autoJoinExtra();
+ }
function autoJoinExtra()
{
//$ret = parent::autoJoin();
- //DB_DataObject::debugLevel(1);
+ // DB_DataObject::debugLevel(1);
// now try and magically join person_table to the right table..
+ return;
+ // this does not work on postgres..
$tn = $this->tableName();
$pt = DB_DataObject::Factory($this->tableName());
$pt->selectAdD();
$pt->selectAdD('distinct(person_table) as person_table');
$pt->whereAdd('person_table IS NOT NULL AND LENGTH(person_table) > 0');
$tbls = $pt->fetchAll('person_table');
+ $pers = DB_DataObject::Factory('Person');
+ $ptbl = $pers->tableName();
+ if (!in_array($ptbl,$tbls)) {
+ $tbls[] = $ptbl;
+
+ }
foreach($tbls as $tbl) {
// find all the columns from the joined table..
$st = DB_DataObject::Factory($tbl);
$tcols = array_keys($st->table());
+
+ $cond = "{$tn}.person_table = '{$tbl}'";
+ if ($tbl == $ptbl) {
+ $cond = "( $cond OR {$tn}.person_table = '')";
+ }
+
foreach($tcols as $col) {
if ($col == 'passwd') {
continue;
}
$cols[$col] = isset($cols[$col] ) ? $cols[$col] : array();
- $cols[$col][] = "WHEN {$tn}.person_table = '$tbl' THEN join_person_table_{$tbl}.{$col}";
+ $cols[$col][] = "WHEN $cond THEN join_person_table_{$tbl}.{$col}";
}
// id's are hard coded...
+
$this->_join .= "
LEFT JOIN {$tbl} AS join_person_table_{$tbl}
ON {$tn}.person_id = join_person_table_{$tbl}.id
- AND {$tn}.person_table = '{$tbl}'
-
+ AND $cond
";
}
foreach($cols as $col=>$whens) {
*/
function auditField($name, $ov, $nv, $old=false )
{
+ // hack..
+ if (is_object($nv)) {
+ return;
+
+ }
+
$x = DB_DataObject::factory('core_event_audit');
$x->setFrom(array(
'event_id' => $this->id,