diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 0a2795226d..b03e7b6b2f 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -4981,6 +4981,51 @@ class learnpath return false; } + /** + * Update the last progress only in case + * + */ + public function updateLpProgress() + { + $debug = $this->debug; + if ($debug) { + error_log('In learnpath::updateLpProgress()', 0); + } + $sessionCondition = api_get_session_condition( + api_get_session_id(), + true, + false + ); + $courseId = api_get_course_int_id(); + $userId = $this->get_user_id(); + $table = Database::get_course_table(TABLE_LP_VIEW); + + [$progress] = $this->get_progress_bar_text('%'); + if ($progress >= 0 && $progress <= 100) { + // Check database. + $progress = (int) $progress; + $sql = "UPDATE $table SET + progress = $progress + WHERE + c_id = $courseId AND + lp_id = ".$this->get_id()." AND + user_id = ".$userId." ".$sessionCondition; + // Ignore errors as some tables might not have the progress field just yet. + Database::query($sql); + if ($debug) { + error_log($sql); + } + $this->progress_db = $progress; + + if (100 == $progress) { + HookLearningPathEnd::create() + ->setEventData(['lp_view_id' => $this->lp_view_id]) + ->hookLearningPathEnd(); + } + } + + } + /** * Saves the last item seen's ID only in case. */ diff --git a/main/lp/learnpathItem.class.php b/main/lp/learnpathItem.class.php index a1997c97a7..c459975279 100755 --- a/main/lp/learnpathItem.class.php +++ b/main/lp/learnpathItem.class.php @@ -4070,6 +4070,9 @@ class learnpathItem } } + // It updates the last progress only in case. + $_SESSION['oLP']->updateLpProgress(); + if ($debug) { error_log('End of learnpathItem::write_to_db()', 0); }