3 * Data class for saving social activities as notices
9 * @author Evan Prodromou <evan@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) 2009, 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')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Data class for saving social activities as notices
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://status.net/
48 class Notice_activity extends Memcached_DataObject
50 public $__table = 'notice_activity'; // table name
52 public $notice_id; // int(4) primary_key not_null
53 public $verb; // varchar(255)
54 public $object; // varchar(255)
57 * Get an instance by key
59 * This is a utility method to get a single instance with a given key value.
61 * @param string $k Key to use to lookup (usually 'notice_id' for this class)
62 * @param mixed $v Value to lookup
64 * @return Notice_activity object found, or null for no hits
68 function staticGet($k, $v=null)
70 $result = Memcached_DataObject::staticGet('Notice_activity', $k, $v);
75 * return table definition for DB_DataObject
77 * DB_DataObject needs to know something about the table to manipulate
78 * instances. This method provides all the DB_DataObject needs to know.
80 * @return array array of column definitions
84 return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
85 'verb' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
86 'object' => DB_DATAOBJECT_STR);
90 * return key definitions for DB_DataObject
92 * DB_DataObject needs to know about keys that the table has, since it
93 * won't appear in StatusNet's own keys list. In most cases, this will
94 * simply reference your keyTypes() function.
96 * @return array list of key field names
101 return array_keys($this->keyTypes());
105 * return key definitions for Memcached_DataObject
107 * Our caching system uses the same key definitions, but uses a different
108 * method to get them. This key information is used to store and clear
109 * cached data, so be sure to list any key that will be used for static
112 * @return array associative array of key definitions, field name to type:
113 * 'K' for primary key: for compound keys, add an entry for each component;
114 * 'U' for unique keys: compound keys are not well supported here.
118 return array('notice_id' => 'K');
122 * Magic formula for non-autoincrementing integer primary keys
124 * If a table has a single integer column as its primary key, DB_DataObject
125 * assumes that the column is auto-incrementing and makes a sequence table
126 * to do this incrementation. Since we don't need this for our class, we
127 * overload this method and return the magic formula that DB_DataObject needs.
129 * @return array magic three-false array that stops auto-incrementing.
132 function sequenceKey()
134 return array(false, false, false);
137 static function setActivity($notice_id, $verb, $object=null)
139 $act = self::staticGet('notice_id', $notice_id);
142 $act = new Notice_activity();
143 $act->notice_id = $notice_id;
145 $act->object = $object;
150 $act->object = $object;