From 45c148be3b1642ed14b765eaabc246b358805a84 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Mon, 14 Aug 2017 09:59:42 +0200 Subject: [PATCH] Rename functions using camelCase - Fix getCurrentScore and userFinishedCourse to use Category instead of course and session code. --- main/admin/skills_profile.php | 2 +- main/badge/assertion.php | 3 +- main/gradebook/get_badges.php | 2 +- main/gradebook/gradebook.php | 2 +- main/gradebook/gradebook_add_link.php | 2 +- main/gradebook/gradebook_edit_link.php | 2 +- main/gradebook/index.php | 12 +- main/gradebook/lib/GradebookUtils.php | 2 +- main/gradebook/lib/be/category.class.php | 203 ++++++++---------- main/gradebook/lib/be/evaluation.class.php | 21 +- main/gradebook/lib/fe/catform.class.php | 2 +- main/gradebook/lib/fe/displaygradebook.php | 2 +- .../gradebook/lib/fe/gradebooktable.class.php | 2 +- main/inc/ajax/model.ajax.php | 2 +- main/inc/ajax/skill.ajax.php | 8 +- main/inc/lib/SequenceResourceManager.php | 5 +- main/inc/lib/gradebook.lib.php | 4 +- main/inc/lib/skill.lib.php | 15 +- main/inc/lib/social.lib.php | 2 +- main/lp/lp_final_item.php | 18 +- main/lp/lp_view.php | 2 +- main/social/skills_wheel.php | 2 +- plugin/grading_electronic/generate.php | 6 +- user_portal.php | 8 +- 24 files changed, 154 insertions(+), 175 deletions(-) diff --git a/main/admin/skills_profile.php b/main/admin/skills_profile.php index 9a40257545..de6a20209e 100755 --- a/main/admin/skills_profile.php +++ b/main/admin/skills_profile.php @@ -64,7 +64,7 @@ if (!empty($users)) { foreach ($users as $user) { $user_info = api_get_user_info($user['user_id']); $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(); $found_counts = 0; foreach ($my_user_skills as $my_skill) { diff --git a/main/badge/assertion.php b/main/badge/assertion.php index 3d80826dc1..bcec9d18dc 100644 --- a/main/badge/assertion.php +++ b/main/badge/assertion.php @@ -20,8 +20,7 @@ if ($userId === 0 || $skillId === 0) { } $objSkill = new Skill(); - -if (!$objSkill->user_has_skill($userId, $skillId, $courseId, $sessionId)) { +if (!$objSkill->userHasSkill($userId, $skillId, $courseId, $sessionId)) { exit; } diff --git a/main/gradebook/get_badges.php b/main/gradebook/get_badges.php index 342b6e904d..8a6c7c6da3 100644 --- a/main/gradebook/get_badges.php +++ b/main/gradebook/get_badges.php @@ -21,7 +21,7 @@ $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); $objSkillRelUser = new SkillRelUser(); -$userSkills = $objSkillRelUser->get_user_skills($userId, $courseId, $sessionId); +$userSkills = $objSkillRelUser->getUserSkills($userId, $courseId, $sessionId); if (empty($userSkills)) { api_not_allowed(true); diff --git a/main/gradebook/gradebook.php b/main/gradebook/gradebook.php index 2a439add2c..1ab4cb4480 100755 --- a/main/gradebook/gradebook.php +++ b/main/gradebook/gradebook.php @@ -483,7 +483,7 @@ if (!empty($keyword)) { $alleval = array(); $alllink = array(); } 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()); } } elseif (isset($_GET['studentoverview'])) { diff --git a/main/gradebook/gradebook_add_link.php b/main/gradebook/gradebook_add_link.php index d7692e719a..4b3f89bb16 100755 --- a/main/gradebook/gradebook_add_link.php +++ b/main/gradebook/gradebook_add_link.php @@ -33,7 +33,7 @@ if ($session_id == 0) { $session_id ); } else { - $all_categories = Category::load_session_categories(null, $session_id); + $all_categories = Category::loadSessionCategories(null, $session_id); } $category = Category :: load($selectCat); $url = api_get_self().'?selectcat='.$selectCat.'&newtypeselected='.$typeSelected.'&course_code='.api_get_course_id().'&'.api_get_cidreq(); diff --git a/main/gradebook/gradebook_edit_link.php b/main/gradebook/gradebook_edit_link.php index b352aedbf2..a88414e8dd 100755 --- a/main/gradebook/gradebook_edit_link.php +++ b/main/gradebook/gradebook_edit_link.php @@ -39,7 +39,7 @@ if ($session_id == 0) { false ); //already init } else { - $cats = Category :: load_session_categories(null, $session_id); + $cats = Category::loadSessionCategories(null, $session_id); } $form = new LinkAddEditForm( diff --git a/main/gradebook/index.php b/main/gradebook/index.php index 56b2b57c38..9fdbbab623 100755 --- a/main/gradebook/index.php +++ b/main/gradebook/index.php @@ -413,14 +413,14 @@ $action = isset($_GET['action']) ? $_GET['action'] : null; switch ($action) { case 'lock': - $category_to_lock = Category :: load($_GET['category_id']); - $category_to_lock[0]->lock_all_items(1); + $category_to_lock = Category::load($_GET['category_id']); + $category_to_lock[0]->lockAllItems(1); $confirmation_message = get_lang('GradebookLockedAlert'); break; case 'unlock': if (api_is_platform_admin()) { - $category_to_lock = Category :: load($_GET['category_id']); - $category_to_lock[0]->lock_all_items(0); + $category_to_lock = Category::load($_GET['category_id']); + $category_to_lock[0]->lockAllItems(0); $confirmation_message = get_lang('EvaluationHasBeenUnLocked'); } break; @@ -770,9 +770,7 @@ if (!empty($selectCat)) { $currentScore = Category::getCurrentScore( $stud_id, - $selectCat, - $course_code, - $session_id, + $cats[0], true ); Category::registerCurrentScore($currentScore, $stud_id, $selectCat); diff --git a/main/gradebook/lib/GradebookUtils.php b/main/gradebook/lib/GradebookUtils.php index ff808f430b..88aac44ab0 100644 --- a/main/gradebook/lib/GradebookUtils.php +++ b/main/gradebook/lib/GradebookUtils.php @@ -1285,7 +1285,7 @@ class GradebookUtils $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $id = intval($id); $evaluation = new Evaluation(); - $evaluation->add_evaluation_log($id); + $evaluation->addEvaluationLog($id); $sql = 'UPDATE '.$table_evaluation.' SET weight = '."'".Database::escape_string($weight)."'".' WHERE id = '.$id; diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index c2367317a7..fe31bb619b 100755 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -89,7 +89,7 @@ class Category implements GradebookItem /** * @return integer|null */ - public function get_certificate_min_score() + public function getCertificateMinScore() { if (!empty($this->certificate_min_score)) { return $this->certificate_min_score; @@ -317,9 +317,9 @@ class Category implements GradebookItem public function get_skills($from_db = true) { if ($from_db) { - $cat_id = $this->get_id(); + $categoryId = $this->get_id(); $gradebook = new Gradebook(); - $skills = $gradebook->get_skills_by_gradebook($cat_id); + $skills = $gradebook->getSkillsByGradebook($categoryId); } else { $skills = $this->skills; } @@ -367,7 +367,7 @@ class Category implements GradebookItem * * @return array */ - public static function load_session_categories( + public static function loadSessionCategories( $id = null, $session_id = null ) { @@ -1289,7 +1289,7 @@ class Category implements GradebookItem // course independent categories if (empty($course_code)) { - $cats = self::get_independent_categories_with_result_for_student( + $cats = self::getIndependentCategoriesWithStudentResult( 0, $stud_id, $cats @@ -1691,12 +1691,14 @@ class Category implements GradebookItem /** * 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( $this->id, - $stud_id + $studentId ); if (count($evals) != 0) { return true; @@ -1708,8 +1710,9 @@ class Category implements GradebookItem $this->id, api_is_allowed_to_edit() ? null : 1 ); + /** @var Category $cat */ foreach ($cats as $cat) { - if ($cat->has_evaluations_with_results_for_student($stud_id)) { + if ($cat->hasEvaluationsWithStudentResults($studentId)) { return true; } } @@ -1721,30 +1724,31 @@ class Category implements GradebookItem /** * Retrieve all categories inside a course independent category * that should be visible to a student. - * @param integer $cat_id parent category - * @param $stud_id student id + * @param int $categoryId parent category + * @param int $studentId * @param array $cats optional: if defined, the categories will be added to this array * @return array */ - public function get_independent_categories_with_result_for_student( - $cat_id, - $stud_id, + public function getIndependentCategoriesWithStudentResult( + $categoryId, + $studentId, $cats = array() ) { $creator = api_is_allowed_to_edit() && !api_is_platform_admin() ? api_get_user_id() : null; - $crsindcats = self::load( + $categories = self::load( null, $creator, '0', - $cat_id, + $categoryId, api_is_allowed_to_edit() ? null : 1 ); - if (!empty($crsindcats)) { - foreach ($crsindcats as $crsindcat) { - if ($crsindcat->has_evaluations_with_results_for_student($stud_id)) { - $cats[] = $crsindcat; + if (!empty($categories)) { + /** @var Category $category */ + foreach ($categories as $category) { + 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) - * @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 int $session_id Session ID (optional) * @param bool $order @@ -1771,7 +1775,7 @@ class Category implements GradebookItem * @return array Array of subcategories */ public function get_subcategories( - $stud_id = null, + $studentId = null, $course_code = null, $session_id = null, $order = null @@ -1788,10 +1792,10 @@ class Category implements GradebookItem } // 1 student - if (isset($stud_id)) { + if (isset($studentId)) { // Special case: this is the root 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 { return self::load( null, @@ -1859,7 +1863,7 @@ class Category implements GradebookItem /** * 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 string $course_code * @param int $sessionId @@ -1867,7 +1871,7 @@ class Category implements GradebookItem * @return array */ public function get_evaluations( - $stud_id = null, + $studentId = null, $recursive = false, $course_code = '', $sessionId = 0 @@ -1882,10 +1886,10 @@ class Category implements GradebookItem } // 1 student - if (isset($stud_id) && !empty($stud_id)) { + if (isset($studentId) && !empty($studentId)) { // Special case: this is the root 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 { $evals = Evaluation::load( null, @@ -1903,25 +1907,57 @@ class Category implements GradebookItem ) { // root 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)) { // inside a course - $evals = Evaluation::load(null, null, $course_code, $this->id, null); + $evals = Evaluation::load( + null, + null, + $course_code, + $this->id, + null + ); } else { // 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 { - $evals = Evaluation::load(null, null, $course_code, $this->id, null); + $evals = Evaluation::load( + null, + null, + $course_code, + $this->id, + null + ); } } if ($recursive) { - $subcats = $this->get_subcategories($stud_id, $course_code, $sessionId); + $subcats = $this->get_subcategories( + $studentId, + $course_code, + $sessionId + ); if (!empty($subcats)) { 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); } } @@ -1932,7 +1968,7 @@ class Category implements GradebookItem /** * 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 string $course_code * @param int $sessionId @@ -1940,7 +1976,7 @@ class Category implements GradebookItem * @return array */ public function get_links( - $stud_id = null, + $studentId = null, $recursive = false, $course_code = '', $sessionId = 0 @@ -1957,8 +1993,8 @@ class Category implements GradebookItem // no links in root or course independent categories if ($this->id == 0) { - } elseif (isset($stud_id)) { - // 1 student $stud_id + } elseif (isset($studentId)) { + // 1 student $studentId $links = LinkFactory::load( null, null, @@ -1983,7 +2019,7 @@ class Category implements GradebookItem if ($recursive) { $subcats = $this->get_subcategories( - $stud_id, + $studentId, $course_code, $sessionId ); @@ -1991,7 +2027,7 @@ class Category implements GradebookItem /** @var Category $subcat */ foreach ($subcats as $subcat) { $sublinks = $subcat->get_links( - $stud_id, + $studentId, false, $course_code, $sessionId @@ -2089,7 +2125,7 @@ class Category implements GradebookItem /** * @param $locked */ - public function lock_all_items($locked) + public function lockAllItems($locked) { if (api_get_setting('gradebook_locking_enabled') == 'true') { $this->lock($locked); @@ -2177,9 +2213,6 @@ class Category implements GradebookItem $userFinishedCourse = self::userFinishedCourse( $user_id, $cats_course[0], - 0, - $courseCode, - $sessionId, true ); @@ -2203,7 +2236,7 @@ class Category implements GradebookItem ); $objSkillRelUser = new SkillRelUser(); - $userSkills = $objSkillRelUser->get_user_skills( + $userSkills = $objSkillRelUser->getUserSkills( $user_id, $courseId, $sessionId @@ -2385,82 +2418,51 @@ class Category implements GradebookItem * @param int $userId The user ID * @param \Category $category Optional. 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 * @return boolean */ public static function userFinishedCourse( $userId, - \Category $category = null, - $categoryId = 0, - $courseCode = null, - $sessionId = 0, + \Category $category, $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; - } - - $category = $cats_course[0]; - } - $currentScore = self::getCurrentScore( $userId, - $category->get_id(), - $courseCode, - $sessionId, + $category, $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 * @param int $userId The user id - * @param int $categoryId The gradebook category - * @param int $courseCode The course code - * @param int $sessionId Optional. The session id + * @param Category $category The gradebook category * @param bool $recalculate * * @return float The score */ public static function getCurrentScore( $userId, - $categoryId, - $courseCode, - $sessionId = 0, + $category, $recalculate = false ) { + if (empty($category)) { + return 0; + } + if ($recalculate) { return self::calculateCurrentScore( $userId, - $categoryId, - $courseCode, - $sessionId + $category ); } @@ -2469,7 +2471,7 @@ class Category implements GradebookItem Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_LOG), [ 'where' => [ - 'category_id = ? AND user_id = ?' => [$categoryId, $userId], + 'category_id = ? AND user_id = ?' => [$category->get_id(), $userId], ], 'order' => 'registered_at DESC', 'limit' => '1', @@ -2487,32 +2489,16 @@ class Category implements GradebookItem /** * Calculate the current score on a gradebook category for a user * @param int $userId The user id - * @param int $categoryId The gradebook category - * @param int $courseCode The course code - * @param int $sessionId Optional. The session id + * @param Category $category The gradebook category * @return float The score */ private static function calculateCurrentScore( $userId, - $categoryId, - $courseCode, - $sessionId + $category ) { - $cats_course = self::load( - $categoryId, - null, - $courseCode, - null, - null, - $sessionId, - false - ); - - if (empty($cats_course)) { + if (empty($category)) { return 0; } - - $category = $cats_course[0]; $courseEvaluations = $category->get_evaluations($userId, true); $courseLinks = $category->get_links($userId, true); $evaluationsAndLinks = array_merge($courseEvaluations, $courseLinks); @@ -2521,7 +2507,6 @@ class Category implements GradebookItem $item = $evaluationsAndLinks[$i]; $score = $item->calc_score($userId); $itemValue = 0; - if (!empty($score)) { $divider = $score[1] == 0 ? 1 : $score[1]; $itemValue = $score[0] / $divider * $item->get_weight(); diff --git a/main/gradebook/lib/be/evaluation.class.php b/main/gradebook/lib/be/evaluation.class.php index 749410aaf6..078bb1c1fd 100755 --- a/main/gradebook/lib/be/evaluation.class.php +++ b/main/gradebook/lib/be/evaluation.class.php @@ -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_linkeval_log = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); $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]); if (!empty($arreval['id'])) { $sql = 'SELECT weight from '.$tbl_grade_evaluations.' @@ -437,7 +437,7 @@ class Evaluation implements GradebookItem //recorded history $eval_log = new Evaluation(); - $eval_log->add_evaluation_log($this->id); + $eval_log->addEvaluationLog($this->id); Database::query($sql); } @@ -447,7 +447,8 @@ class Evaluation implements GradebookItem public function delete() { $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); } @@ -464,9 +465,9 @@ class Evaluation implements GradebookItem $parent = $this->category; } $tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); - $sql = 'SELECT count(id) AS number' - .' FROM '.$tbl_grade_evaluations - ." WHERE name = '".Database::escape_string($name)."'"; + $sql = "SELECT count(id) AS number + FROM $tbl_grade_evaluations + WHERE name = '".Database::escape_string($name)."'"; if (api_is_allowed_to_edit()) { $parent = Category::load($parent); @@ -779,7 +780,7 @@ class Evaluation implements GradebookItem * @return array evaluation objects matching the search criterium * @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); $evals = $rootcat[0]->get_evaluations( diff --git a/main/gradebook/lib/fe/catform.class.php b/main/gradebook/lib/fe/catform.class.php index 845022edd3..ee435783e0 100755 --- a/main/gradebook/lib/fe/catform.class.php +++ b/main/gradebook/lib/fe/catform.class.php @@ -177,7 +177,7 @@ class CatForm extends FormValidator 'skills' => $skills, 'weight' => $this->category_object->get_weight(), '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(), 'is_requirement' => $this->category_object->getIsRequirement(), ) diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index 95dadfb4ac..262f436ec9 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -449,7 +449,7 @@ class DisplayGradebook $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0; $weight = ''.get_lang('TotalWeight').' : '.$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; $edit_icon = ''. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).''; diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index 13bc40b368..f2a2d47271 100755 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -904,7 +904,7 @@ class GradebookTable extends SortableTable */ private function build_certificate_min_score($item) { - return $item->get_certificate_min_score(); + return $item->getCertificateMinScore(); } /** diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 3b54200e2c..535093d535 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -1525,7 +1525,7 @@ switch ($action) { if ($item['parent_id'] != 0) { continue; } - $skills = $obj->get_skills_by_gradebook($item['id']); + $skills = $obj->getSkillsByGradebook($item['id']); //Fixes bug when gradebook doesn't have names if (empty($item['name'])) { diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php index c610a70e70..c6f0b925ed 100755 --- a/main/inc/ajax/skill.ajax.php +++ b/main/inc/ajax/skill.ajax.php @@ -146,7 +146,7 @@ switch ($action) { break; case 'get_user_skill': $skillId = isset($_REQUEST['profile_id']) ? intval($_REQUEST['profile_id']) : 0; - $skill = $skill->user_has_skill($userId, $skillId); + $skill = $skill->userHasSkill($userId, $skillId); if ($skill) { echo 1; } else { @@ -154,11 +154,11 @@ switch ($action) { } break; case 'get_all_user_skills': - $skills = $skill->get_user_skills($userId, true); + $skills = $skill->getUserSkills($userId, true); echo json_encode($skills); break; case 'get_user_skills': - $skills = $skill->get_user_skills($userId, true); + $skills = $skill->getUserSkills($userId, true); Display::display_no_header(); Display::$global_template->assign('skills', $skills); $template = Display::$global_template->get_template('skill/user_skills.tpl'); @@ -222,7 +222,7 @@ switch ($action) { foreach ($users as $user) { $user_info = api_get_user_info($user['user_id']); $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(); foreach ($my_user_skills as $skill_item) { diff --git a/main/inc/lib/SequenceResourceManager.php b/main/inc/lib/SequenceResourceManager.php index 52c07fd81d..5257632285 100644 --- a/main/inc/lib/SequenceResourceManager.php +++ b/main/inc/lib/SequenceResourceManager.php @@ -78,10 +78,7 @@ class SequenceResourceManager if (!empty($userId)) { $itemSession['status'] = $itemSession['status'] && Category::userFinishedCourse( $userId, - $category, - null, - $course->getCode(), - $sessionRequired->getId() + $category ); } } diff --git a/main/inc/lib/gradebook.lib.php b/main/inc/lib/gradebook.lib.php index 6783bec8de..5ab24ec6fa 100755 --- a/main/inc/lib/gradebook.lib.php +++ b/main/inc/lib/gradebook.lib.php @@ -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(); if (!empty($selected_skills)) { foreach ($selected_skills as $skill) { @@ -209,7 +209,7 @@ class Gradebook extends Model * @param int $gradebook_id * @return array|resource */ - public function get_skills_by_gradebook($gradebook_id) + public function getSkillsByGradebook($gradebook_id) { $gradebook_id = intval($gradebook_id); $sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 3fce87e6f4..ab019a1f2e 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -254,7 +254,7 @@ class SkillRelSkill extends Model $skill_rel_user = new SkillRelUser(); 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(); foreach ($passed_skills as $done_skill) { $done_skills[] = $done_skill['skill_id']; @@ -510,7 +510,7 @@ class SkillRelUser extends Model * @param int $sessionId Optional. The session id * @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)) { return array(); @@ -886,7 +886,7 @@ class Skill extends Model ); if (!empty($skill_gradebooks)) { foreach ($skill_gradebooks as $skill_gradebook) { - $user_has_skill = $this->user_has_skill( + $user_has_skill = $this->userHasSkill( $user_id, $skill_gradebook['skill_id'], $courseId, @@ -978,7 +978,7 @@ class Skill extends Model * * @return array */ - public function get_user_skills($userId, $get_skill_data = false) + public function getUserSkills($userId, $get_skill_data = false) { $userId = intval($userId); $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) $skill['data']['achieved'] = false; 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 @@ -1387,7 +1390,7 @@ class Skill extends Model * @param int $sessionId Optional. The session id * @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); $sessionId = intval($sessionId); diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 00adca75ba..f9f6a7e294 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -2070,7 +2070,7 @@ class SocialManager extends UserManager $skill = new Skill(); $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->assign('ranking', $ranking); diff --git a/main/lp/lp_final_item.php b/main/lp/lp_final_item.php index 9b8a836eb7..d24d2f5616 100644 --- a/main/lp/lp_final_item.php +++ b/main/lp/lp_final_item.php @@ -115,7 +115,9 @@ if ($accessGranted == false) { // TODO: Missing validation of learning path completion } else { // A gradebook was found, proceed... - $categoryId = $catLoad[0]->get_id(); + /** @var Category $category */ + $category = $catLoad[0]; + $categoryId = $category->get_id(); $link = LinkFactory::load( null, null, @@ -137,8 +139,12 @@ if ($accessGranted == false) { $userId ); - if (!empty($certificate['pdf_url']) || !empty($certificate['badge_link'])) { - if (is_array($certificate) && isset($certificate['pdf_url'])) { + if (!empty($certificate['pdf_url']) || + !empty($certificate['badge_link']) + ) { + if (is_array($certificate) && + isset($certificate['pdf_url']) + ) { $downloadCertificateLink = generateLPFinalItemTemplateCertificateLinks( $certificate ); @@ -158,9 +164,7 @@ if ($accessGranted == false) { $currentScore = Category::getCurrentScore( $userId, - $categoryId, - $courseCode, - $sessionId, + $category, true ); Category::registerCurrentScore( @@ -235,7 +239,7 @@ function generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId = { $em = Database::getManager(); $skillRelUser = new SkillRelUser(); - $userSkills = $skillRelUser->get_user_skills($userId, $courseId, $sessionId); + $userSkills = $skillRelUser->getUserSkills($userId, $courseId, $sessionId); $skillList = ''; $badgeLink = ''; diff --git a/main/lp/lp_view.php b/main/lp/lp_view.php index 76a8b490d8..48849fc9fa 100755 --- a/main/lp/lp_view.php +++ b/main/lp/lp_view.php @@ -465,7 +465,7 @@ if ($_SESSION['oLP']->current == $_SESSION['oLP']->get_last()) { $gradebookLinks[0]->get_type() == LINK_LEARNPATH && $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'); if ($userScore[0] >= $gradebookMinScore) { diff --git a/main/social/skills_wheel.php b/main/social/skills_wheel.php index 55c6cd4d52..eb9ded05a1 100755 --- a/main/social/skills_wheel.php +++ b/main/social/skills_wheel.php @@ -27,7 +27,7 @@ $userInfo = api_get_user_info(); $skill = new Skill(); $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->addLabel( diff --git a/plugin/grading_electronic/generate.php b/plugin/grading_electronic/generate.php index 7b1141face..1cab158674 100644 --- a/plugin/grading_electronic/generate.php +++ b/plugin/grading_electronic/generate.php @@ -116,9 +116,6 @@ try { $userFinishedCourse = Category::userFinishedCourse( $student->getId(), $gradebook, - 0, - $course->getCode(), - $session ? $session->getId() : 0, true ); @@ -133,8 +130,7 @@ try { $score = Category::getCurrentScore( $student->getId(), - $gradebook->get_id(), - $course->getCode(), + $gradebook, $session ? $session->getId() : 0 ); diff --git a/user_portal.php b/user_portal.php index 3124b7c9dc..4dc1ebf2ac 100755 --- a/user_portal.php +++ b/user_portal.php @@ -313,9 +313,7 @@ if (!empty($courseAndSessions['courses']) && $allow) { foreach ($mainCategoryList as $category) { $parentScore = Category::getCurrentScore( $userId, - $category->get_id(), - $category->get_course_code(), - 0, + $category, true ); @@ -332,9 +330,7 @@ if (!empty($courseAndSessions['courses']) && $allow) { if (!empty($subCategory)) { $score = Category::getCurrentScore( $userId, - $subCategory->get_id(), - $subCategory->get_course_code(), - 0, + $subCategory, true ); $totalScoreWithChildren += $score;