diff --git a/src/application/controller/api/user/random.php b/src/application/controller/api/user/random.php new file mode 100644 index 0000000..9892a16 --- /dev/null +++ b/src/application/controller/api/user/random.php @@ -0,0 +1,30 @@ + false, + 'message' => _('Internal server error'), + 'users' => [], + 'total' => 0 +]; + +$usersTotal = 0; +$users = []; + +foreach ((array) $_modelUser->getLastRandomUsers(APPLICATION_MODULE_USERS_LIMIT) as $user) { + + $users[] = [ + 'userName' => $user['username'] + ]; + + $usersTotal++; +} + +$response = [ + 'success' => true, + 'message' => _('Users received'), + 'users' => $users, + 'total' => $usersTotal +]; + +header('Content-Type: application/json; charset=utf-8'); +echo json_encode($response); \ No newline at end of file diff --git a/src/application/controller/common/module/users.php b/src/application/controller/common/module/users.php new file mode 100644 index 0000000..2534019 --- /dev/null +++ b/src/application/controller/common/module/users.php @@ -0,0 +1,3 @@ +_db->query("SELECT * FROM `user` + JOIN `block` ON (`user`.`blockId` = `block`.`blockId`) + WHERE `block`.`time` > UNIX_TIMESTAMP(CURDATE() - interval 5 YEAR) + ORDER BY RAND() + LIMIT " . (int) $limit); + + return $query->rowCount() ? $query->fetchAll() : []; + + } catch (PDOException $e) { + + trigger_error($e->getMessage()); + return false; + } + } + public function userNameExists(string $userName) { try { diff --git a/src/application/view/common/module/users.phtml b/src/application/view/common/module/users.phtml new file mode 100644 index 0000000..7820c30 --- /dev/null +++ b/src/application/view/common/module/users.phtml @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/src/application/view/home.phtml b/src/application/view/home.phtml index aee893a..eb87ac6 100644 --- a/src/application/view/home.phtml +++ b/src/application/view/home.phtml @@ -2,6 +2,7 @@