Save the last visualization of web page - refs #7279

1.9.x
Angel Fernando Quiroz Campos 11 years ago
parent 61d6071423
commit 651363fc6f
  1. 22
      plugin/tour/ajax/save.ajax.php
  2. 2
      plugin/tour/config.php
  3. 12
      plugin/tour/index.php
  4. 57
      plugin/tour/src/tour_plugin.class.php
  5. 56
      plugin/tour/views/script.tpl

@ -0,0 +1,22 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Get the intro steps for the web page
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.tour
*/
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/main/inc/global.inc.php';
require_once dirname((__DIR__)) . '/config.php';
if (!api_is_anonymous()) {
$currentPageClass = isset($_POST['page_class']) ? $_POST['page_class'] : '';
if (!empty($currentPageClass)) {
$userId = api_get_user_id();
$tourPlugin = Tour::create();
$tourPlugin->saveCompletedTour($currentPageClass, $userId);
}
}

@ -9,6 +9,8 @@
*/
//require_once '../../main/inc/global.inc.php';
define('TABLE_TOUR_LOG', 'plugin_tour_log');
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) . 'tour/src/tour_plugin.class.php';

@ -12,6 +12,8 @@ require_once dirname(__FILE__) . '/config.php';
$pluginPath = api_get_path(PLUGIN_PATH) . 'tour/';
$pluginWebPath = api_get_path(WEB_PLUGIN_PATH) . 'tour/';
$userId = api_get_user_id();
$tourPlugin = Tour::create();
$jsonContent = file_get_contents($pluginPath . 'config/tour.json');
@ -21,16 +23,20 @@ $json = json_decode($jsonContent, true);
$pages = array();
foreach ($json as $pageContent) {
$pages[] = $pageContent['pageClass'];
$pages[] = array(
'pageClass' => $pageContent['pageClass'],
'show' => $tourPlugin->checkTourForUser($pageContent['pageClass'], $userId)
);
}
$_template['pagesClassName'] = json_encode($pages);
$_template['pages'] = json_encode($pages);
$_template['web_path'] = array(
'intro_css' => "{$pluginWebPath}intro.js/introjs.min.css",
'intro_theme_css' => "{$pluginWebPath}intro.js/introjs-nassim.css",
'intro_js' => "{$pluginWebPath}intro.js/intro.min.js",
'steps_ajax' => "{$pluginWebPath}ajax/steps.ajax.php"
'steps_ajax' => "{$pluginWebPath}ajax/steps.ajax.php",
'save_ajax' => "{$pluginWebPath}ajax/save.ajax.php"
);
$_template['text'] = array(

@ -37,12 +37,65 @@ class Tour extends Plugin
public function install()
{
$this->installDatabase();
}
public function uninstall()
{
$this->unistallDatabase();
}
private function installDatabase()
{
$pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG);
$sql = "CREATE TABLE IF NOT EXISTS $pluginTourLogTable ("
. "id int UNSIGNED NOT NULL AUTO_INCREMENT, "
. "page_class varchar(255) NOT NULL, "
. "user_id int UNSIGNED NOT NULL, "
. "visualization_datetime datetime NOT NULL, "
. "PRIMARY KEY PK_tour_log (id))";
Database::query($sql);
}
private function unistallDatabase()
{
$pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG);
$sql = "DROP TABLE IF EXISTS $pluginTourLogTable";
Database::query($sql);
}
public function checkTourForUser($currentPageClass, $userId)
{
$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 = ?" => $userId
)), 'first');
if ($checkResult != false) {
if ($checkResult['qty'] > 0) {
return false;
}
}
return true;
}
public function saveCompletedTour($currentPageClass, $userId)
{
$pluginTourLogTable = Database::get_main_table(TABLE_TOUR_LOG);
Database::insert($pluginTourLogTable, array(
'page_class' => $currentPageClass,
'user_id' => $userId,
'visualization_datetime' => api_get_utc_datetime()
));
}
}

@ -1,19 +1,30 @@
<script type="text/javascript">
var chamiloTour = (function() {
var intro = null;
var currentPageClass = '';
var $btnStart = null;
return {
init: function() {
init: function(pageClass) {
currentPageClass = pageClass;
intro = introJs();
intro.oncomplete(function () {
$.post('{{ tour.web_path.save_ajax }}', {
page_class: currentPageClass
}, function () {
$btnStart.remove();
});
});
},
showStartButton: function(pageClassName) {
$('<button>', {
showStartButton: function() {
$btnStart = $('<button>', {
class: 'btn btn-primary btn-large',
text: '{{ tour.text.start_button }}',
click: function(e) {
e.preventDefault();
var promise = chamiloTour.setSteps(pageClassName);
var promise = chamiloTour.setSteps(currentPageClass);
$.when(promise).done(function (data) {
intro.start();
@ -21,9 +32,9 @@
}
}).appendTo('#tour-button-cotainer');
},
setSteps: function(pageClassName) {
setSteps: function() {
return $.getJSON('{{ tour.web_path.steps_ajax }}', {
'page_class': pageClassName
'page_class': currentPageClass
}, function(response) {
intro.setOptions({
steps: response,
@ -38,27 +49,26 @@
})();
$(document).on('ready', function() {
$('<link>', {
href: '{{ tour.web_path.intro_css }}',
rel: 'stylesheet'
}).appendTo('head');
var pages = {{ tour.pages }};
$('<link>', {
href: '{{ tour.web_path.intro_theme_css }}',
rel: 'stylesheet'
}).appendTo('head');
$.each(pages, function(index, page) {
var thereIsSelectedPage = $(page.pageClass).length > 0;
$.getScript('{{ tour.web_path.intro_js }}', function() {
chamiloTour.init();
});
var pagesClassName = {{ tour.pagesClassName }};
if (thereIsSelectedPage && page.show) {
$('<link>', {
href: '{{ tour.web_path.intro_css }}',
rel: 'stylesheet'
}).appendTo('head');
$.each(pagesClassName, function(index, className) {
var thereIsSelectedPage = $(className).length > 0;
$('<link>', {
href: '{{ tour.web_path.intro_theme_css }}',
rel: 'stylesheet'
}).appendTo('head');
if (thereIsSelectedPage) {
chamiloTour.showStartButton(className);
$.getScript('{{ tour.web_path.intro_js }}', function() {
chamiloTour.init(page.pageClass);
chamiloTour.showStartButton(page.pageClass);
});
}
});
});

Loading…
Cancel
Save