3 * Data class to store local tag subscriptions
7 * @category TagSubPlugin
9 * @author Brion Vibber <brion@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2011, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * For storing the tag subscriptions
37 * @category PollPlugin
39 * @author Brion Vibber <brion@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
45 class TagSub extends Managed_DataObject
47 public $__table = 'tagsub'; // table name
49 public $profile_id; // int -> profile.id
50 public $created; // datetime
53 * The One True Thingy that must be defined and declared.
55 public static function schemaDef()
58 'description' => 'TagSubPlugin tag subscription records',
60 'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this subscription'),
61 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile ID of subscribing user'),
62 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
64 'primary key' => array('tag', 'profile_id'),
65 'foreign keys' => array(
66 'tagsub_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
69 'tagsub_created_idx' => array('created'),
70 'tagsub_profile_id_tag_idx' => array('profile_id', 'tag'),
76 * Start a tag subscription!
78 * @param profile $profile subscriber
79 * @param string $tag subscribee
82 static function start(Profile $profile, $tag)
86 $ts->profile_id = $profile->id;
87 $ts->created = common_sql_now();
89 self::blow('tagsub:by_profile:%d', $profile->id);
94 * End a tag subscription!
96 * @param profile $profile subscriber
97 * @param string $tag subscribee
99 static function cancel(Profile $profile, $tag)
101 $ts = TagSub::pkeyGet(array('tag' => $tag,
102 'profile_id' => $profile->id));
105 self::blow('tagsub:by_profile:%d', $profile->id);
109 static function forProfile(Profile $profile)
113 $keypart = sprintf('tagsub:by_profile:%d', $profile->id);
114 $tagstring = self::cacheGet($keypart);
116 if ($tagstring !== false) { // cache hit
117 if (!empty($tagstring)) {
118 $tags = explode(',', $tagstring);
121 $tagsub = new TagSub();
122 $tagsub->profile_id = $profile->id;
123 $tagsub->selectAdd();
124 $tagsub->selectAdd('tag');
126 if ($tagsub->find()) {
127 $tags = $tagsub->fetchAll('tag');
130 self::cacheSet($keypart, implode(',', $tags));