Re: Competencies Not Working For Classroom Course
Posted: Thu Mar 04, 2021 9:30 pm
I'm not seeing steps to reproduce, so your posts are just a diary of your tests.
FORMA LMS Community
https://forum.formalms.org/forum/
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;
}
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);