Frontend, Bugfixes
This commit is contained in:
@@ -2,14 +2,38 @@
|
||||
|
||||
namespace Api\User;
|
||||
|
||||
use Api\Parameter\Parameter;
|
||||
use \Api\Request;
|
||||
|
||||
class Fetch extends Request {
|
||||
|
||||
const SELECT_SIZE = 20;
|
||||
|
||||
private int $userCount;
|
||||
|
||||
public function __construct($user, $externalCall = false) {
|
||||
parent::__construct($user, $externalCall, array());
|
||||
|
||||
parent::__construct($user, $externalCall, array(
|
||||
'page' => new Parameter('page', Parameter::TYPE_INT, true, 1)
|
||||
));
|
||||
|
||||
$this->loginRequired = true;
|
||||
$this->requiredGroup = USER_GROUP_ADMIN;
|
||||
$this->userCount = 0;
|
||||
}
|
||||
|
||||
private function getUserCount() {
|
||||
|
||||
$sql = $this->user->getSQL();
|
||||
$res = $sql->select($sql->count())->from("User")->execute();
|
||||
$this->success = ($res !== FALSE);
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if ($this->success) {
|
||||
$this->userCount = $res[0]["count"];
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
public function execute($values = array()) {
|
||||
@@ -17,11 +41,25 @@ class Fetch extends Request {
|
||||
return false;
|
||||
}
|
||||
|
||||
$page = $this->getParam("page");
|
||||
if($page < 1) {
|
||||
return $this->createError("Invalid page count");
|
||||
}
|
||||
|
||||
if (!$this->getUserCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = $this->user->getSQL();
|
||||
$res = $sql->select("User.uid as userId", "User.name", "User.email", "Group.uid as groupId", "Group.name as groupName")
|
||||
$res = $sql->select("User.uid as userId", "User.name", "User.email", "User.created_at",
|
||||
"Group.uid as groupId", "Group.name as groupName")
|
||||
->from("User")
|
||||
->leftJoin("UserGroup", "User.uid", "UserGroup.user_id")
|
||||
->leftJoin("Group", "Group.uid", "UserGroup.group_id")
|
||||
->orderBy("User.uid")
|
||||
->ascending()
|
||||
->limit(Fetch::SELECT_SIZE)
|
||||
->offset(($page - 1) * Fetch::SELECT_SIZE)
|
||||
->execute();
|
||||
|
||||
$this->success = ($res !== FALSE);
|
||||
@@ -30,14 +68,15 @@ class Fetch extends Request {
|
||||
if($this->success) {
|
||||
$this->result["users"] = array();
|
||||
foreach($res as $row) {
|
||||
$userId = $row["userId"];
|
||||
$groupId = $row["groupId"];
|
||||
$userId = intval($row["userId"]);
|
||||
$groupId = intval($row["groupId"]);
|
||||
$groupName = $row["groupName"];
|
||||
if (!isset($this->result["users"][$userId])) {
|
||||
$this->result["users"][$userId] = array(
|
||||
"uid" => $userId,
|
||||
"name" => $row["name"],
|
||||
"email" => $row["email"],
|
||||
"created_at" => $row["created_at"],
|
||||
"groups" => array(),
|
||||
);
|
||||
}
|
||||
@@ -46,6 +85,7 @@ class Fetch extends Request {
|
||||
$this->result["users"][$userId]["groups"][$groupId] = $groupName;
|
||||
}
|
||||
}
|
||||
$this->result["pages"] = intval(ceil($this->userCount / Fetch::SELECT_SIZE));
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
|
||||
Reference in New Issue
Block a user