Merge pull request #16931 from civicrm/5.24
[civicrm-core.git] / CRM / Admin / Page / EventTemplate.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 event templates.
20 */
21 class CRM_Admin_Page_EventTemplate extends CRM_Core_Page_Basic {
22
23 /**
24 * The action links that we need to display for the browse screen.
25 *
26 * @var array
27 */
28 public static $_links = NULL;
29
30 /**
31 * Get BAO Name.
32 *
33 * @return string
34 * Classname of BAO.
35 */
36 public function getBAOName() {
37 return 'CRM_Event_BAO_Event';
38 }
39
40 /**
41 * Get action Links.
42 *
43 * @return array
44 * (reference) of action links
45 */
46 public function &links() {
47 if (!(self::$_links)) {
48 // helper variable for nicer formatting
49 self::$_links = [
50 CRM_Core_Action::UPDATE => [
51 'name' => ts('Edit'),
52 'url' => 'civicrm/event/manage/settings',
53 'qs' => 'action=update&id=%%id%%&reset=1',
54 'title' => ts('Edit Event Template'),
55 ],
56 CRM_Core_Action::DELETE => [
57 'name' => ts('Delete'),
58 'url' => 'civicrm/event/manage',
59 'qs' => 'action=delete&id=%%id%%',
60 'title' => ts('Delete Event Template'),
61 ],
62 ];
63 }
64
65 return self::$_links;
66 }
67
68 /**
69 * Browse all event templates.
70 */
71 public function browse() {
72 //get all event templates.
73 $allEventTemplates = [];
74
75 $eventTemplate = new CRM_Event_DAO_Event();
76
77 $eventTypes = CRM_Event_PseudoConstant::eventType();
78 $participantRoles = CRM_Event_PseudoConstant::participantRole();
79 $participantListings = CRM_Event_BAO_Event::buildOptions('participant_listing_id');
80
81 //find all event templates.
82 $eventTemplate->is_template = TRUE;
83 $eventTemplate->find();
84 while ($eventTemplate->fetch()) {
85 CRM_Core_DAO::storeValues($eventTemplate, $allEventTemplates[$eventTemplate->id]);
86
87 //get listing types.
88 if ($eventTemplate->participant_listing_id) {
89 $allEventTemplates[$eventTemplate->id]['participant_listing'] = $participantListings[$eventTemplate->participant_listing_id];
90 }
91
92 //get participant role
93 if ($eventTemplate->default_role_id) {
94 $allEventTemplates[$eventTemplate->id]['participant_role'] = $participantRoles[$eventTemplate->default_role_id];
95 }
96
97 //get event type.
98 if (isset($eventTypes[$eventTemplate->event_type_id])) {
99 $allEventTemplates[$eventTemplate->id]['event_type'] = $eventTypes[$eventTemplate->event_type_id];
100 }
101
102 //form all action links
103 $action = array_sum(array_keys($this->links()));
104
105 //add action links.
106 $allEventTemplates[$eventTemplate->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
107 ['id' => $eventTemplate->id],
108 ts('more'),
109 FALSE,
110 'eventTemplate.manage.action',
111 'Event',
112 $eventTemplate->id
113 );
114 }
115 $this->assign('rows', $allEventTemplates);
116
117 $session = CRM_Core_Session::singleton();
118 $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(),
119 'reset=1&action=browse'
120 ));
121 }
122
123 /**
124 * Get name of edit form.
125 *
126 * @return string
127 * Classname of edit form.
128 */
129 public function editForm() {
130 return 'CRM_Admin_Form_EventTemplate';
131 }
132
133 /**
134 * Get edit form name.
135 *
136 * @return string
137 * name of this page.
138 */
139 public function editName() {
140 return 'Event Templates';
141 }
142
143 /**
144 * Get user context.
145 *
146 * @param null $mode
147 *
148 * @return string
149 * user context.
150 */
151 public function userContext($mode = NULL) {
152 return 'civicrm/admin/eventTemplate';
153 }
154
155 }