Jelajahi Sumber

Fix case with list is too big see BT#12815

jmontoyaa 7 tahun lalu
induk
melakukan
8b2d6b9d1f

+ 53 - 0
main/inc/lib/sessionmanager.lib.php

@@ -1989,6 +1989,59 @@ class SessionManager
                     c_id = $courseId
                     $statusCondition
                 ";
+
+        $result = Database::query($sql);
+        $existingUsers = array();
+        while ($row = Database::fetch_array($result)) {
+            $existingUsers[] = $row['user_id'];
+        }
+
+        return $existingUsers;
+    }
+
+     /**
+     * Returns user list of the current users subscribed in the course-session
+     * @param array $sessionList
+     * @param array $courseList
+     * @param int $status
+     * @param int $start
+     * @param int $limit
+     *
+     * @return array
+     */
+    public static function getUsersByCourseAndSessionList(
+        $sessionList,
+        $courseList,
+        $status = null,
+        $start = null,
+        $limit = null
+    ) {
+        if (empty($sessionList) || empty($courseList)) {
+            return [];
+        }
+        $sessionListToString = implode("','", $sessionList);
+        $courseListToString = implode("','", $courseList);
+
+        $statusCondition = null;
+        if (isset($status) && !is_null($status)) {
+            $status = intval($status);
+            $statusCondition = " AND status = $status";
+        }
+
+        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+
+        $sql = "SELECT DISTINCT user_id
+                FROM $table
+                WHERE
+                    session_id IN ('$sessionListToString') AND
+                    c_id IN ('$courseListToString')
+                    $statusCondition
+                ";
+        if (!is_null($start) && !is_null($limit)) {
+            $start = (int) $start;
+            $limit = (int) $limit;
+            $sql .= "LIMIT $start, $limit";
+        }
         $result = Database::query($sql);
         $existingUsers = array();
         while ($row = Database::fetch_array($result)) {

+ 20 - 3
plugin/studentfollowup/StudentFollowUpPlugin.php

@@ -170,10 +170,12 @@ class StudentFollowUpPlugin extends Plugin
     /**
      * @param string $status
      * @param int $currentUserId
+     * @param int $start
+     * @param int $limit
      *
      * @return array
      */
-    public static function getUsers($status, $currentUserId)
+    public static function getUsers($status, $currentUserId, $start, $limit)
     {
         switch ($status) {
             case COURSEMANAGER:
@@ -204,7 +206,14 @@ class StudentFollowUpPlugin extends Plugin
                 break;
         }
 
-        $userList = [];
+        $userList = SessionManager::getUsersByCourseAndSessionList(
+            $sessions,
+            $courses,
+            $start,
+            $limit
+        );
+
+        /*$userList = [];
         foreach ($sessions as $sessionId) {
             foreach ($courses as $courseId) {
                 $courseInfo = ['real_id' => $courseId];
@@ -215,8 +224,16 @@ class StudentFollowUpPlugin extends Plugin
                 $userList = array_merge($userList, $userFromSessionList);
             }
             $userList = array_unique($userList);
-        }
+        }*/
 
         return $userList;
     }
+
+    /**
+     * @return int
+     */
+    public static function getPageSize()
+    {
+        return 2;
+    }
 }

+ 9 - 3
plugin/studentfollowup/my_students.php

@@ -15,6 +15,8 @@ $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
 $totalItems = 0;
 $items = [];
 $showPrivate = false;
+$pageSize = StudentFollowUpPlugin::getPageSize();
+$firstResults = $pageSize * ($currentPage - 1);
 
 $userList = [];
 if (!api_is_platform_admin()) {
@@ -22,7 +24,12 @@ if (!api_is_platform_admin()) {
     if (api_is_drh()) {
         $status = DRH;
     }
-    $userList = StudentFollowUpPlugin::getUsers($status, $currentUserId);
+    $userList = StudentFollowUpPlugin::getUsers(
+        $status,
+        $currentUserId,
+        $firstResults,
+        $pageSize
+    );
 }
 
 if (!empty($userList) || api_is_platform_admin()) {
@@ -37,14 +44,13 @@ if (!empty($userList) || api_is_platform_admin()) {
         $criteria->andWhere(Criteria::expr()->eq('private', false));
     }
 
-    $pageSize = 2;
     $qb
         ->select('p')
         ->distinct()
         ->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p')
         ->join('p.user', 'u')
         ->addCriteria($criteria)
-        ->setFirstResult($pageSize * ($currentPage - 1))
+        ->setFirstResult($firstResults)
         ->setMaxResults($pageSize)
         ->groupBy('p.user')
         ->orderBy('p.createdAt', 'desc')

+ 1 - 1
plugin/studentfollowup/posts.php

@@ -32,7 +32,7 @@ if ($showPrivate == false) {
     $criteria->andWhere(Criteria::expr()->eq('private', false));
 }
 
-$pageSize = 2;
+$pageSize = StudentFollowUpPlugin::getPageSize();
 
 $qb
     ->select('p')