3 require_once 'Pman/Core/DataObjects/Core_project.php';
5 class Pman_MTrack_DataObjects_Core_project extends Pman_Core_DataObjects_Core_project
9 * check who is trying to access this. false == access denied..
11 function checkPerm($lvl, $au)
13 // var_dump(array($lvl,$au));
18 if (!$au->company_id) {
21 if ($au->company()->comptype != 'OWNER') {
24 // owner.. - we can rely on perms...
26 return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
29 // any other action on perms has to be done by company onwer at present..
30 if (!$au || !$au->company_id || $au->company()->comptype != 'OWNER') {
34 return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
37 function applyFilters($q, $au, $roo)
39 $tn = $this->tableName();
41 $this->code = '*PUBLIC';
43 $this->selectAs(array('id','name','code')); // public an only see so much data.?
45 $roo->jdata($this->fetchAll(false,false,'toArray'));
47 // not sure why this used to say array().. for filter???
48 parent::applyFilters($q, $au, $roo);
50 if (!$au->hasPerm('Core.Projects_All', 'S')) {
51 $pdtn = $this->factory('ProjectDirectory')->tableName();
53 // default behaviour is to only allow access to projects
54 // where the user has a role..
58 (SELECT {$pdtn}.project_id FROM {$pdtn} WHERE
59 person_id = ". $au->id . " and role != ''
62 // can only see projects with repo's.. by default..
67 if (isset($q['_with_tickets'])) {
71 count(mtrack_ticket.id)
75 core_enum as join_status_id
77 join_status_id.id = mtrack_ticket.status
79 (join_status_id.name NOT IN('closed', 'on hold') OR mtrack_ticket.status = 0)
81 mtrack_ticket.project_id = core_project.id
85 count(mtrack_ticket.id)
89 core_enum as join_status_id
91 join_status_id.id = mtrack_ticket.status
93 (join_status_id.name NOT IN('closed', 'on hold') OR mtrack_ticket.status = 0)
95 mtrack_ticket.project_id = core_project.id
96 ),0) > 1, 0 , 0) as has_no_tickets
98 $this->_extra_cols = array('no_tickets','has_no_tickets');
102 if (isset($q['_mtrack_repos_only'])) {
103 //?/ should we hide closed projects by default even from admin?
104 $this->whereAdd("{$tn}.id in (SELECT distinct(project_id) FROM mtrack_repos)");
107 //$p->orderBy('{$tn}.name ASC');
108 //unset($p->client_id); // default projects serach enforces this..
109 //$ar = $p->fetchAll('id', 'name');
124 function projectPerm($project_id, $what, $cando)
129 $p = DB_DataObject::factory('Projects');
130 $p->get($project_id);
131 if (!$this->authUser) {
132 if ($p->code != '*PUBLIC') {
133 return false; // only public projects
138 // all permissions to view public stuff.
141 if (!$this->authUser->hasPerm($what, $cando)) {
142 echo "NO PERMS $what $cando";
143 echo '<PRE>'; print_r($this->authUser->getPerms());
147 //echo "COMPTYPE " . $this->authUser->company()->comptype ;
148 if ($this->authUser->company()->comptype == 'OWNER') {
150 if ($this->authUser->hasPerm('Core.Projects_All', $cando)) { // they can do what they like on all projects.
153 // return $p->hasPerm($what, $cando);
155 // otherwise they have to be a team member of that project.
157 $pd = DB_DataObject::factory('ProjectDirectory');
158 $pd->project_id = $project_id;
159 $pd->user_id = $this->authUser->id;
160 $pd->whereAdd("role != ''");
170 function notifyENDOFDAYMAIL($rcpt, $last_sent_date, $notify, $force)
172 // fisrst use history to show a list of changes between the dates.
173 //die("building end of day mail");
174 //DB_DataObject::debugLevel(1);
175 $start = date('Y-m-d H:i:s', strtotime($notify->act_start . ' - 1 DAY'));
176 $end = date('Y-m-d H:i:s', strtotime($notify->act_start));
178 $d = DB_DataObject::factory('mtrack_change');
179 $d->ontable = 'mtrack_ticket';
180 $d->whereAdd(" mtrack_change.changedate >= '$start' AND mtrack_change.changedate <= '$end'");
182 $d->autoJoinObject('mtrack_ticket');
183 $d->whereAdd('join_project_id_id.id = '. $this->pid());
185 $d->orderBy('mtrack_change.changedate ASC');
187 $res = $d->fetchAll();
190 // group it by projects...
192 foreach($res as $o) {
194 if (!isset($tickets[$o->ontable_id])) {
195 $tickets[$o->ontable_id] = clone($o);
196 $tickets[$o->ontable_id]->changes = array();
199 $tickets[$o->ontable_id]->changes[] = clone($o);
207 //print_r($obj);exit;
208 $ret = $rcpt->buildMail('mtrack_ticket_daily_changes', array(
210 'tickets' => $tickets,
211 'date' => date('d/M/Y', strtotime($notify->act_start)),
214 //print_r($ret);exit;
218 //$rcpt->sendTemplate('repo_daily_changes', $obj);
220 //echo '<PRE>'.htmlspecialchars(print_r($mr,true));