/
Module.php
1466 lines (1373 loc) · 40.1 KB
/
Module.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* +***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* Contributor(s): YetiForce.com
* *********************************************************************************** */
/**
* Vtiger Module Model Class.
*/
class Vtiger_Module_Model extends \vtlib\Module
{
/** Standard module type */
const STANDARD_TYPE = 0;
/** Advanced module type */
const ADVANCED_TYPE = 1;
protected $blocks;
protected $nameFields;
protected $moduleMeta;
protected $fields;
protected $relations;
protected $moduleType = '0';
protected $entityInstance;
/** @var bool */
public $allowTypeChange = true;
/**
* Function to get the Module/Tab id.
*
* @return <Number>
*/
public function getId()
{
return (int) $this->id;
}
public function getName()
{
return $this->name;
}
/**
* Function to check whether the module is an entity type module or not.
*
* @return bool
*/
public function isEntityModule()
{
return '1' == $this->isentitytype;
}
/**
* Function to check whether the module is enabled for quick create.
*
* @return bool
*/
public function isQuickCreateSupported()
{
return $this->isEntityModule() && !$this->isInventory() && \App\Privilege::isPermitted($this->getName(), 'CreateView');
}
/**
* Function to check whether the module is summary view supported.
*
* @return bool
*/
public function isSummaryViewSupported()
{
return true;
}
public function getModuleType()
{
return $this->get('type');
}
public function isInventory()
{
return static::ADVANCED_TYPE === $this->getModuleType();
}
/**
* Function to get singluar label key.
*
* @return string - Singular module label key
*/
public function getSingularLabelKey()
{
return 'SINGLE_' . $this->getName();
}
/**
* Function to get the value of a given property.
*
* @param string $propertyName
*
* @throws Exception
*
* @return <Object>
*/
public function get($propertyName)
{
if (property_exists($this, $propertyName)) {
return $this->{$propertyName};
}
throw new \App\Exceptions\AppException($propertyName . ' doest not exists in class ' . static::class);
}
/**
* Function to set the value of a given property.
*
* @param string $propertyName
* @param <Object> $propertyValue
*
* @return Vtiger_Module_Model instance
*/
public function set($propertyName, $propertyValue)
{
$this->{$propertyName} = $propertyValue;
return $this;
}
/**
* Function checks if the module is Active.
*
* @return bool
*/
public function isActive()
{
return \in_array($this->get('presence'), [0, 2]);
}
/**
* Function checks if the module is enabled for tracking changes.
*
* @return bool
*/
public function isTrackingEnabled()
{
require_once 'modules/ModTracker/ModTracker.php';
$trackingEnabled = ModTracker::isTrackingEnabledForModule($this->getName());
return $this->isActive() && $trackingEnabled;
}
/**
* Function checks if comment is enabled.
*
* @return bool
*/
public function isCommentEnabled()
{
$moduleName = $this->getName();
$cacheName = 'isModuleCommentEnabled';
if (!\App\Cache::has($cacheName, $moduleName)) {
$moduleModel = self::getInstance('ModComments');
$fieldModel = $moduleModel && $moduleModel->isActive() ? $moduleModel->getFieldByName('related_to') : null;
$enabled = $fieldModel && \in_array($moduleName, $fieldModel->getReferenceList());
\App\Cache::save($cacheName, $moduleName, $enabled, \App\Cache::LONG);
}
return \App\Cache::get($cacheName, $moduleName);
}
/**
* Static Function to get the instance of Vtiger Module Model for the given id or name.
*
* @param int|string $mixed id or name of the module
*
* @return self
*/
public static function getInstance($mixed)
{
if (is_numeric($mixed)) {
$mixed = \App\Module::getModuleName($mixed);
}
if (\App\Cache::staticHas('module', $mixed)) {
return \App\Cache::staticGet('module', $mixed);
}
$instance = false;
$moduleObject = parent::getInstance($mixed);
if ($moduleObject) {
$instance = self::getInstanceFromModuleObject($moduleObject);
\App\Cache::staticSave('module', $moduleObject->name, $instance);
}
return $instance;
}
/**
* Function to get the instance of Vtiger Module Model from a given vtlib\Module object.
*
* @param vtlib\Module $moduleObj
*
* @return self
*/
public static function getInstanceFromModuleObject(vtlib\Module $moduleObj)
{
$objectProperties = get_object_vars($moduleObj);
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $objectProperties['name']);
$moduleModel = new $modelClassName();
foreach ($objectProperties as $properName => $propertyValue) {
$moduleModel->{$properName} = $propertyValue;
}
return $moduleModel;
}
/**
* Function to get the instance of Vtiger Module Model from a given list of key-value mapping.
*
* @param array $valueArray
*
* @return self
*/
public static function getInstanceFromArray($valueArray)
{
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $valueArray['name']);
$instance = new $modelClassName();
$instance->initialize($valueArray);
return $instance;
}
/**
* Function to get the ListView Component Name.
*
* @return string
*/
public function getListViewName()
{
return 'List';
}
/**
* Function to get the DetailView Component Name.
*
* @return string
*/
public function getDetailViewName()
{
return 'Detail';
}
/**
* Function to get the EditView Component Name.
*
* @return string
*/
public function getEditViewName()
{
return 'Edit';
}
/**
* Function to get the DuplicateView Component Name.
*
* @return string
*/
public function getDuplicateViewName()
{
return 'Edit';
}
/**
* Function to get the Delete Action Component Name.
*
* @return string
*/
public function getDeleteActionName()
{
return 'Delete';
}
/**
* Function to get the Default View Component Name.
*
* @return string
*/
public function getDefaultViewName()
{
$viewName = App\Config::module($this->getName(), 'defaultViewName');
if (!empty($viewName)) {
return $viewName;
}
return 'List';
}
/**
* Function to get the url for default view of the module.
*
* @return string - url
*/
public function getDefaultUrl()
{
return 'index.php?module=' . $this->getName() . '&view=' . $this->getDefaultViewName();
}
/**
* Function to get the url for list view of the module.
*
* @return string - url
*/
public function getListViewUrl()
{
return 'index.php?module=' . $this->getName() . '&view=' . $this->getListViewName();
}
/**
* Function to get the url for the Create Record view of the module.
*
* @return string - url
*/
public function getCreateRecordUrl()
{
return 'index.php?module=' . $this->getName() . '&view=' . $this->getEditViewName();
}
/**
* Function to get the url for the Create Record view of the module.
*
* @return string - url
*/
public function getQuickCreateUrl()
{
return 'index.php?module=' . $this->getName() . '&view=QuickCreateAjax';
}
/**
* Function to get the url for the Import action of the module.
*
* @return string - url
*/
public function getImportUrl()
{
return 'index.php?module=' . $this->getName() . '&view=Import';
}
/**
* Function to get the url for the Export action of the module.
*
* @return string - url
*/
public function getExportUrl()
{
return 'index.php?module=' . $this->getName() . '&view=Export';
}
/**
* Function to get the url to view Dashboard for the module.
*
* @return string - url
*/
public function getDashBoardUrl()
{
return 'index.php?module=' . $this->getName() . '&view=DashBoard';
}
/**
* Function to get the url to view Details for the module.
*
* @param mixed $id
*
* @return string - url
*/
public function getDetailViewUrl($id)
{
return 'index.php?module=' . $this->getName() . '&view=' . $this->getDetailViewName() . '&record=' . $id;
}
/**
* Function to get a Vtiger Record Model instance from an array of key-value mapping.
*
* @param <Array> $valueArray
* @param mixed $rawData
*
* @return Vtiger_Record_Model or Module Specific Record Model instance
*/
public function getRecordFromArray($valueArray, $rawData = false)
{
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Record', $this->getName());
$recordInstance = new $modelClassName();
if (false !== $rawData) {
foreach ($this->getFields() as $field) {
$column = $field->get('column');
if (isset($rawData[$column])) {
$rawData[$field->getName()] = $rawData[$column];
unset($rawData[$column]);
}
}
}
$recordInstance->setFullForm(false);
return $recordInstance->setData($valueArray)->setModuleFromInstance($this)->setRawData($rawData);
}
/**
* Function returns all the blocks for the module.
*
* @return Vtiger_Block_Model[] - list of block models
*/
public function getBlocks()
{
if (empty($this->blocks)) {
$blocksList = [];
$moduleBlocks = Vtiger_Block_Model::getAllForModule($this);
foreach ($moduleBlocks as &$block) {
$blocksList[$block->get('label')] = $block;
}
$this->blocks = $blocksList;
}
return $this->blocks;
}
/**
* Function that returns all the fields for the module.
*
* @param mixed $blockInstance
*
* @return Vtiger_Field_Model[] - list of field models
*/
public function getFields($blockInstance = false)
{
if (empty($this->fields)) {
$moduleBlockFields = Vtiger_Field_Model::getAllForModule($this);
$this->fields = [];
foreach ($moduleBlockFields as $moduleFields) {
foreach ($moduleFields as $moduleField) {
$block = $moduleField->get('block');
if (empty($block)) {
continue;
}
$this->fields[$moduleField->get('name')] = $moduleField;
}
}
}
return $this->fields;
}
/**
* Function that returns all the fields by blocks.
*
* @return array
*/
public function getFieldsByBlocks()
{
$fieldList = [];
foreach ($this->getFields() as &$field) {
$fieldList[$field->getBlockName()][$field->getName()] = $field;
}
return $fieldList;
}
/**
* Function to get the field mode, the function creates a new object and does not pass a reference.
*
* @param string $fieldName - field name or field id
*
* @return Vtiger_Field_Model
*/
public function getField($fieldName)
{
return Vtiger_Field_Model::getInstance($fieldName, $this);
}
/**
* Function to get the field by column name.
*
* @param string $columnName - column name
*
* @return Vtiger_Field_Model
*/
public function getFieldByColumn($columnName)
{
foreach ($this->getFields() as &$field) {
if ($field->get('column') === $columnName) {
return $field;
}
}
return null;
}
/**
* Get field by field name.
*
* @param string $fieldName
*
* @throws \App\Exceptions\AppException
*
* @return Vtiger_Field_Model|false
*/
public function getFieldByName($fieldName)
{
return $this->getFields()[$fieldName] ?? false;
}
/**
* Function gives fields based on the type.
*
* @param string|string[] $type - field type
* @param bool $active
*
* @return Vtiger_Field_Model[] - list of field models `fieldName => Vtiger_Field_Model`
*/
public function getFieldsByType($type, bool $active = false): array
{
if (!\is_array($type)) {
$type = [$type];
}
$fieldList = [];
foreach ($this->getFields() as $field) {
if (\in_array($field->getFieldDataType(), $type) && (!$active || ($active && $field->isActiveField()))) {
$fieldList[$field->getName()] = $field;
}
}
return $fieldList;
}
public function getFieldsByReference()
{
$fieldList = [];
foreach ($this->getFields() as $field) {
if ($field->isReferenceField()) {
$fieldList[$field->getName()] = $field;
}
}
return $fieldList;
}
/**
* Gets reference fields for module.
*
* @param string $moduleName
*
* @return array
*/
public function getReferenceFieldsForModule(string $moduleName): array
{
$fieldList = [];
foreach ($this->getFields() as $field) {
if ($field->isActiveField() && $field->isReferenceField() && \in_array($moduleName, $field->getReferenceList())) {
$fieldList[$field->getName()] = $field;
}
}
return $fieldList;
}
/**
* Function gives fields based on the uitype.
*
* @param mixed $uitype
*
* @return Vtiger_Field_Model[] with field id as key
*/
public function getFieldsByUiType($uitype)
{
$fieldList = [];
foreach ($this->getFields() as &$field) {
if ($field->get('uitype') === $uitype) {
$fieldList[$field->getName()] = $field;
}
}
return $fieldList;
}
/**
* Function gives fields based on the type.
*
* @return Vtiger_Field_Model[] with field label as key
*/
public function getFieldsByLabel()
{
$fieldList = [];
foreach ($this->getFields() as &$field) {
$fieldList[$field->get('label')] = $field;
}
return $fieldList;
}
/**
* Function gives fields based on the fieldid.
*
* @return Vtiger_Field_Model[] with field id as key
*/
public function getFieldsById()
{
$fieldList = [];
foreach ($this->getFields() as &$field) {
$fieldList[$field->getId()] = $field;
}
return $fieldList;
}
/**
* Function gives fields based on the type.
*
* @param mixed $type
*
* @return Vtiger_Field_Model[] with field id as key
*/
public function getFieldsByDisplayType($type)
{
$fieldList = [];
foreach ($this->getFields() as &$field) {
if ($field->get('displaytype') === $type) {
$fieldList[$field->getName()] = $field;
}
}
return $fieldList;
}
/**
* Function gives list fields for save.
*
* @param Vtiger_Record_Model $recordModel
*
* @return array
*/
public function getFieldsForSave(Vtiger_Record_Model $recordModel)
{
$editFields = [];
foreach (App\Field::getFieldsPermissions($this->getId(), false) as $field) {
$editFields[] = $field['fieldname'];
}
return array_diff($editFields, ['shownerid', 'smcreatorid', 'modifiedtime', 'modifiedby']);
}
/**
* Function to get list of field for summary view.
*
* @return Vtiger_Field_Model[] list of field models
*/
public function getSummaryViewFieldsList()
{
if (!isset($this->summaryFields)) {
$summaryFields = [];
foreach ($this->getFields() as $fieldName => &$fieldModel) {
if ($fieldModel->isSummaryField() && $fieldModel->isActiveField()) {
$summaryFields[$fieldName] = $fieldModel;
}
}
$this->summaryFields = $summaryFields;
}
return $this->summaryFields;
}
/**
* Function that returns all the quickcreate fields for the module.
*
* @return <Array of Vtiger_Field_Model> - list of field models
*/
public function getQuickCreateFields()
{
$quickCreateFieldList = [];
foreach ($this->getFieldsByBlocks() as $blockFields) {
uksort($blockFields, function ($a, $b) use ($blockFields) {
if ($blockFields[$a]->get('quicksequence') === $blockFields[$b]->get('quicksequence')) {
return 0;
}
return $blockFields[$a]->get('quicksequence') < $blockFields[$b]->get('quicksequence') ? -1 : 1;
});
foreach ($blockFields as $fieldName => $fieldModel) {
if ($fieldModel->isQuickCreateEnabled() && $fieldModel->isEditable()) {
$quickCreateFieldList[$fieldName] = $fieldModel;
}
}
}
return $quickCreateFieldList;
}
/**
* Function returns all the relation models.
*
* @return Vtiger_Relation_Model[]
*/
public function getRelations()
{
if (empty($this->relations)) {
$this->relations = Vtiger_Relation_Model::getAllRelations($this);
}
return $this->relations;
}
/**
* Function to retrieve name fields of a module.
*
* @return array - array which contains fields which together construct name fields
*/
public function getNameFields()
{
$entityInfo = App\Module::getEntityInfo($this->getName());
$fieldsName = [];
if ($entityInfo) {
foreach ($entityInfo['fieldnameArr'] as $columnName) {
$fieldsName[] = $this->getFieldByColumn($columnName)->getName();
}
}
return $fieldsName;
}
/**
* Funtion that returns fields that will be showed in the record selection popup.
*
* @return <Array of fields>
*/
public function getPopupFields()
{
if (!empty($this->getEntityInstance()->search_fields_name)) {
return $this->getEntityInstance()->search_fields_name;
}
$queryGenerator = new \App\QueryGenerator($this->getName());
$queryGenerator->initForDefaultCustomView(true, true);
return $queryGenerator->getFields();
}
public function isWorkflowSupported()
{
if ($this->isEntityModule()) {
return true;
}
return false;
}
/**
* Function checks if a module has module sequence numbering.
*
* @return bool
*/
public function hasSequenceNumberField()
{
if (!empty($this->fields)) {
foreach ($this->getFields() as $fieldModel) {
if (4 === $fieldModel->getUIType()) {
return true;
}
}
} else {
return (bool) \App\Fields\RecordNumber::getSequenceNumberFieldName($this->getId());
}
return false;
}
/**
* Get sequence number field name.
*
* @return string|bool
*/
public function getSequenceNumberFieldName()
{
if (!empty($this->fields)) {
foreach ($this->getFields() as $fieldModel) {
if (4 === $fieldModel->getUIType() && $fieldModel->isActiveField()) {
return $fieldModel->getName();
}
}
} else {
return \App\Fields\RecordNumber::getSequenceNumberFieldName($this->getId());
}
return false;
}
/**
* Function to get all modules from CRM.
*
* @param <array> $presence
* @param <array> $restrictedModulesList
* @param mixed $isEntityType
*
* @return <array> List of module models Vtiger_Module_Model
*/
public static function getAll($presence = [], $restrictedModulesList = [], $isEntityType = false)
{
$allModules = \vtlib\Functions::getAllModules($isEntityType, true);
$moduleModels = [];
foreach ($allModules as &$row) {
$moduleModels[$row['tabid']] = self::getInstanceFromArray($row);
}
if ($presence && $moduleModels) {
foreach ($moduleModels as $key => $moduleModel) {
if (!\in_array($moduleModel->get('presence'), $presence)) {
unset($moduleModels[$key]);
}
}
}
if ($restrictedModulesList && $moduleModels) {
foreach ($moduleModels as $key => $moduleModel) {
if (\in_array($moduleModel->getName(), $restrictedModulesList)) {
unset($moduleModels[$key]);
}
}
}
return $moduleModels;
}
/**
* Get entity instance.
*
* @return CRMEntity
*/
public function getEntityInstance()
{
if (isset($this->entityInstance)) {
return $this->entityInstance;
}
return $this->entityInstance = CRMEntity::getInstance($this->getName());
}
public static function getEntityModules()
{
$moduleModels = Vtiger_Cache::get('vtiger', 'EntityModules');
if (!$moduleModels) {
$presence = [0, 2];
$moduleModels = self::getAll($presence);
$restrictedModules = ['Integration', 'Dashboard'];
foreach ($moduleModels as $key => $moduleModel) {
if (\in_array($moduleModel->getName(), $restrictedModules) || 1 != $moduleModel->get('isentitytype')) {
unset($moduleModels[$key]);
}
}
Vtiger_Cache::set('vtiger', 'EntityModules', $moduleModels);
}
return $moduleModels;
}
/**
* Function to get the list of all accessible modules for Quick Create.
*
* @param bool $restrictList
* @param bool $tree
*
* @return <Array> - List of Vtiger_Record_Model or Module Specific Record Model instances
*/
public static function getQuickCreateModules($restrictList = false, $tree = false)
{
$restrictListString = $restrictList ? 1 : 0;
if ($tree) {
$userModel = App\User::getCurrentUserModel();
$quickCreateModulesTreeCache = App\Cache::get('getQuickCreateModules', 'tree' . $restrictListString . $userModel->getDetail('roleid'));
if (false !== $quickCreateModulesTreeCache) {
return $quickCreateModulesTreeCache;
}
} else {
$quickCreateModules = App\Cache::get('getQuickCreateModules', $restrictListString);
if (false !== $quickCreateModules) {
return $quickCreateModules;
}
}
$userPrivModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
$query = new \App\Db\Query();
$query->select(['vtiger_tab.*'])->from('vtiger_field')
->innerJoin('vtiger_tab', 'vtiger_tab.tabid = vtiger_field.tabid')
->where(['<>', 'vtiger_tab.presence', 1]);
if ($tree) {
$query->andWhere(['<>', 'vtiger_tab.name', 'Users']);
} else {
$query->andWhere(['or', 'quickcreate = 0', 'quickcreate = 2'])
->andWhere(['<>', 'vtiger_tab.type', 1])->distinct();
}
if ($restrictList) {
$query->andWhere(['not in', 'vtiger_tab.name', ['ModComments', 'PriceBooks', 'CallHistory', 'OSSMailView', 'SMSNotifier']]);
}
$quickCreateModules = [];
$dataReader = $query->createCommand()->query();
while ($row = $dataReader->read()) {
if ($userPrivModel->hasModuleActionPermission($row['tabid'], 'CreateView')) {
$moduleModel = self::getInstanceFromArray($row);
$quickCreateModules[$row['name']] = $moduleModel;
}
}
if ($tree) {
$menu = Vtiger_Menu_Model::getAll();
$quickCreateModulesTree = [];
foreach ($menu as $parent) {
if (!empty($parent['childs'])) {
$items = [];
foreach ($parent['childs'] as $child) {
if (isset($quickCreateModules[$child['mod']])) {
$items[$quickCreateModules[$child['mod']]->name] = $quickCreateModules[$child['mod']];
unset($quickCreateModules[$child['mod']]);
}
}
if (!empty($items)) {
$quickCreateModulesTree[] = ['name' => $parent['name'], 'icon' => $parent['icon'], 'modules' => $items];
}
}
}
if (!empty($quickCreateModules)) {
$quickCreateModulesTree[] = ['name' => 'LBL_OTHER', 'icon' => 'yfm-Other', 'modules' => $quickCreateModules];
}
App\Cache::save('getQuickCreateModules', 'tree' . $restrictListString . $userPrivModel->get('roleid'), $quickCreateModulesTree);
return $quickCreateModulesTree;
}
App\Cache::save('getQuickCreateModules', $restrictListString, $quickCreateModules);
return $quickCreateModules;
}
/**
* Get modules with picklists.
*
* @return \self[]
*/
public static function getPicklistSupportedModules()
{
$modules = App\Fields\Picklist::getModules();
$modulesModelsList = [];
foreach ($modules as $moduleData) {
$instance = new self();
$instance->name = $moduleData['tablabel'];
$instance->label = $moduleData['tabname'];
$modulesModelsList[] = $instance;
}
return $modulesModelsList;
}
/**
* Undocumented function.
*
* @param string $moduleName
*
* @return $this
*/
public static function getCleanInstance(string $moduleName)
{
$modelClassName = Vtiger_Loader::getComponentClassName('Model', 'Module', $moduleName);
return new $modelClassName();
}
/**
* Function to get the Quick Links for the module.
*
* @param array $linkParams
*
* @return Vtiger_Link_Model[]
*/
public function getSideBarLinks($linkParams)
{
$menuUrl = '';
if (isset($_REQUEST['parent'])) {
$menuUrl .= '&parent=' . \App\Request::_getByType('parent', 'Alnum');
}
if (isset($_REQUEST['mid'])) {
$menuUrl .= '&mid=' . \App\Request::_getInteger('mid');
}
$links = Vtiger_Link_Model::getAllByType($this->getId(), ['SIDEBARLINK', 'SIDEBARWIDGET'], $linkParams);
$userPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => 'LBL_RECORDS_LIST',
'linkurl' => $this->getListViewUrl() . $menuUrl,
'linkicon' => 'fas fa-list',
]);
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => 'LBL_RECORDS_PREVIEW_LIST',
'linkurl' => "index.php?module={$this->getName()}&view=ListPreview{$menuUrl}",
'linkicon' => 'far fa-list-alt',
]);
if ($userPrivilegesModel->hasModulePermission('Dashboard') && $userPrivilegesModel->hasModuleActionPermission($this->getId(), 'Dashboard')) {
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => 'LBL_DASHBOARD',
'linkurl' => $this->getDashBoardUrl() . $menuUrl,
'linkicon' => 'fas fa-desktop',
]);
}
$treeViewModel = Vtiger_TreeView_Model::getInstance($this->getName());
if ($treeViewModel->isActive()) {
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => $treeViewModel->getName(),
'linkurl' => $treeViewModel->getTreeViewUrl() . $menuUrl,
'linkicon' => 'fas fa-tree',
]);
}
if ($this->isPermitted('Kanban') && \App\Utils\Kanban::getBoards($this->getName(), true)) {
$links['SIDEBARLINK'][] = Vtiger_Link_Model::getInstanceFromValues([
'linktype' => 'SIDEBARLINK',
'linklabel' => 'LBL_VIEW_KANBAN',
'linkurl' => 'index.php?module=' . $this->getName() . '&view=Kanban' . $menuUrl,
'linkicon' => 'yfi yfi-kanban',
]);
}
return $links;
}
/**
* Function returns latest comments for the module.
*
* @param <Vtiger_Paging_Model> $pagingModel
*
* @return <Array>
*/
public function getComments($pagingModel)
{
$comments = [];
if (!$this->isCommentEnabled()) {