Merge pull request #21470 from mattwire/templatecontributioncreate
[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 $allEventTemplates[$eventTemplate->id]['participant_listing'] = ts('Disabled');
89 if ($eventTemplate->participant_listing_id) {
90 $allEventTemplates[$eventTemplate->id]['participant_listing'] = $participantListings[$eventTemplate->participant_listing_id];
91 }
92
93 //get participant role
94 $allEventTemplates[$eventTemplate->id]['participant_role'] = '';
95 if ($eventTemplate->default_role_id) {
96 $allEventTemplates[$eventTemplate->id]['participant_role'] = $participantRoles[$eventTemplate->default_role_id];
97 }
98
99 //get event type.
100 $allEventTemplates[$eventTemplate->id]['event_type'] = '';
101 if (isset($eventTypes[$eventTemplate->event_type_id])) {
102 $allEventTemplates[$eventTemplate->id]['event_type'] = $eventTypes[$eventTemplate->event_type_id];
103 }
104
105 //form all action links
106 $action = array_sum(array_keys($this->links()));
107
108 //add action links.
109 $allEventTemplates[$eventTemplate->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
110 ['id' => $eventTemplate->id],
111 ts('more'),
112 FALSE,
113 'eventTemplate.manage.action',
114 'Event',
115 $eventTemplate->id
116 );
117 }
118 $this->assign('rows', $allEventTemplates);
119
120 $session = CRM_Core_Session::singleton();
121 $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(),
122 'reset=1&action=browse'
123 ));
124 }
125
126 /**
127 * Get name of edit form.
128 *
129 * @return string
130 * Classname of edit form.
131 */
132 public function editForm() {
133 return 'CRM_Admin_Form_EventTemplate';
134 }
135
136 /**
137 * Get edit form name.
138 *
139 * @return string
140 * name of this page.
141 */
142 public function editName() {
143 return 'Event Templates';
144 }
145
146 /**
147 * Get user context.
148 *
149 * @param null $mode
150 *
151 * @return string
152 * user context.
153 */
154 public function userContext($mode = NULL) {
155 return 'civicrm/admin/eventTemplate';
156 }
157
158 }