]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Move getConnectedApps() from Profile to User, where it belongs
[quix0rs-gnu-social.git] / classes / Profile.php
index 37d2c571f9391a265666aa4417bfcba3fb9fd766..e29e6db7b7c3c92e4a9f708fa29cacda05a54e82 100644 (file)
@@ -125,6 +125,14 @@ class Profile extends Memcached_DataObject
         return $avatar;
     }
 
+    /**
+     * Delete attached avatars for this user from the database and filesystem.
+     * This should be used instead of a batch delete() to ensure that files
+     * get removed correctly.
+     *
+     * @param boolean $original true to delete only the original-size file
+     * @return <type>
+     */
     function delete_avatars($original=true)
     {
         $avatar = new Avatar();
@@ -401,31 +409,6 @@ class Profile extends Memcached_DataObject
         return $profile;
     }
 
-    function getConnectedApps($offset = 0, $limit = null)
-    {
-        $qry =
-          'SELECT u.* ' .
-          'FROM oauth_application_user u, oauth_application a ' .
-          'WHERE u.profile_id = %d ' .
-          'AND a.id = u.application_id ' .
-          'AND u.access_type > 0 ' .
-          'ORDER BY u.created DESC ';
-
-        if ($offset > 0) {
-            if (common_config('db','type') == 'pgsql') {
-                $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-            } else {
-                $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-            }
-        }
-
-        $apps = new Oauth_application_user();
-
-        $cnt = $apps->query(sprintf($qry, $this->id));
-
-        return $apps;
-    }
-
     function subscriptionCount()
     {
         $c = common_memcache();
@@ -473,6 +456,29 @@ class Profile extends Memcached_DataObject
         return $cnt;
     }
 
+    /**
+     * Is this profile subscribed to another profile?
+     *
+     * @param Profile $other
+     * @return boolean
+     */
+    function isSubscribed($other)
+    {
+        return Subscription::exists($this, $other);
+    }
+
+    /**
+     * Are these two profiles subscribed to each other?
+     *
+     * @param Profile $other
+     * @return boolean
+     */
+    function mutuallySubscribed($other)
+    {
+        return $this->isSubscribed($other) &&
+          $other->isSubscribed($this);
+    }
+
     function hasFave($notice)
     {
         $cache = common_memcache();
@@ -620,9 +626,11 @@ class Profile extends Memcached_DataObject
         $this->_deleteMessages();
         $this->_deleteTags();
         $this->_deleteBlocks();
+        $this->delete_avatars();
 
-        $related = array('Avatar',
-                         'Reply',
+        // Warning: delete() will run on the batch objects,
+        // not on individual objects.
+        $related = array('Reply',
                          'Group_member',
                          );
         Event::handle('ProfileDeleteRelated', array($this, &$related));
@@ -876,6 +884,7 @@ class Profile extends Memcached_DataObject
             case Right::NEWNOTICE:
             case Right::NEWMESSAGE:
             case Right::SUBSCRIBE:
+            case Right::CREATEGROUP:
                 $result = !$this->isSilenced();
                 break;
             case Right::PUBLICNOTICE: