/** * Get a HTML button for subscribe to session * @param int $sessionId The session ID * @param string $sessionName The session name * @param boolean $checkRequirements Optional. * Whether the session has requirement. Default is false * @return string The button HTML */ public function getRegisteredInSessionButton($sessionId, $sessionName, $checkRequirements = false) { if ($checkRequirements) { $url = api_get_path(WEB_AJAX_PATH); $url .= 'sequence.ajax.php?'; $url .= http_build_query(['a' => 'get_requirements', 'id' => intval($sessionId), 'type' => SequenceResource::SESSION_TYPE]); return Display::toolbarButton(get_lang('CheckRequirements'), $url, 'check-circle', 'primary', ['class' => 'btn-lg btn-block ajax', 'data-title' => get_lang('CheckRequirements'), 'data-size' => 'md']); } $catalogSessionAutoSubscriptionAllowed = false; if (api_get_setting('session.catalog_allow_session_auto_subscription') === 'true') { $catalogSessionAutoSubscriptionAllowed = true; } $url = api_get_path(WEB_CODE_PATH); if ($catalogSessionAutoSubscriptionAllowed) { $url .= 'auth/courses.php?'; $url .= http_build_query(['action' => 'subscribe_to_session', 'session_id' => intval($sessionId)]); $result = Display::toolbarButton(get_lang('Subscribe'), $url, 'check-circle', 'primary', ['class' => 'btn-lg btn-block ajax', 'data-title' => get_lang('AreYouSureToSubscribe'), 'data-size' => 'md']); } else { $url .= 'inc/email_editor.php?'; $url .= http_build_query(['action' => 'subscribe_me_to_session', 'session' => Security::remove_XSS($sessionName)]); $result = Display::toolbarButton(get_lang('Subscribe'), $url, 'check-circle', 'primary', ['class' => 'btn-lg btn-block']); } $hook = HookResubscribe::create(); if (!empty($hook)) { $hook->setEventData(array('session_id' => intval($sessionId))); try { $hook->notifyResubscribe(HOOK_EVENT_TYPE_PRE); } catch (Exception $exception) { $result = $exception->getMessage(); } } return $result; }
/** * Uninstall the Resubscription hook */ public function uninstallHook() { $hook = HookResubscription::create(); HookResubscribe::create()->detach($hook); }