Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy functions from TabHeader back to the only caller #29490

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 198 additions & 4 deletions CRM/Event/Form/ManageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function preProcess() {
}

// also set up tabs
CRM_Event_Form_ManageEvent_TabHeader::build($this);
$this->build();

// Set Done button URL and breadcrumb. Templates go back to Manage Templates,
// otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
Expand Down Expand Up @@ -307,7 +307,7 @@ public function endPostProcess() {
// hack for special cases.
switch ($className) {
case 'Event':
$attributes = $this->getVar('_attributes');
$attributes = $this->_attributes;
$subPage = CRM_Utils_Request::retrieveComponent($attributes);
break;

Expand Down Expand Up @@ -337,7 +337,7 @@ public function endPostProcess() {
}
}
$this->postProcessHook();
if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
if ($this->controller->getButtonName('submit') === "_qf_{$className}_upload_done") {
if ($this->_isTemplate) {
CRM_Core_Session::singleton()
->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
Expand All @@ -358,7 +358,7 @@ public function endPostProcess() {
* @return string
*/
public function getTemplateFileName() {
if ($this->controller->getPrint() || $this->getVar('_id') <= 0 || $this->_action & CRM_Core_Action::DELETE) {
if ($this->controller->getPrint() || $this->_id <= 0 || $this->_action & CRM_Core_Action::DELETE) {
return parent::getTemplateFileName();
}
else {
Expand Down Expand Up @@ -387,4 +387,198 @@ public function getEventID() {
return $this->_id ? (int) $this->_id : NULL;
}

/**
*
* @return array
* @throws \CRM_Core_Exception
*/
private function build() {
$tabs = $this->get('tabHeader');
if (!$tabs || empty($_GET['reset'])) {
$tabs = $this->processTab();
$this->set('tabHeader', $tabs);
}
$this->assign('tabHeader', $tabs);
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
->addSetting([
'tabSettings' => [
'active' => $this->getCurrentTab($tabs),
],
]);
CRM_Event_Form_ManageEvent::addProfileEditScripts();
return $tabs;
}

/**
* @return array
* @throws Exception
*/
private function processTab() {
if ($this->getEventID() <= 0) {
return NULL;
}

$default = [
'link' => NULL,
'valid' => TRUE,
'active' => TRUE,
'current' => FALSE,
'class' => 'ajaxForm',
];

$tabs = [];
$tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] + $default;
$tabs['location'] = ['title' => ts('Event Location')] + $default;
// If CiviContribute is active, create the Fees tab.
if (CRM_Core_Component::isEnabled('CiviContribute')) {
$tabs['fee'] = ['title' => ts('Fees')] + $default;
}
$tabs['registration'] = ['title' => ts('Online Registration')] + $default;
// @fixme I don't understand the event permissions check here - can we just get rid of it?
$permissions = CRM_Event_BAO_Event::getAllPermissions();
if (CRM_Core_Permission::check('administer CiviCRM data') || !empty($permissions[CRM_Core_Permission::EDIT])) {
$tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage'] + $default;
}

$tabs['friend'] = ['title' => ts('Tell a Friend')] + $default;
$tabs['pcp'] = ['title' => ts('Personal Campaigns')] + $default;
$tabs['repeat'] = ['title' => ts('Repeat')] + $default;

// Repeat tab must refresh page when switching repeat mode so js & vars will get set-up
if (!$this->_isRepeatingEvent) {
unset($tabs['repeat']['class']);
}

$eventID = $this->getEventID();
if ($eventID) {
// disable tabs based on their configuration status
$sql = "
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
FROM civicrm_event e
LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )
LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
WHERE e.id = %1
";
//Check if repeat is configured
CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event');
$params = [
1 => [$eventID, 'Integer'],
2 => [CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID, 'Integer'],
];
$dao = CRM_Core_DAO::executeQuery($sql, $params);
if (!$dao->fetch()) {
throw new CRM_Core_Exception('Unable to determine Event information');
}
if (!$dao->is_location) {
$tabs['location']['valid'] = FALSE;
}
if (!$dao->is_online_registration) {
$tabs['registration']['valid'] = FALSE;
}
if (!$dao->is_monetary) {
$tabs['fee']['valid'] = FALSE;
}
if (!$dao->is_active) {
$tabs['friend']['valid'] = FALSE;
}
if (!$dao->is_pcp) {
$tabs['pcp']['valid'] = FALSE;
}
if (!$dao->is_reminder) {
$tabs['reminder']['valid'] = FALSE;
}
if (!$dao->is_repeating_event) {
$tabs['repeat']['valid'] = FALSE;
}
}

// see if any other modules want to add any tabs
// note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs,
['event_id' => $eventID]);

$fullName = $this->_name;
$className = CRM_Utils_String::getClassName($fullName);
$new = '';

// hack for special cases.
switch ($className) {
case 'Event':
$attributes = $this->_attributes;
$class = CRM_Utils_Request::retrieveComponent($attributes);
break;

case 'EventInfo':
$class = 'settings';
break;

case 'ScheduleReminders':
$class = 'reminder';
break;

default:
$class = strtolower($className);
break;
}

if (array_key_exists($class, $tabs)) {
$tabs[$class]['current'] = TRUE;
$qfKey = $this->get('qfKey');
if ($qfKey) {
$tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
}
}

if ($eventID) {
$reset = !empty($_GET['reset']) ? 'reset=1&' : '';

foreach ($tabs as $key => $value) {
if (!isset($tabs[$key]['qfKey'])) {
$tabs[$key]['qfKey'] = NULL;
}

$action = 'update';
if ($key === 'reminder') {
$action = 'browse';
}

$link = "civicrm/event/manage/{$key}";
$query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}";

$tabs[$key]['link'] = (isset($value['link']) ? $value['link'] :
CRM_Utils_System::url($link, $query));
}
}

return $tabs;
}

/**
* @param $tabs
*
* @return int|string
*/
private function getCurrentTab($tabs) {
static $current = FALSE;

if ($current) {
return $current;
}

if (is_array($tabs)) {
foreach ($tabs as $subPage => $pageVal) {
if (($pageVal['current'] ?? NULL) === TRUE) {
$current = $subPage;
break;
}
}
}

$current = $current ?: 'settings';
return $current;
}

}
14 changes: 14 additions & 0 deletions CRM/Event/Form/ManageEvent/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* Helper class to build navigation links
*
* @deprecated since 5.72 will be removed around 5.78.
*/
class CRM_Event_Form_ManageEvent_TabHeader {

Expand All @@ -25,8 +27,11 @@ class CRM_Event_Form_ManageEvent_TabHeader {
*
* @return array
* @throws \CRM_Core_Exception
*
* @deprecated since 5.72 will be removed around 5.78.
*/
public static function build(&$form) {
CRM_Core_Error::deprecatedWarning('no alternative');
$tabs = $form->get('tabHeader');
if (!$tabs || empty($_GET['reset'])) {
$tabs = self::process($form);
Expand All @@ -49,8 +54,11 @@ public static function build(&$form) {
*
* @return array
* @throws Exception
*
* @deprecated since 5.72 will be removed around 5.78.
*/
public static function process(&$form) {
CRM_Core_Error::deprecatedWarning('no alternative');
if ($form->getVar('_id') <= 0) {
return NULL;
}
Expand Down Expand Up @@ -194,8 +202,11 @@ public static function process(&$form) {

/**
* @param CRM_Event_Form_ManageEvent $form
*
* @deprecated since 5.72 will be removed around 5.78.
*/
public static function reset(&$form) {
CRM_Core_Error::deprecatedWarning('no alternative');
$tabs = self::process($form);
$form->set('tabHeader', $tabs);
}
Expand All @@ -204,8 +215,11 @@ public static function reset(&$form) {
* @param $tabs
*
* @return int|string
*
* @deprecated since 5.72 will be removed around 5.78.
*/
public static function getCurrentTab($tabs) {
CRM_Core_Error::deprecatedWarning('no alternative');
static $current = FALSE;

if ($current) {
Expand Down