Replace former calendar year with natural year and add new calendar year option - refs BT#9438

1.10.x
Imanol Losada 10 years ago
parent e3839a7a33
commit 53067f1138
  1. 18
      plugin/resubscription/src/HookResubscription.php
  2. 4
      plugin/resubscription/src/Resubscription.php

@ -31,13 +31,17 @@ class HookResubscription extends HookObserver implements HookResubscribeObserver
$resubscriptionLimit = Resubscription::create()->get('resubscription_limit');
$limitDate = gmdate('Y-m-d');
// Initialize variables as a calendar year by default
$limitDateFormat = 'Y-01-01';
$limitDate = gmdate($limitDateFormat);
$resubscriptionOffset = "1 year";
switch ($resubscriptionLimit) {
case 'calendar_year':
$resubscriptionLimit = "1 year";
$limitDate = gmdate('Y-m-d', strtotime(gmdate('Y-m-d')." -$resubscriptionLimit"));
break;
// No need to use a 'switch' with only two options so an 'if' is enough.
// However this could change if the number of options increases
if ($resubscriptionLimit === 'natural_year') {
$limitDateFormat = 'Y-m-d';
$limitDate = gmdate($limitDateFormat);
$limitDate = gmdate($limitDateFormat, strtotime("$limitDate -$resubscriptionOffset"));
}
$join = " INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)."ON id = id_session";
@ -94,7 +98,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"));
$resubscriptionDate = gmdate($limitDateFormat, strtotime($endDate." +$resubscriptionOffset"));
$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"));

@ -16,7 +16,8 @@ class Resubscription extends Plugin implements HookPluginInterface
protected function __construct()
{
$options = array(
'calendar_year' => get_lang('CalendarYear')
'calendar_year' => get_lang('CalendarYear'),
'natural_year' => get_lang('NaturalYear')
);
$parameters = array(
'resubscription_limit' => array(
@ -24,7 +25,6 @@ class Resubscription extends Plugin implements HookPluginInterface
'options' => $options
)
);
parent::__construct('0.1', 'Imanol Losada Oriol', $parameters);
}

Loading…
Cancel
Save