get_string('filter'); $filter_uid = $this->get_int('uid'); $max = $this->get_int('max'); $query = $this->db() ->select($select) ->from('api.user u'); if ($filter_type && $filter_uid) { switch ($filter_type) { // only show followers case 'follower': $query = $query ->join('xssbook.follow f', 'f.follower_id = u.id AND f.followee_id', 'INNER') ->eq($filter_uid) ->where('f.value = TRUE'); break; // only show followees case 'followee': $query = $query ->join('xssbook.follow f', 'f.followee_id = u.id AND f.follower_id', 'INNER') ->eq($filter_uid) ->where('f.value = TRUE'); break; } } if ($max) { $query = $query ->where('u.id') ->le($max); } return $query; } public function get_people(): array { $filter_type = $this->get_string('filter'); $filter_uid = $this->get_int('uid'); $page = $this->get_int('page', 0); $page_size = PEOPLE_PAGE_SIZE; $offset = $page_size * $page; $users = $this->get_filted_query('u.*') ->order_by('u.id', 'DESC') ->offset($offset) ->limit($page_size) ->rows(); $count = $this->get_filted_query('COUNT(u.id) AS count') ->row()['count']; $max = 0; foreach ($users as $user) $max = max($max, $user['id']); return array( 'users' => $users, 'count' => $count, 'page_size' => $page_size, 'max_id' => $max, 'filter_type' => $filter_type, 'filter_uid' => $filter_uid, ); } }