Competencies Not Working For Classroom Course
Re: Competencies Not Working For Classroom Course
I'm not seeing steps to reproduce, so your posts are just a diary of your tests.
Per supporto GRATUITO contattatemi in privato qui
-
- FormaLms User
- Posts: 69
- Joined: Wed Oct 21, 2020 11:43 pm
Re: Competencies Not Working For Classroom Course
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.
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
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.
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.
Per supporto GRATUITO contattatemi in privato qui
Re: Competencies Not Working For Classroom Course
Give it a try:
in /appCore/models/CompetencesAdm.php
rewrite function assignCompetenceUsers as follows:
and function assignCourseCompetencesToUser as follows:
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;
}
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;
}
Per supporto GRATUITO contattatemi in privato qui
-
- FormaLms User
- Posts: 69
- Joined: Wed Oct 21, 2020 11:43 pm
Re: Competencies Not Working For Classroom Course
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
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...
updateUserStatusInCourse takes a variable $new_date_complete, which if empty, inserts Now() into the query...
The rabbit hole gets deeper
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...
-
- FormaLms User
- Posts: 69
- Joined: Wed Oct 21, 2020 11:43 pm
Re: Competencies Not Working For Classroom Course
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
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
Per supporto GRATUITO contattatemi in privato qui
Re: Competencies Not Working For Classroom Course
Moreover, you need to call the assignCourseCompetencesToUser function AFTER setDateFinished.
In /appLms/lib/lib.date.php change:
to:
In /appLms/lib/lib.date.php change:
Code: Select all
$cmodel->assignCourseCompetencesToUser($id_course, $id_user);
$this->setDateFinished($id_date, $id_user);
Code: Select all
$this->setDateFinished($id_date, $id_user);
$cmodel->assignCourseCompetencesToUser($id_course, $id_user);
Per supporto GRATUITO contattatemi in privato qui
-
- FormaLms User
- Posts: 69
- Joined: Wed Oct 21, 2020 11:43 pm
Re: Competencies Not Working For Classroom Course
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.
I'm looking at lib.subscribe.php now for the bug.
Re: Competencies Not Working For Classroom Course
You must be missing something. I've tried and it works.
Per supporto GRATUITO contattatemi in privato qui