Skip to content

Commit

Permalink
Update LP view using lp min time BT#15020
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Dec 5, 2018
1 parent cebc8e0 commit 85e1093
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 245 deletions.
157 changes: 88 additions & 69 deletions main/lp/learnpath.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2407,54 +2407,54 @@ public static function isBlockedByPrerequisite(
$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;
if (api_get_configuration_value('lp_minimum_time')) {
// ## 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
);
// 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;
if ($lpTime < ($accumulateWorkTime * 60)) {
$isBlocked = true;
}
}
}


}

return $isBlocked;
Expand Down Expand Up @@ -14006,56 +14006,75 @@ public function getAccumulateWorkTime()
*/
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;
$table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT SUM(accumulate_work_time) AS total
FROM $table
WHERE c_id = ".$this->course_int_id;
$result = Database::query($sql);
$myrow = Database::fetch_array($result);
return $myrow['tt'];
$row = Database::fetch_array($result);

return (int) $row['total'];
}

/**
* 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
*
* @return bool
*/
public function setAccumulateWorkTime($value)
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::setAccumulateScormTime()', 0);
if (!api_get_configuration_value('lp_minimum_time')) {
return false;
}
$this->accumulateWorkTime = intval($value);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);

$this->accumulateWorkTime = (int) $value;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET accumulate_work_time = ".$this->accumulateWorkTime."
$sql = "UPDATE $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)
/**
* @param int $lpId
* @param int $courseId
*
* @return mixed
*/
public static function getAccumulateWorkTimePrerequisite($lpId, $courseId)
{
$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";
$lpId = (int) $lpId;
$courseId = (int) $courseId;

$table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT accumulate_work_time
FROM $table
WHERE c_id = $courseId AND id = $lpId";
$result = Database::query($sql);
$myrow = Database::fetch_array($result);
$row = Database::fetch_array($result);

return $myrow['accumulate_work_time'];
return $row['accumulate_work_time'];
}

public function getAccumulateWorkTimeTotal($c_id)
/**
* @param int $courseId
*
* @return int
*/
public static function getAccumulateWorkTimeTotal($courseId)
{
$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;
$table = Database::get_course_table(TABLE_LP_MAIN);
$courseId = (int) $courseId;
$sql = "SELECT SUM(accumulate_work_time) AS total
FROM $table
WHERE c_id = $courseId";
$result = Database::query($sql);
$myrow = Database::fetch_array($result);
$row = Database::fetch_array($result);

return $myrow['tt'];
return (int) $row['total'];
}
}
92 changes: 49 additions & 43 deletions main/lp/lp_ajax_switch_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,58 +220,64 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
$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;
}*/
}
$updateMinTime = '';
if (api_get_configuration_value('lp_minimum_time')) {
$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;
// 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;
/*
* 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()
);

//$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;
}

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);
$updateMinTime = "update_time_bar('$time_spent','$time_total','%');".
"update_cronometro('$hour','$minute','$second');";
}

$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."');".
$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_time_bar('$time_spent','$time_total','%');".
"update_cronometro('$hour','$minute','$second');";
$updateMinTime
;

$return .= 'updateGamificationValues(); ';

Expand Down
22 changes: 21 additions & 1 deletion main/lp/lp_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ function(reponse) {
error_log('Entered lp_controller.php -+- (action: '.$action.')');
}

// ## NSR - log
$lp_id = (!empty($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0);
switch ($action) {
case 'view':
case 'content':
$lp_detail_id = $_SESSION['oLP']->get_current_item_id();
break;
default:
$lp_detail_id = (!empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0);
}

$logInfo = [
'tool' => TOOL_LEARNPATH,
'tool_id' => $lp_id,
'tool_id_detail' => $lp_detail_id,
'action' => !empty($action) ? $action : 'list',
'info' => '',
];
Event::registerLog($logInfo);

// format title to be displayed correctly if QUIZ
$post_title = '';
if (isset($_POST['title'])) {
Expand Down Expand Up @@ -1030,7 +1050,7 @@ function(reponse) {
}
$_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
$_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
$_SESSION['oLP']->setAccumulateWorkTime($_REQUEST['accumulate_work_time']);
$_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
$_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);

$subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
Expand Down
17 changes: 8 additions & 9 deletions main/lp/lp_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +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>');
if (api_get_configuration_value('lp_minimum_time')) {
$accumulateTime = $_SESSION['oLP']->getAccumulateWorkTime();
$form->addText('accumulate_work_time', [get_lang('LearnpathTimeIn'), get_lang('LpAccumulateTimeDescription')]);
$defaults['accumulate_work_time'] = $accumulateTime;
}

//Start date
// Start date
$form->addElement(
'checkbox',
'activate_start_date_check',
Expand Down
Loading

0 comments on commit 85e1093

Please sign in to comment.