Commit | Line | Data |
---|---|---|
11a60382 D |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
11a60382 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
11a60382 D |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
11a60382 D |
16 | */ |
17 | ||
18 | /** | |
19 | * This class is a wrapper that moves some boilerplate code out of the Form class and helps remove some ambiguity with name and label. | |
20 | */ | |
21 | class CRM_Activity_BAO_ActivityType { | |
22 | ||
23 | /** | |
24 | * key/value pair for this activity type | |
25 | * | |
26 | * @var array | |
27 | * machineName The internal name for lookups - matches up to option_value 'name' column in the database | |
28 | * displayLabel The label used for display/output - matches up to option_value 'label' column in the database | |
29 | * id The value used to initialize this object - matches up to the option_value 'value' column in the database | |
30 | */ | |
31 | protected $_activityType = [ | |
32 | 'machineName' => NULL, | |
33 | 'displayLabel' => NULL, | |
34 | 'id' => NULL, | |
35 | ]; | |
36 | ||
37 | /** | |
38 | * Constructor | |
39 | * | |
40 | * @param $activity_type_id int This matches up to the option_value 'value' column in the database. | |
41 | */ | |
42 | public function __construct($activity_type_id) { | |
43 | $this->setActivityType($activity_type_id); | |
44 | } | |
45 | ||
46 | /** | |
47 | * Get the key/value pair representing this activity type. | |
48 | * | |
49 | * @return array | |
50 | * @see $this->_activityType | |
51 | */ | |
52 | public function getActivityType() { | |
53 | return $this->_activityType; | |
54 | } | |
55 | ||
56 | /** | |
57 | * Look up the key/value pair representing this activity type from the id. | |
58 | * Generally called from constructor. | |
59 | * | |
60 | * @param $activity_type_id int This matches up to the option_value 'value' column in the database. | |
61 | */ | |
62 | public function setActivityType($activity_type_id) { | |
63 | if ($activity_type_id && is_numeric($activity_type_id)) { | |
64 | ||
65 | /* | |
66 | * These are pulled from CRM_Activity_Form_Activity. | |
67 | * To avoid unexpectedly changing things like introducing hidden | |
68 | * business logic or changing permission checks I've kept it using | |
69 | * the same function call. It may or may not be desired to have | |
70 | * that but this at least doesn't introduce anything that wasn't | |
71 | * there before. | |
72 | */ | |
73 | $machineNames = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $activity_type_id, 'name'); | |
74 | $displayLabels = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $activity_type_id, 'label'); | |
75 | ||
76 | $this->_activityType = [ | |
6b409353 CW |
77 | 'machineName' => $machineNames[$activity_type_id] ?? NULL, |
78 | 'displayLabel' => $displayLabels[$activity_type_id] ?? NULL, | |
11a60382 D |
79 | 'id' => $activity_type_id, |
80 | ]; | |
81 | } | |
82 | } | |
83 | ||
84 | } |