Minor - format code, improve code

pull/2970/head
Julio Montoya 6 years ago
parent 0b00703d7a
commit b73da946d8
  1. 16
      main/gradebook/lib/GradebookUtils.php
  2. 8
      main/gradebook/lib/be/category.class.php
  3. 8
      main/gradebook/lib/fe/displaygradebook.php
  4. 2
      main/inc/lib/certificate.lib.php
  5. 4
      main/inc/lib/document.lib.php

@ -707,9 +707,12 @@ class GradebookUtils
$date_certificate $date_certificate
) { ) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql = 'SELECT COUNT(id) as count $cat_id = (int) $cat_id;
FROM '.$table.' gc $user_id = (int) $user_id;
WHERE gc.cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'" ';
$sql = "SELECT COUNT(id) as count
FROM $table gc
WHERE gc.cat_id = $cat_id AND user_id = $user_id ";
$rs_exist = Database::query($sql); $rs_exist = Database::query($sql);
$row = Database::fetch_array($rs_exist); $row = Database::fetch_array($rs_exist);
if ($row['count'] == 0) { if ($row['count'] == 0) {
@ -734,8 +737,11 @@ class GradebookUtils
public static function get_certificate_by_user_id($cat_id, $user_id) public static function get_certificate_by_user_id($cat_id, $user_id)
{ {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql = 'SELECT * FROM '.$table.' $cat_id = (int) $cat_id;
WHERE cat_id="'.intval($cat_id).'" AND user_id="'.intval($user_id).'"'; $user_id = (int) $user_id;
$sql = "SELECT * FROM $table
WHERE cat_id = $cat_id AND user_id = $user_id ";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');

@ -2131,20 +2131,18 @@ class Category implements GradebookItem
return false; return false;
} }
$cattotal = self::load($category_id); $scoretotal = $category->calc_score($user_id);
$scoretotal = $cattotal[0]->calc_score($user_id);
// Do not remove this the gradebook/lib/fe/gradebooktable.class.php // Do not remove this the gradebook/lib/fe/gradebooktable.class.php
// file load this variable as a global // file load this variable as a global
$scoredisplay = ScoreDisplay::instance(); $scoredisplay = ScoreDisplay::instance();
$my_score_in_gradebook = $scoredisplay->display_score( $my_score_in_gradebook = $scoredisplay->display_score(
$scoretotal, $scoretotal,
SCORE_SIMPLE SCORE_SIMPLE
); );
$my_certificate = GradebookUtils::get_certificate_by_user_id( $my_certificate = GradebookUtils::get_certificate_by_user_id(
$category->get_id(), $category_id,
$user_id $user_id
); );
@ -2156,7 +2154,7 @@ class Category implements GradebookItem
api_get_utc_datetime() api_get_utc_datetime()
); );
$my_certificate = GradebookUtils::get_certificate_by_user_id( $my_certificate = GradebookUtils::get_certificate_by_user_id(
$category->get_id(), $category_id,
$user_id $user_id
); );
} }

@ -393,7 +393,8 @@ class DisplayGradebook
isset($_GET['selectcat']) && $_GET['selectcat'] != 0) && isset($_GET['selectcat']) && $_GET['selectcat'] != 0) &&
isset($_GET['studentoverview']) isset($_GET['studentoverview'])
) { ) {
$header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank"> $header .= '<td style="vertical-align: top;">
<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
'.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).' '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
'.get_lang('ExportPDF').'</a>'; '.get_lang('ExportPDF').'</a>';
} }
@ -550,17 +551,16 @@ class DisplayGradebook
'</a>'; '</a>';
} }
if (api_is_allowed_to_edit(null, true) || $isCoach) { if ($isCoach || api_is_allowed_to_edit(null, true)) {
echo $toolbar = Display::toolbarAction( echo $toolbar = Display::toolbarAction(
'gradebook-actions', 'gradebook-actions',
[$actionsLeft, $actionsRight] [$actionsLeft, $actionsRight]
); );
} }
if (api_is_allowed_to_edit(null, true) || $accessToEdit) { if ($accessToEdit || api_is_allowed_to_edit(null, true)) {
$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->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0; $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0;
if (!empty($min_certification)) { if (!empty($min_certification)) {

@ -211,6 +211,7 @@ class Certificate extends Model
$params['hide_print_button'] = isset($params['hide_print_button']) ? true : false; $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false;
$categoryId = 0; $categoryId = 0;
$my_category = [];
if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) { if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
$categoryId = $this->certificate_data['cat_id']; $categoryId = $this->certificate_data['cat_id'];
$my_category = Category::load($categoryId); $my_category = Category::load($categoryId);
@ -227,7 +228,6 @@ class Certificate extends Model
$sessionId = $category->get_session_id(); $sessionId = $category->get_session_id();
$skill = new Skill(); $skill = new Skill();
$skill->addSkillToUser( $skill->addSkillToUser(
$this->user_id, $this->user_id,
$category, $category,

@ -1835,7 +1835,7 @@ class DocumentManager
public static function get_default_certificate_id($course_id, $session_id = 0) public static function get_default_certificate_id($course_id, $session_id = 0)
{ {
$tbl_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $tbl_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$session_id = intval($session_id); $session_id = (int) $session_id;
if (empty($session_id)) { if (empty($session_id)) {
$session_id = api_get_session_id(); $session_id = api_get_session_id();
} }
@ -1843,7 +1843,7 @@ class DocumentManager
if (empty($session_id)) { if (empty($session_id)) {
$sql_session = 'AND (session_id = 0 OR isnull(session_id)) '; $sql_session = 'AND (session_id = 0 OR isnull(session_id)) ';
} elseif ($session_id > 0) { } elseif ($session_id > 0) {
$sql_session = 'AND session_id='.intval($session_id); $sql_session = 'AND session_id='.$session_id;
} else { } else {
$sql_session = ''; $sql_session = '';
} }

Loading…
Cancel
Save