Explorar o código

Added a platform setting that determines how the users should be sorted: on first name or on last name.
This setting is currently only used in the list of users when sending a new document in the dropbox functionality.
In course.lib.php there is now also a BIG performance improvement because no query is needed for every individual user (100 users in course meant that there were 101 queries while now there is only 1)

Patrick Cool %!s(int64=15) %!d(string=hai) anos
pai
achega
b0c1303ee4

+ 2 - 2
main/dropbox/dropbox_functions.inc.php

@@ -570,7 +570,7 @@ function display_add_form()
 		$complete_user_list_for_dropbox = array();
 		if(api_get_setting('dropbox_allow_student_to_student')=='true' || $_user['status'] != STUDENT)
 		{
-			$complete_user_list_for_dropbox = CourseManager :: get_user_list_from_course_code($course_info['code'],true,$_SESSION['id_session']);
+			$complete_user_list_for_dropbox = CourseManager :: get_user_list_from_course_code($course_info['code'],true,$_SESSION['id_session'],'',api_get_setting('user_order_by'));
 		}
 		$complete_user_list2 = CourseManager :: get_coach_list_from_course_code($course_info['code'],$_SESSION['id_session']);
 		$complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox,$complete_user_list2);
@@ -578,7 +578,7 @@ function display_add_form()
 	else{
 		if(api_get_setting('dropbox_allow_student_to_student')=='true' || $_user['status'] != STUDENT)
 		{
-			$complete_user_list_for_dropbox = CourseManager :: get_user_list_from_course_code($course_info['code'],true,$_SESSION['id_session']);
+			$complete_user_list_for_dropbox = CourseManager :: get_user_list_from_course_code($course_info['code'],true,$_SESSION['id_session'],'',api_get_setting('user_order_by'));
 		}
 		else
 		{

+ 23 - 9
main/inc/lib/course.lib.php

@@ -849,19 +849,32 @@ class CourseManager {
 	 *	Return user info array of all users registered in the specified real or virtual course
 	 *	This only returns the users that are registered in this actual course, not linked courses.
 	 *
-	 *	@param string $course_code
-	 *	@return array with user info
+	 * @param string $course_code the code of the course
+	 * @param boolean $with_session determines if the course is used in a session or not
+	 * @param integer $session_id the id of the session
+	 * @param string $limit the LIMIT statement of the sql statement
+	 * @param string $order_by the field to order the users by. Valid values are 'lastname', 'firstname', 'username', 'email', 'official_code' OR a part of a SQL statement that starts with ORDER BY ...
+	 * @return array
 	 */
 	public static function get_user_list_from_course_code($course_code, $with_session = true, $session_id = 0, $limit = '', $order_by = '') {
 
-		$session_id = intval($session_id);
-		$course_code = Database::escape_string($course_code);
+		// variable initialisation
+		$session_id 	= intval($session_id);
+		$users		= array();
+        $course_code 	= Database::escape_string($course_code);
+		$where 			= array();
+		// if the $order_by does not contain 'ORDER BY' we have to check if it is a valid field that can be sorted on
+		if (!strstr($order_by,'ORDER BY')){		
+			if (!empty($order_by) AND in_array($order_by, array('lastname', 'firstname', 'username', 'email', 'official_code'))){
+				$order_by = 'ORDER BY user.'.$order_by;
+			} else {
+				$order_by = '';
+			}
+		}		
 
-		$users = array();
-		$where = array();
 		$sql = $session_id == 0
-			? 'SELECT DISTINCT course_rel_user.status, user.user_id, course_rel_user.role, course_rel_user.tutor_id '
-			: 'SELECT DISTINCT user.user_id, user.status ';
+			? 'SELECT DISTINCT course_rel_user.status, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.*  '
+			: 'SELECT DISTINCT user.user_id, user.status, user.*  ';
 
 		$sql .= ' FROM '.Database::get_main_table(TABLE_MAIN_USER).' as user ';
 
@@ -889,7 +902,8 @@ class CourseManager {
 		$rs = Database::query($sql, __FILE__, __LINE__);
 
 		while ($user = Database::fetch_array($rs)) {
-			$user_info = Database::get_user_info_from_id($user['user_id']);
+			//$user_info = Database::get_user_info_from_id($user['user_id']);
+			$user_info = $user;
 			$user_info['status'] = $user['status'];
 			if (isset($user['role'])) {
 				$user_info['role'] = $user['role'];

+ 4 - 0
main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql

@@ -66,6 +66,10 @@ UPDATE TABLE settings_current SET selected_value = '1.8.6.2.9070' WHERE variable
 
 INSERT INTO course_field (field_type, field_variable, field_display_text, field_default_value, field_visible, field_changeable) values (10, 'special_course','SpecialCourse', 'Yes', 1 , 1);
 
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('user_order_by', NULL, 'radio', 'User', 'lastname', 'OrderUsersByTitle', 'OrderUsersByComment', NULL, NULL, 1);
+INSERT INTO settings_options (variable, value, display_text) VALUES ('user_order_by','firstname','FirstName');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('user_order_by','lastname','LastName');
+
 -- xxSTATSxx
 ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
 ALTER TABLE track_e_online ADD INDEX (course);