Changes of the last few months including restructuring system from using only ranks to permissions
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
function getUser($username)
|
||||
{
|
||||
$result = $this->db->query('SELECT ID, username, displayname, email, rank, profile_picture, header_image, about, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE username = ? AND is_activated = TRUE LIMIT 1', [$username])->result_array();
|
||||
$result = $this->db->query('SELECT ID, username, displayname, email, rank, profile_picture, header_image, about, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE username = ? AND is_activated = TRUE AND isDeleted = FALSE LIMIT 1', [$username])->result_array();
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
{
|
||||
for ($i = 0; $i < sizeof($userList); $i++) {
|
||||
if ((isset($userList[$i]['header_image']) && ($userList[$i]['header_image'] == '' || $userList[$i]['header_image'] == NULL)) || !isset($userList[$i]['header_image'])) {
|
||||
$userList[$i]['header_image'] = substr(base_url(), 0, base_url() - 1) . ':5000/' . $userList[$i]['displayname'];
|
||||
$userList[$i]['header_image'] = 'https://cdn.kinogofdog.eu' . '/' . $userList[$i]['displayname'];
|
||||
}
|
||||
if (isset($userList[$i]['profile_picture']) && $userList[$i]['profile_picture'] == '') {
|
||||
$userList[$i]['profile_picture'] = base_url('/f/8d204712d8132b36d765640ce775ce15');
|
||||
@@ -64,7 +64,7 @@
|
||||
public function getFollowers($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$followers = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followerUserID WHERE followedUserID = ? ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$followers = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followerUserID WHERE followedUserID = ? AND is_activated = TRUE AND isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$this->db->cache_on();
|
||||
$followers = $this->setDefaultImages($followers);
|
||||
$followers = $this->mergeFollowerCount($followers);
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
function getUserByID($id)
|
||||
{
|
||||
$result = $this->db->query('SELECT ID, original_name, username, displayname, email, rank, profile_picture, header_image, is_activated, about, lastLogin, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE ID = ? AND is_activated = TRUE LIMIT 1', [$id])->result_array();
|
||||
$result = $this->db->query('SELECT ID, original_name, username, displayname, email, rank, profile_picture, header_image, is_activated, about, lastLogin, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE ID = ? AND is_activated = TRUE AND isDeleted = FALSE LIMIT 1', [$id])->result_array();
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
@@ -83,14 +83,14 @@
|
||||
}
|
||||
|
||||
function getUserEmailByID($id) {
|
||||
$result = $this->db->query('SELECT email FROM users WHERE ID = ? AND is_activated = TRUE', [$id])->result_array();
|
||||
$result = $this->db->query('SELECT email FROM users WHERE ID = ? AND is_activated = TRUE AND isDeleted = TRUE', [$id])->result_array();
|
||||
return !empty($result) ? $result[0]['email'] : '';
|
||||
}
|
||||
|
||||
public function getFollowing($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$following = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followedUserID WHERE followerUserID = ? ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$following = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followedUserID WHERE followerUserID = ? AND isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$this->db->cache_on();
|
||||
$following = $this->setDefaultImages($following);
|
||||
$following = $this->mergeFollowerCount($following);
|
||||
@@ -187,14 +187,14 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
|
||||
function getActiveUsers($count)
|
||||
{
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, lastLogin, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users WHERE isCurrentlyOnline = TRUE ORDER BY lastLogin DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, lastLogin, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users WHERE isCurrentlyOnline = TRUE AND is_activated = TRUE AND isDeleted = FALSE ORDER BY lastLogin DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->setDefaultImages($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNewestUsers($count)
|
||||
{
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, date_created, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users ORDER BY date_created DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, date_created, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users WHERE is_activated = TRUE AND isDeleted = FALSE ORDER BY date_created DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->setDefaultImages($data);
|
||||
return $data;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
$dbClause = join(' AND ', $conditions);
|
||||
$inputs[] = $amount;
|
||||
$inputs[] = $offset;
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, header_image, about, rank FROM users WHERE ' . $dbClause . ' LIMIT ? OFFSET ?', $inputs)->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, header_image, about, rank FROM users WHERE is_activated = TRUE AND isDeleted = FALSE AND ' . $dbClause . ' LIMIT ? OFFSET ?', $inputs)->result_array();
|
||||
|
||||
$data = $this->setDefaultImages($data);
|
||||
$data = $this->setRankname($data);
|
||||
@@ -238,4 +238,36 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
return $this->db->query('SELECT language, count(*) langUserCount FROM users GROUP BY language ORDER BY language')->result_array();
|
||||
}
|
||||
|
||||
public function deleteUser($id) {
|
||||
$this->db->query('UPDATE users SET isDeleted = TRUE, isCurrentlyOnline = FALSE, lastOnlineUpdate = NULL WHERE ID = ?', [$id])->result_array();
|
||||
}
|
||||
|
||||
public function getPermissions($userID) {
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT * FROM user_permissions WHERE userID = ?', [$userID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$perms = [];
|
||||
|
||||
foreach ($result as $item) {
|
||||
$perms[] = $item['permissionType'] . '.' . $item['permissionName'];
|
||||
}
|
||||
|
||||
return $perms;
|
||||
}
|
||||
|
||||
public function hasPermission($userID, $permType, $permName) {
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT ID FROM user_permissions WHERE userID = ? AND permissionType = ? AND permissionName = ?', [$userID, $permType, $permName])->result_array();
|
||||
$this->db->cache_on();
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
public function addPermission($userID, $permissionGroup, $permissionName, $givenBy) {
|
||||
$this->db->query('INSERT INTO user_permissions (userID, permissionType, permissionName, givenBy) VALUES (?, ?, ?, ?)', [$userID, $permissionGroup, $permissionName, $givenBy]);
|
||||
}
|
||||
|
||||
public function revokePermission($userID, $permissionGroup, $permissionName) {
|
||||
$this->db->query('DELETE FROM user_permissions WHERE userID = ? AND permissionType = ? AND permissionName = ?', [$userID, $permissionGroup, $permissionName]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user