Merge pull request #23267 from civicrm/5.49
[civicrm-core.git] / CRM / Admin / Page / ContactType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of contact Subtypes.
20 */
21 class CRM_Admin_Page_ContactType extends CRM_Core_Page_Basic {
22
23 public $useLivePageJS = TRUE;
24
25 /**
26 * The action links that we need to display for the browse screen.
27 *
28 * @var array
29 */
30 public static $_links = NULL;
31
32 /**
33 * Get BAO Name.
34 *
35 * @return string
36 * Classname of BAO.
37 */
38 public function getBAOName() {
39 return 'CRM_Contact_BAO_ContactType';
40 }
41
42 /**
43 * Get action Links.
44 *
45 * @return array
46 * (reference) of action links
47 */
48 public function &links() {
49 if (!(self::$_links)) {
50 self::$_links = [
51 CRM_Core_Action::UPDATE => [
52 'name' => ts('Edit'),
53 'url' => 'civicrm/admin/options/subtype',
54 'qs' => 'action=update&id=%%id%%&reset=1',
55 'title' => ts('Edit Contact Type'),
56 ],
57 CRM_Core_Action::DISABLE => [
58 'name' => ts('Disable'),
59 'ref' => 'crm-enable-disable',
60 'title' => ts('Disable Contact Type'),
61 ],
62 CRM_Core_Action::ENABLE => [
63 'name' => ts('Enable'),
64 'ref' => 'crm-enable-disable',
65 'title' => ts('Enable Contact Type'),
66 ],
67 CRM_Core_Action::DELETE => [
68 'name' => ts('Delete'),
69 'url' => 'civicrm/admin/options/subtype',
70 'qs' => 'action=delete&id=%%id%%',
71 'title' => ts('Delete Contact Type'),
72 ],
73 ];
74 }
75 return self::$_links;
76 }
77
78 /**
79 * Run page.
80 */
81 public function run() {
82 $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0);
83 $this->assign('action', $action);
84 $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
85 if (!$action) {
86 $this->browse();
87 }
88 return parent::run();
89 }
90
91 /**
92 * Browse contact types.
93 */
94 public function browse() {
95 $rows = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE);
96 foreach ($rows as $key => $value) {
97 $mask = NULL;
98 if (!empty($value['is_reserved'])) {
99 $mask = CRM_Core_Action::UPDATE;
100 }
101 else {
102 $mask -= CRM_Core_Action::DELETE - 2;
103 if (!empty($value['is_active'])) {
104 $mask -= CRM_Core_Action::ENABLE;
105 }
106 else {
107 $mask -= CRM_Core_Action::DISABLE;
108 }
109 }
110 $rows[$key]['action'] = CRM_Core_Action::formLink(self::links(), $mask,
111 ['id' => $value['id']],
112 ts('more'),
113 FALSE,
114 'contactType.manage.action',
115 'ContactType',
116 $value['id']
117 );
118 }
119 $this->assign('rows', $rows);
120 }
121
122 /**
123 * Get name of edit form.
124 *
125 * @return string
126 * Classname of edit form.
127 */
128 public function editForm() {
129 return 'CRM_Admin_Form_ContactType';
130 }
131
132 /**
133 * Get edit form name.
134 *
135 * @return string
136 * name of this page.
137 */
138 public function editName() {
139 return 'Contact Types';
140 }
141
142 /**
143 * Get user context.
144 *
145 * @param null $mode
146 *
147 * @return string
148 * user context.
149 */
150 public function userContext($mode = NULL) {
151 return 'civicrm/admin/options/subtype';
152 }
153
154 }