Integrate Advanced Session in the core - refs BT#9049

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent ced56e27fc
commit 3512ea4f7c
  1. 12
      main/admin/resume_session.php
  2. 6
      main/admin/session_add.php
  3. 8
      main/admin/session_edit.php
  4. 10
      main/auth/courses_controller.php
  5. 4
      main/inc/ajax/session.ajax.php
  6. 58
      main/inc/lib/sessionmanager.lib.php
  7. 1
      main/install/db_main.sql
  8. 1
      main/install/migrate-db-1.9.0-1.10.0-pre.sql
  9. 10
      main/session/index.php
  10. 10
      plugin/advancedsessions/config.php
  11. 10
      plugin/advancedsessions/install.php
  12. 3
      plugin/advancedsessions/lang/english.php
  13. 10
      plugin/advancedsessions/plugin.php
  14. 151
      plugin/advancedsessions/src/AdvancedSessionsPlugin.class.php
  15. 10
      plugin/advancedsessions/uninstall.php

@ -245,17 +245,15 @@ if (SessionManager::durationPerUserIsEnabled()) {
}
?>
<?php
if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
$sessionDescription = AdvancedSessionsPlugin::getSessionDescription($sessionId);
$sessionDescription = SessionManager::getSessionDescription($sessionId);
if (!empty($sessionDescription)) {
?>
if (!empty($sessionDescription)) {
?>
<tr>
<td><?php echo get_lang('Description'); ?></td>
<td><?php echo AdvancedSessionsPlugin::getSessionDescription($sessionId) ?></td>
<td><?php echo $sessionDescription ?></td>
</tr>
<?php
}
<?php
}
?>
</table>

@ -139,9 +139,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
);
if ($return == strval(intval($return))) {
if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
AdvancedSessionsPlugin::saveSessionFieldValue($return, $_POST['description']);
}
SessionManager::saveSessionDescription($return, $_POST['description']);
// integer => no error on session creation
header('Location: add_courses_to_session.php?id_session='.$return.'&add=true&msg=');
@ -231,7 +229,6 @@ $Categories = SessionManager::get_all_session_category();
?>
</div>
</div>
<?php if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) { ?>
<div class="control-group">
<label class="control-label" for="description"><?php echo get_lang('Description') ?></label>
<div class="controls">
@ -240,7 +237,6 @@ $Categories = SessionManager::get_all_session_category();
<?php echo $fckEditor->CreateHtml(); ?>
</div>
</div>
<?php } ?>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionCategory') ?>

@ -102,9 +102,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
);
if ($return == strval(intval($return))) {
if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
AdvancedSessionsPlugin::saveSessionFieldValue($return, $_POST['description']);
}
SessionManager::saveSessionDescription($return, $_POST['description']);
header('Location: resume_session.php?id_session='.$return);
exit();
@ -165,17 +163,15 @@ if (!empty($return)) {
</select>
</div>
</div>
<?php if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) { ?>
<div class="control-group">
<label class="control-label" for="description"><?php echo get_lang('Description') ?></label>
<div class="controls">
<?php $fckEditor = new FCKeditor('description'); ?>
<?php $fckEditor->ToolbarSet = 'TrainingDescription'; ?>
<?php $fckEditor->Value = AdvancedSessionsPlugin::getSessionDescription($id) ; ?>
<?php $fckEditor->Value = SessionManager::getSessionDescription($id) ; ?>
<?php echo $fckEditor->CreateHtml(); ?>
</div>
</div>
<?php } ?>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionCategory') ?>

@ -546,12 +546,6 @@ class CoursesController
// Get session search catalogue URL
$courseUrl = getCourseCategoryUrl(1, $limit['length'], null, 0, 'subscribe');
$showDescription = false;
if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
$showDescription = true;
}
foreach ($sessions as $session) {
$sessionsBlock = array(
'id' => $session['id'],
@ -566,13 +560,11 @@ class CoursesController
'hasDescription' => false
);
if ($showDescription) {
$sessionDescription = AdvancedSessionsPlugin::getSessionDescription($session['id']);
$sessionDescription = SessionManager::getSessionDescription($session['id']);
if (!empty($sessionDescription)) {
$sessionsBlock['hasDescription'] = true;
}
}
$sessionsBlocks[] = $sessionsBlock;
}

@ -109,19 +109,17 @@ switch ($action) {
case 'get_description':
$sessionId = intval($_GET['session']);
if (AdvancedSessionsPlugin::hasDescriptionField()) {
$sessionInfo = api_get_session_info($sessionId);
?>
<h2><?php echo $sessionInfo['name'] ?></h2><br>
<div class="home-course-intro">
<div class="page-course">
<div class="page-course-intro">
<p><?php echo AdvancedSessionsPlugin::getSessionDescription($sessionId) ?></p>
<p><?php echo SessionManager::getSessionDescription($sessionId) ?></p>
</div>
</div>
</div>
<?php
}
default:
echo '';
}

@ -5399,4 +5399,62 @@ class SessionManager
return false;
}
/**
* Get the session description
* @param int $sessionId The session id
* @return string The session description. Otherwise return null
*/
public static function getSessionDescription($sessionId)
{
$sessionId = intval($sessionId);
$fieldValue = new ExtraFieldValue('session');
$description = $fieldValue->get_values_by_handler_and_field_variable($sessionId, 'description', false);
return $description !== false ? trim($description['field_value']) : '';
}
/**
* Whether the session has not description extra field insert a new record. Otherwise update the record
* @param int $sessionId The session id
* @param string $description The session description
* @return void
*/
public static function saveSessionDescription($sessionId, $description)
{
$sessionId = intval($sessionId);
$fieldValuesTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$fieldValue = new ExtraFieldValue('session');
$descriptionValue = $fieldValue->get_values_by_handler_and_field_variable($sessionId, 'description', false);
if ($descriptionValue === false) {
$sessionField = new ExtraField('session');
$fieldInfo = $sessionField->get_handler_field_info_by_field_variable('description');
if (empty($fieldInfo)) {
return;
}
$attributes = array(
'session_id' => $sessionId,
'field_id' => $fieldInfo['id'],
'field_value' => $description,
'tms' => api_get_utc_datetime()
);
Database::insert($fieldValuesTable, $attributes);
} else {
$attributes = array(
'field_value' => $description,
'tms' => api_get_utc_datetime()
);
Database::update($fieldValuesTable, $attributes, array(
'id = ?' => $descriptionValue['id']
));
}
}
}

@ -3027,3 +3027,4 @@ CREATE TABLE usergroup_rel_question (
);
-- 1.10.x-specific, non-course-related, database changes
INSERT INTO session_field (field_type, field_variable, field_display_text, field_default_value) values (2, 'description','Description', NULL);

@ -13,6 +13,7 @@
-- This first part is for the main database
-- xxMAINxx
INSERT INTO session_field (field_type, field_variable, field_display_text, field_default_value) values (2, 'description','Description', NULL);

