]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/NoticeTitle/Notice_title.php
The overloaded DB_DataObject function staticGet is now called getKV
[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 Managed_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      * return table definition for DB_DataObject
57      *
58      * DB_DataObject needs to know something about the table to manipulate
59      * instances. This method provides all the DB_DataObject needs to know.
60      *
61      * @return array array of column definitions
62      */
63     function table()
64     {
65         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
66                      'title' => DB_DATAOBJECT_STR);
67     }
68
69     /**
70      * return key definitions for DB_DataObject
71      *
72      * @return array list of key field names
73      */
74     function keys()
75     {
76         return array_keys($this->keyTypes());
77     }
78
79     /**
80      * return key definitions for Memcached_DataObject
81      *
82      * @return array list mapping field names to key types
83      */
84     function keyTypes()
85     {
86         return array('notice_id' => 'K');
87     }
88
89     /**
90      * Magic formula for non-autoincrementing integer primary keys
91      *
92      * @return array magic three-false array that stops auto-incrementing.
93      */
94     function sequenceKey()
95     {
96         return array(false, false, false);
97     }
98
99     /**
100      * Get a notice title based on the notice
101      *
102      * @param Notice $notice Notice to fetch a title for
103      *
104      * @return string title of the notice, or null if none
105      */
106     static function fromNotice($notice)
107     {
108         $nt = Notice_title::getKV('notice_id', $notice->id);
109         if (empty($nt)) {
110             return null;
111         } else {
112             return $nt->title;
113         }
114     }
115 }