Init advanced subscription plugin - refs BT#9092

1.10.x
Daniel Barreto 10 years ago
parent 0a921c4b5f
commit 0c77db9dd5
  1. 4
      plugin/advancedsubscription/README.md
  2. 15
      plugin/advancedsubscription/config.php
  3. 7
      plugin/advancedsubscription/index.php
  4. 15
      plugin/advancedsubscription/install.php
  5. 21
      plugin/advancedsubscription/lang/english.php
  6. 21
      plugin/advancedsubscription/lang/french.php
  7. 21
      plugin/advancedsubscription/lang/spanish.php
  8. 12
      plugin/advancedsubscription/plugin.php
  9. 2
      plugin/advancedsubscription/readme.txt
  10. 286
      plugin/advancedsubscription/src/advanced_subscription_plugin.class.php
  11. 1
      plugin/advancedsubscription/src/index.php
  12. 16
      plugin/advancedsubscription/uninstall.php

@ -0,0 +1,4 @@
Advanced subscription plugin for Chamilo LMS
=======================================
@TODO:Edit README.md

@ -0,0 +1,15 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin
* @author Daniel Alejandro Barreto Alva <daniel.barreto@beeznest.com>
* @package chamilo.plugin.advanced_subscription
*/
define('TABLE_ADV_SUB_QUEUE', 'plugin_advsub_queue');
define('TABLE_ADV_SUB_MAIL', 'plugin_advsub_mail');
define('TABLE_ADV_SUB_MAIL_TYPE', 'plugin_advsub_mail_type');
define('TABLE_ADV_SUB_MAIL_STATUS', 'plugin_advsub_mail_status');
require_once __DIR__ . '/../../main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php';
require_once api_get_path(PLUGIN_PATH) . 'advancedsubscription/src/advanced_subscription_plugin.class.php';

@ -0,0 +1,7 @@
<?php
/* For license terms, see /license.txt */
/**
* Show form
*/
require_once('config.php');
require_once('src/index.php');

