]> 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 d799a7d892a74636fde5733f66981a8449aa76ac..1aee2c2b57fcc18092e82a69124ad0b71cb16a75 100644 (file)
@@ -138,7 +138,7 @@ class Contact extends BaseObject
         */
        public static function unmarkForArchival(array $contact)
        {
-               $condition = array('`id` => ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE);
+               $condition = array('`id` = ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE);
                $exists = dba::exists('contact', $condition);
 
                // We don't need to update, we never marked this contact for archival
@@ -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,16 +494,15 @@ 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;
        }
 
@@ -614,7 +615,7 @@ class Contact extends BaseObject
                                'readonly' => 0, 'pending' => 0)
                        );
 
-                       $s = dba::select('contact', array('id'), array('nurl' => normalise_link($data["url"]), 'uid' => $uid), array('order' => 'id', 'limit' => 2));
+                       $s = dba::select('contact', array('id'), array('nurl' => normalise_link($data["url"]), 'uid' => $uid), array('order' => array('id'), 'limit' => 2));
                        $contacts = dba::inArray($s);
                        if (!DBM::is_result($contacts)) {
                                return 0;
@@ -735,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
@@ -760,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);
 
@@ -819,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;
+       }
 }