|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TimeControl calendar model file. |
|
5
|
|
|
* |
|
6
|
|
|
* @package Model |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright YetiForce S.A. |
|
9
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
10
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* TimeControl calendar model class. |
|
15
|
|
|
*/ |
|
16
|
|
|
class OSSTimeControl_Calendar_Model extends Vtiger_Calendar_Model |
|
17
|
|
|
{ |
|
18
|
|
|
/** {@inheritdoc} */ |
|
19
|
|
|
public function getCalendarTypes(): array |
|
20
|
|
|
{ |
|
21
|
|
|
$calendarTypes = []; |
|
22
|
|
|
$moduleField = $this->getModule()->getFieldByName('timecontrol_type'); |
|
23
|
|
|
if ($moduleField && $moduleField->isActiveField()) { |
|
24
|
|
|
$calendarTypes = $moduleField->getPicklistValues(); |
|
25
|
|
|
} |
|
26
|
|
|
return $calendarTypes; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get query. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \App\Db\Query |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getQuery() |
|
35
|
|
|
{ |
|
36
|
|
|
$queryGenerator = new App\QueryGenerator($this->getModuleName()); |
|
37
|
|
|
if ($this->has('customFilter')) { |
|
38
|
|
|
$queryGenerator->initForCustomViewById($this->get('customFilter')); |
|
39
|
|
|
} |
|
40
|
|
|
$queryGenerator->setFields(['id', 'date_start', 'time_start', 'time_end', 'due_date', 'timecontrol_type', 'name', 'assigned_user_id']); |
|
41
|
|
|
if ($types = $this->get('types')) { |
|
42
|
|
|
$queryGenerator->addCondition('timecontrol_type', implode('##', $types), 'e'); |
|
43
|
|
|
} |
|
44
|
|
|
if ($this->get('start') && $this->get('end')) { |
|
45
|
|
|
$dbStartDateOject = DateTimeField::convertToDBTimeZone($this->get('start')); |
|
46
|
|
|
$dbStartDateTime = $dbStartDateOject->format('Y-m-d H:i:s'); |
|
47
|
|
|
$dbStartDate = $dbStartDateOject->format('Y-m-d'); |
|
48
|
|
|
$dbEndDateObject = DateTimeField::convertToDBTimeZone($this->get('end')); |
|
49
|
|
|
$dbEndDateTime = $dbEndDateObject->format('Y-m-d H:i:s'); |
|
50
|
|
|
$dbEndDate = $dbEndDateObject->format('Y-m-d'); |
|
51
|
|
|
$queryGenerator->addNativeCondition([ |
|
52
|
|
|
'or', |
|
53
|
|
|
[ |
|
54
|
|
|
'and', |
|
55
|
|
|
['>=', new \yii\db\Expression("CONCAT(vtiger_osstimecontrol.date_start, ' ', vtiger_osstimecontrol.time_start)"), $dbStartDateTime], |
|
56
|
|
|
['<=', new \yii\db\Expression("CONCAT(vtiger_osstimecontrol.date_start, ' ', vtiger_osstimecontrol.time_start)"), $dbEndDateTime], |
|
57
|
|
|
], |
|
58
|
|
|
[ |
|
59
|
|
|
'and', |
|
60
|
|
|
['>=', new \yii\db\Expression("CONCAT(vtiger_osstimecontrol.due_date, ' ', vtiger_osstimecontrol.time_end)"), $dbStartDateTime], |
|
61
|
|
|
['<=', new \yii\db\Expression("CONCAT(vtiger_osstimecontrol.due_date, ' ', vtiger_osstimecontrol.time_end)"), $dbEndDateTime], |
|
62
|
|
|
], |
|
63
|
|
|
[ |
|
64
|
|
|
'and', |
|
65
|
|
|
['<', 'vtiger_osstimecontrol.date_start', $dbStartDate], |
|
66
|
|
|
['>', 'vtiger_osstimecontrol.due_date', $dbEndDate], |
|
67
|
|
|
], |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$query = $queryGenerator->createQuery(); |
|
72
|
|
|
if ($this->has('filters')) { |
|
73
|
|
|
foreach ($this->get('filters') as $filter) { |
|
74
|
|
|
$filterClassName = Vtiger_Loader::getComponentClassName('CalendarFilter', $filter['name'], $this->getModuleName()); |
|
75
|
|
|
$filterInstance = new $filterClassName(); |
|
76
|
|
|
if ($filterInstance->checkPermissions() && $conditions = $filterInstance->getCondition($filter['value'])) { |
|
77
|
|
|
$query->andWhere($conditions); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
$conditions = []; |
|
82
|
|
|
if (!empty($this->get('user')) && isset($this->get('user')['selectedIds'][0])) { |
|
83
|
|
|
$selectedUsers = $this->get('user'); |
|
84
|
|
|
$selectedIds = $selectedUsers['selectedIds']; |
|
85
|
|
|
if ('all' !== $selectedIds[0]) { |
|
86
|
|
|
$conditions[] = ['vtiger_crmentity.smownerid' => $selectedIds]; |
|
87
|
|
|
$subQuery = (new \App\Db\Query())->select(['crmid'])->from('u_#__crmentity_showners')->where(['userid' => $selectedIds]); |
|
88
|
|
|
$conditions[] = ['vtiger_crmentity.crmid' => $subQuery]; |
|
89
|
|
|
} |
|
90
|
|
|
if (isset($selectedUsers['excludedIds']) && 'all' === $selectedIds[0]) { |
|
91
|
|
|
$conditions[] = ['not in', 'vtiger_crmentity.smownerid', $selectedUsers['excludedIds']]; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
if ($conditions) { |
|
95
|
|
|
$query->andWhere(array_merge(['or'], $conditions)); |
|
96
|
|
|
} |
|
97
|
|
|
$query->orderBy(['vtiger_osstimecontrol.date_start' => SORT_ASC, 'vtiger_osstimecontrol.time_start' => SORT_ASC]); |
|
98
|
|
|
|
|
99
|
|
|
return $query; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Function to get records. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getEntity() |
|
108
|
|
|
{ |
|
109
|
|
|
$dataReader = $this->getQuery()->createCommand()->query(); |
|
110
|
|
|
$result = []; |
|
111
|
|
|
$moduleModel = $this->getModule(); |
|
112
|
|
|
$isSummaryViewSupported = $moduleModel->isSummaryViewSupported(); |
|
113
|
|
|
$colors = \App\Fields\Picklist::getColors('timecontrol_type', false); |
|
114
|
|
|
while ($record = $dataReader->read()) { |
|
115
|
|
|
$item = []; |
|
116
|
|
|
$item['id'] = $record['id']; |
|
117
|
|
|
$item['title'] = \App\Purifier::encodeHtml($record['name']); |
|
118
|
|
|
|
|
119
|
|
|
$dateTimeInstance = new DateTimeField($record['date_start'] . ' ' . $record['time_start']); |
|
|
|
|
|
|
120
|
|
|
$item['start'] = DateTimeField::convertToUserTimeZone($record['date_start'] . ' ' . $record['time_start'])->format('Y-m-d') . ' ' . $dateTimeInstance->getFullcalenderTime(); |
|
121
|
|
|
$item['start_display'] = $dateTimeInstance->getDisplayDateTimeValue(); |
|
122
|
|
|
|
|
123
|
|
|
$dateTimeInstance = new DateTimeField($record['due_date'] . ' ' . $record['time_end']); |
|
124
|
|
|
$item['end'] = DateTimeField::convertToUserTimeZone($record['due_date'] . ' ' . $record['time_end'])->format('Y-m-d') . ' ' . $dateTimeInstance->getFullcalenderTime(); |
|
125
|
|
|
$item['end_display'] = $dateTimeInstance->getDisplayDateTimeValue(); |
|
126
|
|
|
|
|
127
|
|
|
$item['borderColor'] = $colors[$record['timecontrol_type']] ?? ''; |
|
128
|
|
|
$item['className'] = 'js-popover-tooltip--record ownerCBg_' . $record['assigned_user_id']; |
|
129
|
|
|
if ($isSummaryViewSupported) { |
|
130
|
|
|
$item['url'] = 'index.php?module=' . $this->getModuleName() . '&view=Detail&record=' . $record['id']; |
|
131
|
|
|
$item['className'] .= ' js-show-modal'; |
|
132
|
|
|
} else { |
|
133
|
|
|
$item['url'] = $moduleModel->getDetailViewUrl($record['id']); |
|
134
|
|
|
} |
|
135
|
|
|
$result[] = $item; |
|
136
|
|
|
} |
|
137
|
|
|
$dataReader->close(); |
|
138
|
|
|
return $result; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|