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