Rename functions using camelCase

- Fix getCurrentScore and userFinishedCourse to use Category instead of
course and session code.
pull/2487/head
jmontoyaa 8 years ago
parent b5569fbb82
commit 45c148be3b
  1. 2
      main/admin/skills_profile.php
  2. 3
      main/badge/assertion.php
  3. 2
      main/gradebook/get_badges.php
  4. 2
      main/gradebook/gradebook.php
  5. 2
      main/gradebook/gradebook_add_link.php
  6. 2
      main/gradebook/gradebook_edit_link.php
  7. 12
      main/gradebook/index.php
  8. 2
      main/gradebook/lib/GradebookUtils.php
  9. 203
      main/gradebook/lib/be/category.class.php
  10. 21
      main/gradebook/lib/be/evaluation.class.php
  11. 2
      main/gradebook/lib/fe/catform.class.php
  12. 2
      main/gradebook/lib/fe/displaygradebook.php
  13. 2
      main/gradebook/lib/fe/gradebooktable.class.php
  14. 2
      main/inc/ajax/model.ajax.php
  15. 8
      main/inc/ajax/skill.ajax.php
  16. 5
      main/inc/lib/SequenceResourceManager.php
  17. 4
      main/inc/lib/gradebook.lib.php
  18. 15
      main/inc/lib/skill.lib.php
  19. 2
      main/inc/lib/social.lib.php
  20. 18
      main/lp/lp_final_item.php
  21. 2
      main/lp/lp_view.php
  22. 2
      main/social/skills_wheel.php
  23. 6
      plugin/grading_electronic/generate.php
  24. 8
      user_portal.php

