]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User_group.php
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
[quix0rs-gnu-social.git] / classes / User_group.php
old mode 100755 (executable)
new mode 100644 (file)
index d152f9d..9f99777
@@ -50,13 +50,50 @@ class User_group extends Memcached_DataObject
 
     function getNotices($offset, $limit)
     {
-        $qry =
-          'SELECT notice.* ' .
-          'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' .
-          'WHERE group_inbox.group_id = %d ';
-        return Notice::getStream(sprintf($qry, $this->id),
-                                 'group:notices:'.$this->id,
-                                 $offset, $limit);
+        $ids = Notice::stream(array($this, '_streamDirect'),
+                              array(),
+                              'user_group:notice_ids:' . $this->id,
+                              $offset, $limit);
+
+        return Notice::getStreamByIds($ids);
+    }
+
+    function _streamDirect($offset, $limit, $since_id, $max_id, $since)
+    {
+        $inbox = new Group_inbox();
+
+        $inbox->group_id = $this->id;
+
+        $inbox->selectAdd();
+        $inbox->selectAdd('notice_id');
+
+        if ($since_id != 0) {
+            $inbox->whereAdd('notice_id > ' . $since_id);
+        }
+
+        if ($max_id != 0) {
+            $inbox->whereAdd('notice_id <= ' . $max_id);
+        }
+
+        if (!is_null($since)) {
+            $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
+        }
+
+        $inbox->orderBy('notice_id DESC');
+
+        if (!is_null($offset)) {
+            $inbox->limit($offset, $limit);
+        }
+
+        $ids = array();
+
+        if ($inbox->find()) {
+            while ($inbox->fetch()) {
+                $ids[] = $inbox->notice_id;
+            }
+        }
+
+        return $ids;
     }
 
     function allowedNickname($nickname)
@@ -88,10 +125,33 @@ class User_group extends Memcached_DataObject
         return $members;
     }
 
+    function getBlocked($offset=0, $limit=null)
+    {
+        $qry =
+          'SELECT profile.* ' .
+          'FROM profile JOIN group_block '.
+          'ON profile.id = group_block.blocked ' .
+          'WHERE group_block.group_id = %d ' .
+          'ORDER BY group_block.modified DESC ';
+
+        if ($limit != null) {
+            if (common_config('db','type') == 'pgsql') {
+                $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+            } else {
+                $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+            }
+        }
+
+        $blocked = new Profile();
+
+        $blocked->query(sprintf($qry, $this->id));
+        return $blocked;
+    }
+
     function setOriginal($filename)
     {
         $imagefile = new ImageFile($this->id, Avatar::path($filename));
-        
+
         $orig = clone($this);
         $this->original_logo = Avatar::url($filename);
         $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
@@ -100,4 +160,9 @@ class User_group extends Memcached_DataObject
         common_debug(common_log_objstring($this));
         return $this->update($orig);
     }
+
+    function getBestName()
+    {
+        return ($this->fullname) ? $this->fullname : $this->nickname;
+    }
 }