-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
CBTagTask.inc
81 lines (78 loc) · 3.49 KB
/
CBTagTask.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*************************************************************************************************
* Copyright 2014 JPL TSolucio, S.L. -- This file is a part of TSOLUCIO coreBOS Customizations.
* Licensed under the vtiger CRM Public License Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You can redistribute it and/or modify it
* under the terms of the License. JPL TSolucio, S.L. reserves all rights not expressly
* granted by the License. coreBOS distributed by JPL TSolucio S.L. is distributed in
* the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Unless required by
* applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT ANY WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing
* permissions and limitations under the License. You may obtain a copy of the License
* at <http://corebos.org/documentation/doku.php?id=en:devel:vpl11>
*************************************************************************************************
* Author : JPL TSolucio, S. L.
*************************************************************************************************/
require_once 'modules/com_vtiger_workflow/VTEntityCache.inc';
require_once 'modules/com_vtiger_workflow/VTWorkflowUtils.php';
class CBTagTask extends VTTask {
public $executeImmediately = true;
public $queable = true;
public $listoftags;
public $addrel;
public $forallusers;
public function getFieldNames() {
return array('listoftags', 'addrel', 'forallusers');
}
public function doTask(&$entity) {
global $current_user, $logbg;
$logbg->debug('> TagTask');
list($cto, $cto_id) = explode('x', $entity->getId());
if (!empty($cto_id) && !empty($this->listoftags)) {
$setype = getSalesEntityType($cto_id);
require_once 'include/freetag/freetag.class.php';
$freetag = new freetag();
if ($this->addrel) {
if ($this->forallusers) {
$usrs = get_user_array();
$users = '';
foreach ($usrs as $uid => $uname) {
if (!empty($uid)) {
$users.= $uid.',';
}
}
$users = trim($users, ',');
} else {
$users = $current_user->id;
}
$freetag->tag_object($users, $cto_id, $this->listoftags, $setype);
$logmsg = '(TagTask) ADD object tag';
$this->logmessages[] = $logmsg;
$this->logmessages[] = json_encode([$users, $cto_id, $this->listoftags, $setype]);
$logbg->debug($logmsg, [$users, $cto_id, $this->listoftags, $setype]);
} else {
if ($this->forallusers) {
$logmsg = '(TagTask) DELETE object tags for all users';
$this->logmessages[] = $logmsg;
$this->logmessages[] = json_encode([$cto_id, $this->listoftags]);
$logbg->debug($logmsg, [$cto_id, $this->listoftags]);
$freetag->delete_object_tags($cto_id, $this->listoftags);
} else {
$logmsg = '(TagTask) DELETE object tag for';
$this->logmessages[] = $logmsg;
$this->logmessages[] = json_encode([$current_user->id, $cto_id, $this->listoftags]);
$logbg->debug($logmsg, [$current_user->id, $cto_id, $this->listoftags]);
$freetag->delete_object_tag($current_user->id, $cto_id, $this->listoftags);
}
}
} else {
$logmsg = '(TagTask) not called: cto_id or listoftags are empty';
$this->logmessages[] = $logmsg;
$logbg->debug($logmsg);
}
$logbg->debug('< TagTask');
}
}
?>