Actualización

This commit is contained in:
Xes
2025-04-10 12:36:07 +02:00
parent 1da7c3f3b9
commit 4aff98e77b
3147 changed files with 320647 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
Resubscription
==============
Limit session re-subscriptions by checking whether the user was already
subscribed to a specific course *through a session* over the last 12
months or the last calendar year (from 1st of January to 31st of December).
This plugin does not support sessions by "duration" at this time, so the
date of last access is based on the session's access_end_date field, which
defines when student access is removed (not the "display" end date, which
is the date that shows in the session's public details).

View File

@@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
require_once api_get_path(SYS_PATH).'main/inc/global.inc.php';

View File

@@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
require_once __DIR__.'/config.php';

View File

@@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Initialization install.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
require_once __DIR__.'/config.php';
Resubscription::create()->install();

View File

@@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Strings to english L10n.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
$strings['plugin_title'] = 'Resubscription';
$strings['plugin_comment'] = 'This plugin limits session re-subscription for users who already followed a course through another session not so long ago.';
$strings['resubscription_limit'] = 'Resubscription limit';
$strings['resubscription_limit_help'] = 'This limits how often a user can be resubscribed';
$strings['CanResubscribeFromX'] = 'Subscription available from %s';

View File

@@ -0,0 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Strings to French L10n.
*
* @package chamilo.plugin.resubscription
*/
$strings['plugin_title'] = 'Réinscription';
$strings['plugin_comment'] = 'Ce plugin permet de limiter les réinscriptions à des sessions qui contiennent des cours que les utilisateurs ont déjà suivi moins d\'un an auparavant.';
$strings['resubscription_limit'] = 'Limite de réinscription';
$strings['resubscription_limit_help'] = 'Type de limite (calendrier : du 1/1 au 31/12, ou naturelle : 365 jours après la fin de la session précédente.';
$strings['CanResubscribeFromX'] = 'Réinscription possible à partir du %s';

View File

@@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Strings to spanish L10n.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
$strings['plugin_title'] = 'Reinscripción';
$strings['plugin_comment'] = 'Este plugin limita las reinscripiones a sesiones para los usuarios que ya siguieron un curso de la sesión a través de otra sesión no tanto tiempo atrás.';
$strings['resubscription_limit'] = 'Límite de reinscripción';
$strings['resubscription_limit_help'] = 'Esto limita cada cuánto puede reinscribirse un usuario';
$strings['CanResubscribeFromX'] = 'Inscripción posible a partir del %s';

View File

@@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Get the plugin info.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
require_once __DIR__.'/config.php';
$plugin_info = Resubscription::create()->get_info();

View File

@@ -0,0 +1,112 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Hook to limit session resubscriptions.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
class HookResubscription extends HookObserver implements HookResubscribeObserverInterface
{
/**
* Class constructor.
*/
public function __construct()
{
parent::__construct(
'plugin/resubscription/src/Resubscription.php',
'resubscription'
);
}
/**
* Limit session resubscription when a Chamilo user is resubscribed to a session.
*
* @param HookCreateUserEventInterface $hook The hook
*/
public function hookResubscribe(HookResubscribeEventInterface $hook)
{
$data = $hook->getEventData();
if ($data['type'] === HOOK_EVENT_TYPE_PRE) {
$resubscriptionLimit = Resubscription::create()->get('resubscription_limit');
// Initialize variables as a calendar year by default
$limitDateFormat = 'Y-01-01';
$limitDate = gmdate($limitDateFormat);
$resubscriptionOffset = "1 year";
// 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)." s ON s.id = su.session_id";
// User sessions and courses
$userSessions = Database::select(
'su.session_id, s.access_end_date',
Database::get_main_table(TABLE_MAIN_SESSION_USER).' su '.$join,
[
'where' => [
'su.user_id = ? AND s.access_end_date >= ?' => [
api_get_user_id(),
$limitDate,
],
],
'order' => 'access_end_date DESC',
]
);
$userSessionCourses = [];
foreach ($userSessions as $userSession) {
$userSessionCourseResult = Database::select(
'c_id',
Database::get_main_table(TABLE_MAIN_SESSION_COURSE),
[
'where' => [
'session_id = ?' => [
$userSession['session_id'],
],
],
]
);
foreach ($userSessionCourseResult as $userSessionCourse) {
if (!isset($userSessionCourses[$userSessionCourse['c_id']])) {
$userSessionCourses[$userSessionCourse['c_id']] = $userSession['access_end_date'];
}
}
}
// Current session and courses
$currentSessionCourseResult = Database::select(
'c_id',
Database::get_main_table(TABLE_MAIN_SESSION_COURSE),
[
'where' => [
'session_id = ?' => [
$data['session_id'],
],
],
]
);
// Check if current course code matches with one of the users
foreach ($currentSessionCourseResult as $currentSessionCourse) {
if (isset($userSessionCourses[$currentSessionCourse['c_id']])) {
$endDate = $userSessionCourses[$currentSessionCourse['c_id']];
$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"));
}
}
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Limit session resubscriptions.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
class Resubscription extends Plugin implements HookPluginInterface
{
/**
* Class constructor.
*/
protected function __construct()
{
$options = [
'calendar_year' => get_lang('CalendarYear'),
'natural_year' => get_lang('NaturalYear'),
];
$parameters = [
'resubscription_limit' => [
'type' => 'select',
'options' => $options,
],
];
parent::__construct('0.1', 'Imanol Losada Oriol', $parameters);
}
/**
* Instance the plugin.
*
* @staticvar null $result
*
* @return Resubscription
*/
public static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
/**
* Install the plugin.
*/
public function install()
{
$this->installHook();
}
/**
* Uninstall the plugin.
*/
public function uninstall()
{
$this->uninstallHook();
}
/**
* Install the Resubscription hook.
*/
public function installHook()
{
$hook = HookResubscription::create();
HookResubscribe::create()->attach($hook);
}
/**
* Uninstall the Resubscription hook.
*/
public function uninstallHook()
{
$hook = HookResubscription::create();
HookResubscribe::create()->detach($hook);
}
}

View File

@@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Initialization uninstall.
*
* @author Imanol Losada Oriol <imanol.losada@beeznest.com>
*
* @package chamilo.plugin.resubscription
*/
require_once __DIR__.'/config.php';
Resubscription::create()->uninstall();