@ -0,0 +1,15 @@
<?php
/* For license terms, see /license.txt */
/**
* This script is included by main/admin/settings.lib.php and generally
* includes things to execute in the main database (settings_current table)
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
require_once dirname(__FILE__) . '/config.php';
if (!api_is_platform_admin()) {
die ('You must have admin permissions to install plugins');
}
AdvancedSubscriptionPlugin::create()->install();

@ -0,0 +1,21 @@
<?php
/* Strings for settings */
$strings['plugin_title'] = 'Inscripción Avanzada';
$strings['plugin_comment'] = 'Plugin que permite gestionar la inscripción en cola a sesiones con comunicación a a un portal externo';
$strings['uit_value'] = 'Valor de la Unidad Impositiva Tributaria (UIT)';
$strings['ws_url'] = 'URL del Webservice';
$strings['min_profile_percentage'] = 'Porcentaje mínimo de perfil completado';
$strings['max_expended_uit'] = 'Limite anual de cursos en UIT por año(Medido en UIT)';
$strings['max_expended_num'] = 'Limite anual de cursos en horas por año(Medido en UIT)';
$strings['max_course_times'] = 'Limite anual de cantidad de cursos por año';
$strings['check_induction'] = 'Activar requerimiento de curso inducción';
/* String for error message about requirements */
$strings['AdvancedSubscriptionNotConnected'] = "Usted no está conectado en la plataforma. Por favor ingrese su usuario / constraseña para poder inscribirse";
$strings['AdvancedSubscriptionProfileIncomplete'] = "Su perfil no es lo suficientemente completo para poder inscribirse al curso. Por favor complete su perfil";
$strings['AdvancedSubscriptionIncompleteInduction'] = "Usted aún no ha completado el curso de inducción. Por favor complete el curso inducción";
$strings['AdvancedSubscriptionCostXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s UIT para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionTimeXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s horas para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionCourseXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s cursos que ha seguido este año";
$strings['AdvancedSubscriptionNotMoreAble'] = "Lo sentimos, usted ya no cumple con las condiciones iniciales para poder inscribirse al curso";

@ -0,0 +1,21 @@
<?php
/* Strings for settings */
$strings['plugin_title'] = 'Inscripción Avanzada';
$strings['plugin_comment'] = 'Plugin que permite gestionar la inscripción en cola a sesiones con comunicación a a un portal externo';
$strings['uit_value'] = 'Valor de la Unidad Impositiva Tributaria (UIT)';
$strings['ws_url'] = 'URL del Webservice';
$strings['min_profile_percentage'] = 'Porcentaje mínimo de perfil completado';
$strings['max_expended_uit'] = 'Limite anual de cursos en UIT por año(Medido en UIT)';
$strings['max_expended_num'] = 'Limite anual de cursos en horas por año(Medido en UIT)';
$strings['max_course_times'] = 'Limite anual de cantidad de cursos por año';
$strings['check_induction'] = 'Activar requerimiento de curso inducción';
/* String for error message about requirements */
$strings['AdvancedSubscriptionNotConnected'] = "Usted no está conectado en la plataforma. Por favor ingrese su usuario / constraseña para poder inscribirse";
$strings['AdvancedSubscriptionProfileIncomplete'] = "Su perfil no es lo suficientemente completo para poder inscribirse al curso. Por favor complete su perfil";
$strings['AdvancedSubscriptionIncompleteInduction'] = "Usted aún no ha completado el curso de inducción. Por favor complete el curso inducción";
$strings['AdvancedSubscriptionCostXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s UIT para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionTimeXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s horas para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionCourseXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s cursos que ha seguido este año";
$strings['AdvancedSubscriptionNotMoreAble'] = "Lo sentimos, usted ya no cumple con las condiciones iniciales para poder inscribirse al curso";

@ -0,0 +1,21 @@
<?php
/* Strings for settings */
$strings['plugin_title'] = 'Inscripción Avanzada';
$strings['plugin_comment'] = 'Plugin que permite gestionar la inscripción en cola a sesiones con comunicación a a un portal externo';
$strings['uit_value'] = 'Valor de la Unidad Impositiva Tributaria (UIT)';
$strings['ws_url'] = 'URL del Webservice';
$strings['min_profile_percentage'] = 'Porcentaje mínimo de perfil completado';
$strings['max_expended_uit'] = 'Limite anual de cursos en UIT por año(Medido en UIT)';
$strings['max_expended_num'] = 'Limite anual de cursos en horas por año(Medido en UIT)';
$strings['max_course_times'] = 'Limite anual de cantidad de cursos por año';
$strings['check_induction'] = 'Activar requerimiento de curso inducción';
/* String for error message about requirements */
$strings['AdvancedSubscriptionNotConnected'] = "Usted no está conectado en la plataforma. Por favor ingrese su usuario / constraseña para poder inscribirse";
$strings['AdvancedSubscriptionProfileIncomplete'] = "Su perfil no es lo suficientemente completo para poder inscribirse al curso. Por favor complete su perfil";
$strings['AdvancedSubscriptionIncompleteInduction'] = "Usted aún no ha completado el curso de inducción. Por favor complete el curso inducción";
$strings['AdvancedSubscriptionCostXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s UIT para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionTimeXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s horas para los cursos que ha seguido este año";
$strings['AdvancedSubscriptionCourseXLimitReached'] = "Lo sentimos, usted ya ha alcanzado el límite anual de %s cursos que ha seguido este año";
$strings['AdvancedSubscriptionNotMoreAble'] = "Lo sentimos, usted ya no cumple con las condiciones iniciales para poder inscribirse al curso";

@ -0,0 +1,12 @@
<?php
/* For license terms, see /license.txt */
/**
* This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different).
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
* @package chamilo.plugin.advanced_subscription
*/
/**
* Plugin details (must be present)
*/
require_once __DIR__ . '/config.php';
$plugin_info = AdvancedSubscriptionPlugin::create()->get_info();

@ -0,0 +1,2 @@
Advanced subscription plugin<br/><br/>
@TODO: Complete readme.txt

@ -0,0 +1,286 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @TODO: Improve description
* This class is used to add an advanced subscription allowing the admin to
* create user queues requesting a subscribe to a session
* @package chamilo.plugin.advanced_subscription
*/
class AdvancedSubscriptionPlugin extends Plugin
{
/**
* Constructor
*/
function __construct()
{
$parameters = array(
'uit_value' => 'boolean',
'ws_url' => 'text',
'min_profile_percentage' => 'text',
'max_expended_uit' => 'text',
'max_expended_num' => 'text',
'max_course_times' => 'text',
'check_induction' => 'boolean',
'confirmation_message' => 'wysiwyg'
);
parent::__construct('1.0', 'Daniel Alejandro Barreto Alva', $parameters);
}
/**
* Instance the plugin
* @staticvar null $result
* @return AdvancedSubscriptionPlugin
*/
static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
/**
* Install the plugin
* @return void
*/
public function install()
{
$this->installDatabase();
}
/**
* Uninstall the plugin
* @return void
*/
public function uninstall()
{
$this->unistallDatabase();
}
/**
* Create the database tables for the plugin
* @return void
*/
private function installDatabase()
{
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL);
$pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE);
$pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS);
$sql = "CREATE TABLE IF NOT EXISTS $pAdvSubQueueTable (" .
"id int UNSIGNED NOT NULL AUTO_INCREMENT, " .
"session_id varchar(255) NOT NULL, " .
"user_id int UNSIGNED NOT NULL, " .
"status int UNSIGNED NOT NULL, " .
"created_at datetime NOT NULL, " .
"updated_at datetime NULL, " .
"PRIMARY KEY PK_tour_log (id)); ";
$sql .= "CREATE TABLE $pAdvSubMailTypeTable ( " .
"id int UNSIGNED NOT NULL AUTO_INCREMENT, " .
"description char(20), " .
"PRIMARY KEY PK_advsub_mail_type (id) " .
"); ";
$sql .= "CREATE TABLE $pAdvSubMailTable ( " .
"id int UNSIGNED NOT NULL AUTO_INCREMENT, " .
"message_id, mail_type_id, mail_status_id, " .
"PRIMARY KEY PK_advsub_mail (id) " .
"); ";
$sql .= "CREATE TABLE $pAdvSubMailStatusTable ( " .
"id int UNSIGNED NOT NULL AUTO_INCREMENT, " .
"description char(20), " .
"PRIMARY KEY PK_advsub_mail_status (id) " .
"); ";
echo $sql;
//Database::query($sql);
}
/**
* Drop the database tables for the plugin
* @return void
*/
private function unistallDatabase()
{
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL);
$pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE);
$pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS);
$sql = "DROP TABLE IF EXISTS $pAdvSubQueueTable; ";
$sql .= "DROP TABLE IF EXISTS $pAdvSubMailTable; ";
$sql .= "DROP TABLE IF EXISTS $pAdvSubMailTypeTable; ";
$sql .= "DROP TABLE IF EXISTS $pAdvSubMailStatusTable; ";
Database::query($sql);
}
/**
* Return true if user is able to be added to queue for session subscription
* @param $userId
* @throws Exception
* @return bool
*/
public function isAbleToRequest($userId)
{
$isAble = false;
$advSubPlugin = self::create();
$wsUrl = $advSubPlugin->get('ws_url');
// @TODO: Get connection status from user by WS
$isConnected = true;
if ($isConnected) {
$profileCompletedMin = $advSubPlugin->get('min_profile_percentage');
// @TODO: Get completed profile percentage by WS
$profileCompleted = 100.0;
if ($profileCompleted > $profileCompletedMin) {
$checkInduction = $advSubPlugin->get('check_induction');
// @TODO: check if user have completed at least one induction session
$completedInduction = true;
if (!$checkInduction || $completedInduction) {
$uitMax = $advSubPlugin->get('uit_value');
$uitMax *= $advSubPlugin->get('max_expended_uit');
// @TODO: Get UIT completed by user this year by WS
$uitUser = 0;
if ($uitMax > $uitUser) {
$expendedTimeMax = $advSubPlugin->get('max_expended_time');
// @TODO: Get Expended time from user data
$expendedTime = 0;
if ($expendedTimeMax > $expendedTime) {
$expendedNumMax = $advSubPlugin->get('max_expended_num');
// @TODO: Get Expended num from user
$expendedNum = 0;
if ($expendedNumMax > $expendedNum) {
$isAble = true;
} else {
throw new \Exception(get_lang('AdvancedSubscriptionCourseXLimitReached'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionTimeXLimitReached'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionCostXLimitReached'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionIncompleteInduction'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionProfileIncomplete'));
}
} else {
throw new \Exception(get_lang('AdvancedSubscriptionNotConnected'));
}
return $isAble;
}
/**
* @param $userId
* @param $sessionId
*/
public function addToQueue($userId, $sessionId)
{
$now = api_get_utc_datetime();
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$sql = "INSERT INTO $pAdvSubQueueTable ( " .
"session_id, user_id, status, created_at, updated_at " .
") VALUES ( " .
"$sessionId, $userId, 0, $now, NULL ";
"); ";
}
/**
* @param $userId
* @param $sessionId
* @return bool|string
*/
public function startSubscription($userId, $sessionId)
{
$result = false;
$advSub = self::create();
try {
if ($advSub->isAbleToRequest($userId)) {
$advSub->addToQueue($userId, $sessionId);
$result = true;
} else {
throw new \Exception(get_lang('AdvancedSubscriptionNotMoreAble'));
}
} catch (Exception $e) {
$result = $e->getMessage();
}
return $result;
}
/**
* Check whether the tour should be displayed to the user
* @param string $currentPageClass The class of the current page
* @param int $userId The user id
* @return boolean If the user has seen the tour return false, otherwise return true
*/
public function checkTourForUser($currentPageClass, $userId)
{
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL);
$pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE);
$pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS);
$pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG);
$checkResult = Database::select('count(1) as qty', $pluginTourLogTable, array(
'where' => array(
"page_class = '?' AND " => $currentPageClass,
"user_id = ?" => intval($userId)
)), 'first');
if ($checkResult !== false) {
if ($checkResult['qty'] > 0) {
return false;
}
}
return true;
}
/**
* Set the tour as seen
* @param string $currentPageClass The class of the current page
* @param int $userId The user id
* @return void
*/
public function saveCompletedTour($currentPageClass, $userId)
{
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL);
$pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE);
$pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS);
$pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG);
Database::insert($pluginTourLogTable, array(
'page_class' => $currentPageClass,
'user_id' => intval($userId),
'visualization_datetime' => api_get_utc_datetime()
));
}
/**
* Get the configuration to show the tour in pages
* @return array The config data
*/
public function getTourConfig()
{
$pAdvSubQueueTable = Database::get_main_table(TABLE_ADV_SUB_QUEUE);
$pAdvSubMailTable = Database::get_main_table(TABLE_ADV_SUB_MAIL);
$pAdvSubMailTypeTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_TYPE);
$pAdvSubMailStatusTable = Database::get_main_table(TABLE_ADV_SUB_MAIL_STATUS);
$pluginPath = api_get_path(PLUGIN_PATH) . 'tour/';
$jsonContent = file_get_contents($pluginPath . 'config/tour.json');
$jsonData = json_decode($jsonContent, true);
return $jsonData;
}
}

@ -0,0 +1,16 @@
<?php
/* For license terms, see /license.txt */
/**
* This script is included by main/admin/settings.lib.php when unselecting a plugin
* and is meant to remove things installed by the install.php script in both
* the global database and the courses tables
* @package chamilo.plugin.buycourses
*/
/**
* Queries
*/
require_once dirname(__FILE__) . '/config.php';
if (!api_is_platform_admin()) {
die ('You must have admin permissions to install plugins');
}
AdvancedSubscriptionPlugin::create()->uninstall();
Loading…
Cancel
Save