X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=NotifyAction.php;h=968eace383b3c76fa12053984f3831482502f19d;hb=refs%2Fheads%2Fmaster;hp=8b0b9156fe3db382f7b5c5e756b64d9a8820c26e;hpb=53c3aa7723a4b8d665c419a85344c842759eb5c5;p=Pman.Core diff --git a/NotifyAction.php b/NotifyAction.php index 8b0b9156..968eace3 100644 --- a/NotifyAction.php +++ b/NotifyAction.php @@ -7,6 +7,7 @@ * * */ +require_once 'Pman.php'; class Pman_Core_NotifyAction extends Pman { @@ -15,7 +16,7 @@ class Pman_Core_NotifyAction extends Pman { $au = $this->getAuthUser(); if (!$au) { - $this->jerr("Not authenticated", array('authFailure' => true)); + $this->jerror("LOGIN-NOAUTH", "Not authenticated", array('authFailure' => true)); } // workflow only applicable to owner company.. if ($au->company()->comptype != 'OWNER') { @@ -30,44 +31,54 @@ class Pman_Core_NotifyAction extends Pman } - function get() + function get($v, $opts=array()) { $this->jerr("invalid request"); } - function post() + function post($v) { // needs: (Array of...) - // on_table, action(eg. APPROVAL) - // on_id (comma delimited.) + // on_table, + // action(eg. APPROVAL) + // on_id (comma delimited.) + //DB_DataObject::debugLevel(1); $n = DB_DataObject::factory('core_notify'); $n->person_id = $this->authUser->id; // in theory in workflow, this could trigger another action... // if watch is on it.. - foreach(array('on_table','on_id','action') as $k) { + foreach(array('ontable','onid','action') as $k) { if (empty($_POST[$k])) { $this->jerr("missing argument $k"); } - if ($k == 'on_id') { + if ($k == 'onid') { continue; } - $n->$k = $v; + $n->$k = $_POST[$k]; } - $ids = explode(',', $_POST['on_id']); + $n->whereAdd('sent < act_when'); // not issued yet.. $n->whereAdd("join_watch_id_id.medium = '". $n->escape($n->action) ."'"); - $n->whereAddIn('core_notify.id', $ids, 'int' ); + $n->whereAddIn('core_notify.onid', explode(',', $_POST['onid']), 'int' ); $n->autoJoin(); $ar = $n->fetchAll(); + $done = array(); + foreach($ar as $n) { $nc = clone($n); $nc->sent = date('Y-m-d H:i:s'); $nc->update($n); - // add an event????? + // add an event????? - yeap... only once per object + $key = implode(':', array($nc->ontable,$nc->onid)); + if (!isset($done[$key])) { + + $e = $this->addEvent($_POST['action'],$n->object()); + } + $done[$key] = true; } - + $this->jok("updated"); }