Passed
Pull Request — developer (#15831)
by Arkadiusz
20:14
created

Vtiger_MassActionAjax_View::transferOwnership()   B

Complexity

Conditions 7
Paths 2

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 13
cp 0
rs 8.8333
cc 7
nc 2
nop 1
crap 56
1
<?php
2
/* +***********************************************************************************
3
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
4
 * ("License"); You may not use this file except in compliance with the License
5
 * The Original Code is:  vtiger CRM Open Source
6
 * The Initial Developer of the Original Code is vtiger.
7
 * Portions created by vtiger are Copyright (C) vtiger.
8
 * All Rights Reserved.
9
 * Contributor(s): YetiForce S.A.
10
 * *********************************************************************************** */
11
12
class Vtiger_MassActionAjax_View extends Vtiger_IndexAjax_View
13
{
14
	use \App\Controller\ExposeMethod;
15
16
	public function __construct()
17
	{
18
		parent::__construct();
19
		$this->exposeMethod('showMassEditForm');
20
		$this->exposeMethod('showAddCommentForm');
21
		$this->exposeMethod('showSendSMSForm');
22
	}
23
24
	/**
25
	 * Function returns the mass edit form.
26
	 *
27
	 * @param \App\Request $request
28
	 *
29
	 * @throws \App\Exceptions\NoPermitted
30
	 */
31
	public function showMassEditForm(App\Request $request)
32
	{
33
		$moduleName = $request->getModule();
34
		$viewer = $this->getViewer($request);
35
		$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
36
		if (!$moduleModel->isPermitted('MassEdit')) {
37
			throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
38
		}
39
		$recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceForModule($moduleModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_MASSEDIT);
40
		$picklistDependencyDatasource = \App\Fields\Picklist::getPicklistDependencyDatasource($moduleName);
41
42
		$viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', \App\Json::encode($picklistDependencyDatasource));
43
		$viewer->assign('CURRENTDATE', date('Y-n-j'));
44
		$viewer->assign('MODE', 'massedit');
45
		$viewer->assign('MODULE', $moduleName);
46
		$viewer->assign('CVID', $request->getByType('viewname', 2));
47
		$viewer->assign('SELECTED_IDS', $request->getArray('selected_ids', 2));
48
		$viewer->assign('EXCLUDED_IDS', $request->getArray('excluded_ids', 2));
49
		$viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance);
50
		$viewer->assign('MODULE_MODEL', $moduleModel);
51
		$viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure());
52
		$viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
53
		$viewer->assign('MODULE_MODEL', $moduleModel);
54
		$viewer->assign('MAPPING_RELATED_FIELD', \App\Json::encode(\App\ModuleHierarchy::getRelationFieldByHierarchy($moduleName)));
55
		$viewer->assign('LIST_FILTER_FIELDS', \App\Json::encode(\App\ModuleHierarchy::getFieldsForListFilter($moduleName)));
56
		$viewer->assign('OPERATOR', $request->getByType('operator'));
57
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
0 ignored issues
show
Bug introduced by
It seems like $request->getByType('search_key', 'Alnum') can also be of type boolean; however, parameter $fieldName of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, /** @scrutinizer ignore-type */ $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('operator') can also be of type boolean; however, parameter $operator of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), /** @scrutinizer ignore-type */ $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('search_value', 'Text') can also be of type boolean; however, parameter $value of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue(/** @scrutinizer ignore-type */ $request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
58
		$viewer->assign('SEARCH_KEY', $request->getByType('search_key', 'Alnum'));
59
		$viewer->assign('SEARCH_PARAMS', App\Condition::validSearchParams($moduleName, $request->getArray('search_params'), false));
60
		$viewer->view('MassEditForm.tpl', $moduleName);
61
	}
62
63
	/**
64
	 * Function returns the Add Comment form.
65
	 *
66
	 * @param \App\Request $request
67
	 *
68
	 * @throws \App\Exceptions\NoPermitted
69
	 */
70
	public function showAddCommentForm(App\Request $request)
