Skip to main content
Sign in
Snippets Groups Projects
Commit bf1bf8c4 authored by Sulthan Dzaky Alfaro's avatar Sulthan Dzaky Alfaro
Browse files

add list user

parent 0c845d20
No related branches found
No related tags found
No related merge requests found
<?php
require_once SRC_ROOT_PATH . "/app/baseclasses/BaseController.php";
require_once SRC_ROOT_PATH . "/app/models/UserModel.php";
class GetAllUserController extends BaseController{
protected static $instance;
private function __construct($srv){
parent::__construct($srv);
}
public static function getInstance(){
if(!isset(self::$instance)){
self::$instance = new static(UserModel::getInstance());
}
return self::$instance;
}
public function get($urlParams){
$data = $this->srv->getAllUser();
if($data!=null){
return json_encode(array(
'status' => 'success',
'message' => 'Success to get all user',
'data' => $data
));
}
else{
return json_encode(array(
'status' => 'failed',
'message' => 'Failed to get all user',
));
}
}
}
?>
\ No newline at end of file
......@@ -28,11 +28,17 @@ class UserModel
public function getAllUser(){
try{
$user = $_SESSION['user_id'];
$db = PDOHandler::getInstance()->getPDO();
$sql = "SELECT * FROM users";
$sql = "SELECT * FROM users WHERE id != $user AND role='user' ORDER BY id";
$result = $db->query($sql);
if($result){
$hasil = $result->fetchAll(PDO::FETCH_ASSOC);
return $hasil;
}
else{
return null;
}
}catch(Exception $e){
return null;
}
......
......
......@@ -16,10 +16,10 @@ function Navbar()
Home
</div>
</a>
<a href="#">
<div class="sidebar-menu__item">
<a href="/user">
<div class="sidebar-menu__item sidebar-menu__item--active">
<img src="/public/assets/followed.jpg" class="sidebar-menu__item-icon" />
Followed
User
</div>
</a>
<a href="/profiles">
......
......
<?php
require_once PAGE_PATH . "/templates/navbar.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User</title>
<link rel="stylesheet" href="/public/css/shared.css" />
<link rel="stylesheet" href="/public/css/user.css" />
<link rel="stylesheet" href="/public/css/home.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
</head>
<body>
<div class="layout">
<?php
echo Navbar();
?>
<div class="dropdowntempat">
<select id="dropdown" name="selectedOption">
<option value="username">Username</option>
<option value="name">Profile Name</option>
</select>
<div class="input-search">
<input type="text" id="search" placeholder="Search" class="input-search-text">
<button id="search-button" class="search-button">Search</button>
</div>
<div id="list-user"></div>
</div>
</div>
<script src="/public/js/user.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -11,6 +11,7 @@ require_once SRC_ROOT_PATH . "/app/router/Router.php";
require_once CONTROLLER_PATH . "/User/LoginController.php";
require_once CONTROLLER_PATH . "/User/LogoutController.php";
require_once CONTROLLER_PATH . "/User/RegisterController.php";
require_once CONTROLLER_PATH . "/User/GetAllUserController.php";
require_once CONTROLLER_PATH . "/Admin/AdminController.php";
require_once CONTROLLER_PATH . "/Admin/BanController.php";
require_once CONTROLLER_PATH . "/Admin/UnbanController.php";
......@@ -64,13 +65,14 @@ $router->addHandler("/api/profile", ProfileController::getInstance(), []);
$router->addHandler("/api/profileuser/*", ProfileUserController::getInstance(), []);
$router->addHandler("/api/follow", FollowController::getInstance(), []);
$router->addHandler("/api/unfollow", UnfollowController::getInstance(), []);
$router->addHandler("/api/getalluser", GetAllUserController::getInstance(), []);
$router->addHandler("/", HomePage::getInstance(), []);
$router->addHandler("/login", LoginPage::getInstance(), []);
$router->addHandler("/compose/kicau", ComposePage::getInstance(), [CheckLogin::getInstance()]);
$router->addHandler("/compose/create", PostController::getInstance(), [CheckLogin::getInstance()]);
// $router->addHandler("/*", UserPage::getInstance(), []);
$router->addHandler("/user", UserPage::getInstance(), []);
$router->addHandler("/settings/*", SettingsPage::getInstance(), [CheckLogin::getInstance()]);
$router->addHandler("/admin/*", AdminPage::getInstance(), [CheckAdmin::getInstance()]);
$router->addHandler("/admin/unban/*", AdminPageUnban::getInstance(), [CheckAdmin::getInstance()]);
......
......
.dropdowntempat #dropdown{
background-color: #007bff;
color: #fff;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 10px;
}
.input-search{
margin-top: 20px;
}
.input-search input{
padding: 10px;
border: 1px solid #ccc;
border-radius: 20px;
margin-right: 5px;
width: 570px;
height:50px;
box-sizing: border-box;
}
.input-search button{
padding: 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 20px;
cursor: pointer;
height: 50px;
width: 70px;
}
.input-search button:hover{
background-color: #6545a0;
}
\ No newline at end of file
const valuedropdown = document.querySelector('#dropdown');
const valuesearch = document.querySelector('#search');
const buttonsearch = document.getElementById('search-button');
function makeListUser(data){
const listuser = document.getElementById('list-user');
data.forEach(element => {
const username = document.createElement('p');
username.textContent = "@"+element.username;
const nama = document.createElement('p');
nama.textContent = element.profile_name;
const simpanidentitas = document.createElement('div');
simpanidentitas.classList.add('kolom');
simpanidentitas.appendChild(nama);
simpanidentitas.appendChild(username);
const fotoprofile = document.createElement('img');
fotoprofile.classList.add('fotoprofil');
if(element.profile_picture_path==null){
fotoprofile.src = '/public/assets/kajuha.jpg';
}
else{
path = element.profile_picture_path;
path = path.replace("/var/www/html", '');
fotoprofile.src = path;
}
const identitas = document.createElement('div');
identitas.classList.add('iden');
identitas.appendChild(fotoprofile);
identitas.appendChild(simpanidentitas);
identitas.addEventListener('click',function(){gotoProfile(element.id)});
const box = document.createElement('div');
box.classList.add('box');
box.appendChild(identitas);
listuser.appendChild(box);
});
}
const xhr = new XMLHttpRequest();
xhr.open('GET','/api/getalluser');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
makeListUser(response.data);
} else {
console.error('Gagal melakukan permintaan');
}
}
};
xhr.send();
buttonsearch.addEventListener('click',function(){
const xhr = new XMLHttpRequest();
xhr.open('GET','/api/getalluser');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
let data = response.data
ambildata = [];
if(valuedropdown.value=='username'){
for (let index = 0; index < data.length; index++) {
var regex = new RegExp(`.*${valuesearch.value}.*`);
if(regex.test(data[index].username)){
ambildata.push(data[index]);
}
}
}
else if(valuedropdown.value=='name'){
for (let index = 0; index < data.length; index++) {
var regex = new RegExp(`.*${valuesearch.value}.*`);
if(regex.test(data[index].profile_name)){
ambildata.push(data[index]);
}
}
}
var hapus = document.querySelectorAll(".box");
hapus.forEach(function(e){
e.remove();
});
makeListUser(ambildata);
} else {
console.error('Gagal melakukan permintaan');
}
}
};
xhr.send();
});
function gotoProfile(userid){
console.log(userid,"user");
window.location.href = "/profiles/"+userid;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment