3 * Data class for storing notice-to-Facebook-item mappings
9 * @author Zach Copley <zach@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) 2010, 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 mapping notices to Facebook stream items
39 * Note that notice_id is unique only within a single database; if you
40 * want to share this data for some reason, get the notice's URI and use
41 * that instead, since it's universally unique.
45 * @author Zach Copley <zach@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47 * @link http://status.net/
52 class Notice_to_item extends Memcached_DataObject
54 public $__table = 'notice_to_item'; // table name
55 public $notice_id; // int(4) primary_key not_null
56 public $item_id; // varchar(255) not null
57 public $created; // datetime
60 * Get an instance by key
62 * This is a utility method to get a single instance with a given key value.
64 * @param string $k Key to use to lookup
65 * @param mixed $v Value to lookup
67 * @return Notice_to_item object found, or null for no hits
71 function staticGet($k, $v=null)
73 return Memcached_DataObject::staticGet('Notice_to_item', $k, $v);
77 * return table definition for DB_DataObject
79 * DB_DataObject needs to know something about the table to manipulate
80 * instances. This method provides all the DB_DataObject needs to know.
82 * @return array array of column definitions
88 'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
89 'item_id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
90 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
94 static function schemaDef()
97 new ColumnDef('notice_id', 'integer', null, false, 'PRI'),
98 new ColumnDef('item_id', 'varchar', 255, false, 'UNI'),
99 new ColumnDef('created', 'datetime', null, false)
104 * return key definitions for DB_DataObject
106 * DB_DataObject needs to know about keys that the table has, since it
107 * won't appear in StatusNet's own keys list. In most cases, this will
108 * simply reference your keyTypes() function.
110 * @return array list of key field names
115 return array_keys($this->keyTypes());
119 * return key definitions for Memcached_DataObject
121 * Our caching system uses the same key definitions, but uses a different
122 * method to get them. This key information is used to store and clear
123 * cached data, so be sure to list any key that will be used for static
126 * @return array associative array of key definitions, field name to type:
127 * 'K' for primary key: for compound keys, add an entry for each component;
128 * 'U' for unique keys: compound keys are not well supported here.
133 return array('notice_id' => 'K', 'item_id' => 'U');
137 * Magic formula for non-autoincrementing integer primary keys
139 * If a table has a single integer column as its primary key, DB_DataObject
140 * assumes that the column is auto-incrementing and makes a sequence table
141 * to do this incrementation. Since we don't need this for our class, we
142 * overload this method and return the magic formula that DB_DataObject needs.
144 * @return array magic three-false array that stops auto-incrementing.
147 function sequenceKey()
149 return array(false, false, false);
153 * Save a mapping between a notice and a Facebook item
155 * @param integer $notice_id ID of the notice in StatusNet
156 * @param integer $item_id ID of the stream item on Facebook
158 * @return Notice_to_item new object for this value
161 static function saveNew($notice_id, $item_id)
163 $n2i = Notice_to_item::staticGet('notice_id', $notice_id);
169 $n2i = Notice_to_item::staticGet('item_id', $item_id);
176 "Mapping notice {$notice_id} to Facebook item {$item_id}",
180 $n2i = new Notice_to_item();
182 $n2i->notice_id = $notice_id;
183 $n2i->item_id = $item_id;
184 $n2i->created = common_sql_now();