@ -354,11 +354,10 @@ if (!empty($start) && !empty($end)) {
echo Display::tag('h1', $session_info['name']);
echo $dates.'<br />';
if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
$sessionDescription = AdvancedSessionsPlugin::getSessionDescription($session_id);
$sessionDescription = SessionManager::getSessionDescription($session_id);
if (!empty($sessionDescription)) {
?>
if (!empty($sessionDescription)) {
?>
<div class="home-course-intro">
<div class="page-course">
<div class="page-course-intro">
@ -366,8 +365,7 @@ if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescrip
</div>
</div>
</div>
<?php
}
<?php
}
// All Learnpaths grid settings (First tab, first subtab)

@ -1,10 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.advancedSessions
*/
require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php';
require_once api_get_path(PLUGIN_PATH) . 'advancedsessions/src/AdvancedSessionsPlugin.class.php';

@ -1,10 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Plugin Installation
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.advancedSessions
*/
require_once __DIR__ . '/config.php';
AdvancedSessionsPlugin::create()->install();

@ -1,3 +0,0 @@
<?php
$strings['plugin_title'] = "Advanced Sessions";
$strings['plugin_comment'] = "Add a session extra field for to set a session description";

@ -1,10 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show the JavaScript template in the web pages
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.advancedSessions
*/
require_once __DIR__.'/config.php';
$plugin_info = AdvancedSessionsPlugin::create()->get_info();

@ -1,151 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* The Advanced Session allow add sessions' extra fields
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.advancedSessions
*/
class AdvancedSessionsPlugin extends Plugin
{
const FIELD_NAME = 'advsess_description';
const FIELD_TITLE = 'AdvSessDescription';
/**
* Class constructor
*/
protected function __construct()
{
parent::__construct('1.0', 'Angel Fernando Quiroz Campos');
}
/**
* Instance the plugin
* @staticvar null $result
* @return Tour
*/
static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
/**
* Install the plugin
* @return void
*/
public function install()
{
$this->createSessionFields();
}
/**
* Uninstall the plugin
* @return void
*/
public function uninstall()
{
$this->removeSessionFields();
}
/**
* Create the extra field for session description
*/
private function createSessionFields()
{
SessionManager::create_session_extra_field(self::FIELD_NAME, ExtraField::FIELD_TYPE_TEXTAREA, self::FIELD_TITLE);
}
/**
* Remove the extra field for session description
*/
private function removeSessionFields()
{
$sessionField = new ExtraField('session');
$fieldInfo = $sessionField->get_handler_field_info_by_field_variable(self::FIELD_NAME);
if (!empty($fieldInfo)) {
$sessionField->delete($fieldInfo['id']);
}
}
/**
* Get the extra field information
* @return array
*/
public static function getFieldInfo()
{
$sessionField = new ExtraField('session');
$fieldInfo = $sessionField->get_handler_field_info_by_field_variable(self::FIELD_NAME);
return $fieldInfo;
}
/**
* Check whether the session extra field for description exists
* @return boolean
*/
public static function hasDescriptionField()
{
$fieldInfo = self::getFieldInfo();
return empty($fieldInfo) ? false : true;
}
/**
* Whether the session has not description extra field insert a new record. Otherwise update the record
* @param int $id The session id
* @param string $description The session description
* @return void
*/
public static function saveSessionFieldValue($id, $description)
{
$id = intval($id);
$fieldValuesTable = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$fieldValue = new ExtraFieldValue('session');
$descriptionValue = $fieldValue->get_values_by_handler_and_field_variable($id, self::FIELD_NAME, false);
if ($descriptionValue === false) {
$fieldInfo = self::getFieldInfo();
if (empty($fieldInfo)) {
return;
}
$attributes = array(
'session_id' => $id,
'field_id' => $fieldInfo['id'],
'field_value' => $description,
'tms' => api_get_utc_datetime()
);
Database::insert($fieldValuesTable, $attributes);
} else {
$attributes = array(
'field_value' => $description,
'tms' => api_get_utc_datetime()
);
Database::update($fieldValuesTable, $attributes, array(
'id = ?' => $descriptionValue['id']
));
}
}
/**
* Get the session description
* @param int $sessionId The session id
* @return string The session description. Otherwise return null
*/
public static function getSessionDescription($sessionId) {
$sessionId = intval($sessionId);
$fieldValue = new ExtraFieldValue('session');
$description = $fieldValue->get_values_by_handler_and_field_variable($sessionId, self::FIELD_NAME, false);
return $description !== false ? trim($description['field_value']) : '';
}
}

@ -1,10 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Plugin Uninstallation
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.advancedSessions
*/
require_once __DIR__ . '/config.php';
AdvancedSessionsPlugin::create()->uninstall();
Loading…
Cancel
Save