]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/NoticeTitle/classes/Notice_title.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / NoticeTitle / classes / 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 = 191;   // not 255 because utf8mb4 takes more space
50
51     public $__table = 'notice_title'; // table name
52     public $notice_id;                         // int(11)  primary_key not_null
53     public $title;                             // varchar(191)   not 255 because utf8mb4 takes more space
54     public $created;                           // datetime()   not_null
55     public $modified;                          // timestamp()   not_null default_CURRENT_TIMESTAMP
56
57     public static function schemaDef()
58     {
59         return array(
60             'fields' => array(
61                 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
62                 'title' => array('type' => 'varchar', 'length' => Notice_title::MAXCHARS, 'description' => 'title to notice'),
63                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
64                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
65             ),
66             'primary key' => array('notice_id'),
67             'foreign keys' => array(
68                 'notice_title_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
69             ),
70         );
71     }
72
73     /**
74      * Get a notice title based on the notice
75      *
76      * @param Notice $notice Notice to fetch a title for
77      *
78      * @return string title of the notice, or null if none
79      */
80     static function fromNotice(Notice $notice)
81     {
82         $nt = Notice_title::getKV('notice_id', $notice->id);
83         if (empty($nt)) {
84             return null;
85         } else {
86             return $nt->title;
87         }
88     }
89 }