f92b53c80caec9b441bb9344e3926c1e0430b0ca
[Pman.Core] / NotifyAction.php
1 <?php
2 /**
3  * in theory a generic 'action' handler..
4  *
5  * Part of the eventual workflow code...
6  * -> at present, just flags something as done.....
7  *
8  *
9  */
10
11 class Pman_Core_NotifyAction extends Pman
12 {
13     
14     function getAuth()
15     {
16         $au = $this->getAuthUser();
17         if (!$au) {
18              $this->jerr("Not authenticated", array('authFailure' => true));
19         }
20         // workflow only applicable to owner company..
21         if ($au->company()->comptype != 'OWNER') {
22             $this->jerr("Core:NotifyAction: invalid user - not owner company.");
23             
24         }
25         
26         $this->authUser = $au;
27         // check that it's a supplier!!!! 
28         
29         return true; 
30     }
31     
32     
33     function get()
34     {
35         $this->jerr("invalid request");
36         
37     }
38     function post()
39     {
40         // needs: (Array of...)
41         //   on_table,
42         //   action(eg. APPROVAL)
43         //   on_id (comma delimited.)
44         $n = DB_DataObject::factory('core_notify');
45         $n->person_id = $this->authUser->id;
46         // in theory in workflow, this could trigger another action...
47         // if watch is on it..
48         foreach(array('on_table','on_id','action') as $k) {
49             if (empty($_POST[$k])) {
50                 $this->jerr("missing argument $k");
51             }
52             if ($k == 'on_id') {
53                 continue;
54             }
55             $n->$k = $v;
56         }
57         $ids = explode(',', $_POST['on_id']);
58         $n->whereAdd('sent < act_when'); // not issued yet..
59         $n->whereAdd("join_watch_id_id.medium = '". $n->escape($n->action) ."'");
60         $n->whereAddIn('core_notify.id', $ids, 'int' );
61         $n->autoJoin();
62         $ar = $n->fetchAll();
63         
64         foreach($ar as $n) {
65             $nc = clone($n);
66             $nc->sent = date('Y-m-d H:i:s');
67             $nc->update($n);
68             
69             // add an event?????
70         }
71         
72         
73         
74     }
75     
76 }