Skip to content

Commit

Permalink
Rename function register_user_info_about_certificate registerUserInfo…
Browse files Browse the repository at this point in the history
…AboutCertificate, improve queries
  • Loading branch information
jmontoyaa committed Dec 8, 2016
1 parent e33f0eb commit 03a12a2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
3 changes: 2 additions & 1 deletion main/forum/forumfunction.inc.php
Expand Up @@ -5384,7 +5384,8 @@ function count_number_of_post_for_user_thread($thread_id, $user_id)
{
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
$course_id = api_get_course_int_id();
$sql = "SELECT count(*) as count FROM $table_posts
$sql = "SELECT count(iid) as count
FROM $table_posts
WHERE c_id = $course_id AND
thread_id=".intval($thread_id)." AND
poster_id = ".intval($user_id)." AND visible = 1 ";
Expand Down
22 changes: 12 additions & 10 deletions main/gradebook/lib/GradebookUtils.php
Expand Up @@ -573,19 +573,21 @@ public static function parse_xml_data($file)

/**
* register user info about certificate
* @param int The category id
* @param int The user id
* @param float The score obtained for certified
* @param Datetime The date when you obtained the certificate
* @param integer $cat_id
* @param integer $user_id
* @param string $date_certificate
* @param int $cat_id The category id
* @param int $user_id The user id
* @param float $score_certificate The score obtained for certified
* @param string $date_certificate The date when you obtained the certificate
*
* @return void
*/
public static function register_user_info_about_certificate($cat_id, $user_id, $score_certificate, $date_certificate)
{
public static function registerUserInfoAboutCertificate(
$cat_id,
$user_id,
$score_certificate,
$date_certificate
) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql = 'SELECT COUNT(*) as count
$sql = 'SELECT COUNT(id) as count
FROM ' . $table . ' gc
WHERE gc.cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '" ';
$rs_exist = Database::query($sql);
Expand Down
2 changes: 1 addition & 1 deletion main/gradebook/lib/be/category.class.php
Expand Up @@ -1992,7 +1992,7 @@ public static function register_user_certificate($category_id, $user_id)
);

if (empty($my_certificate)) {
GradebookUtils::register_user_info_about_certificate(
GradebookUtils::registerUserInfoAboutCertificate(
$category_id,
$user_id,
$my_score_in_gradebook,
Expand Down
24 changes: 11 additions & 13 deletions main/inc/lib/course.lib.php
Expand Up @@ -1661,7 +1661,8 @@ public static function get_users_count_in_course(
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];

$sql = 'SELECT DISTINCT count(*) as count FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
$sql = 'SELECT DISTINCT count(user.id) as count
FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
$where = array();
if (!empty($session_id)) {
$sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' as session_course_user
Expand Down Expand Up @@ -1704,8 +1705,8 @@ public static function get_users_count_in_course(

/**
* Get a list of coaches of a course and a session
* @param string Course code
* @param int Session ID
* @param string $course_code
* @param int $session_id
* @param bool $addGeneralCoach
* @return array List of users
*/
Expand Down Expand Up @@ -1808,7 +1809,6 @@ public static function get_student_list_from_course_code(

// students subscribed to the course through a session
if ($with_session) {

$joinSession = "";
//Session creation date
if (!empty($date_from) && !empty($date_to)) {
Expand Down Expand Up @@ -1881,7 +1881,6 @@ public static function get_teacher_list_from_course_code($course_code)
return $teachers;
}


/**
* Return user info array of all teacher-users registered in a course
* This only returns the users that are registered in this actual course, not linked courses.
Expand Down Expand Up @@ -1964,7 +1963,7 @@ public static function get_teacher_list_from_course_code_to_string(
}

if (!empty($list)) {
if ($orderList === true){
if ($orderList === true) {
$html .= '<ul class="user-teacher">';
foreach ($list as $teacher){
$html .= Display::tag('li', Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY) . ' ' . $teacher);
Expand Down Expand Up @@ -2063,14 +2062,14 @@ public static function get_coachs_from_course_to_string(
$course_coachs[] = $coach_name;
}
}
$coaches_to_string = null;

$coaches_to_string = '';
if (!empty($course_coachs)) {
if ($orderList === true){
if ($orderList === true) {
$html .= '<ul class="user-coachs">';
foreach ($course_coachs as $coachs){
$html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
}
foreach ($course_coachs as $coachs) {
$html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
}
$html .= '</ul>';
} else {
$coaches_to_string = array_to_string($course_coachs, $separator);
Expand All @@ -2093,7 +2092,6 @@ public static function get_coachs_from_course_to_string(
public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0)
{
$complete_user_list = array();

//get users from real course
$user_list = self::get_user_list_from_course_code($course_code, $session_id);
foreach ($user_list as $this_user) {
Expand Down Expand Up @@ -4251,7 +4249,7 @@ public static function generate_nice_next_course_code($wanted_code)
$wanted_code = CourseManager::generate_course_code($wanted_code);
$table = Database::get_main_table(TABLE_MAIN_COURSE);
$wanted_code = Database::escape_string($wanted_code);
$sql = "SELECT count(*) as count
$sql = "SELECT count(id) as count
FROM $table
WHERE code LIKE '$wanted_code%'";
$result = Database::query($sql);
Expand Down
33 changes: 18 additions & 15 deletions main/inc/lib/tracking.lib.php
Expand Up @@ -2712,19 +2712,19 @@ public static function get_avg_student_score(
* This function does not take the results of a Test out of a LP
*
* @param int|array Array of user ids or an user id
* @param string Course code
* @param array List of LP ids
* @param int Session id (optional), if param $session_id is null(default)
* @param string $course_code Course code
* @param array $lp_ids List of LP ids
* @param int $session_id Session id (optional), if param $session_id is 0(default)
* it'll return results including sessions, 0 = session is not filtered
* @param bool Returns an array of the type [sum_score, num_score] if set to true
* @param bool get only the latest attempts or ALL attempts
* @return string Value (number %) Which represents a round integer explain in got in 3.
*/
public static function getAverageStudentScore(
$student_id,
$course_code = null,
$course_code = '',
$lp_ids = array(),
$session_id = null
$session_id = 0
) {
if (empty($student_id)) {
return 0;
Expand Down Expand Up @@ -2764,9 +2764,9 @@ public static function getAverageStudentScore(
}

$conditionsToString = implode('AND ', $conditions);
$sql = "SELECT SUM(lp_iv.score) sum_score,
SUM(lp_i.max_score) sum_max_score,
count(*) as count
$sql = "SELECT
SUM(lp_iv.score) sum_score,
SUM(lp_i.max_score) sum_max_score
FROM $lp_table as lp
INNER JOIN $lp_item_table as lp_i
ON lp.id = lp_id AND lp.c_id = lp_i.c_id
Expand All @@ -2776,15 +2776,15 @@ public static function getAverageStudentScore(
ON lp_i.id = lp_iv.lp_item_id AND lp_view.c_id = lp_iv.c_id AND lp_iv.lp_view_id = lp_view.id
WHERE (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') AND
$conditionsToString
";
";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');

if (empty($row['sum_max_score'])) {
return 0;
}

return ($row['sum_score'] / $row['sum_max_score'])*100;
return ($row['sum_score'] / $row['sum_max_score']) * 100;

}

Expand Down Expand Up @@ -4017,7 +4017,7 @@ public static function get_tools_most_used_by_course($courseId, $session_id = nu
* BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES
* @param int User Id
* @param int Course Id
* @param int Session Id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
* @param int Session Id (optional), if param $session_id is 0 (default) it'll return results including sessions, 0 = session is not filtered
* @param string Date from
* @param string Date to
* @return array Data
Expand Down Expand Up @@ -4146,19 +4146,22 @@ public static function get_total_clicks($userId, $courseId, $sessionId = 0, $dat
* @param int Limit (optional, default = 0, 0 = without limit)
* @return array documents downloaded
*/
public static function get_documents_most_downloaded_by_course($course_code, $session_id = null, $limit = 0)
public static function get_documents_most_downloaded_by_course($course_code, $session_id = 0, $limit = 0)
{
//protect data
$courseId = api_get_course_int_id($course_code);
$data = array();

$TABLETRACK_DOWNLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$session_id = intval($session_id);
if (!empty($session_id)) {
$condition_session = ' AND down_session_id = '. $session_id;
}
$sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
$sql = "SELECT
down_doc_path,
COUNT(DISTINCT down_user_id),
COUNT(down_doc_path) as count_down
FROM $TABLETRACK_DOWNLOADS
WHERE c_id = $courseId
$condition_session
Expand Down

3 comments on commit 03a12a2

@ywarnier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've been renaming a few of these recently... as a suggestion, I would avoid renaming functions between minor versions, because if someone wants (later) to do a cherry-pick to fix only one bug, they will face a conflict in the functions naming.
It is not a very strong issue, but I think it would be best to keep functions renaming for major versions only.

@jmontoyaa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it.

@ywarnier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure: I'm definitely in favour of the renaming. Just better between major versions.

Please sign in to comment.