]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Merge pull request #8464 from annando/notice
[friendica.git] / src / Model / User.php
index 9c6f29ba01e5462751f71ae19eb93bd1f1e0cacd..351982e8add93cccc2f726f197b7a4da1cfe3591 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Model;
 
 use DivineOmega\PasswordExposed;
 use Exception;
+use Friendica\Content\Pager;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
@@ -894,7 +895,7 @@ class User
         */
        public static function block(int $uid, bool $block = true)
        {
-               return DBA::update('user', ['blocked' => 0], ['uid' => $uid]);
+               return DBA::update('user', ['blocked' => $block], ['uid' => $uid]);
        }
 
        /**
@@ -941,6 +942,34 @@ class User
                );
        }
 
+       /**
+        * Denys a pending registration
+        *
+        * @param string $hash The hash of the pending user
+        *
+        * This does not have to go through user_remove() and save the nickname
+        * permanently against re-registration, as the person was not yet
+        * allowed to have friends on this system
+        *
+        * @return bool True, if the deny was successfull
+        * @throws Exception
+        */
+       public static function deny(string $hash)
+       {
+               $register = Register::getByHash($hash);
+               if (!DBA::isResult($register)) {
+                       return false;
+               }
+
+               $user = User::getById($register['uid']);
+               if (!DBA::isResult($user)) {
+                       return false;
+               }
+
+               return DBA::delete('user', ['uid' => $register['uid']]) &&
+                      Register::deleteByHash($register['hash']);
+       }
+
        /**
         * Creates a new user based on a minimal set and sends an email to this user
         *
@@ -1122,11 +1151,11 @@ class User
        }
 
        /**
-        * @param object $uid user to remove
+        * @param int $uid user to remove
         * @return bool
         * @throws InternalServerErrorException
         */
-       public static function remove($uid)
+       public static function remove(int $uid)
        {
                if (!$uid) {
                        return false;
@@ -1288,4 +1317,47 @@ class User
 
                return $statistics;
        }
+
+       /**
+        * Get all users of the current node
+        *
+        * @param int    $start Start count (Default is 0)
+        * @param int    $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
+        * @param string $type  The type of users, which should get (all, bocked, removed)
+        * @param string $order Order of the user list (Default is 'contact.name')
+        * @param string $order_direction Order direction (Default is ASC)
+        *
+        * @return array The list of the users
+        * @throws Exception
+        */
+       public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+')
+       {
+               $sql_order           = '`' . str_replace('.', '`.`', $order) . '`';
+               $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC';
+
+               switch ($type) {
+                       case 'active':
+                               $sql_extra = 'AND `user`.`blocked` = 0';
+                               break;
+                       case 'blocked':
+                               $sql_extra = 'AND `user`.`blocked` = 1';
+                               break;
+                       case 'removed':
+                               $sql_extra = 'AND `user`.`account_removed` = 1';
+                               break;
+                       case 'all':
+                       default:
+                               $sql_extra = '';
+                               break;
+               }
+
+               $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created`
+                               FROM `user`
+                               INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
+                               WHERE `user`.`verified` $sql_extra
+                               ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count
+               );
+
+               return DBA::toArray($usersStmt);
+       }
 }