@@ -6769,31 +6769,32 @@ function WSCertificatesList($startingDate = '', $endingDate = '')
6769
6769
$ userTable = Database::get_main_table (TABLE_MAIN_USER );
6770
6770
$ categoryTable = Database::get_main_table (TABLE_MAIN_GRADEBOOK_CATEGORY );
6771
6771
6772
- $ query = "SELECT
6773
- certificate.id,
6774
- user.username,
6775
- category.course_code,
6776
- category.session_id,
6777
- certificate.user_id,
6778
- certificate.cat_id,
6779
- certificate.created_at,
6780
- certificate.path_certificate
6781
- FROM $ certificateTable AS certificate
6782
- JOIN $ userTable AS user
6783
- ON certificate.user_id = user.user_id
6784
- JOIN $ categoryTable AS category
6785
- ON certificate.cat_id = category.id " ;
6772
+ $ conditions = [];
6786
6773
6787
6774
if (!empty ($ startingDate ) && !empty ($ endingDate )) {
6788
- $ query .= " WHERE certificate.created_at BETWEEN ' $ startingDate ' AND ' $ endingDate' " ;
6775
+ $ conditions [ ' certificate.created_at BETWEEN ? AND ? ' ] = [ $ startingDate , $ endingDate] ;
6789
6776
} elseif (!empty ($ startingDate )) {
6790
- $ query .= " WHERE certificate.created_at >= ' $ startingDate' " ;
6777
+ $ conditions [ ' certificate.created_at >= ? ' ] = [ $ startingDate] ;
6791
6778
} elseif (!empty ($ endingDate )) {
6792
- $ query .= " WHERE certificate.created_at <= ' $ endingDate' " ;
6779
+ $ conditions [ ' certificate.created_at <= ? ' ] = [ $ endingDate] ;
6793
6780
}
6794
6781
6795
- $ queryResult = Database::query ($ query );
6796
- while ($ row = Database::fetch_array ($ queryResult )) {
6782
+ $ queryResult = Database::select (
6783
+ [
6784
+ 'certificate.id ' ,
6785
+ 'user.username ' ,
6786
+ 'category.course_code ' ,
6787
+ 'category.session_id ' ,
6788
+ 'certificate.user_id ' ,
6789
+ 'certificate.cat_id ' ,
6790
+ 'certificate.created_at ' ,
6791
+ 'certificate.path_certificate ' ,
6792
+ ],
6793
+ $ certificateTable ,
6794
+ ['where ' => $ conditions ]
6795
+ );
6796
+
6797
+ foreach ($ queryResult as $ row ) {
6797
6798
$ userPath = USermanager::getUserPathById ($ row ['user_id ' ], 'web ' );
6798
6799
$ row ['path_certificate ' ] = $ userPath .'/certificate ' .$ row ['path_certificate ' ];
6799
6800
$ result [] = $ row ;
0 commit comments