Passed
Push — developer ( a71332...bcab7f )
by Radosław
16:27
created

Users_ExportData_Action::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 10
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Export data file.
4
 *
5
 * @package Action
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Radosław Skrzypczak <[email protected]>
10
 */
11
/**
12
 * Export data class.
13
 */
14
class Users_ExportData_Action extends Vtiger_ExportData_Action
0 ignored issues
show
Bug introduced by
The type Vtiger_ExportData_Action was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
{
16
	/** {@inheritdoc} */
17
	public function checkPermission(App\Request $request)
18
	{
19
		$this->moduelName = $request->getModule();
0 ignored issues
show
Bug Best Practice introduced by
The property moduelName does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
		if (!\App\User::getCurrentUserModel()->isAdmin()) {
21
			throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
22
		}
23
	}
24
25
	/** {@inheritdoc} */
26
	public function process(App\Request $request)
27
	{
28
		$this->exportModel = \App\Export\ExportRecords::getInstance($this->moduelName, 'csv')
0 ignored issues
show
Bug Best Practice introduced by
The property exportModel does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
			->setLimit(\App\Config::performance('MAX_NUMBER_EXPORT_RECORDS'))
30
			->setFormat(\App\Export\ExportRecords::EXPORT_FORMAT);
31
		$this->exportModel->fullData = true;
32
33
		$this->setDataFromRequest($request);
34
		$this->exportModel->sendHttpHeader();
35
		$this->exportModel->exportData();
36
	}
37
38
	/** {@inheritdoc} */
39
	public function setDataFromRequest(App\Request $request)
40
	{
41
		$searchParams = \App\Condition::validSearchParams($this->moduelName, $request->getArray('search_params'));
42
		$operator = $request->isEmpty('operator') ? '' : $request->getByType('operator');
43
		if ($operator && $searchValue = \App\Condition::validSearchValue($request->getByType('search_value', \App\Purifier::TEXT), $this->moduelName, $request->getByType('search_key', \App\Purifier::ALNUM), $operator)) {
44
			$searchKey = $request->getByType('search_key', \App\Purifier::ALNUM);
45
		}
46
47
		$queryGenerator = $this->exportModel->getQueryGenerator();
48
		$queryGenerator->addCondition('status', 'Active', 'e');
49
50
		switch ($request->getMode()) {
51
				case 'ExportAllData':
52
					break;
53
				case 'ExportSelectedRecords':
54
					$selectedIds = $request->getArray('selected_ids', \App\Purifier::ALNUM);
55
					if ($selectedIds && 'all' !== $selectedIds[0]) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $selectedIds of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56
						$queryGenerator->addCondition('id', $selectedIds, 'e');
57
					}
58
					$queryGenerator->parseAdvFilter($queryGenerator->parseBaseSearchParamsToCondition($searchParams));
59
					if ($excludedIds = $request->getArray('excluded_ids', \App\Purifier::INTEGER)) {
60
						$queryGenerator->addCondition('id', $excludedIds, 'n');
61
					}
62
					if ($operator && $searchValue && $searchKey) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $searchValue does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $searchKey does not seem to be defined for all execution paths leading up to this point.
Loading history...
63
						$queryGenerator->addCondition($searchKey, $searchValue, $operator);
64
					}
65
					break;
66
				default:
67
					throw new \App\Exceptions\IllegalValue('ERR_FIELD_NOT_FOUND||mode');
68
			}
69
	}
70
}
71