1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\libraries\rest_api\calculations; |
4
|
|
|
|
5
|
|
|
use EventEspresso\core\libraries\rest_api\RestException; |
6
|
|
|
use EEH_Inflector; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Base |
10
|
|
|
* Description here |
11
|
|
|
* |
12
|
|
|
* @package Event Espresso |
13
|
|
|
* @subpackage |
14
|
|
|
* @author Mike Nelson |
15
|
|
|
*/ |
16
|
|
|
class Base |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param $required_permission |
21
|
|
|
* @param $attempted_calculation |
22
|
|
|
* @throws RestException |
23
|
|
|
*/ |
24
|
|
|
protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
25
|
|
|
{ |
26
|
|
View Code Duplication |
if (! current_user_can($required_permission)) { |
27
|
|
|
throw new RestException( |
28
|
|
|
'permission_denied', |
29
|
|
|
sprintf( |
30
|
|
|
__( |
31
|
|
|
// @codingStandardsIgnoreStart |
32
|
|
|
'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
33
|
|
|
// @codingStandardsIgnoreEnd |
34
|
|
|
'event_espresso' |
35
|
|
|
), |
36
|
|
|
$attempted_calculation, |
37
|
|
|
EEH_Inflector::pluralize_and_lower($this->getResourceName()), |
38
|
|
|
$required_permission |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Gets the name of the resource of the called class |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function getResourceName() |
51
|
|
|
{ |
52
|
|
|
return substr(__CLASS__, strrpos(__CLASS__, '\\') + 1); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns an array to be used for the schema for the calculated fields. |
57
|
|
|
* @since $VID:$ |
58
|
|
|
* @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays { |
59
|
|
|
* @type string $description |
60
|
|
|
* @type string $type, eg "string", "int", "boolean", "object", "array", etc |
61
|
|
|
* } |
62
|
|
|
*/ |
63
|
|
|
public function schemaForCalculations() |
64
|
|
|
{ |
65
|
|
|
return array(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the json schema for the given calculation index. |
70
|
|
|
* |
71
|
|
|
* @since $VID:$ |
72
|
|
|
* @param $calculation_index |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function schemaForCalculation($calculation_index) |
76
|
|
|
{ |
77
|
|
|
$schema_map = $this->schemaForCalculations(); |
78
|
|
|
return isset($schema_map[ $calculation_index ]) ? $schema_map[ $calculation_index ] : array(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|