This repository was archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 754
/
Copy pathTreeView.php
186 lines (170 loc) · 4.15 KB
/
TreeView.php
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* Basic TreeView Model Class.
*
* @copyright YetiForce Sp. z o.o
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Mariusz Krzaczkowski <[email protected]>
* @author Radosław Skrzypczak <[email protected]>
*/
class Vtiger_TreeView_Model extends \App\Base
{
public static $_cached_instance;
/**
* Function to get the Module Name.
*
* @return string Module name
*/
public function getModuleName()
{
return $this->get('moduleName');
}
/**
* Active tree tab.
*
* @return bool
*/
public function isActive()
{
return false;
}
/**
* Load tree tab label.
*
* @return string
*/
public function getName()
{
return 'LBL_TREE_VIEW';
}
/**
* Load tree ID.
*
* @return type
*/
public function getTemplate()
{
return $this->getTreeField()['fieldparams'];
}
/**
* Load tree field info.
*
* @return array
*/
public function getTreeField()
{
if ($this->has('fieldTemp')) {
return $this->get('fieldTemp');
}
$fieldTemp = (new App\Db\Query())->select(['tablename', 'columnname', 'fieldname', 'fieldparams'])
->from('vtiger_field')
->where(['uitype' => 302, 'tabid' => \App\Module::getModuleId($this->getModuleName())])
->one();
if (!$fieldTemp) {
throw new \App\Exceptions\AppException('ERR_TREE_NOT_FOUND');
}
$this->set('fieldTemp', $fieldTemp);
return $fieldTemp;
}
/**
* Load records tree address.
*
* @return string - url
*/
public function getTreeViewUrl()
{
return 'index.php?module=' . $this->getModuleName() . '&view=TreeRecords';
}
/**
* Static Function to get the instance of Vtiger TreeView Model for the given Vtiger Module Model.
*
* @param string $moduleName
*
* @throws \App\Exceptions\AppException
*
* @return Vtiger_TreeView_Model
*/
public static function getInstance(string $moduleName)
{
if (isset(self::$_cached_instance[$moduleName])) {
return self::$_cached_instance[$moduleName];
}
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'TreeView', $moduleName);
$instance = new $modelClassName();
self::$_cached_instance[$moduleName] = $instance->set('moduleName', $moduleName);
return self::$_cached_instance[$moduleName];
}
/**
* Function to get Basic links for tree view
*
* @return array of Basic links
*/
public function getBasicLinks(): array
{
$moduleName = $this->getModuleName();
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
$basicLinks = [];
if ($moduleModel->isPermitted('CreateView')) {
$basicLinks[] = [
'linktype' => 'LISTVIEWBASIC',
'linklabel' => 'LBL_ADD_RECORD',
'linkurl' => $moduleModel->getCreateRecordUrl(),
'linkclass' => 'btn-light addButton modCT_' . $moduleModel->getName(),
'linkicon' => 'fas fa-plus',
'showLabel' => 1,
'linkhref' => true
];
}
return $basicLinks;
}
/**
* Function to get the list of tree view links.
*
* @param <Array> $linkParams
*
* @return <Array> - Associate array of Link Type to List of Vtiger_Link_Model instances
*/
public function getListViewLinks()
{
$basicLinks = $this->getBasicLinks();
$links = [];
foreach ($basicLinks as $basicLink) {
$links['LISTVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($basicLink);
}
return $links;
}
/**
* Load tree.
*
* @return string
*/
public function getTreeList()
{
$tree = [];
$lastId = 0;
$dataReader = (new App\Db\Query())
->from('vtiger_trees_templates_data')
->where(['templateid' => $this->getTemplate()])
->createCommand()->query();
while ($row = $dataReader->read()) {
$treeID = (int) ltrim($row['tree'], 'T');
$pieces = explode('::', $row['parentTree']);
end($pieces);
$parent = (int) ltrim(prev($pieces), 'T');
$tree[] = [
'id' => $treeID,
'type' => 'category',
'record_id' => $row['tree'],
'parent' => $parent == 0 ? '#' : $parent,
'text' => \App\Language::translate($row['name'], $this->getModuleName()),
'state' => ($row['state']) ? $row['state'] : '',
'icon' => $row['icon'],
];
if ($treeID > $lastId) {
$lastId = $treeID;
}
}
$this->lastTreeId = $lastId;
return $tree;
}
}