71
	{
72
		$sourceModule = $request->getModule();
73
		$moduleName = 'ModComments';
74
		$moduleModel = Vtiger_Module_Model::getInstance($sourceModule);
75
		$userPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
76
		if (!$userPrivilegesModel->hasModulePermission($sourceModule) || !($moduleModel->isCommentEnabled() && $userPrivilegesModel->hasModuleActionPermission($moduleName, 'CreateView') && $moduleModel->isPermitted('MassAddComment'))) {
0 ignored issues
show
Bug introduced by
$sourceModule of type string is incompatible with the type integer expected by parameter $mixed of Users_Privileges_Model::hasModulePermission(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
		if (!$userPrivilegesModel->hasModulePermission(/** @scrutinizer ignore-type */ $sourceModule) || !($moduleModel->isCommentEnabled() && $userPrivilegesModel->hasModuleActionPermission($moduleName, 'CreateView') && $moduleModel->isPermitted('MassAddComment'))) {
Loading history...
77
			throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
78
		}
79
		$viewer = $this->getViewer($request);
80
		$viewer->assign('SOURCE_MODULE', $sourceModule);
81
		$viewer->assign('MODULE', $moduleName);
82
		$viewer->assign('CVID', $request->getByType('viewname', 2));
83
		$viewer->assign('SELECTED_IDS', $request->getArray('selected_ids', 2));
84
		$viewer->assign('EXCLUDED_IDS', $request->getArray('excluded_ids', 2));
85
		$viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
86
		$viewer->assign('OPERATOR', $request->getByType('operator'));
87
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
0 ignored issues
show
Bug introduced by
It seems like $request->getByType('search_key', 'Alnum') can also be of type boolean; however, parameter $fieldName of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, /** @scrutinizer ignore-type */ $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('operator') can also be of type boolean; however, parameter $operator of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), /** @scrutinizer ignore-type */ $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('search_value', 'Text') can also be of type boolean; however, parameter $value of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue(/** @scrutinizer ignore-type */ $request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
88
		$viewer->assign('ENTITY_STATE', $request->getByType('entityState'));
89
		$viewer->assign('SEARCH_KEY', $request->getByType('search_key', 'Alnum'));
90
		$viewer->assign('SEARCH_PARAMS', App\Condition::validSearchParams($sourceModule, $request->getArray('search_params'), false));
91
		$viewer->view('AddCommentForm.tpl', $moduleName);
92
	}
93
94
	/**
95
	 * Function shows form that will lets you send SMS.
96
	 *
97
	 * @param \App\Request $request
98
	 *
99
	 * @throws \App\Exceptions\NoPermitted
100
	 */
101
	public function showSendSMSForm(App\Request $request)
102
	{
103
		$sourceModule = $request->getModule();
104
		$moduleName = 'SMSNotifier';
105
		$selectedIds = $request->getArray('selected_ids', 2);
106
		$currentUserPriviligesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
107
		if (!$currentUserPriviligesModel->hasModuleActionPermission($moduleName, 'CreateView') || !$currentUserPriviligesModel->hasModuleActionPermission($sourceModule, 'MassSendSMS') || !SMSNotifier_Module_Model::checkServer()) {
108
			throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
109
		}
110
111
		$moduleModel = Vtiger_Module_Model::getInstance($sourceModule);
112
		$phoneFields = $moduleModel->getFieldsByType('phone');
113
		$viewer = $this->getViewer($request);
114
115
		if (\is_array($selectedIds) && 1 === \count($selectedIds) && 'all' !== $selectedIds[0]) {
116
			$recordId = current($selectedIds);
117
			$selectedRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $sourceModule);
118
			$viewer->assign('SINGLE_RECORD', $selectedRecordModel);
119
		}
120
		$viewer->assign('VIEWNAME', $request->getByType('viewname', 2));
121
		$viewer->assign('MODULE', $moduleName);
122
		$viewer->assign('SOURCE_MODULE', $sourceModule);
123
		$viewer->assign('SELECTED_IDS', $selectedIds);
124
		$viewer->assign('EXCLUDED_IDS', $request->getArray('excluded_ids', 2));
125
		$viewer->assign('ENTITY_STATE', $request->getByType('entityState'));
126
		$viewer->assign('PHONE_FIELDS', $phoneFields);
127
		$viewer->assign('OPERATOR', $request->getByType('operator'));
128
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
0 ignored issues
show
Bug introduced by
It seems like $request->getByType('operator') can also be of type boolean; however, parameter $operator of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

128
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), /** @scrutinizer ignore-type */ $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('search_key', 'Alnum') can also be of type boolean; however, parameter $fieldName of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

128
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue($request->getByType('search_value', 'Text'), $moduleName, /** @scrutinizer ignore-type */ $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
Bug introduced by
It seems like $request->getByType('search_value', 'Text') can also be of type boolean; however, parameter $value of App\Condition::validSearchValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

128
		$viewer->assign('ALPHABET_VALUE', App\Condition::validSearchValue(/** @scrutinizer ignore-type */ $request->getByType('search_value', 'Text'), $moduleName, $request->getByType('search_key', 'Alnum'), $request->getByType('operator')));
Loading history...
129
		$viewer->assign('SEARCH_KEY', $request->getByType('search_key', 'Alnum'));
130
		$viewer->assign('SEARCH_PARAMS', App\Condition::validSearchParams($sourceModule, $request->getArray('search_params'), false));
131
		$viewer->view('SendSMSForm.tpl', $moduleName);
132
	}
133
}
134