Skip to content
Permalink
Browse files

WIP: Adding AccumulateWorkTime (a.k.a lp min time) BT#15020

New conf setting: $_configuration['lp_minimum_time'] = false;
Code added "as is" from NSR
  • Loading branch information...
jmontoyaa committed Dec 5, 2018
1 parent d2c22a5 commit fe19616765fe16813c25e2d5f4014292e3d7fc09
@@ -1045,6 +1045,12 @@
// Improve speed when rendering gradebook student reports using Doctrine APCU cache
// $_configuration['gradebook_use_apcu_cache'] = true;
// Add a minimum time limit to be in the learning path
// in order to get the last item completed
// Requires a DB change:
// ALTER TABLE c_lp ADD accumulate_work_time INT NOT NULL;
//$_configuration['lp_minimum_time'] = false;
// ------ Custom DB changes (keep this at the end)
// Add user activation by confirmation email
// This option prevents the new user to login in the platform if your account is not confirmed via email
@@ -61,6 +61,7 @@ class learnpath
public $theme; // The current theme of the learning path.
public $preview_image; // The current image of the learning path.
public $accumulateScormTime; // Flag to decide whether to accumulate SCORM time or not
public $accumulateWorkTime; // The min time of learnpath
// Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
public $prevent_reinit = 1;
@@ -164,6 +165,7 @@ public function __construct($course, $lp_id, $user_id)
$this->ref = $row['ref'];
$this->categoryId = $row['category_id'];
$this->accumulateScormTime = isset($row['accumulate_scorm_time']) ? $row['accumulate_scorm_time'] : 'true';
$this->accumulateWorkTime = isset($row['accumulate_work_time']) ? $row['accumulate_work_time'] : 0;
if (!empty($row['publicated_on'])) {
$this->publicated_on = $row['publicated_on'];
@@ -2404,6 +2406,55 @@ public static function isBlockedByPrerequisite(
if ($progress < 100) {
$isBlocked = true;
}
// ## NSR - bloquear si no supera tiempo minimo
// TL --- Tiempo minimo para superar la lección ( en minutos )
$accumulateWorkTime = self::getAccumulateWorkTimePrerequisite($prerequisite, $courseInfo['real_id']);
if ($accumulateWorkTime > 0) {
// TT --- Tiempo total del curso
$accumulateWorkTimeTotal = self::getAccumulateWorkTimeTotal($courseInfo['real_id']);
// P y TC --- Conectamos con la tabla plugin_licences_course_session en la que se indica que porcentaje del tiempo se aplica
$perc = 100;
$tc = $accumulateWorkTimeTotal;
if (!empty($sessionId) && $sessionId != 0) {
$sql = "SELECT hours, perc FROM plugin_licences_course_session WHERE session_id = $sessionId";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$aux = Database::fetch_assoc($res);
$perc = $aux['perc'];
$tc = $aux['hours'] * 60;
}
}
// PL --- Porcentaje lección (tiempo leccion / tiempo total curso)
$pl = $accumulateWorkTime / $accumulateWorkTimeTotal;
/*
* TL: Tiempo que pone en una lección
* TT : tiempo total que pone Teresa (suma tiempos lecciones curso)
* PL: Fracción que supone una lección sobre el tiempo total = TL/TT
* TC: Tiempo que dice el cliente que tiene el curso
* P: porcentaje mínimo conexión que indica el cliente
*
* el tiempo mínimo de cada lección sería: PL x TC x P /100
*/
$accumulateWorkTime = ($pl * $tc * $perc / 100);
// Tiempo empleado hasta el momento en la leccion ( en segundos )
$lpTime = Tracking::get_time_spent_in_lp(
$studentId,
$courseInfo['code'],
array($prerequisite),
$sessionId
);
if ($lpTime < ($accumulateWorkTime * 60)) {
$isBlocked = true;
}
}
}
return $isBlocked;

return '';
}

/**
* Get whether this is a learning path with the accumulated work time or not
* @return int
*/
public function getAccumulateWorkTime()
{
return $this->accumulateWorkTime;
}

/**
* Get whether this is a learning path with the accumulated work time or not
* @return int
*/
public function getAccumulateWorkTimeTotalCourse()
{
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "SELECT SUM(accumulate_work_time) AS tt FROM $lp_table WHERE c_id = ".$this->course_int_id;
$result = Database::query($sql);
$myrow = Database::fetch_array($result);
return $myrow['tt'];
}

