Merge pull request #15833 from yashodha/participant_edit
[civicrm-core.git] / CRM / Activity / BAO / ActivityType.php
CommitLineData
11a60382
D
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
11a60382
D
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
11a60382
D
32 */
33
34/**
35 * This class is a wrapper that moves some boilerplate code out of the Form class and helps remove some ambiguity with name and label.
36 */
37class CRM_Activity_BAO_ActivityType {
38
39 /**
40 * key/value pair for this activity type
41 *
42 * @var array
43 * machineName The internal name for lookups - matches up to option_value 'name' column in the database
44 * displayLabel The label used for display/output - matches up to option_value 'label' column in the database
45 * id The value used to initialize this object - matches up to the option_value 'value' column in the database
46 */
47 protected $_activityType = [
48 'machineName' => NULL,
49 'displayLabel' => NULL,
50 'id' => NULL,
51 ];
52
53 /**
54 * Constructor
55 *
56 * @param $activity_type_id int This matches up to the option_value 'value' column in the database.
57 */
58 public function __construct($activity_type_id) {
59 $this->setActivityType($activity_type_id);
60 }
61
62 /**
63 * Get the key/value pair representing this activity type.
64 *
65 * @return array
66 * @see $this->_activityType
67 */
68 public function getActivityType() {
69 return $this->_activityType;
70 }
71
72 /**
73 * Look up the key/value pair representing this activity type from the id.
74 * Generally called from constructor.
75 *
76 * @param $activity_type_id int This matches up to the option_value 'value' column in the database.
77 */
78 public function setActivityType($activity_type_id) {
79 if ($activity_type_id && is_numeric($activity_type_id)) {
80
81 /*
82 * These are pulled from CRM_Activity_Form_Activity.
83 * To avoid unexpectedly changing things like introducing hidden
84 * business logic or changing permission checks I've kept it using
85 * the same function call. It may or may not be desired to have
86 * that but this at least doesn't introduce anything that wasn't
87 * there before.
88 */
89 $machineNames = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $activity_type_id, 'name');
90 $displayLabels = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $activity_type_id, 'label');
91
92 $this->_activityType = [
93 'machineName' => CRM_Utils_Array::value($activity_type_id, $machineNames),
94 'displayLabel' => CRM_Utils_Array::value($activity_type_id, $displayLabels),
95 'id' => $activity_type_id,
96 ];
97 }
98 }
99
100}