]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/NoticeTitle/Notice_title.php
Merge branch 'master' of gitorious.org:statusnet/mainline
[quix0rs-gnu-social.git] / plugins / NoticeTitle / Notice_title.php
1 <?php
2 /**
3  * Data class for notice titles
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) 2010, 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 notice titles
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 class Notice_title extends Memcached_DataObject
48 {
49     const MAXCHARS = 255;
50
51     public $__table = 'notice_title'; // table name
52     public $notice_id;                         // int(4)  primary_key not_null
53     public $title;                             // varchar(255)
54
55     /**
56      * Get an instance by key
57      *
58      * This is a utility method to get a single instance with a given key value.
59      *
60      * @param string $k Key to use to lookup (usually 'user_id' for this class)
61      * @param mixed  $v Value to lookup
62      *
63      * @return Notice_title object found, or null for no hits
64      *
65      */
66     function staticGet($k, $v=null)
67     {
68         return Memcached_DataObject::staticGet('Notice_title', $k, $v);
69     }
70
71     /**
72      * return table definition for DB_DataObject
73      *
74      * DB_DataObject needs to know something about the table to manipulate
75      * instances. This method provides all the DB_DataObject needs to know.
76      *
77      * @return array array of column definitions
78      */
79     function table()
80     {
81         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
82                      'title' => DB_DATAOBJECT_STR);
83     }
84
85     /**
86      * return key definitions for DB_DataObject
87      *
88      * @return array list of key field names
89      */
90     function keys()
91     {
92         return array_keys($this->keyTypes());
93     }
94
95     /**
96      * return key definitions for Memcached_DataObject
97      *
98      * @return array list mapping field names to key types
99      */
100     function keyTypes()
101     {
102         return array('notice_id' => 'K');
103     }
104
105     /**
106      * Magic formula for non-autoincrementing integer primary keys
107      *
108      * @return array magic three-false array that stops auto-incrementing.
109      */
110     function sequenceKey()
111     {
112         return array(false, false, false);
113     }
114
115     /**
116      * Get a notice title based on the notice
117      *
118      * @param Notice $notice Notice to fetch a title for
119      *
120      * @return string title of the notice, or null if none
121      */
122     static function fromNotice($notice)
123     {
124         $nt = Notice_title::staticGet('notice_id', $notice->id);
125         if (empty($nt)) {
126             return null;
127         } else {
128             return $nt->title;
129         }
130     }
131 }