]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Merge remote-tracking branch 'upstream/develop' into contact-tabs
[friendica.git] / src / Model / Contact.php
index 18c378179e329284bacbf0cebf3ecf1e3ceea7b3..12ec06012d038bc50c4ba9c48c43cc7498d4dda7 100644 (file)
@@ -2124,7 +2124,7 @@ class Contact
                        return false;
                }
 
-               if (ContactRelation::isDiscoverable($ret['url'])) {
+               if (Contact\Relation::isDiscoverable($ret['url'])) {
                        Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
                }
 
@@ -3056,13 +3056,47 @@ class Contact
                return array_slice($contacts, $start, $limit);
        }
 
+       /**
+        * Returns a list of all common friends between two given public contact ids.
+        *
+        * @param int $cid1  first public contact id
+        * @param int $cid2  second public contact id
+        * @return int
+        */
+       public static function countContactsOfContact(int $cid)
+       {
+               return DBA::count('contact',
+                       ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ?)
+                       OR `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)",
+                       $cid, $cid]
+               );
+       }
+
+       /**
+        * Returns a list of all contacts of a given public contact id.
+        *
+        * @param int $cid   public contact id
+        * @param int $start optional, default 0
+        * @param int $limit optional, default 80
+        * @return array
+        */
+       public static function getContactsOfContact(int $cid, int $start = 0, int $limit = 80)
+       {
+               return DBA::selectToArray('contact', [],
+                       ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ?)
+                       OR `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)",
+                       $cid, $cid],
+                       ['limit' => [$start, $limit]]
+               );
+       }
+
        /**
         * Add public contacts from an array
         *
         * @param array $urls
         * @return array result "count", "added" and "updated"
         */
-       public static function addContactsByArray(array $urls)
+       public static function addByUrls(array $urls)
        {
                $added = 0;
                $updated = 0;
@@ -3259,4 +3293,24 @@ class Contact
                $fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow(), 'updated' => $last_updated];
                DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
        }
+
+       /**
+        * Returns a random, global contact of the current node
+        *
+        * @return string The profile URL
+        * @throws Exception
+        */
+       public static function getRandomUrl()
+       {
+               $r = DBA::selectFirst('contact', ['url'], [
+                       "`uid` = ? AND `network` = ? AND NOT `failed` AND `last-item` > ?",
+                       0, Protocol::DFRN, DateTimeFormat::utc('now - 1 month'),
+               ], ['order' => ['RAND()']]);
+
+               if (DBA::isResult($r)) {
+                       return $r['url'];
+               }
+
+               return '';
+       }
 }