]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Managed_DataObject now has listGet for all classes
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 18 Aug 2013 19:02:33 +0000 (21:02 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 18 Aug 2013 19:02:33 +0000 (21:02 +0200)
classes/Managed_DataObject.php
classes/Memcached_DataObject.php
classes/Notice.php
lib/conversationnoticestream.php
lib/threadednoticelist.php
lib/useractivitystream.php

index e473a2bf03d512685133d83a5fae776d7ef4f378..b4eab98f8a3aa63cc7751cba8f82ee76d44ce8c8 100644 (file)
@@ -61,6 +61,24 @@ abstract class Managed_DataObject extends Memcached_DataObject
         return parent::pkeyGetClass(get_called_class(), $kv);
     }
 
         return parent::pkeyGetClass(get_called_class(), $kv);
     }
 
+    /**
+     * Get a multi-instance object
+     *
+     * This is a utility method to get multiple instances with a given set of
+     * values for a specific key column. Usually used for the primary key when
+     * multiple values are desired.
+     *
+     * @param array $keyCol  key column name
+     * @param array $keyVals array of key values
+     *
+     * @return get_called_class() object with multiple instances if found, or null for no hits
+     *
+     */
+    static function listGet($keyCol, $keyVals)
+    {
+        return parent::listGetClass(get_called_class(), $keyCol, $keyVals);
+    }
+
     /**
      * get/set an associative array of table columns
      *
     /**
      * get/set an associative array of table columns
      *
index f95d055c01d4e38fcdb7bae3f623d27f5a301468..72eb9b9188ad62429eb83d4fc9e28b8d62254872 100644 (file)
@@ -267,7 +267,7 @@ class Memcached_DataObject extends Safe_DataObject
         return $pkey;
     }
 
         return $pkey;
     }
 
-    function listGet($cls, $keyCol, $keyVals)
+    static function listGetClass($cls, $keyCol, $keyVals)
     {
         $pkeyMap = array_fill_keys($keyVals, array());
         $result = array_fill_keys($keyVals, array());
     {
         $pkeyMap = array_fill_keys($keyVals, array());
         $result = array_fill_keys($keyVals, array());
@@ -312,7 +312,7 @@ class Memcached_DataObject extends Safe_DataObject
             }
             $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
             if ($i->find()) {
             }
             $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
             if ($i->find()) {
-                sprintf("listGet() got {$i->N} results for class $cls key $keyCol");
+                sprintf(__CLASS__ . "() got {$i->N} results for class $cls key $keyCol");
                 while ($i->fetch()) {
                     $copy = clone($i);
                     $copy->encache();
                 while ($i->fetch()) {
                     $copy = clone($i);
                     $copy->encache();
index 743eba12bf9b0f9598f6f97e161bbb7a39f925ea..4f78343798e18ed571151f270eb8e5b0ae834520 100644 (file)
@@ -823,7 +823,7 @@ class Notice extends Managed_DataObject
             return $this->_attachments;
         }
                
             return $this->_attachments;
         }
                
-               $f2ps = Memcached_DataObject::listGet('File_to_post', 'post_id', array($this->id));
+        $f2ps = File_to_post::listGet('post_id', array($this->id));
                
                $ids = array();
                
                
                $ids = array();
                
@@ -1380,7 +1380,7 @@ class Notice extends Managed_DataObject
             return $this->_replies;
         }
 
             return $this->_replies;
         }
 
-        $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', array($this->id));
+        $replyMap = Reply::listGet('notice_id', array($this->id));
 
         $ids = array();
 
 
         $ids = array();
 
@@ -1458,7 +1458,7 @@ class Notice extends Managed_DataObject
             return $this->_groups;
         }
         
             return $this->_groups;
         }
         
-        $gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', array($this->id));
+        $gis = Group_inbox::listGet('notice_id', array($this->id));
 
         $ids = array();
 
 
         $ids = array();
 
@@ -2607,7 +2607,7 @@ class Notice extends Managed_DataObject
        {
         $ids = self::_idsOf($notices);
                
        {
         $ids = self::_idsOf($notices);
                
-               $gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', $ids);
+        $gis = Group_inbox::listGet('notice_id', $ids);
                
         $gids = array();
 
                
         $gids = array();
 
@@ -2648,7 +2648,7 @@ class Notice extends Managed_DataObject
     {
         $ids = self::_idsOf($notices);
 
     {
         $ids = self::_idsOf($notices);
 
-               $f2pMap = Memcached_DataObject::listGet('File_to_post', 'post_id', $ids);
+        $f2pMap = File_to_post::listGet('post_id', $ids);
                
                $fileIds = array();
                
                
                $fileIds = array();
                
@@ -2686,7 +2686,7 @@ class Notice extends Managed_DataObject
         if (isset($this->_faves) && is_array($this->_faves)) {
             return $this->_faves;
         }
         if (isset($this->_faves) && is_array($this->_faves)) {
             return $this->_faves;
         }
-        $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', array($this->id));
+        $faveMap = Fave::listGet('notice_id', array($this->id));
         $this->_faves = $faveMap[$this->id];
         return $this->_faves;
     }
         $this->_faves = $faveMap[$this->id];
         return $this->_faves;
     }
@@ -2699,7 +2699,7 @@ class Notice extends Managed_DataObject
     static function fillFaves(&$notices)
     {
         $ids = self::_idsOf($notices);
     static function fillFaves(&$notices)
     {
         $ids = self::_idsOf($notices);
-        $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', $ids);
+        $faveMap = Fave::listGet('notice_id', $ids);
         $cnt = 0;
         $faved = array();
         foreach ($faveMap as $id => $faves) {
         $cnt = 0;
         $faved = array();
         foreach ($faveMap as $id => $faves) {
@@ -2717,7 +2717,7 @@ class Notice extends Managed_DataObject
     static function fillReplies(&$notices)
     {
         $ids = self::_idsOf($notices);
     static function fillReplies(&$notices)
     {
         $ids = self::_idsOf($notices);
-        $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', $ids);
+        $replyMap = Reply::listGet('notice_id', $ids);
         foreach ($notices as $notice) {
             $replies = $replyMap[$notice->id];
             $ids = array();
         foreach ($notices as $notice) {
             $replies = $replyMap[$notice->id];
             $ids = array();
@@ -2735,7 +2735,7 @@ class Notice extends Managed_DataObject
         if (isset($this->_repeats) && is_array($this->_repeats)) {
             return $this->_repeats;
         }
         if (isset($this->_repeats) && is_array($this->_repeats)) {
             return $this->_repeats;
         }
-        $repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', array($this->id));
+        $repeatMap = Notice::listGet('repeat_of', array($this->id));
         $this->_repeats = $repeatMap[$this->id];
         return $this->_repeats;
     }
         $this->_repeats = $repeatMap[$this->id];
         return $this->_repeats;
     }
@@ -2748,7 +2748,7 @@ class Notice extends Managed_DataObject
     static function fillRepeats(&$notices)
     {
         $ids = self::_idsOf($notices);
     static function fillRepeats(&$notices)
     {
         $ids = self::_idsOf($notices);
-        $repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', $ids);
+        $repeatMap = Notice::listGet('repeat_of', $ids);
         foreach ($notices as $notice) {
                $repeats = $repeatMap[$notice->id];
             $notice->_setRepeats($repeats);
         foreach ($notices as $notice) {
                $repeats = $repeatMap[$notice->id];
             $notice->_setRepeats($repeats);
index c43b5deb24a3bd12d5d26da534a21036bcc17ac3..1d823760d7cab592b3b4f54f98b4d729f1e3737a 100644 (file)
@@ -78,7 +78,7 @@ class RawConversationNoticeStream extends NoticeStream
 
     function getNotices($offset, $limit, $sinceId = null, $maxId = null)
     {
 
     function getNotices($offset, $limit, $sinceId = null, $maxId = null)
     {
-        $all = Memcached_DataObject::listGet('Notice', 'conversation', array($this->id));
+        $all = Notice::listGet('conversation', array($this->id));
         $notices = $all[$this->id];
         // Re-order in reverse-chron
         usort($notices, array('RawConversationNoticeStream', '_reverseChron'));
         $notices = $all[$this->id];
         // Re-order in reverse-chron
         usort($notices, array('RawConversationNoticeStream', '_reverseChron'));
index 8621590ad68acfcaa258d236a46ff5cbf6613974..5c45b5a831ba93bd0ec56b695c1d6eec208e7238 100644 (file)
@@ -130,7 +130,7 @@ class ThreadedNoticeList extends NoticeList
             $convId[] = $notice->conversation;
         }
         $convId = array_unique($convId);
             $convId[] = $notice->conversation;
         }
         $convId = array_unique($convId);
-        $allMap = Memcached_DataObject::listGet('Notice', 'conversation', $convId);
+        $allMap = Notice::listGet('conversation', $convId);
         $allArray = array();
         foreach ($allMap as $convId => $convNotices) {
             $allArray = array_merge($allArray, $convNotices);
         $allArray = array();
         foreach ($allMap as $convId => $convNotices) {
             $allArray = array_merge($allArray, $convNotices);
index f4a771c5f0cbec97d6033d7051ca2f585811ef4b..246bdb5d90e97341be23607f79e27cb98d07144d 100644 (file)
@@ -376,7 +376,7 @@ class UserActivityStream extends AtomUserNoticeFeed
 
     function getMessagesTo()
     {
 
     function getMessagesTo()
     {
-        $msgMap = Memcached_DataObject::listGet('Message', 'to_profile', array($this->user->id));
+        $msgMap = Message::listGet('to_profile', array($this->user->id));
 
         $messages = $msgMap[$this->user->id];
 
 
         $messages = $msgMap[$this->user->id];
 
@@ -389,7 +389,7 @@ class UserActivityStream extends AtomUserNoticeFeed
 
     function getMessagesFrom()
     {
 
     function getMessagesFrom()
     {
-        $msgMap = Memcached_DataObject::listGet('Message', 'from_profile', array($this->user->id));
+        $msgMap = Message::listGet('from_profile', array($this->user->id));
 
         $messages = $msgMap[$this->user->id];
 
 
         $messages = $msgMap[$this->user->id];