Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * Helper class to build navigation links | |
22 | */ | |
23 | class CRM_Event_Form_ManageEvent_TabHeader { | |
24 | ||
0cf587a7 | 25 | /** |
c65ce939 | 26 | * @param CRM_Event_Form_ManageEvent $form |
0cf587a7 EM |
27 | * |
28 | * @return array | |
c1bd8375 | 29 | * @throws \CRM_Core_Exception |
0cf587a7 | 30 | */ |
00be9182 | 31 | public static function build(&$form) { |
6a488035 | 32 | $tabs = $form->get('tabHeader'); |
8cc574cf | 33 | if (!$tabs || empty($_GET['reset'])) { |
6a488035 TO |
34 | $tabs = self::process($form); |
35 | $form->set('tabHeader', $tabs); | |
36 | } | |
37 | $form->assign_by_ref('tabHeader', $tabs); | |
4165b7e5 | 38 | CRM_Core_Resources::singleton() |
96ed17aa | 39 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
be2fb01f CW |
40 | ->addSetting([ |
41 | 'tabSettings' => [ | |
353ffa53 | 42 | 'active' => self::getCurrentTab($tabs), |
be2fb01f CW |
43 | ], |
44 | ]); | |
bfd83a87 | 45 | CRM_Event_Form_ManageEvent::addProfileEditScripts(); |
6a488035 TO |
46 | return $tabs; |
47 | } | |
48 | ||
0cf587a7 | 49 | /** |
c65ce939 | 50 | * @param CRM_Event_Form_ManageEvent $form |
0cf587a7 EM |
51 | * |
52 | * @return array | |
53 | * @throws Exception | |
54 | */ | |
00be9182 | 55 | public static function process(&$form) { |
6a488035 TO |
56 | if ($form->getVar('_id') <= 0) { |
57 | return NULL; | |
58 | } | |
59 | ||
be2fb01f | 60 | $default = [ |
4b628e67 CW |
61 | 'link' => NULL, |
62 | 'valid' => TRUE, | |
63 | 'active' => TRUE, | |
64 | 'current' => FALSE, | |
65 | 'class' => 'ajaxForm', | |
be2fb01f | 66 | ]; |
4b628e67 | 67 | |
be2fb01f CW |
68 | $tabs = []; |
69 | $tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] + $default; | |
70 | $tabs['location'] = ['title' => ts('Event Location')] + $default; | |
71 | $tabs['fee'] = ['title' => ts('Fees')] + $default; | |
72 | $tabs['registration'] = ['title' => ts('Online Registration')] + $default; | |
cfbfd406 MWMC |
73 | // @fixme I don't understand the event permissions check here - can we just get rid of it? |
74 | $permissions = CRM_Event_BAO_Event::getAllPermissions(); | |
75 | if (CRM_Core_Permission::check('administer CiviCRM') || !empty($permissions[CRM_Core_Permission::EDIT])) { | |
be2fb01f | 76 | $tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage'] + $default; |
209989e3 | 77 | } |
be2fb01f CW |
78 | $tabs['conference'] = ['title' => ts('Conference Slots')] + $default; |
79 | $tabs['friend'] = ['title' => ts('Tell a Friend')] + $default; | |
80 | $tabs['pcp'] = ['title' => ts('Personal Campaigns')] + $default; | |
81 | $tabs['repeat'] = ['title' => ts('Repeat')] + $default; | |
209989e3 | 82 | |
c65ce939 CW |
83 | // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up |
84 | if (!$form->_isRepeatingEvent) { | |
85 | unset($tabs['repeat']['class']); | |
86 | } | |
87 | ||
6a488035 | 88 | // check if we're in shopping cart mode for events |
aaffa79f | 89 | $enableCart = Civi::settings()->get('enable_cart'); |
6a488035 TO |
90 | if (!$enableCart) { |
91 | unset($tabs['conference']); | |
92 | } | |
93 | ||
94 | $eventID = $form->getVar('_id'); | |
a215a5b0 | 95 | if ($eventID) { |
0cf587a7 | 96 | // disable tabs based on their configuration status |
be2fb01f | 97 | $eventNameMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings([ |
46f5566c | 98 | 'id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID, |
be2fb01f | 99 | ])); |
a215a5b0 | 100 | $sql = " |
6063a2f1 | 101 | SELECT e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder, re.id as is_repeating_event |
a215a5b0 DS |
102 | FROM civicrm_event e |
103 | LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id ) | |
104 | LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id ) | |
50a23755 | 105 | LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 ) |
6063a2f1 | 106 | LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' ) |
a215a5b0 DS |
107 | WHERE e.id = %1 |
108 | "; | |
62933949 | 109 | //Check if repeat is configured |
110 | $eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event'); | |
be2fb01f CW |
111 | $params = [ |
112 | 1 => [$eventID, 'Integer'], | |
113 | 2 => [$eventNameMapping->getId(), 'Integer'], | |
114 | ]; | |
a215a5b0 DS |
115 | $dao = CRM_Core_DAO::executeQuery($sql, $params); |
116 | if (!$dao->fetch()) { | |
117 | CRM_Core_Error::fatal(); | |
118 | } | |
119 | if (!$dao->is_location) { | |
120 | $tabs['location']['valid'] = FALSE; | |
121 | } | |
122 | if (!$dao->is_online_registration) { | |
123 | $tabs['registration']['valid'] = FALSE; | |
124 | } | |
125 | if (!$dao->is_monetary) { | |
126 | $tabs['fee']['valid'] = FALSE; | |
127 | } | |
128 | if (!$dao->is_active) { | |
129 | $tabs['friend']['valid'] = FALSE; | |
130 | } | |
131 | if (!$dao->is_pcp) { | |
132 | $tabs['pcp']['valid'] = FALSE; | |
133 | } | |
134 | if (!$dao->is_reminder) { | |
135 | $tabs['reminder']['valid'] = FALSE; | |
136 | } | |
a50a97b8 | 137 | if (!$dao->is_repeating_event) { |
62933949 | 138 | $tabs['repeat']['valid'] = FALSE; |
139 | } | |
a215a5b0 | 140 | } |
6a488035 | 141 | |
c1ad592f | 142 | // see if any other modules want to add any tabs |
a215a5b0 | 143 | // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation. |
c1ad592f | 144 | CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs, |
be2fb01f | 145 | ['event_id' => $eventID]); |
c1ad592f | 146 | |
353ffa53 | 147 | $fullName = $form->getVar('_name'); |
6a488035 | 148 | $className = CRM_Utils_String::getClassName($fullName); |
353ffa53 | 149 | $new = ''; |
4d3e4dbe | 150 | |
6a488035 TO |
151 | // hack for special cases. |
152 | switch ($className) { | |
153 | case 'Event': | |
154 | $attributes = $form->getVar('_attributes'); | |
b90552b7 | 155 | $class = CRM_Utils_Request::retrieveComponent($attributes); |
6a488035 TO |
156 | break; |
157 | ||
c13a1cff AN |
158 | case 'EventInfo': |
159 | $class = 'settings'; | |
160 | break; | |
161 | ||
6a488035 TO |
162 | case 'ScheduleReminders': |
163 | $class = 'reminder'; | |
6a488035 TO |
164 | break; |
165 | ||
166 | default: | |
167 | $class = strtolower($className); | |
168 | break; | |
169 | } | |
170 | ||
171 | if (array_key_exists($class, $tabs)) { | |
172 | $tabs[$class]['current'] = TRUE; | |
173 | $qfKey = $form->get('qfKey'); | |
174 | if ($qfKey) { | |
175 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
176 | } | |
177 | } | |
178 | ||
179 | if ($eventID) { | |
0d8afee2 | 180 | $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; |
6a488035 TO |
181 | |
182 | foreach ($tabs as $key => $value) { | |
183 | if (!isset($tabs[$key]['qfKey'])) { | |
184 | $tabs[$key]['qfKey'] = NULL; | |
185 | } | |
186 | ||
e8e90f7e | 187 | $action = 'update'; |
4d3e4dbe | 188 | if ($key == 'reminder') { |
189 | $action = 'browse'; | |
190 | } | |
191 | ||
2f3732a9 FG |
192 | $link = "civicrm/event/manage/{$key}"; |
193 | $query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}"; | |
e84a94d2 | 194 | |
32f93260 | 195 | $tabs[$key]['link'] = (isset($value['link']) ? $value['link'] : |
2f3732a9 | 196 | CRM_Utils_System::url($link, $query)); |
74affe5c | 197 | } |
6a488035 | 198 | } |
fa3dbfbd | 199 | |
6a488035 TO |
200 | return $tabs; |
201 | } | |
202 | ||
0cf587a7 | 203 | /** |
c65ce939 | 204 | * @param CRM_Event_Form_ManageEvent $form |
0cf587a7 | 205 | */ |
00be9182 | 206 | public static function reset(&$form) { |
6a488035 TO |
207 | $tabs = self::process($form); |
208 | $form->set('tabHeader', $tabs); | |
209 | } | |
210 | ||
0cf587a7 EM |
211 | /** |
212 | * @param $tabs | |
213 | * | |
214 | * @return int|string | |
215 | */ | |
00be9182 | 216 | public static function getCurrentTab($tabs) { |
6a488035 TO |
217 | static $current = FALSE; |
218 | ||
219 | if ($current) { | |
220 | return $current; | |
221 | } | |
222 | ||
223 | if (is_array($tabs)) { | |
224 | foreach ($tabs as $subPage => $pageVal) { | |
c1bd8375 | 225 | if (CRM_Utils_Array::value('current', $pageVal) === TRUE) { |
6a488035 TO |
226 | $current = $subPage; |
227 | break; | |
228 | } | |
229 | } | |
230 | } | |
231 | ||
232 | $current = $current ? $current : 'settings'; | |
233 | return $current; | |
234 | } | |
96025800 | 235 | |
6a488035 | 236 | } |