|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package org.openpsa.relatedto |
|
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Find relatedto suspects |
|
11
|
|
|
* |
|
12
|
|
|
* @package org.openpsa.relatedto |
|
13
|
|
|
*/ |
|
14
|
|
|
class org_openpsa_relatedto_finder_event extends org_openpsa_relatedto_finder |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var org_openpsa_calendar_event_dba |
|
18
|
|
|
*/ |
|
19
|
|
|
private $event; |
|
20
|
|
|
|
|
21
|
9 |
|
public function __construct(org_openpsa_calendar_event_dba $event) |
|
22
|
|
|
{ |
|
23
|
9 |
|
$this->event = $event; |
|
24
|
9 |
|
} |
|
25
|
|
|
|
|
26
|
9 |
|
public function process() |
|
27
|
|
|
{ |
|
28
|
9 |
|
if (midcom::get()->componentloader->is_installed('org.openpsa.projects')) { |
|
29
|
|
|
// Do not seek if we have only one participant (gives a ton of results, most of them useless) |
|
30
|
9 |
|
if (count($this->event->participants) < 2) { |
|
31
|
9 |
|
debug_add("we have less than two participants, skipping seek"); |
|
32
|
|
|
} elseif ($suspect_links = $this->find_in_projects()) { |
|
33
|
|
|
$this->save($suspect_links); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
9 |
|
if (midcom::get()->componentloader->is_installed('org.openpsa.sales')) { |
|
37
|
|
|
// if we have less than two participants, abort |
|
38
|
9 |
|
if (count($this->event->participants) > 2) { |
|
39
|
|
|
if ($suspect_links = $this->find_in_sales()) { |
|
40
|
|
|
$this->save($suspect_links); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
9 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Current rule: all participants of event must be either manager, contact or resource in task |
|
48
|
|
|
* that overlaps in time with the event. |
|
49
|
|
|
*/ |
|
50
|
|
|
private function find_in_projects() : array |
|
51
|
|
|
{ |
|
52
|
|
|
if ($cnt = $this->count_links($this->event->guid, org_openpsa_projects_task_dba::class, 'outgoing')) { |
|
53
|
|
|
debug_add("Found {$cnt} confirmed links already, skipping seek"); |
|
54
|
|
|
return []; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$mc = org_openpsa_projects_task_resource_dba::new_collector(); |
|
58
|
|
|
//Target task starts or ends inside given events window or starts before and ends after |
|
59
|
|
|
$mc->add_constraint('task.start', '<=', $this->event->end); |
|
60
|
|
|
$mc->add_constraint('task.end', '>=', $this->event->start); |
|
61
|
|
|
//Target task is active |
|
62
|
|
|
$mc->add_constraint('task.status', '<', org_openpsa_projects_task_status_dba::COMPLETED); |
|
63
|
|
|
$mc->add_constraint('task.status', '<>', org_openpsa_projects_task_status_dba::DECLINED); |
|
64
|
|
|
//Each event participant is either manager or member (resource/contact) in task |
|
65
|
|
|
$mc->begin_group('OR'); |
|
66
|
|
|
$mc->add_constraint('task.manager', 'IN', array_keys($this->event->participants)); |
|
67
|
|
|
$mc->add_constraint('person', 'IN', array_keys($this->event->participants)); |
|
68
|
|
|
$mc->end_group(); |
|
69
|
|
|
$suspects = $mc->get_values('task'); |
|
70
|
|
|
if (empty($suspects)) { |
|
71
|
|
|
return []; |
|
72
|
|
|
} |
|
73
|
|
|
$qb = org_openpsa_projects_task_dba::new_query_builder(); |
|
74
|
|
|
$qb->add_constraint('id', 'IN', array_unique($suspects)); |
|
75
|
|
|
|
|
76
|
|
|
$defaults = $this->suspect_defaults($this->event, 'org.openpsa.calendar', 'outgoing'); |
|
77
|
|
|
return $this->prepare_links($qb, 'org.openpsa.projects', $defaults); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Current rule: all participants of event must be either manager,contact or resource in task |
|
83
|
|
|
* that overlaps in time with the event. |
|
84
|
|
|
*/ |
|
85
|
|
|
private function find_in_sales() : array |
|
86
|
|
|
{ |
|
87
|
|
|
if ($cnt = $this->count_links($this->event->guid, [org_openpsa_sales_salesproject_dba::class, org_openpsa_sales_salesproject_deliverable_dba::class], 'incoming')) { |
|
88
|
|
|
debug_add("Found {$cnt} confirmed links already, skipping seek"); |
|
89
|
|
|
return []; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$mc = org_openpsa_contacts_role_dba::new_collector('role', org_openpsa_sales_salesproject_dba::ROLE_MEMBER); |
|
93
|
|
|
$mc->add_constraint('person', 'IN', array_keys($this->event->participants)); |
|
94
|
|
|
$guids = $mc->get_values('objectGuid'); |
|
95
|
|
|
|
|
96
|
|
|
$qb = org_openpsa_sales_salesproject_dba::new_query_builder(); |
|
97
|
|
|
|
|
98
|
|
|
// Target sales project starts or ends inside given events window or starts before and ends after |
|
99
|
|
|
$qb->add_constraint('start', '<=', $this->event->end); |
|
100
|
|
|
$qb->begin_group('OR'); |
|
101
|
|
|
$qb->add_constraint('end', '>=', $this->event->start); |
|
102
|
|
|
$qb->add_constraint('end', '=', 0); |
|
103
|
|
|
$qb->end_group(); |
|
104
|
|
|
|
|
105
|
|
|
//Target sales project is active |
|
106
|
|
|
$qb->add_constraint('state', '=', org_openpsa_sales_salesproject_dba::STATE_ACTIVE); |
|
107
|
|
|
|
|
108
|
|
|
//Each event participant is either manager or member (resource/contact) in task |
|
109
|
|
|
$qb->begin_group('OR'); |
|
110
|
|
|
$qb->add_constraint('owner', 'IN', array_keys($this->event->participants)); |
|
111
|
|
|
$qb->add_constraint('guid', 'IN', $guids); |
|
112
|
|
|
$qb->end_group(); |
|
113
|
|
|
|
|
114
|
|
|
$defaults = $this->suspect_defaults($this->event, 'org.openpsa.calendar', 'incoming'); |
|
115
|
|
|
$this->prepare_links($qb, 'org.openpsa.sales', $defaults); |
|
116
|
|
|
} |
|
117
|
|
|
} |