]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - Notice_activity.php
gitignore
[quix0rs-gnu-social.git] / Notice_activity.php
1 <?php
2 /**
3  * Data class for saving social activities as notices
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2009, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Data class for saving social activities as notices
38  *
39  * @category Action
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  *
45  * @see      DB_DataObject
46  */
47
48 class Notice_activity extends Memcached_DataObject
49 {
50     public $__table = 'notice_activity';     // table name
51
52     public $notice_id;              // int(4)  primary_key not_null
53     public $verb;                   // varchar(255)
54     public $object;                 // varchar(255)
55
56     /**
57      * Get an instance by key
58      *
59      * This is a utility method to get a single instance with a given key value.
60      *
61      * @param string $k Key to use to lookup (usually 'notice_id' for this class)
62      * @param mixed  $v Value to lookup
63      *
64      * @return Notice_activity object found, or null for no hits
65      *
66      */
67
68     function staticGet($k, $v=null)
69     {
70         common_debug("Notice_activity::staticGet($k, $v)");
71         $result = Memcached_DataObject::staticGet('Notice_activity', $k, $v);
72         return $result;
73     }
74
75     /**
76      * return table definition for DB_DataObject
77      *
78      * DB_DataObject needs to know something about the table to manipulate
79      * instances. This method provides all the DB_DataObject needs to know.
80      *
81      * @return array array of column definitions
82      */
83     function table()
84     {
85         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
86                      'verb' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
87                      'object' => DB_DATAOBJECT_STR);
88     }
89
90     /**
91      * return key definitions for DB_DataObject
92      *
93      * DB_DataObject needs to know about keys that the table has, since it
94      * won't appear in StatusNet's own keys list. In most cases, this will
95      * simply reference your keyTypes() function.
96      *
97      * @return array list of key field names
98      */
99
100     function keys()
101     {
102         return array_keys($this->keyTypes());
103     }
104
105     /**
106      * return key definitions for Memcached_DataObject
107      *
108      * Our caching system uses the same key definitions, but uses a different
109      * method to get them. This key information is used to store and clear
110      * cached data, so be sure to list any key that will be used for static
111      * lookups.
112      *
113      * @return array associative array of key definitions, field name to type:
114      *         'K' for primary key: for compound keys, add an entry for each component;
115      *         'U' for unique keys: compound keys are not well supported here.
116      */
117     function keyTypes()
118     {
119         return array('notice_id' => 'K');
120     }
121
122     /**
123      * Magic formula for non-autoincrementing integer primary keys
124      *
125      * If a table has a single integer column as its primary key, DB_DataObject
126      * assumes that the column is auto-incrementing and makes a sequence table
127      * to do this incrementation. Since we don't need this for our class, we
128      * overload this method and return the magic formula that DB_DataObject needs.
129      *
130      * @return array magic three-false array that stops auto-incrementing.
131      */
132
133     function sequenceKey()
134     {
135         return array(false, false, false);
136     }
137
138     static function setActivity($notice_id, $verb, $object=null)
139     {
140         $act = self::staticGet('notice_id', $notice_id);
141
142         if (empty($act)) {
143             $act = new Notice_activity();
144             $act->notice_id = $notice_id;
145             $act->verb = $verb;
146             $act->object = $object;
147             $act->insert();
148         } else {
149             $orig = clone($act);
150             $act->verb = $verb;
151             $act->object = $object;
152             $act->update($orig);
153         }
154     }
155 }