Add plugin files - refs BT#9438

1.10.x
Imanol Losada 11 years ago
parent 5cb082885a
commit 05ae9e78b1
  1. 4
      plugin/resubscription/README.md
  2. 9
      plugin/resubscription/config.php
  3. 8
      plugin/resubscription/index.php
  4. 10
      plugin/resubscription/install.php
  5. 13
      plugin/resubscription/lang/english.php
  6. 13
      plugin/resubscription/lang/spanish.php
  7. 10
      plugin/resubscription/plugin.php
  8. 2
      plugin/resubscription/readme.txt
  9. 98
      plugin/resubscription/src/HookResubscription.php
  10. 72
      plugin/resubscription/src/Resubscription.php
  11. 10
      plugin/resubscription/uninstall.php

@ -0,0 +1,4 @@
Resubscription
==============
Limit session resubscriptions

@ -0,0 +1,9 @@
<?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';

@ -0,0 +1,8 @@
<?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';

@ -0,0 +1,10 @@
<?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();

@ -0,0 +1,13 @@
<?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 resubscription.';
$strings['resubscription_limit'] = 'Resubscription limit';
$strings['resubscription_limit_help'] = 'This limits how often a user can be resubscribed';
$strings['CanResubscribeFromX'] = 'Subscription available from %s';

@ -0,0 +1,13 @@
<?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.';
$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';

@ -0,0 +1,10 @@
<?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();

@ -0,0 +1,2 @@
<h1>Resubscription</h1>
<p>Limit session resubscriptions</p>

@ -0,0 +1,98 @@
<?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');
$limitDate = gmdate('Y-m-d', strtotime(gmdate('Y-m-d')." -$resubscriptionLimit year"));
$join = " INNER JOIN ".Database::get_main_table(TABLE_MAIN_SESSION)."ON id = id_session";
// User sessions and courses
$userSessions = Database::select(
'id_session, date_end',
Database::get_main_table(TABLE_MAIN_SESSION_USER).$join,
array(
'where' => array(
'id_user = ? AND date_end >= ?' => array(
api_get_user_id(),
$limitDate
)
),
'order' => 'date_end DESC'
)
);
$userSessionCourses = array();
foreach ($userSessions as $userSession) {
$userSessionCourseResult = Database::select(
'course_code',
Database::get_main_table(TABLE_MAIN_SESSION_COURSE),
array(
'where' => array(
'id_session = ?' => array(
$userSession['id_session']
)
)
)
);
foreach ($userSessionCourseResult as $userSessionCourse) {
if (!isset($userSessionCourses[$userSessionCourse['course_code']])) {
$userSessionCourses[$userSessionCourse['course_code']] = $userSession['date_end'];
}
}
}
// Current session and courses
$currentSessionCourseResult = Database::select(
'course_code',
Database::get_main_table(TABLE_MAIN_SESSION_COURSE),
array(
'where' => array(
'id_session = ?' => array(
$data['session_id']
)
)
)
);
// Check if current course code matches with one of the users
foreach ($currentSessionCourseResult as $currentSessionCourse) {
if (isset($userSessionCourses[$currentSessionCourse['course_code']])) {
$endDate = $userSessionCourses[$currentSessionCourse['course_code']];
$resubscriptionDate = gmdate('Y-m-d', strtotime($endDate." +$resubscriptionLimit year"));
$icon = Display::return_icon('students.gif', get_lang('Student'));
$canResubscribeFrom = sprintf(get_plugin_lang('CanResubscribeFromX', 'resubscription'), $resubscriptionDate);
$data['result'] = Display::label($icon . ' ' . $canResubscribeFrom, "info");
}
}
}
}
}

@ -0,0 +1,72 @@
<?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()
{
$parameters = array(
'resubscription_limit' => 'text'
);
parent::__construct('0.1', 'Imanol Losada Oriol', $parameters);
}
/**
* Instance the plugin
* @staticvar null $result
* @return Resubscription
*/
static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
/**
* Install the plugin
*/
public function install()
{
$this->installHook();
}
/**
* Uninstall the plugin
* @return void
*/
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);
}
}

@ -0,0 +1,10 @@
<?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();
Loading…
Cancel
Save