The Elearning Community • Competencies Not Working For Classroom Course - Page 3
Page 3 of 4

Re: Competencies Not Working For Classroom Course

Posted: Thu Mar 04, 2021 9:30 pm
by alfa24
I'm not seeing steps to reproduce, so your posts are just a diary of your tests.

Re: Competencies Not Working For Classroom Course

Posted: Thu Mar 04, 2021 10:21 pm
by scubatricky
Thanks alfa24, suffice to say the code you posted previously updates the DB correctly, but somewhere else in the system is resetting the date automatically straight after the update. This can be watched with a trace on the DB field when running the code.

I'll continue debugging the code and find out what else is changing the field back to the Now() value.

The help is appreciated, I'll search an alternative solution.

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 10:46 am
by alfa24
Problem found.
call to CompetencesAdm->assignCompetenceUsers is not accepting date parameter (it will set always NOW).
The function is called by CompetencesAdm->assignCourseCompetencesToUser.

The solution requires some more analysis, but I'm on it.

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 11:32 am
by alfa24
Give it a try:

in /appCore/models/CompetencesAdm.php

rewrite function assignCompetenceUsers as follows:

Code: Select all

public function assignCompetenceUsers($id_competence, $users, $track = false, $completion_date = false) {
		if ($id_competence <= 0) return false; //invalid competence
		if (count($users) <= 0) return true; //0 users operations always "successfull"

		//set insert values for query
		$values = array();
		foreach ($users as $id_user => $score) {
			if ($score > 0) {
				$values[] = "("
					.(int)$id_competence.", "
					.(int)$id_user.", "
					.(float)$score.", "
					.($completion_date?'" '.$completion_date.'"':" NOW()")
					.")";
			}
		}

		if (count($values) > 0) {
			$query = "INSERT INTO ".$this->_getCompetencesUsersTable()." "
				." (id_competence, id_user, score_got, last_assign_date) VALUES "
				.implode(",", $values);
			$res = $this->db->query($query);
		} else {
			//we were trying to assign some invalid score <= 0
			return false;
		}

		//track the operation
		if ($track) {
			$params = new stdClass();
			$params->operation = "manual_assign"; //the type of operation (manual, course etc.)
			$params->id_course = 0; //the id of the course which has assigned the score
			$params->assigned_by = Docebo::user()->getIdSt(); //user/administrator who has assigned the score to the user
			$params->date_assignment = date("Y-m-d H:i:s"); //the date of the operation
			$params->score_assigned = $score; //the score assigned
			$params->score_total = $score;
			$this->trackOperation($id_competence, array_keys($users), $params);
		}

		return $res ? true : false;
	}
and function assignCourseCompetencesToUser as follows:

Code: Select all

public function assignCourseCompetencesToUser($id_course, $id_user, $track = true) {
		if ($id_course <= 0) return false;
		if ($id_user <= 0) return false;

		$ccomps = $this->getCourseCompetences($id_course, true);
		//$ccomps = $this->getCompetencesInfo($_comps);
		$ucomps = $this->getUserCompetences($id_user);

                list($completion_date) = sql_fetch_row(sql_query("SELECT date_complete FROM %lms_courseuser WHERE idCourse = '".$id_course."' AND idUser = '".$id_user."';"));
		if($completion_date == NULL) return false;

		//addScoreToUsers
		//assignCompetenceUsers
		$res = true;
		foreach ($ccomps as $id_competence => $competence) {
			if (array_key_exists($id_competence, $ucomps)) { //check if the competence already exists for the user
				$res = $this->addScoreToUsers($id_competence, $id_user, $competence->score);
			} else {
				$user_score = array($id_user => $competence->score);
				$res = $this->assignCompetenceUsers($id_competence, $user_score, false, $completion_date);
			}
			
			//track the operation
			if ($track) {
				$params = new stdClass();
				$params->operation = "course_finish"; //the type of operation (manual, course etc.)
				$params->id_course = $id_course; //the id of the course which has assigned the score
				$params->assigned_by = 0; //user/administrator who has assigned the score to the user
				$params->date_assignment = date("Y-m-d H:i:s"); //the date of the operation
				$params->score_assigned = $competence->score; //the score assigned
				$params->score_total = $competence->score + (array_key_exists($id_competence, $ucomps)
						? $ucomps[$id_competence]->score_got + $competence->score
						: 0);
				$this->trackOperation($id_competence, $id_user, $params);
			}
		}

		return $res;
	}

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 4:28 pm
by scubatricky
:lol: alfa24, you may be my twin, I'm just looking through SubscriptionsAlms.php and it appears to call updateUserStatusInCourse, just after setDateFinished has been called.

updateUserStatusInCourse takes a variable $new_date_complete, which if empty, inserts Now() into the query...

The rabbit hole gets deeper :D

I will implement your code and see if there are other areas where Now() is the default value if a variable isn't passed.

Many many thanks for your input and help on this...I'm looking through code and debugging things as I go. I also downloaded the original code for Spaghetti LMS today... :lol:

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 4:35 pm
by scubatricky
Just implemented the above code in the competencies files, no change to behaviour unfortunately. After dinner this evening I will trace through lib.subscribe.php and find the error.

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 4:52 pm
by alfa24
If you need it to be working on classroom courses, you need the previous fix too: https://forum.formalms.org/topic.html?p=24255#p24255

Re: Competencies Not Working For Classroom Course

Posted: Fri Mar 05, 2021 5:14 pm
by alfa24
Moreover, you need to call the assignCourseCompetencesToUser function AFTER setDateFinished.
In /appLms/lib/lib.date.php change:

Code: Select all

$cmodel->assignCourseCompetencesToUser($id_course, $id_user);
$this->setDateFinished($id_date, $id_user);
to:

Code: Select all

$this->setDateFinished($id_date, $id_user);
$cmodel->assignCourseCompetencesToUser($id_course, $id_user);

Re: Competencies Not Working For Classroom Course

Posted: Sun Mar 07, 2021 1:28 pm
by scubatricky
Unfortunately no success. Marking a student as attended, and setting their course status to complete adds Now() to the learning_courseuser -> date_completed field.

I'm looking at lib.subscribe.php now for the bug.

Re: Competencies Not Working For Classroom Course

Posted: Sun Mar 07, 2021 2:49 pm
by alfa24
You must be missing something. I've tried and it works.

This site uses cookies.

Some of the cookies we use are essential for parts of the site to operate and have already been set. We also use Google Analytics scripts, which all use cookies.
You may delete or block all cookies from this site in your browser options.