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