Skills : Validate user skills by subcategory in gradebook - refs BT#19823

pull/4219/head
Christian 4 years ago
parent 7c9d54d0a6
commit 4661eb7f10
  1. 15
      main/gradebook/gradebook_edit_cat.php
  2. 39
      main/gradebook/lib/be/category.class.php
  3. 40
      main/gradebook/lib/fe/catform.class.php
  4. 64
      main/inc/lib/skill.lib.php
  5. 5
      main/install/configuration.dist.php

@ -9,7 +9,7 @@ require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
GradebookUtils::block_students();
$edit_cat = isset($_REQUEST['editcat']) ? (int) $_REQUEST['editcat'] : 0;
$enableGradeSubCategorySkills = (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement'));
$catedit = Category::load($edit_cat);
$form = new CatForm(
CatForm::TYPE_EDIT,
@ -62,6 +62,13 @@ if ($form->validate()) {
if ($values['hid_parent_id'] == 0) {
$cat->set_certificate_min_score($values['certif_min_score']);
} else {
if ($enableGradeSubCategorySkills) {
$allowSkillsBySubCategory = $cat->getAllowSkillBySubCategory($cat->get_parent_id());
if ($allowSkillsBySubCategory) {
$cat->set_certificate_min_score($values['certif_min_score']);
}
}
}
$visible = 1;
@ -75,6 +82,12 @@ if ($form->validate()) {
} else {
$cat->setIsRequirement(false);
}
if ($enableGradeSubCategorySkills) {
$allowSkillsBySubCategory = isset($values['allow_skills_by_subcategory']);
$cat->updateAllowSkillBySubCategory($allowSkillsBySubCategory);
}
$cat->save();
header('Location: '.Category::getUrl().'editcat=&selectcat='.$cat->get_parent_id());
exit;

@ -713,6 +713,39 @@ class Category implements GradebookItem
);
}
/**
* Update value to allow user skills by subcategory passed.
*
* @param $value
*/
public function updateAllowSkillBySubCategory($value)
{
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$value = (int) $value;
$upd = 'UPDATE '.$table.' SET allow_skills_by_subcategory = '.$value.' WHERE id = '.intval($this->id);
Database::query($upd);
}
/**
* Get the value to Allow skill by subcategory.
*
* @return bool
*/
public function getAllowSkillBySubCategory($parentId = null)
{
$id = (int) $this->id;
if (isset($parentId)) {
$id = (int) $parentId;
}
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT allow_skills_by_subcategory FROM '.$table.' WHERE id = '.$id;
$rs = Database::query($sql);
$value = (bool) Database::result($rs, 0, 0);
return $value;
}
/**
* Update link weights see #5168.
*
@ -2127,6 +2160,11 @@ class Category implements GradebookItem
$userHasSkills = false;
if ($skillToolEnabled) {
$skill = new Skill();
$objSkillRelUser = new SkillRelUser();
// It cleans the previous results to generate the new user skills
$objSkillRelUser->deleteUserSkill($user_id, $courseId, $sessionId);
$skill->addSkillToUser(
$user_id,
$category,
@ -2134,7 +2172,6 @@ class Category implements GradebookItem
$sessionId
);
$objSkillRelUser = new SkillRelUser();
$userSkills = $objSkillRelUser->getUserSkills(
$user_id,
$courseId,

@ -292,6 +292,19 @@ class CatForm extends FormValidator
true,
['maxlength' => '5']
);
if (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement')) {
// It allows the acquisition of competencies independently in the subcategories
$allowSkillsBySubCategory = $this->addCheckBox(
'allow_skills_by_subcategory',
[
null,
get_lang('ItAllowsTheAcquisitionOfSkillsBySubCategories'),
],
get_lang('AllowsSkillsBySubCategories')
);
$allowSkillsBySubCategory->setChecked($this->category_object->getAllowSkillBySubCategory());
}
} else {
$questionWeighting = $value;
$defaultCertification = api_number_format($this->category_object->getCertificateMinScore(), 2);
@ -330,6 +343,33 @@ class CatForm extends FormValidator
0
);
} else {
// It enables minimun score to get the skills independant assigment
if (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement')) {
$allowSkillsBySubCategory = $this->category_object->getAllowSkillBySubCategory($this->category_object->get_parent_id());
if ($allowSkillsBySubCategory) {
$this->addText(
'certif_min_score',
get_lang('SkillMinScore'),
true,
['maxlength' => '5']
);
$this->addRule(
'certif_min_score',
get_lang('OnlyNumbers'),
'numeric'
);
$this->addRule(
'certif_min_score',
get_lang('NegativeValue'),
'compare',
'>=',
'server',
false,
false,
0
);
}
}
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
}

@ -624,6 +624,25 @@ class SkillRelUser extends Model
return Database::fetch_assoc($result);
}
/**
* Delete a user skill by course.
*
* @param int $userId
* @param int $courseId
* @param int $sessionId
*/
public function deleteUserSkill($userId, $courseId, $sessionId = 0)
{
$whereSession = ($sessionId ? " AND session_id = $sessionId" : " AND session_id IS NULL");
$sql = "DELETE FROM {$this->table}
WHERE
user_id = $userId AND
course_id = $courseId
$whereSession";
Database::query($sql);
}
/**
* Get the URL for the issue.
*
@ -1171,10 +1190,18 @@ class Skill extends Model
$category->get_course_code(),
$category->get_session_id()
);
$scoreSubCategories = $this->getSubCategoryResultScore($category, $userId);
if (!empty($subCategories)) {
/** @var Category $subCategory */
foreach ($subCategories as $subCategory) {
$this->addSkillToUser($userId, $subCategory, $courseId, $sessionId);
$scoreChecked = true;
if (!empty($scoreSubCategories[$subCategory->get_id()])) {
$resultScore = $scoreSubCategories[$subCategory->get_id()];
$scoreChecked = ($resultScore['user_score'] >= $resultScore['min_score']);
}
if ($scoreChecked) {
$this->addSkillToUser($userId, $subCategory, $courseId, $sessionId);
}
}
}
}
@ -1208,6 +1235,41 @@ class Skill extends Model
return true;
}
/**
* Get the results of user in a subCategory.
*
* @param $category
* @param $userId
*
* @return array
*/
public function getSubCategoryResultScore($category, $userId)
{
$scoreSubCategories = [];
if (true === api_get_configuration_value('gradebook_enable_subcategory_skills_independant_assignement')) {
$subCategories = $category->get_subcategories(
$userId,
$category->get_course_code(),
$category->get_session_id()
);
$alleval = $category->get_evaluations($userId, false, $category->get_course_code(),
$category->get_session_id());
$alllink = $category->get_links($userId, true, $category->get_course_code(), $category->get_session_id());
$datagen = new GradebookDataGenerator($subCategories, $alleval, $alllink);
$gradeResult = $datagen->get_data();
foreach ($gradeResult as $data) {
/** @var AbstractLink $item */
$item = $data[0];
if ('Category' === get_class($item)) {
$scoreSubCategories[$item->get_id()]['min_score'] = $item->getCertificateMinScore();
$scoreSubCategories[$item->get_id()]['user_score'] = round($data['result_score'][0]);
}
}
}
return $scoreSubCategories;
}
/* Deletes a skill */
public function delete($skill_id)
{

@ -2156,6 +2156,11 @@ INSERT INTO `extra_field` (`extra_field_type`, `field_type`, `variable`, `displa
// User extra fields to be check on user edition to generate a specific process if it was modified
//$_configuration['user_edition_extra_field_to_check'] = 'ExtrafieldLabel';
// Enable skills in subcategory to work independant on assignement
// Require DB changes:
// ALTER TABLE gradebook_category ADD allow_skills_by_subcategory tinyint(1) NOT NULL DEFAULT '1';
//$_configuration['gradebook_enable_subcategory_skills_independant_assignement'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save