@@ -533,6 +533,10 @@ public static function get_table_type_course($type)
533533 {
534534 global $ table_evaluated ;
535535
536+ if (!isset ($ table_evaluated [$ type ][0 ])) {
537+ throw new \InvalidArgumentException ('Unknown evaluated type: ' .$ type );
538+ }
539+
536540 return Database::get_course_table ($ table_evaluated [$ type ][0 ]);
537541 }
538542
@@ -674,18 +678,24 @@ public static function get_list_users_certificates($cat_id = null, $userList = [
674678 {
675679 $ table_certificate = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CERTIFICATE );
676680 $ table_user = Database::get_main_table (TABLE_MAIN_USER );
677- $ sql = 'SELECT DISTINCT u.id as user_id, u.lastname, u.firstname, u.username, gc.created_at
678- FROM ' .$ table_user .' u
679- INNER JOIN ' .$ table_certificate .' gc
680- ON u.id = gc.user_id ' ;
681+
682+ $ sql = 'SELECT DISTINCT u.id AS user_id, u.lastname, u.firstname, u.username, gc.created_at
683+ FROM ' .$ table_user .' u
684+ INNER JOIN ' .$ table_certificate .' gc ON u.id = gc.user_id ' ;
685+
686+ $ where = [];
687+
681688 if (!is_null ($ cat_id ) && $ cat_id > 0 ) {
682- $ sql . = ' WHERE cat_id= ' . intval ( $ cat_id) ;
689+ $ where [] = 'gc. cat_id = ' .( int ) $ cat_id ;
683690 }
684691 if (!empty ($ userList )) {
685- $ userList = array_map ('intval ' , $ userList );
686- $ userListCondition = implode ("',' " , $ userList );
687- $ sql .= " AND u.id IN (' $ userListCondition') " ;
692+ $ ids = array_map ('intval ' , $ userList );
693+ $ where [] = 'u.id IN ( ' .implode (', ' , $ ids ).') ' ;
694+ }
695+ if ($ where ) {
696+ $ sql .= ' WHERE ' .implode (' AND ' , $ where );
688697 }
698+
689699 $ sql .= ' ORDER BY ' .(api_sort_by_first_name () ? 'u.firstname ' : 'u.lastname ' );
690700 $ rs = Database::query ($ sql );
691701
@@ -1210,39 +1220,31 @@ public static function get_all_users($evals = [], $links = []): array
12101220 */
12111221 public static function find_students ($ mask = '' )
12121222 {
1213- // students shouldn't be here // don't search if mask empty
1214- if (!api_is_allowed_to_edit () || empty ($ mask )) {
1223+ if (!api_is_allowed_to_edit () || $ mask === '' ) {
12151224 return null ;
12161225 }
1226+
12171227 $ mask = Database::escape_string ($ mask );
12181228 $ tbl_user = Database::get_main_table (TABLE_MAIN_USER );
1219- $ tbl_cru = Database::get_main_table (TABLE_MAIN_COURSE_USER );
1220- $ sql = 'SELECT DISTINCT user.id as user_id, user.lastname, user.firstname, user.email, user.official_code
1221- FROM ' .$ tbl_user .' user ' ;
1222- if (!api_is_platform_admin ()) {
1223- $ sql .= ', ' .$ tbl_cru .' cru ' ;
1224- }
1229+ $ tbl_cru = Database::get_main_table (TABLE_MAIN_COURSE_USER );
12251230
1226- $ sql .= ' WHERE user.status = ' .STUDENT ;
1227- $ sql .= ' AND (user.lastname LIKE ' ."'% " .$ mask ."%' " ;
1228- $ sql .= ' OR user.firstname LIKE ' ."'% " .$ mask ."%') " ;
1231+ $ sql = 'SELECT DISTINCT user.id AS user_id, user.lastname, user.firstname, user.email, user.official_code
1232+ FROM ' .$ tbl_user .' user ' ;
12291233
12301234 if (!api_is_platform_admin ()) {
1231- $ sql .= ' AND user.id = cru.user_id AND
1232- cru.relation_type <> ' .COURSE_RELATION_TYPE_RRHH .' AND
1233- cru.c_id in (
1234- SELECT c_id FROM ' .$ tbl_cru .'
1235- WHERE
1236- user_id = ' .api_get_user_id ().' AND
1237- status = ' .COURSEMANAGER .'
1238- )
1239- ' ;
1235+ $ sql .= ' INNER JOIN ' .$ tbl_cru .' cru ON (cru.user_id = user.id)
1236+ AND cru.relation_type <> ' .COURSE_RELATION_TYPE_RRHH .'
1237+ AND cru.c_id IN (
1238+ SELECT c_id FROM ' .$ tbl_cru .'
1239+ WHERE user_id = ' .api_get_user_id ().' AND status = ' .COURSEMANAGER .'
1240+ ) ' ;
12401241 }
12411242
1242- $ sql .= ' ORDER BY lastname, firstname ' ;
1243- if (api_is_western_name_order ()) {
1244- $ sql .= ' ORDER BY firstname, lastname ' ;
1245- }
1243+ $ sql .= ' WHERE user.status = ' .STUDENT .'
1244+ AND (user.lastname LIKE \'% ' .$ mask .'% \' OR user.firstname LIKE \'% ' .$ mask .'% \') ' ;
1245+
1246+ $ orderBy = api_is_western_name_order () ? 'firstname, lastname ' : 'lastname, firstname ' ;
1247+ $ sql .= ' ORDER BY ' .$ orderBy ;
12461248
12471249 $ result = Database::query ($ sql );
12481250
@@ -1281,14 +1283,13 @@ public static function updateLinkWeight($linkId, $name, $weight)
12811283 $ row_attendance = Database::fetch_array ($ rs_attendance );
12821284 $ sql = 'UPDATE ' .$ tbl_attendance .' SET
12831285 attendance_weight = ' .api_float_val ($ weight ).'
1284- WHERE c_id = ' . $ course_id . ' AND id = ' .intval ($ row_attendance ['ref_id ' ]);
1286+ WHERE id = ' .intval ($ row_attendance ['ref_id ' ]);
12851287 Database::query ($ sql );
12861288 }
12871289 // Update weight into forum thread
12881290 $ sql = 'UPDATE ' .$ tbl_forum_thread .' SET
12891291 thread_weight = ' .api_float_val ($ weight ).'
12901292 WHERE
1291- c_id = ' .$ course_id .' AND
12921293 iid = (
12931294 SELECT ref_id FROM ' .$ table_link .'
12941295 WHERE id= ' .$ linkId .' AND type= ' .LINK_FORUM_THREAD .'
@@ -1300,15 +1301,14 @@ public static function updateLinkWeight($linkId, $name, $weight)
13001301 ->createQuery ('
13011302 UPDATE ChamiloCourseBundle:CStudentPublication w
13021303 SET w.weight = :final_weight
1303- WHERE w.cId = :course
1304- AND w.iid = (
1304+ WHERE
1305+ w.iid = (
13051306 SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l
13061307 WHERE l.id = :link AND l.type = :type
13071308 )
13081309 ' )
13091310 ->execute ([
13101311 'final_weight ' => $ weight ,
1311- 'course ' => $ course_id ,
13121312 'link ' => $ linkId ,
13131313 'type ' => LINK_STUDENTPUBLICATION ,
13141314 ]);
0 commit comments