INFRA-132 - Civi - PHPStorm cleanup
[civicrm-core.git] / CRM / Event / Form / ManageEvent / TabHeader.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Helper class to build navigation links
38 */
39class CRM_Event_Form_ManageEvent_TabHeader {
40
0cf587a7 41 /**
c490a46a 42 * @param CRM_Core_Form $form
0cf587a7
EM
43 *
44 * @return array
45 */
00be9182 46 public static function build(&$form) {
6a488035 47 $tabs = $form->get('tabHeader');
8cc574cf 48 if (!$tabs || empty($_GET['reset'])) {
6a488035
TO
49 $tabs = self::process($form);
50 $form->set('tabHeader', $tabs);
51 }
52 $form->assign_by_ref('tabHeader', $tabs);
4165b7e5 53 CRM_Core_Resources::singleton()
96ed17aa 54 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
0479b4c8
TO
55 ->addSetting(array(
56 'tabSettings' => array(
4165b7e5
CW
57 'active' => self::getCurrentTab($tabs),
58 )));
bfd83a87 59 CRM_Event_Form_ManageEvent::addProfileEditScripts();
6a488035
TO
60 return $tabs;
61 }
62
0cf587a7 63 /**
c490a46a 64 * @param CRM_Core_Form $form
0cf587a7
EM
65 *
66 * @return array
67 * @throws Exception
68 */
00be9182 69 public static function process(&$form) {
6a488035
TO
70 if ($form->getVar('_id') <= 0) {
71 return NULL;
72 }
73
4b628e67
CW
74 $default = array(
75 'link' => NULL,
76 'valid' => TRUE,
77 'active' => TRUE,
78 'current' => FALSE,
79 'class' => 'ajaxForm',
80 );
81
209989e3 82 $tabs = array();
83 $tabs['settings'] = array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default;
84 $tabs['location'] = array('title' => ts('Event Location')) + $default;
85 $tabs['fee'] = array('title' => ts('Fees')) + $default;
86 $tabs['registration'] = array('title' => ts('Online Registration')) + $default;
87 if (CRM_Core_Permission::check('administer CiviCRM')) {
88 $tabs['reminder'] = array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default;
89 }
90 $tabs['conference'] = array('title' => ts('Conference Slots')) + $default;
91 $tabs['friend'] = array('title' => ts('Tell a Friend')) + $default;
92 $tabs['pcp'] = array('title' => ts('Personal Campaigns')) + $default;
62933949 93 $tabs['repeat'] = array('title' => ts('Repeat')) + $default;
209989e3 94
6a488035
TO
95 // check if we're in shopping cart mode for events
96 $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
97 'enable_cart'
98 );
6a488035
TO
99 if (!$enableCart) {
100 unset($tabs['conference']);
101 }
102
103 $eventID = $form->getVar('_id');
a215a5b0 104 if ($eventID) {
0cf587a7 105 // disable tabs based on their configuration status
a215a5b0 106 $sql = "
6063a2f1 107SELECT 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
108FROM civicrm_event e
109LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
110LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
111LEFT JOIN civicrm_action_mapping map ON ( map.entity_value = 'civicrm_event' )
112LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = map.id AND sch.entity_value = %1 )
6063a2f1 113LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
a215a5b0
DS
114WHERE e.id = %1
115";
62933949 116 //Check if repeat is configured
117 $eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event');
a215a5b0
DS
118 $params = array(1 => array($eventID, 'Integer'));
119 $dao = CRM_Core_DAO::executeQuery($sql, $params);
120 if (!$dao->fetch()) {
121 CRM_Core_Error::fatal();
122 }
123 if (!$dao->is_location) {
124 $tabs['location']['valid'] = FALSE;
125 }
126 if (!$dao->is_online_registration) {
127 $tabs['registration']['valid'] = FALSE;
128 }
129 if (!$dao->is_monetary) {
130 $tabs['fee']['valid'] = FALSE;
131 }
132 if (!$dao->is_active) {
133 $tabs['friend']['valid'] = FALSE;
134 }
135 if (!$dao->is_pcp) {
136 $tabs['pcp']['valid'] = FALSE;
137 }
138 if (!$dao->is_reminder) {
139 $tabs['reminder']['valid'] = FALSE;
140 }
a50a97b8 141 if (!$dao->is_repeating_event) {
62933949 142 $tabs['repeat']['valid'] = FALSE;
143 }
a215a5b0 144 }
6a488035 145
c1ad592f 146 // see if any other modules want to add any tabs
a215a5b0 147 // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
c1ad592f 148 CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs,
149 array('event_id' => $eventID));
150
6a488035
TO
151 $fullName = $form->getVar('_name');
152 $className = CRM_Utils_String::getClassName($fullName);
153 $new = '';
4d3e4dbe 154
6a488035
TO
155 // hack for special cases.
156 switch ($className) {
157 case 'Event':
158 $attributes = $form->getVar('_attributes');
159 $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
160 break;
161
c13a1cff
AN
162 case 'EventInfo':
163 $class = 'settings';
164 break;
165
6a488035
TO
166 case 'ScheduleReminders':
167 $class = 'reminder';
6a488035
TO
168 break;
169
170 default:
171 $class = strtolower($className);
172 break;
173 }
174
175 if (array_key_exists($class, $tabs)) {
176 $tabs[$class]['current'] = TRUE;
177 $qfKey = $form->get('qfKey');
178 if ($qfKey) {
179 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
180 }
181 }
182
183 if ($eventID) {
0d8afee2 184 $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
6a488035
TO
185
186 foreach ($tabs as $key => $value) {
187 if (!isset($tabs[$key]['qfKey'])) {
188 $tabs[$key]['qfKey'] = NULL;
189 }
190
e8e90f7e 191 $action = 'update';
4d3e4dbe 192 if ($key == 'reminder') {
193 $action = 'browse';
194 }
195
6a488035 196 $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/event/manage/{$key}",
4d3e4dbe 197 "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}"
6a488035 198 );
74affe5c 199 }
6a488035 200 }
fa3dbfbd 201
6a488035
TO
202 return $tabs;
203 }
204
0cf587a7
EM
205 /**
206 * @param $form
207 */
00be9182 208 public static function reset(&$form) {
6a488035
TO
209 $tabs = self::process($form);
210 $form->set('tabHeader', $tabs);
211 }
212
0cf587a7
EM
213 /**
214 * @param $tabs
215 *
216 * @return int|string
217 */
00be9182 218 public static function getCurrentTab($tabs) {
6a488035
TO
219 static $current = FALSE;
220
221 if ($current) {
222 return $current;
223 }
224
225 if (is_array($tabs)) {
226 foreach ($tabs as $subPage => $pageVal) {
227 if ($pageVal['current'] === TRUE) {
228 $current = $subPage;
229 break;
230 }
231 }
232 }
233
234 $current = $current ? $current : 'settings';
235 return $current;
236 }
237}