]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Contact.php
Add block/unblock methods to Contact class
[friendica.git] / src / Object / Contact.php
index 4f0b237dec406ae66a53feb6cabb6da02ee105f9..1aee2c2b57fcc18092e82a69124ad0b71cb16a75 100644 (file)
@@ -477,12 +477,14 @@ class Contact extends BaseObject
                                "SELECT COUNT(*) AS `total`
                                 FROM `contact`
                                 WHERE `uid` = %d
-                                AND `self` = 0
+                                AND NOT `self`
+                                AND NOT `blocked`
+                                AND NOT `pending`
                                 AND `id` NOT IN (
                                        SELECT DISTINCT(`contact-id`)
                                        FROM `group_member`
                                        WHERE `uid` = %d
-                               ) ", intval($uid), intval($uid)
+                               )", intval($uid), intval($uid)
                        );
 
                        return $r;
@@ -492,13 +494,13 @@ class Contact extends BaseObject
                        "SELECT *
                        FROM `contact`
                        WHERE `uid` = %d
-                       AND `self` = 0
+                       AND NOT `self`
+                       AND NOT `blocked`
+                       AND NOT `pending`
                        AND `id` NOT IN (
                                SELECT DISTINCT(`contact-id`)
                                FROM `group_member` WHERE `uid` = %d
                        )
-                       AND `blocked` = 0
-                       AND `pending` = 0
                        LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count)
                );
                return $r;
@@ -734,6 +736,8 @@ class Contact extends BaseObject
         */
        public static function getPostsFromUrl($contact_url)
        {
+               $a = self::getApp();
+
                require_once 'include/conversation.php';
 
                // There are no posts with "uid = 0" with connector networks
@@ -759,7 +763,6 @@ class Contact extends BaseObject
                        " ORDER BY `item`.`created` DESC LIMIT %d, %d", intval($author_id), intval(local_user()), intval($a->pager['start']), intval($a->pager['itemspage'])
                );
 
-               $a = self::getApp();
 
                $o = conversation($a, $r, 'community', false);
 
@@ -818,4 +821,30 @@ class Contact extends BaseObject
 
                return $account_type;
        }
+
+       /**
+        * @brief Blocks a contact
+        *
+        * @param int $uid
+        * @return bool
+        */
+       public static function block($uid)
+       {
+               $return = dba::update('contact', ['blocked' => true], ['id' => $uid]);
+
+               return $return;
+       }
+
+       /**
+        * @brief Unblocks a contact
+        *
+        * @param int $uid
+        * @return bool
+        */
+       public static function unblock($uid)
+       {
+               $return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
+
+               return $return;
+       }
 }