3 * Data class to store local search subscriptions
7 * @category SearchSubPlugin
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 search 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/
46 class SearchSub extends Managed_DataObject
48 public $__table = 'searchsub'; // table name
49 public $search; // text
50 public $profile_id; // int -> profile.id
51 public $created; // datetime
54 * The One True Thingy that must be defined and declared.
56 public static function schemaDef()
59 'description' => 'SearchSubPlugin search subscription records',
61 'search' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash search associated with this subscription'),
62 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile ID of subscribing user'),
63 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
65 'primary key' => array('search', 'profile_id'),
66 'foreign keys' => array(
67 'searchsub_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
70 'searchsub_created_idx' => array('created'),
71 'searchsub_profile_id_tag_idx' => array('profile_id', 'search'),
77 * Start a search subscription!
79 * @param profile $profile subscriber
80 * @param string $search subscribee
83 static function start(Profile $profile, $search)
85 $ts = new SearchSub();
86 $ts->search = $search;
87 $ts->profile_id = $profile->id;
88 $ts->created = common_sql_now();
90 self::blow('searchsub:by_profile:%d', $profile->id);
95 * End a search subscription!
97 * @param profile $profile subscriber
98 * @param string $search subscribee
100 static function cancel(Profile $profile, $search)
102 $ts = SearchSub::pkeyGet(array('search' => $search,
103 'profile_id' => $profile->id));
106 self::blow('searchsub:by_profile:%d', $profile->id);
110 static function forProfile(Profile $profile)
114 $keypart = sprintf('searchsub:by_profile:%d', $profile->id);
115 $searchstring = self::cacheGet($keypart);
117 if ($searchstring !== false) {
118 if (!empty($searchstring)) {
119 $searches = explode(',', $searchstring);
122 $searchsub = new SearchSub();
123 $searchsub->profile_id = $profile->id;
124 $searchsub->selectAdd();
125 $searchsub->selectAdd('search');
127 if ($searchsub->find()) {
128 $searches = $searchsub->fetchAll('search');
131 self::cacheSet($keypart, implode(',', $searches));