/**
* Set whether this is a learning path with the accumulated work time or not
* @param int $value (0 = false, 1 = true)
* @return bool Always returns true
*/
public function setAccumulateWorkTime($value)
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::setAccumulateScormTime()', 0);
}
$this->accumulateWorkTime = intval($value);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET accumulate_work_time = ".$this->accumulateWorkTime."
WHERE c_id = ".$this->course_int_id." AND id = $lp_id";
Database::query($sql);

return true;
}

public function getAccumulateWorkTimePrerequisite($lp_id, $c_id)
{
$lp_id = intval($lp_id);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT accumulate_work_time
FROM $lp_table
WHERE c_id = ".$c_id." AND id = $lp_id";
$result = Database::query($sql);
$myrow = Database::fetch_array($result);

return $myrow['accumulate_work_time'];
}

public function getAccumulateWorkTimeTotal($c_id)
{
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT SUM(accumulate_work_time) AS tt
FROM $lp_table
WHERE c_id = ".$c_id;
$result = Database::query($sql);
$myrow = Database::fetch_array($result);

return $myrow['tt'];
}
}
@@ -217,10 +217,62 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
"olms.lms_item_core_exit = '".$mycore_exit."';".
"olms.asset_timer = 0;";
$timeLp = $mylp->getAccumulateWorkTime();
$timeTotalCourse = $mylp->getAccumulateWorkTimeTotalCourse();
$perc = 100;
$tc = $timeTotalCourse;
$sessionId = api_get_session_id();
if (!empty($sessionId) && $sessionId != 0) {
/*$sql = "SELECT hours, perc FROM plugin_licences_course_session WHERE session_id = $sessionId";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$aux = Database::fetch_assoc($res);
$perc = $aux['perc'];
$tc = $aux['hours'] * 60;
}*/
}
// PL --- Porcentaje lección (tiempo leccion / tiempo total curso)
$pl = $timeLp / $timeTotalCourse;
/*
* TL: Tiempo que pone en una lección
* TT : tiempo total que pone Teresa (suma tiempos lecciones curso)
* PL: Fracción que supone una lección sobre el tiempo total = TL/TT
* TC: Tiempo que dice el cliente que tiene el curso
* P: porcentaje mínimo conexión que indica el cliente
*
* el tiempo mínimo de cada lección sería: PL x TC x P /100
*/
// Aplicamos el porcentaje si no hubiese definido un porcentaje por defecto es 100%
$time_total = intval($pl * $tc * $perc / 100) * 60;
//$time_total = $mylp->getAccumulateWorkTime() * 60;
$lpTime = Tracking::get_time_spent_in_lp(
$user_id,
api_get_course_id(),
array($lp_id),
api_get_session_id()
);
if ($lpTime >= $time_total) {
$time_spent = $time_total;
} else {
$time_spent = $lpTime;
}
$hour = (intval($lpTime/3600)) < 10 ? '0'.intval($lpTime/3600) : intval($lpTime/3600);
$minute = date("i", $lpTime);
$second = date("s", $lpTime);
$return .= "update_toc('unhighlight','".$current_item."');".
"update_toc('highlight','".$new_item_id."');".
"update_toc('$mylesson_status','".$new_item_id."');".
"update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
"update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');".
"update_time_bar('$time_spent','$time_total','%');".
"update_cronometro('$hour','$minute','$second');";
$return .= 'updateGamificationValues(); ';
$mylp->set_error_msg('');
@@ -1029,12 +1029,9 @@ function(reponse) {
$hide_toc_frame = null;
}
$_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
$_SESSION['oLP']->set_prerequisite(
isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0
);
$_SESSION['oLP']->set_use_max_score(
isset($_POST['use_max_score']) ? 1 : 0
);
$_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
$_SESSION['oLP']->setAccumulateWorkTime($_REQUEST['accumulate_work_time']);
$_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
$subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
$_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
@@ -156,8 +156,17 @@ function activate_end_date() {
$form->addElement('html', $items);
$form->addElement('html', '<div class="help-block">'.get_lang('LpPrerequisiteDescription').'</div>');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-2"></div>');
$form->addElement('html', '</div>');
// Time Control
$accumulateTime = $_SESSION['oLP']->getAccumulateWorkTime();
$items = '<input size="10" class="form-control" name="accumulate_work_time" type="text" value="'.$accumulateTime.'">';
$form->addElement('html', '<div class="form-group">');
$form->addElement('html', '<label class="col-md-2 control-label" style="margin-top:-10px">'.get_lang('LearnpathTimeIn').'</label>');
$form->addElement('html', '<div class="col-md-2">');
$form->addElement('html', $items);
$form->addElement('html', '</div><div class="col-md-8">');
$form->addElement('html', '<div class="help-block">'.get_lang('LpAccumulateTimeDescription').'</div></div></div>');
//Start date
$form->addElement(
'checkbox',
@@ -392,6 +392,82 @@ function confirmation(name) {
}
}
// ## NSR
if ($progress < 100) {
$ending = false;
}
// ## NSR
// Time info
// TL --- Tiempo minimo para superar la lección ( en minutos )
$accumulateWorkTime = learnpath::getAccumulateWorkTimePrerequisite($id, api_get_course_int_id());
if ($accumulateWorkTime > 0) {
// TT --- Tiempo total del curso
$accumulateWorkTimeTotal = learnpath::getAccumulateWorkTimeTotal(api_get_course_int_id());
// Tiempo empleado hasta el momento en la leccion ( en segundos )
$lpTime = Tracking::get_time_spent_in_lp(
$userId,
api_get_course_id(),
array($id),
api_get_session_id()
);
// Conectamos con la tabla plugin_licences_course_session en la que se indica que porcentaje del tiempo se aplica
$perc = 100;
$tc = $accumulateWorkTimeTotal;
/*if (!empty($current_session) && $current_session != 0) {
$sql = "SELECT hours, perc FROM plugin_licences_course_session WHERE session_id = $current_session";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$aux = Database::fetch_assoc($res);
$perc = $aux['perc'];
$tc = ($aux['hours'] * 60);
}
}*/
// PL --- Porcentaje lección (tiempo leccion / tiempo total curso)
$pl = $accumulateWorkTime / $accumulateWorkTimeTotal;
/*
* TL: Tiempo que pone en una lección
* TT : tiempo total que pone Teresa (suma tiempos lecciones curso)
* PL: Fracción que supone una lección sobre el tiempo total = TL/TT
* TC: Tiempo que dice el cliente que tiene el curso
* P: porcentaje mínimo conexión que indica el cliente
*
* el tiempo mínimo de cada lección sería: PL x TC x P /100
*/
// Aplicamos el porcentaje si no hubiese definido un porcentaje por defecto es 100%
$accumulateWorkTime = ($pl * $tc * $perc / 100);
// Si el tiempo empleado es menor que lo necesario mostramos un icono en la columna de acción indicando la advertencia
$dsp_accumulateWorkTime = '';
if ($lpTime < ($accumulateWorkTime*60)) {
$dsp_accumulateWorkTime = Display::return_icon('warning.png', get_lang('LpMessageTimeMin').' - '.api_time_to_hms($lpTime).' / '.api_time_to_hms($accumulateWorkTime*60)).'<b>'.api_time_to_hms($lpTime).' / '.api_time_to_hms($accumulateWorkTime*60).'</b>';
}
// Calculamos el porcentaje superado del tiempo para la barra de "superacion de tiempo mínimo"
if ($lpTime >= ($accumulateWorkTime*60)) {
$time_progress_perc = '100%';
$time_progress_value = 100;
} else {
$time_progress_value = intval(($lpTime * 100) / ($accumulateWorkTime*60));
}
// ## NSR
if ($time_progress_value < 100) {
$ending = false;
}
$dsp_time = learnpath::get_progress_bar($time_progress_value, '%');
} else {
$dsp_time = '';
$dsp_accumulateWorkTime = '';
}
$token_parameter = "&sec_token=$token";
$dsp_edit_lp = null;
$dsp_publish = null;
@@ -893,6 +969,7 @@ function confirmation(name) {
'action_subscribe_users' => $subscribeUsers,
'action_update_scorm' => $actionUpdateScormFile,
'action_export_to_course_build' => $actionExportToCourseBuild,
'info_time_prerequisite' => $dsp_accumulateWorkTime,
];
$lpIsShown = true;

0 comments on commit fe19616

Please sign in to comment.
You can’t perform that action at this time.