VTEntityMethodManager::methodsForModule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
 * **************************************************************************** */
10
11
/**
12
 * Class VTEntityMethodManager.
13
 */
14
class VTEntityMethodManager
15
{
16
	/**
17
	 * Add entity method.
18
	 *
19
	 * @param string $moduleName
20
	 * @param string $methodName
21
	 * @param string $functionPath
22
	 * @param string $functionName
23
	 */
24
	public function addEntityMethod($moduleName, $methodName, $functionPath, $functionName)
25
	{
26
		$db = \App\Db::getInstance();
27
		$db->createCommand()
28
			->insert('com_vtiger_workflowtasks_entitymethod', [
29
				'module_name' => $moduleName,
30
				'function_path' => $functionPath,
31
				'function_name' => $functionName,
32
				'method_name' => $methodName,
33
			])->execute();
34
	}
35
36
	/**
37
	 * Execute method.
38
	 *
39
	 * @param Vtiger_Record_Model $recordModel
40
	 * @param string              $methodName
41
	 */
42
	public function executeMethod(Vtiger_Record_Model $recordModel, $methodName)
43
	{
44
		$data = (new \App\Db\Query())->select(['function_path', 'function_name'])->from('com_vtiger_workflowtasks_entitymethod')->where(['module_name' => $recordModel->getModuleName(), 'method_name' => $methodName])->one();
45
		if ($data) {
46
			require_once $data['function_path'];
47
			\call_user_func("{$data['function_name']}::$methodName", $recordModel);
48
		}
49
	}
50
51
	/**
52
	 * Get methods for module.
53
	 *
54
	 * @param string $moduleName
55
	 *
56
	 * @return array
57
	 */
58
	public function methodsForModule($moduleName)
59
	{
60
		return (new \App\Db\Query())->select(['method_name'])->from('com_vtiger_workflowtasks_entitymethod')->where(['module_name' => $moduleName])->column();
61
	}
62
63
	/**
64
	 * Function to remove workflowtasks entity method.
65
	 *
66
	 * @param string $moduleName Module Name
67
	 * @param string $methodName Entity Method Name
68
	 */
69
	public function removeEntityMethod($moduleName, $methodName)
70
	{
71
		\App\Db::getInstance()->createCommand()->delete('com_vtiger_workflowtasks_entitymethod', ['module_name' => $moduleName, 'method_name' => $methodName])->execute();
72
	}
73
}
74