@ -64,7 +64,7 @@ if (!empty($users)) {
foreach ($users as $user) { foreach ($users as $user) {
$user_info = api_get_user_info($user['user_id']); $user_info = api_get_user_info($user['user_id']);
$user_list[$user['user_id']]['user'] = $user_info; $user_list[$user['user_id']]['user'] = $user_info;
$my_user_skills = $skill_rel_user->get_user_skills($user['user_id']); $my_user_skills = $skill_rel_user->getUserSkills($user['user_id']);
$user_skills = array(); $user_skills = array();
$found_counts = 0; $found_counts = 0;
foreach ($my_user_skills as $my_skill) { foreach ($my_user_skills as $my_skill) {

@ -20,8 +20,7 @@ if ($userId === 0 || $skillId === 0) {
} }
$objSkill = new Skill(); $objSkill = new Skill();
if (!$objSkill->userHasSkill($userId, $skillId, $courseId, $sessionId)) {
if (!$objSkill->user_has_skill($userId, $skillId, $courseId, $sessionId)) {
exit; exit;
} }

@ -21,7 +21,7 @@ $courseId = api_get_course_int_id();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$objSkillRelUser = new SkillRelUser(); $objSkillRelUser = new SkillRelUser();
$userSkills = $objSkillRelUser->get_user_skills($userId, $courseId, $sessionId); $userSkills = $objSkillRelUser->getUserSkills($userId, $courseId, $sessionId);
if (empty($userSkills)) { if (empty($userSkills)) {
api_not_allowed(true); api_not_allowed(true);

@ -483,7 +483,7 @@ if (!empty($keyword)) {
$alleval = array(); $alleval = array();
$alllink = array(); $alllink = array();
} else { } else {
$alleval = Evaluation::find_evaluations($keyword, $cats[0]->get_id()); $alleval = Evaluation::findEvaluations($keyword, $cats[0]->get_id());
$alllink = LinkFactory::find_links($keyword, $cats[0]->get_id()); $alllink = LinkFactory::find_links($keyword, $cats[0]->get_id());
} }
} elseif (isset($_GET['studentoverview'])) { } elseif (isset($_GET['studentoverview'])) {

@ -33,7 +33,7 @@ if ($session_id == 0) {
$session_id $session_id
); );
} else { } else {
$all_categories = Category::load_session_categories(null, $session_id); $all_categories = Category::loadSessionCategories(null, $session_id);
} }
$category = Category :: load($selectCat); $category = Category :: load($selectCat);
$url = api_get_self().'?selectcat='.$selectCat.'&newtypeselected='.$typeSelected.'&course_code='.api_get_course_id().'&'.api_get_cidreq(); $url = api_get_self().'?selectcat='.$selectCat.'&newtypeselected='.$typeSelected.'&course_code='.api_get_course_id().'&'.api_get_cidreq();

@ -39,7 +39,7 @@ if ($session_id == 0) {
false false
); //already init ); //already init
} else { } else {
$cats = Category :: load_session_categories(null, $session_id); $cats = Category::loadSessionCategories(null, $session_id);
} }
$form = new LinkAddEditForm( $form = new LinkAddEditForm(

@ -413,14 +413,14 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) { switch ($action) {
case 'lock': case 'lock':
$category_to_lock = Category :: load($_GET['category_id']); $category_to_lock = Category::load($_GET['category_id']);
$category_to_lock[0]->lock_all_items(1); $category_to_lock[0]->lockAllItems(1);
$confirmation_message = get_lang('GradebookLockedAlert'); $confirmation_message = get_lang('GradebookLockedAlert');
break; break;
case 'unlock': case 'unlock':
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$category_to_lock = Category :: load($_GET['category_id']); $category_to_lock = Category::load($_GET['category_id']);
$category_to_lock[0]->lock_all_items(0); $category_to_lock[0]->lockAllItems(0);
$confirmation_message = get_lang('EvaluationHasBeenUnLocked'); $confirmation_message = get_lang('EvaluationHasBeenUnLocked');
} }
break; break;
@ -770,9 +770,7 @@ if (!empty($selectCat)) {
$currentScore = Category::getCurrentScore( $currentScore = Category::getCurrentScore(
$stud_id, $stud_id,
$selectCat, $cats[0],
$course_code,
$session_id,
true true
); );
Category::registerCurrentScore($currentScore, $stud_id, $selectCat); Category::registerCurrentScore($currentScore, $stud_id, $selectCat);

@ -1285,7 +1285,7 @@ class GradebookUtils
$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$id = intval($id); $id = intval($id);
$evaluation = new Evaluation(); $evaluation = new Evaluation();
$evaluation->add_evaluation_log($id); $evaluation->addEvaluationLog($id);
$sql = 'UPDATE '.$table_evaluation.' $sql = 'UPDATE '.$table_evaluation.'
SET weight = '."'".Database::escape_string($weight)."'".' SET weight = '."'".Database::escape_string($weight)."'".'
WHERE id = '.$id; WHERE id = '.$id;

@ -89,7 +89,7 @@ class Category implements GradebookItem
/** /**
* @return integer|null * @return integer|null
*/ */
public function get_certificate_min_score() public function getCertificateMinScore()
{ {
if (!empty($this->certificate_min_score)) { if (!empty($this->certificate_min_score)) {
return $this->certificate_min_score; return $this->certificate_min_score;
@ -317,9 +317,9 @@ class Category implements GradebookItem
public function get_skills($from_db = true) public function get_skills($from_db = true)
{ {
if ($from_db) { if ($from_db) {
$cat_id = $this->get_id(); $categoryId = $this->get_id();
$gradebook = new Gradebook(); $gradebook = new Gradebook();
$skills = $gradebook->get_skills_by_gradebook($cat_id); $skills = $gradebook->getSkillsByGradebook($categoryId);
} else { } else {
$skills = $this->skills; $skills = $this->skills;
} }
@ -367,7 +367,7 @@ class Category implements GradebookItem
* *
* @return array * @return array
*/ */
public static function load_session_categories( public static function loadSessionCategories(
$id = null, $id = null,
$session_id = null $session_id = null
) { ) {
@ -1289,7 +1289,7 @@ class Category implements GradebookItem
// course independent categories // course independent categories
if (empty($course_code)) { if (empty($course_code)) {
$cats = self::get_independent_categories_with_result_for_student( $cats = self::getIndependentCategoriesWithStudentResult(
0, 0,
$stud_id, $stud_id,
$cats $cats
@ -1691,12 +1691,14 @@ class Category implements GradebookItem
/** /**
* Check if a category contains evaluations with a result for a given student * Check if a category contains evaluations with a result for a given student
* @param int $studentId
* @return bool
*/ */
public function has_evaluations_with_results_for_student($stud_id) public function hasEvaluationsWithStudentResults($studentId)
{ {
$evals = Evaluation::get_evaluations_with_result_for_student( $evals = Evaluation::get_evaluations_with_result_for_student(
$this->id, $this->id,
$stud_id $studentId
); );
if (count($evals) != 0) { if (count($evals) != 0) {
return true; return true;
@ -1708,8 +1710,9 @@ class Category implements GradebookItem
$this->id, $this->id,
api_is_allowed_to_edit() ? null : 1 api_is_allowed_to_edit() ? null : 1
); );
/** @var Category $cat */
foreach ($cats as $cat) { foreach ($cats as $cat) {
if ($cat->has_evaluations_with_results_for_student($stud_id)) { if ($cat->hasEvaluationsWithStudentResults($studentId)) {
return true; return true;
} }
} }
@ -1721,30 +1724,31 @@ class Category implements GradebookItem
/** /**
* Retrieve all categories inside a course independent category * Retrieve all categories inside a course independent category
* that should be visible to a student. * that should be visible to a student.
* @param integer $cat_id parent category * @param int $categoryId parent category
* @param $stud_id student id * @param int $studentId
* @param array $cats optional: if defined, the categories will be added to this array * @param array $cats optional: if defined, the categories will be added to this array
* @return array * @return array
*/ */
public function get_independent_categories_with_result_for_student( public function getIndependentCategoriesWithStudentResult(
$cat_id, $categoryId,
$stud_id, $studentId,
$cats = array() $cats = array()
) { ) {
$creator = api_is_allowed_to_edit() && !api_is_platform_admin() ? api_get_user_id() : null; $creator = api_is_allowed_to_edit() && !api_is_platform_admin() ? api_get_user_id() : null;
$crsindcats = self::load( $categories = self::load(
null, null,
$creator, $creator,
'0', '0',
$cat_id, $categoryId,
api_is_allowed_to_edit() ? null : 1 api_is_allowed_to_edit() ? null : 1
); );
if (!empty($crsindcats)) { if (!empty($categories)) {
foreach ($crsindcats as $crsindcat) { /** @var Category $category */
if ($crsindcat->has_evaluations_with_results_for_student($stud_id)) { foreach ($categories as $category) {
$cats[] = $crsindcat; if ($category->hasEvaluationsWithStudentResults($studentId)) {
$cats[] = $category;
} }
} }
} }
@ -1763,7 +1767,7 @@ class Category implements GradebookItem
/** /**
* Get appropriate subcategories visible for the user (and optionally the course and session) * Get appropriate subcategories visible for the user (and optionally the course and session)
* @param int $stud_id student id (default: all students) * @param int $studentId student id (default: all students)
* @param string $course_code Course code (optional) * @param string $course_code Course code (optional)
* @param int $session_id Session ID (optional) * @param int $session_id Session ID (optional)
* @param bool $order * @param bool $order
@ -1771,7 +1775,7 @@ class Category implements GradebookItem
* @return array Array of subcategories * @return array Array of subcategories
*/ */
public function get_subcategories( public function get_subcategories(
$stud_id = null, $studentId = null,
$course_code = null, $course_code = null,
$session_id = null, $session_id = null,
$order = null $order = null
@ -1788,10 +1792,10 @@ class Category implements GradebookItem
} }
// 1 student // 1 student
if (isset($stud_id)) { if (isset($studentId)) {
// Special case: this is the root // Special case: this is the root
if ($this->id == 0) { if ($this->id == 0) {
return self::get_root_categories_for_student($stud_id, $course_code, $session_id); return self::get_root_categories_for_student($studentId, $course_code, $session_id);
} else { } else {
return self::load( return self::load(
null, null,
@ -1859,7 +1863,7 @@ class Category implements GradebookItem
/** /**
* Get appropriate evaluations visible for the user * Get appropriate evaluations visible for the user
* @param int $stud_id student id (default: all students) * @param int $studentId student id (default: all students)
* @param boolean $recursive process subcategories (default: no recursion) * @param boolean $recursive process subcategories (default: no recursion)
* @param string $course_code * @param string $course_code
* @param int $sessionId * @param int $sessionId
@ -1867,7 +1871,7 @@ class Category implements GradebookItem
* @return array * @return array
*/ */
public function get_evaluations( public function get_evaluations(
$stud_id = null, $studentId = null,
$recursive = false, $recursive = false,
$course_code = '', $course_code = '',
$sessionId = 0 $sessionId = 0
@ -1882,10 +1886,10 @@ class Category implements GradebookItem
} }
// 1 student // 1 student
if (isset($stud_id) && !empty($stud_id)) { if (isset($studentId) && !empty($studentId)) {
// Special case: this is the root // Special case: this is the root
if ($this->id == 0) { if ($this->id == 0) {
$evals = Evaluation::get_evaluations_with_result_for_student(0, $stud_id); $evals = Evaluation::get_evaluations_with_result_for_student(0, $studentId);
} else { } else {
$evals = Evaluation::load( $evals = Evaluation::load(
null, null,
@ -1903,25 +1907,57 @@ class Category implements GradebookItem
) { ) {
// root // root
if ($this->id == 0) { if ($this->id == 0) {
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); $evals = Evaluation::load(
null,
api_get_user_id(),
null,
$this->id,
null
);
} elseif (isset($this->course_code) && !empty($this->course_code)) { } elseif (isset($this->course_code) && !empty($this->course_code)) {
// inside a course // inside a course
$evals = Evaluation::load(null, null, $course_code, $this->id, null); $evals = Evaluation::load(
null,
null,
$course_code,
$this->id,
null
);
} else { } else {
// course independent // course independent
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); $evals = Evaluation::load(
null,
api_get_user_id(),
null,
$this->id,
null
);
} }
} else { } else {
$evals = Evaluation::load(null, null, $course_code, $this->id, null); $evals = Evaluation::load(
null,
null,
$course_code,
$this->id,
null
);
} }
} }
if ($recursive) { if ($recursive) {
$subcats = $this->get_subcategories($stud_id, $course_code, $sessionId); $subcats = $this->get_subcategories(
$studentId,
$course_code,
$sessionId
);
if (!empty($subcats)) { if (!empty($subcats)) {
foreach ($subcats as $subcat) { foreach ($subcats as $subcat) {
$subevals = $subcat->get_evaluations($stud_id, true, $course_code); $subevals = $subcat->get_evaluations(
$studentId,
true,
$course_code
);
$evals = array_merge($evals, $subevals); $evals = array_merge($evals, $subevals);
} }
} }
@ -1932,7 +1968,7 @@ class Category implements GradebookItem
/** /**
* Get appropriate links visible for the user * Get appropriate links visible for the user
* @param int $stud_id student id (default: all students) * @param int $studentId student id (default: all students)
* @param boolean $recursive process subcategories (default: no recursion) * @param boolean $recursive process subcategories (default: no recursion)
* @param string $course_code * @param string $course_code
* @param int $sessionId * @param int $sessionId
@ -1940,7 +1976,7 @@ class Category implements GradebookItem
* @return array * @return array
*/ */
public function get_links( public function get_links(
$stud_id = null, $studentId = null,
$recursive = false, $recursive = false,
$course_code = '', $course_code = '',
$sessionId = 0 $sessionId = 0
@ -1957,8 +1993,8 @@ class Category implements GradebookItem
// no links in root or course independent categories // no links in root or course independent categories
if ($this->id == 0) { if ($this->id == 0) {
} elseif (isset($stud_id)) { } elseif (isset($studentId)) {
// 1 student $stud_id // 1 student $studentId
$links = LinkFactory::load( $links = LinkFactory::load(
null, null,
null, null,
@ -1983,7 +2019,7 @@ class Category implements GradebookItem
if ($recursive) { if ($recursive) {
$subcats = $this->get_subcategories( $subcats = $this->get_subcategories(
$stud_id, $studentId,
$course_code, $course_code,
$sessionId $sessionId
); );
@ -1991,7 +2027,7 @@ class Category implements GradebookItem
/** @var Category $subcat */ /** @var Category $subcat */
foreach ($subcats as $subcat) { foreach ($subcats as $subcat) {
$sublinks = $subcat->get_links( $sublinks = $subcat->get_links(
$stud_id, $studentId,
false, false,
$course_code, $course_code,
$sessionId $sessionId
@ -2089,7 +2125,7 @@ class Category implements GradebookItem
/** /**
* @param $locked * @param $locked
*/ */
public function lock_all_items($locked) public function lockAllItems($locked)
{ {
if (api_get_setting('gradebook_locking_enabled') == 'true') { if (api_get_setting('gradebook_locking_enabled') == 'true') {
$this->lock($locked); $this->lock($locked);
@ -2177,9 +2213,6 @@ class Category implements GradebookItem
$userFinishedCourse = self::userFinishedCourse( $userFinishedCourse = self::userFinishedCourse(
$user_id, $user_id,
$cats_course[0], $cats_course[0],
0,
$courseCode,
$sessionId,
true true
); );
@ -2203,7 +2236,7 @@ class Category implements GradebookItem
); );
$objSkillRelUser = new SkillRelUser(); $objSkillRelUser = new SkillRelUser();
$userSkills = $objSkillRelUser->get_user_skills( $userSkills = $objSkillRelUser->getUserSkills(
$user_id, $user_id,
$courseId, $courseId,
$sessionId $sessionId
@ -2385,82 +2418,51 @@ class Category implements GradebookItem
* @param int $userId The user ID * @param int $userId The user ID
* @param \Category $category Optional. The gradebook category. * @param \Category $category Optional. The gradebook category.
* To check by the gradebook category * To check by the gradebook category
* @param int $categoryId Optional. The gradebook category ID.
* To check by the category ID
* @param string $courseCode Optional. The course code
* @param int $sessionId Optional. The session ID
* @param boolean $recalculateScore Whether recalculate the score * @param boolean $recalculateScore Whether recalculate the score
* @return boolean * @return boolean
*/ */
public static function userFinishedCourse( public static function userFinishedCourse(
$userId, $userId,
\Category $category = null, \Category $category,
$categoryId = 0,
$courseCode = null,
$sessionId = 0,
$recalculateScore = false $recalculateScore = false
) { ) {
if (is_null($category) && empty($categoryId)) { if (empty($category)) {
return false;
}
$courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
if (is_null($category) && !empty($categoryId)) {
$cats_course = self::load(
$categoryId,
null,
$courseCode,
null,
null,
$sessionId,
false
);
if (empty($cats_course)) {
return false; return false;
} }
$category = $cats_course[0];
}
$currentScore = self::getCurrentScore( $currentScore = self::getCurrentScore(
$userId, $userId,
$category->get_id(), $category,
$courseCode,
$sessionId,
$recalculateScore $recalculateScore
); );
$minCertificateScore = $category->get_certificate_min_score(); $minCertificateScore = $category->getCertificateMinScore();
$passedCourse = $currentScore >= $minCertificateScore;
return !empty($minCertificateScore) && $currentScore >= $minCertificateScore; return $passedCourse;
} }
/** /**
* Get the current score (as percentage) on a gradebook category for a user * Get the current score (as percentage) on a gradebook category for a user
* @param int $userId The user id * @param int $userId The user id
* @param int $categoryId The gradebook category * @param Category $category The gradebook category
* @param int $courseCode The course code
* @param int $sessionId Optional. The session id
* @param bool $recalculate * @param bool $recalculate
* *
* @return float The score * @return float The score
*/ */
public static function getCurrentScore( public static function getCurrentScore(
$userId, $userId,
$categoryId, $category,
$courseCode,
$sessionId = 0,
$recalculate = false $recalculate = false
) { ) {
if (empty($category)) {
return 0;
}
if ($recalculate) { if ($recalculate) {
return self::calculateCurrentScore( return self::calculateCurrentScore(
$userId, $userId,
$categoryId, $category
$courseCode,
$sessionId
); );
} }
@ -2469,7 +2471,7 @@ class Category implements GradebookItem
Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_LOG), Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_LOG),
[ [
'where' => [ 'where' => [
'category_id = ? AND user_id = ?' => [$categoryId, $userId], 'category_id = ? AND user_id = ?' => [$category->get_id(), $userId],
], ],
'order' => 'registered_at DESC', 'order' => 'registered_at DESC',
'limit' => '1', 'limit' => '1',
@ -2487,32 +2489,16 @@ class Category implements GradebookItem
/** /**
* Calculate the current score on a gradebook category for a user * Calculate the current score on a gradebook category for a user
* @param int $userId The user id * @param int $userId The user id
* @param int $categoryId The gradebook category * @param Category $category The gradebook category
* @param int $courseCode The course code
* @param int $sessionId Optional. The session id
* @return float The score * @return float The score
*/ */
private static function calculateCurrentScore( private static function calculateCurrentScore(
$userId, $userId,
$categoryId, $category
$courseCode,
$sessionId
) { ) {
$cats_course = self::load( if (empty($category)) {
$categoryId,
null,
$courseCode,
null,
null,
$sessionId,
false
);
if (empty($cats_course)) {
return 0; return 0;
} }
$category = $cats_course[0];
$courseEvaluations = $category->get_evaluations($userId, true); $courseEvaluations = $category->get_evaluations($userId, true);
$courseLinks = $category->get_links($userId, true); $courseLinks = $category->get_links($userId, true);
$evaluationsAndLinks = array_merge($courseEvaluations, $courseLinks); $evaluationsAndLinks = array_merge($courseEvaluations, $courseLinks);
@ -2521,7 +2507,6 @@ class Category implements GradebookItem
$item = $evaluationsAndLinks[$i]; $item = $evaluationsAndLinks[$i];
$score = $item->calc_score($userId); $score = $item->calc_score($userId);
$itemValue = 0; $itemValue = 0;
if (!empty($score)) { if (!empty($score)) {
$divider = $score[1] == 0 ? 1 : $score[1]; $divider = $score[1] == 0 ? 1 : $score[1];
$itemValue = $score[0] / $divider * $item->get_weight(); $itemValue = $score[0] / $divider * $item->get_weight();

@ -372,15 +372,15 @@ class Evaluation implements GradebookItem
} }
/** /**
* @param int $idevaluation * @param int $id
*/ */
public function add_evaluation_log($idevaluation) public function addEvaluationLog($id)
{ {
if (!empty($idevaluation)) { if (!empty($id)) {
$tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$tbl_grade_linkeval_log = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); $tbl_grade_linkeval_log = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG);
$eval = new Evaluation(); $eval = new Evaluation();
$dateobject = $eval->load($idevaluation, null, null, null, null); $dateobject = $eval->load($id, null, null, null, null);
$arreval = get_object_vars($dateobject[0]); $arreval = get_object_vars($dateobject[0]);
if (!empty($arreval['id'])) { if (!empty($arreval['id'])) {
$sql = 'SELECT weight from '.$tbl_grade_evaluations.' $sql = 'SELECT weight from '.$tbl_grade_evaluations.'
@ -437,7 +437,7 @@ class Evaluation implements GradebookItem
//recorded history //recorded history
$eval_log = new Evaluation(); $eval_log = new Evaluation();
$eval_log->add_evaluation_log($this->id); $eval_log->addEvaluationLog($this->id);
Database::query($sql); Database::query($sql);
} }
@ -447,7 +447,8 @@ class Evaluation implements GradebookItem
public function delete() public function delete()
{ {
$tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); $sql = 'DELETE FROM '.$tbl_grade_evaluations.'
WHERE id = '.intval($this->id);
Database::query($sql); Database::query($sql);
} }
@ -464,9 +465,9 @@ class Evaluation implements GradebookItem
$parent = $this->category; $parent = $this->category;
} }
$tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = 'SELECT count(id) AS number' $sql = "SELECT count(id) AS number
.' FROM '.$tbl_grade_evaluations FROM $tbl_grade_evaluations
." WHERE name = '".Database::escape_string($name)."'"; WHERE name = '".Database::escape_string($name)."'";
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$parent = Category::load($parent); $parent = Category::load($parent);
@ -779,7 +780,7 @@ class Evaluation implements GradebookItem
* @return array evaluation objects matching the search criterium * @return array evaluation objects matching the search criterium
* @todo can be written more efficiently using a new (but very complex) sql query * @todo can be written more efficiently using a new (but very complex) sql query
*/ */
public function find_evaluations($name_mask, $selectcat) public function findEvaluations($name_mask, $selectcat)
{ {
$rootcat = Category::load($selectcat); $rootcat = Category::load($selectcat);
$evals = $rootcat[0]->get_evaluations( $evals = $rootcat[0]->get_evaluations(

@ -177,7 +177,7 @@ class CatForm extends FormValidator
'skills' => $skills, 'skills' => $skills,
'weight' => $this->category_object->get_weight(), 'weight' => $this->category_object->get_weight(),
'visible' => $this->category_object->is_visible(), 'visible' => $this->category_object->is_visible(),
'certif_min_score' => $this->category_object->get_certificate_min_score(), 'certif_min_score' => $this->category_object->getCertificateMinScore(),
'generate_certificates' => $this->category_object->getGenerateCertificates(), 'generate_certificates' => $this->category_object->getGenerateCertificates(),
'is_requirement' => $this->category_object->getIsRequirement(), 'is_requirement' => $this->category_object->getIsRequirement(),
) )

@ -449,7 +449,7 @@ class DisplayGradebook
$weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0; $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
$weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight; $weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
$min_certification = (intval($catobj->get_certificate_min_score() > 0) ? $catobj->get_certificate_min_score() : 0); $min_certification = (intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0);
$min_certification = get_lang('CertificateMinScore').' : '.$min_certification; $min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
$edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'. $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>'; Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';

@ -904,7 +904,7 @@ class GradebookTable extends SortableTable
*/ */
private function build_certificate_min_score($item) private function build_certificate_min_score($item)
{ {
return $item->get_certificate_min_score(); return $item->getCertificateMinScore();
} }
/** /**

@ -1525,7 +1525,7 @@ switch ($action) {
if ($item['parent_id'] != 0) { if ($item['parent_id'] != 0) {
continue; continue;
} }
$skills = $obj->get_skills_by_gradebook($item['id']); $skills = $obj->getSkillsByGradebook($item['id']);
//Fixes bug when gradebook doesn't have names //Fixes bug when gradebook doesn't have names
if (empty($item['name'])) { if (empty($item['name'])) {

@ -146,7 +146,7 @@ switch ($action) {
break; break;
case 'get_user_skill': case 'get_user_skill':
$skillId = isset($_REQUEST['profile_id']) ? intval($_REQUEST['profile_id']) : 0; $skillId = isset($_REQUEST['profile_id']) ? intval($_REQUEST['profile_id']) : 0;
$skill = $skill->user_has_skill($userId, $skillId); $skill = $skill->userHasSkill($userId, $skillId);
if ($skill) { if ($skill) {
echo 1; echo 1;
} else { } else {
@ -154,11 +154,11 @@ switch ($action) {
} }
break; break;
case 'get_all_user_skills': case 'get_all_user_skills':
$skills = $skill->get_user_skills($userId, true); $skills = $skill->getUserSkills($userId, true);
echo json_encode($skills); echo json_encode($skills);
break; break;
case 'get_user_skills': case 'get_user_skills':
$skills = $skill->get_user_skills($userId, true); $skills = $skill->getUserSkills($userId, true);
Display::display_no_header(); Display::display_no_header();
Display::$global_template->assign('skills', $skills); Display::$global_template->assign('skills', $skills);
$template = Display::$global_template->get_template('skill/user_skills.tpl'); $template = Display::$global_template->get_template('skill/user_skills.tpl');
@ -222,7 +222,7 @@ switch ($action) {
foreach ($users as $user) { foreach ($users as $user) {
$user_info = api_get_user_info($user['user_id']); $user_info = api_get_user_info($user['user_id']);
$user_list[$user['user_id']]['user'] = $user_info; $user_list[$user['user_id']]['user'] = $user_info;
$my_user_skills = $skill_rel_user->get_user_skills($user['user_id']); $my_user_skills = $skill_rel_user->getUserSkills($user['user_id']);
$user_skill_list = array(); $user_skill_list = array();
foreach ($my_user_skills as $skill_item) { foreach ($my_user_skills as $skill_item) {

@ -78,10 +78,7 @@ class SequenceResourceManager
if (!empty($userId)) { if (!empty($userId)) {
$itemSession['status'] = $itemSession['status'] && Category::userFinishedCourse( $itemSession['status'] = $itemSession['status'] && Category::userFinishedCourse(
$userId, $userId,
$category, $category
null,
$course->getCode(),
$sessionRequired->getId()
); );
} }
} }

@ -191,7 +191,7 @@ class Gradebook extends Model
) )
); );
$selected_skills = self::get_skills_by_gradebook($gradebook_id); $selected_skills = self::getSkillsByGradebook($gradebook_id);
$clean_selected_skills = array(); $clean_selected_skills = array();
if (!empty($selected_skills)) { if (!empty($selected_skills)) {
foreach ($selected_skills as $skill) { foreach ($selected_skills as $skill) {
@ -209,7 +209,7 @@ class Gradebook extends Model
* @param int $gradebook_id * @param int $gradebook_id
* @return array|resource * @return array|resource
*/ */
public function get_skills_by_gradebook($gradebook_id) public function getSkillsByGradebook($gradebook_id)
{ {
$gradebook_id = intval($gradebook_id); $gradebook_id = intval($gradebook_id);
$sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill $sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill

@ -254,7 +254,7 @@ class SkillRelSkill extends Model
$skill_rel_user = new SkillRelUser(); $skill_rel_user = new SkillRelUser();
if ($load_user_data) { if ($load_user_data) {
$passed_skills = $skill_rel_user->get_user_skills($user_id); $passed_skills = $skill_rel_user->getUserSkills($user_id);
$done_skills = array(); $done_skills = array();
foreach ($passed_skills as $done_skill) { foreach ($passed_skills as $done_skill) {
$done_skills[] = $done_skill['skill_id']; $done_skills[] = $done_skill['skill_id'];
@ -510,7 +510,7 @@ class SkillRelUser extends Model
* @param int $sessionId Optional. The session id * @param int $sessionId Optional. The session id
* @return array The skill list. Otherwise return false * @return array The skill list. Otherwise return false
*/ */
public function get_user_skills($userId, $courseId = 0, $sessionId = 0) public function getUserSkills($userId, $courseId = 0, $sessionId = 0)
{ {
if (empty($userId)) { if (empty($userId)) {
return array(); return array();
@ -886,7 +886,7 @@ class Skill extends Model
); );
if (!empty($skill_gradebooks)) { if (!empty($skill_gradebooks)) {
foreach ($skill_gradebooks as $skill_gradebook) { foreach ($skill_gradebooks as $skill_gradebook) {
$user_has_skill = $this->user_has_skill( $user_has_skill = $this->userHasSkill(
$user_id, $user_id,
$skill_gradebook['skill_id'], $skill_gradebook['skill_id'],
$courseId, $courseId,
@ -978,7 +978,7 @@ class Skill extends Model
* *
* @return array * @return array
*/ */
public function get_user_skills($userId, $get_skill_data = false) public function getUserSkills($userId, $get_skill_data = false)
{ {
$userId = intval($userId); $userId = intval($userId);
$sql = 'SELECT DISTINCT s.id, s.name, s.icon, u.id as issue $sql = 'SELECT DISTINCT s.id, s.name, s.icon, u.id as issue
@ -1117,7 +1117,10 @@ class Skill extends Model
// User achieved the skill (depends in the gradebook with certification) // User achieved the skill (depends in the gradebook with certification)
$skill['data']['achieved'] = false; $skill['data']['achieved'] = false;
if ($user_id) { if ($user_id) {
$skill['data']['achieved'] = $this->user_has_skill($user_id, $skill['id']); $skill['data']['achieved'] = $this->userHasSkill(
$user_id,
$skill['id']
);
} }
// Check if the skill has related gradebooks // Check if the skill has related gradebooks
@ -1387,7 +1390,7 @@ class Skill extends Model
* @param int $sessionId Optional. The session id * @param int $sessionId Optional. The session id
* @return boolean Whether the user has the skill return true. Otherwise return false * @return boolean Whether the user has the skill return true. Otherwise return false
*/ */
public function user_has_skill($userId, $skillId, $courseId = 0, $sessionId = 0) public function userHasSkill($userId, $skillId, $courseId = 0, $sessionId = 0)
{ {
$courseId = intval($courseId); $courseId = intval($courseId);
$sessionId = intval($sessionId); $sessionId = intval($sessionId);

@ -2070,7 +2070,7 @@ class SocialManager extends UserManager
$skill = new Skill(); $skill = new Skill();
$ranking = $skill->get_user_skill_ranking($userId); $ranking = $skill->get_user_skill_ranking($userId);
$skills = $skill->get_user_skills($userId, true); $skills = $skill->getUserSkills($userId, true);
$template = new Template(null, false, false, false, false, false); $template = new Template(null, false, false, false, false, false);
$template->assign('ranking', $ranking); $template->assign('ranking', $ranking);

@ -115,7 +115,9 @@ if ($accessGranted == false) {
// TODO: Missing validation of learning path completion // TODO: Missing validation of learning path completion
} else { } else {
// A gradebook was found, proceed... // A gradebook was found, proceed...
$categoryId = $catLoad[0]->get_id(); /** @var Category $category */
$category = $catLoad[0];
$categoryId = $category->get_id();
$link = LinkFactory::load( $link = LinkFactory::load(
null, null,
null, null,
@ -137,8 +139,12 @@ if ($accessGranted == false) {
$userId $userId
); );
if (!empty($certificate['pdf_url']) || !empty($certificate['badge_link'])) { if (!empty($certificate['pdf_url']) ||
if (is_array($certificate) && isset($certificate['pdf_url'])) { !empty($certificate['badge_link'])
) {
if (is_array($certificate) &&
isset($certificate['pdf_url'])
) {
$downloadCertificateLink = generateLPFinalItemTemplateCertificateLinks( $downloadCertificateLink = generateLPFinalItemTemplateCertificateLinks(
$certificate $certificate
); );
@ -158,9 +164,7 @@ if ($accessGranted == false) {
$currentScore = Category::getCurrentScore( $currentScore = Category::getCurrentScore(
$userId, $userId,
$categoryId, $category,
$courseCode,
$sessionId,
true true
); );
Category::registerCurrentScore( Category::registerCurrentScore(
@ -235,7 +239,7 @@ function generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId =
{ {
$em = Database::getManager(); $em = Database::getManager();
$skillRelUser = new SkillRelUser(); $skillRelUser = new SkillRelUser();
$userSkills = $skillRelUser->get_user_skills($userId, $courseId, $sessionId); $userSkills = $skillRelUser->getUserSkills($userId, $courseId, $sessionId);
$skillList = ''; $skillList = '';
$badgeLink = ''; $badgeLink = '';

@ -465,7 +465,7 @@ if ($_SESSION['oLP']->current == $_SESSION['oLP']->get_last()) {
$gradebookLinks[0]->get_type() == LINK_LEARNPATH && $gradebookLinks[0]->get_type() == LINK_LEARNPATH &&
$gradebookLinks[0]->get_ref_id() == $_SESSION['oLP']->lp_id $gradebookLinks[0]->get_ref_id() == $_SESSION['oLP']->lp_id
) { ) {
$gradebookMinScore = $categories[0]->get_certificate_min_score(); $gradebookMinScore = $categories[0]->getCertificateMinScore();
$userScore = $gradebookLinks[0]->calc_score($user_id, 'best'); $userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
if ($userScore[0] >= $gradebookMinScore) { if ($userScore[0] >= $gradebookMinScore) {

@ -27,7 +27,7 @@ $userInfo = api_get_user_info();
$skill = new Skill(); $skill = new Skill();
$ranking = $skill->get_user_skill_ranking($userId); $ranking = $skill->get_user_skill_ranking($userId);
$skills = $skill->get_user_skills($userId, true); $skills = $skill->getUserSkills($userId, true);
$dialogForm = new FormValidator('form', 'post', null, null, ['id' => 'add_item']); $dialogForm = new FormValidator('form', 'post', null, null, ['id' => 'add_item']);
$dialogForm->addLabel( $dialogForm->addLabel(

@ -116,9 +116,6 @@ try {
$userFinishedCourse = Category::userFinishedCourse( $userFinishedCourse = Category::userFinishedCourse(
$student->getId(), $student->getId(),
$gradebook, $gradebook,
0,
$course->getCode(),
$session ? $session->getId() : 0,
true true
); );
@ -133,8 +130,7 @@ try {
$score = Category::getCurrentScore( $score = Category::getCurrentScore(
$student->getId(), $student->getId(),
$gradebook->get_id(), $gradebook,
$course->getCode(),
$session ? $session->getId() : 0 $session ? $session->getId() : 0
); );

@ -313,9 +313,7 @@ if (!empty($courseAndSessions['courses']) && $allow) {
foreach ($mainCategoryList as $category) { foreach ($mainCategoryList as $category) {
$parentScore = Category::getCurrentScore( $parentScore = Category::getCurrentScore(
$userId, $userId,
$category->get_id(), $category,
$category->get_course_code(),
0,
true true
); );
@ -332,9 +330,7 @@ if (!empty($courseAndSessions['courses']) && $allow) {
if (!empty($subCategory)) { if (!empty($subCategory)) {
$score = Category::getCurrentScore( $score = Category::getCurrentScore(
$userId, $userId,
$subCategory->get_id(), $subCategory,
$subCategory->get_course_code(),
0,
true true
); );
$totalScoreWithChildren += $score; $totalScoreWithChildren += $score;

Loading…
Cancel
Save