]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact/User.php
Changed to null-coalscing style (??) as sugguested by @MrPetovan
[friendica.git] / src / Model / Contact / User.php
index 7d6ce17dac82b2fcd3539dce7c6f21b96a506131..665b95624dd477dc7c84eee76a300f341d396c87 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -95,16 +95,17 @@ class User
                $update_fields = self::preparedFields($fields);
                if (!empty($update_fields)) {
                        $contacts = DBA::select('contact', ['uri-id', 'uid'], $condition);
-                       while ($row = DBA::fetch($contacts)) {
-                               if (empty($row['uri-id']) || empty($contact['uid'])) {
+                       while ($contact = DBA::fetch($contacts)) {
+                               if (empty($contact['uri-id']) || empty($contact['uid'])) {
                                        continue;
                                }
-                               $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
-                               Logger::info('Updated user contact', ['uid' => $row['uid'], 'uri-id' => $row['uri-id'], 'ret' => $ret]);
+                               $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']]);
+                               Logger::info('Updated user contact', ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'ret' => $ret]);
                        }
 
                        DBA::close($contacts);
                }
+
                DBA::commit();  
        }
 
@@ -148,9 +149,9 @@ class User
 
                $contact = Contact::getById($cdata['public']);
                if ($blocked) {
-                       Protocol::block($contact);
+                       Protocol::block($contact, $uid);
                } else {
-                       Protocol::unblock($contact);
+                       Protocol::unblock($contact, $uid);
                }
 
                if ($cdata['user'] != 0) {
@@ -310,4 +311,48 @@ class User
 
                return $collapsed;
        }
+
+       /**
+        * Set/Release that the user is blocked by the contact
+        *
+        * @param int     $cid     Either public contact id or user's contact id
+        * @param int     $uid     User ID
+        * @param boolean $blocked Is the user blocked or unblocked by the contact?
+        * @throws \Exception
+        */
+       public static function setIsBlocked($cid, $uid, $blocked)
+       {
+               $cdata = Contact::getPublicAndUserContactID($cid, $uid);
+               if (empty($cdata)) {
+                       return;
+               }
+
+               DBA::update('user-contact', ['is-blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);
+       }
+
+       /**
+        * Returns if the user is blocked by the contact
+        *
+        * @param int $cid Either public contact id or user's contact id
+        * @param int $uid User ID
+        *
+        * @return boolean Is the user blocked or unblocked by the contact?
+        * @throws \Exception
+        */
+       public static function isIsBlocked($cid, $uid)
+       {
+               $cdata = Contact::getPublicAndUserContactID($cid, $uid);
+               if (empty($cdata)) {
+                       return false;
+               }
+
+               if (!empty($cdata['public'])) {
+                       $public_contact = DBA::selectFirst('user-contact', ['is-blocked'], ['cid' => $cdata['public'], 'uid' => $uid]);
+                       if (DBA::isResult($public_contact)) {
+                               return $public_contact['is-blocked'];
+                       }
+               }
+
+               return false;
+       }
 }