From e3839a7a331aca987849d01ccd689b988ef60e70 Mon Sep 17 00:00:00 2001 From: Imanol Losada Date: Tue, 31 Mar 2015 17:38:39 -0500 Subject: [PATCH] Replace configuration textfield with select - refs BT#9438 --- plugin/resubscription/src/HookResubscription.php | 14 +++++++++++--- plugin/resubscription/src/Resubscription.php | 8 +++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugin/resubscription/src/HookResubscription.php b/plugin/resubscription/src/HookResubscription.php index e0c4e0cb0b..e71b675fba 100644 --- a/plugin/resubscription/src/HookResubscription.php +++ b/plugin/resubscription/src/HookResubscription.php @@ -28,8 +28,17 @@ class HookResubscription extends HookObserver implements HookResubscribeObserver { $data = $hook->getEventData(); if ($data['type'] === HOOK_EVENT_TYPE_PRE) { + $resubscriptionLimit = Resubscription::create()->get('resubscription_limit'); - $limitDate = gmdate('Y-m-d', strtotime(gmdate('Y-m-d')." -$resubscriptionLimit year")); + + $limitDate = gmdate('Y-m-d'); + + switch ($resubscriptionLimit) { + case 'calendar_year': + $resubscriptionLimit = "1 year"; + $limitDate = gmdate('Y-m-d', strtotime(gmdate('Y-m-d')." -$resubscriptionLimit")); + break; + } $join = " INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)."ON id = id_session"; @@ -85,7 +94,7 @@ class HookResubscription extends HookObserver implements HookResubscribeObserver foreach ($currentSessionCourseResult as $currentSessionCourse) { if (isset($userSessionCourses[$currentSessionCourse['course_code']])) { $endDate = $userSessionCourses[$currentSessionCourse['course_code']]; - $resubscriptionDate = gmdate('Y-m-d', strtotime($endDate." +$resubscriptionLimit year")); + $resubscriptionDate = gmdate('Y-m-d', strtotime($endDate." +$resubscriptionLimit")); $icon = Display::return_icon('students.gif', get_lang('Student')); $canResubscribeFrom = sprintf(get_plugin_lang('CanResubscribeFromX', 'resubscription'), $resubscriptionDate); throw new Exception(Display::label($icon . ' ' . $canResubscribeFrom, "info")); @@ -93,5 +102,4 @@ class HookResubscription extends HookObserver implements HookResubscribeObserver } } } - } diff --git a/plugin/resubscription/src/Resubscription.php b/plugin/resubscription/src/Resubscription.php index a1e9554122..e30636045b 100644 --- a/plugin/resubscription/src/Resubscription.php +++ b/plugin/resubscription/src/Resubscription.php @@ -15,8 +15,14 @@ class Resubscription extends Plugin implements HookPluginInterface */ protected function __construct() { + $options = array( + 'calendar_year' => get_lang('CalendarYear') + ); $parameters = array( - 'resubscription_limit' => 'text' + 'resubscription_limit' => array( + 'type' => 'select', + 'options' => $options + ) ); parent::__construct('0.1', 'Imanol Losada Oriol', $parameters);