]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile_list.php
Stronger typing, require array where param array
[quix0rs-gnu-social.git] / classes / Profile_list.php
index cf0a255e75c8c0e2a930a83eda5e87df3b5444ee..b922c92a146ad32260bdedb71c9bbd6742272b78 100644 (file)
@@ -30,7 +30,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
  */
 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
-class Profile_list extends Memcached_DataObject
+class Profile_list extends Managed_DataObject
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -48,23 +48,42 @@ class Profile_list extends Memcached_DataObject
     public $tagged_count;                    // smallint
     public $subscriber_count;                // smallint
 
-    /* Static get */
-    function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Profile_list',$k,$v); }
-
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    /**
-     * return a profile_list record, given its tag and tagger.
-     *
-     * @param array $kv ideally array('tag' => $tag, 'tagger' => $tagger)
-     *
-     * @return Profile_list a Profile_list object with the given tag and tagger.
-     */
-
-    function pkeyGet($kv)
+    public static function schemaDef()
     {
-        return Memcached_DataObject::pkeyGet('Profile_list', $kv);
+        return array(
+            'fields' => array(
+                'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
+                'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
+                'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'people tag'),
+                'description' => array('type' => 'text', 'description' => 'description of the people tag'),
+                'private' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this tag private'),
+
+                'created' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was added'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date the tag was modified'),
+
+                'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'universal identifier'),
+                'mainpage' => array('type' => 'varchar', 'length' => 255, 'description' => 'page to link to'),
+                'tagged_count' => array('type' => 'int', 'default' => 0, 'description' => 'number of people tagged with this tag by this user'),
+                'subscriber_count' => array('type' => 'int', 'default' => 0, 'description' => 'number of subscribers to this tag'),
+            ),
+            'primary key' => array('tagger', 'tag'),
+            'unique keys' => array(
+                'profile_list_id_key' => array('id')
+            ),
+            'foreign keys' => array(
+                'profile_list_tagger_fkey' => array('profile', array('tagger' => 'id')),
+            ),
+            'indexes' => array(
+                'profile_list_modified_idx' => array('modified'),
+                'profile_list_tag_idx' => array('tag'),
+                'profile_list_tagger_tag_idx' => array('tagger', 'tag'),
+                'profile_list_tagged_count_idx' => array('tagged_count'),
+                'profile_list_subscriber_count_idx' => array('subscriber_count'),
+            ),
+        );
     }
 
     /**
@@ -75,7 +94,7 @@ class Profile_list extends Memcached_DataObject
 
     function getTagger()
     {
-        return Profile::staticGet('id', $this->tagger);
+        return Profile::getKV('id', $this->tagger);
     }
 
     /**
@@ -185,10 +204,12 @@ class Profile_list extends Memcached_DataObject
     function getSubscribers($offset=0, $limit=null, $since=0, $upto=0)
     {
         $subs = new Profile();
-        $sub = new Profile_tag_subscription();
-        $sub->profile_tag_id = $this->id;
 
-        $subs->joinAdd($sub);
+        $subs->joinAdd(
+            array('id', 'profile_tag_subscription:profile_id')
+        );
+        $subs->whereAdd('profile_tag_subscription.profile_tag_id = ' . $this->id);
+
         $subs->selectAdd('unix_timestamp(profile_tag_subscription.' .
                          'created) as "cursor"');
 
@@ -326,6 +347,8 @@ class Profile_list extends Memcached_DataObject
         Profile_tag::cleanup($this);
         Profile_tag_subscription::cleanup($this);
 
+        self::blow('profile:lists:%d', $this->tagger);
+
         return parent::delete();
     }
 
@@ -470,6 +493,23 @@ class Profile_list extends Memcached_DataObject
         return $count;
     }
 
+    /**
+     * get the cached number of profiles subscribed to this
+     * people tag, re-count if the argument is true.
+     *
+     * @param boolean $recount  whether to ignore cache
+     *
+     * @return integer count
+     */
+
+    function blowNoticeStreamCache($all=false)
+    {
+        self::blow('profile_list:notice_ids:%d', $this->id);
+        if ($all) {
+            self::blow('profile_list:notice_ids:%d;last', $this->id);
+        }
+    }
+
     /**
      * get the Profile_list object by the
      * given tagger and with given tag
@@ -562,7 +602,7 @@ class Profile_list extends Memcached_DataObject
      *
      * @return mixed Profile_list on success, false on fail
      */
-    static function saveNew($fields) {
+    static function saveNew(array $fields) {
         extract($fields);
 
         $ptag = new Profile_list();
@@ -630,7 +670,7 @@ class Profile_list extends Memcached_DataObject
 
         if (!isset($mainpage) || empty($mainpage)) {
             $orig = clone($ptag);
-            $user = User::staticGet('id', $ptag->tagger);
+            $user = User::getKV('id', $ptag->tagger);
             if(!empty($user)) {
                 $ptag->mainpage = common_local_url('showprofiletag', array('tag' => $ptag->tag, 'tagger' => $user->nickname));
             } else {
@@ -673,7 +713,7 @@ class Profile_list extends Memcached_DataObject
 
      // XXX: This should be in Memcached_DataObject... eventually.
 
-    static function getAtCursor($fn, $args, $cursor, $count=20)
+    static function getAtCursor($fn, array $args, $cursor, $count=20)
     {
         $items = array();
 
@@ -846,7 +886,7 @@ class Profile_list extends Memcached_DataObject
      * @return Profile_list results
      */
 
-    static function getByKeys($keys) {
+    static function getByKeys(array $keys) {
         $cache = Cache::instance();
 
         if (!empty($cache)) {
@@ -893,4 +933,13 @@ class Profile_list extends Memcached_DataObject
             return new ArrayWrapper($wrapped);
         }
     }
+
+    function insert()
+    {
+        $result = parent::insert();
+        if ($result) {
+            self::blow('profile:lists:%d', $this->tagger);
+        }
+        return $result;
+    }
 }