Notice_title.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  33. /**
  34. * Data class for notice titles
  35. *
  36. * @category Action
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  40. * @link http://status.net/
  41. *
  42. * @see DB_DataObject
  43. */
  44. class Notice_title extends Managed_DataObject
  45. {
  46. const MAXCHARS = 191; // not 255 because utf8mb4 takes more space
  47. public $__table = 'notice_title'; // table name
  48. public $notice_id; // int(11) primary_key not_null
  49. public $title; // varchar(191) not 255 because utf8mb4 takes more space
  50. public $created; // datetime() not_null
  51. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  52. public static function schemaDef()
  53. {
  54. return array(
  55. 'fields' => array(
  56. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
  57. 'title' => array('type' => 'varchar', 'length' => Notice_title::MAXCHARS, 'description' => 'title to notice'),
  58. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  59. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  60. ),
  61. 'primary key' => array('notice_id'),
  62. 'foreign keys' => array(
  63. 'notice_title_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  64. ),
  65. );
  66. }
  67. /**
  68. * Get a notice title based on the notice
  69. *
  70. * @param Notice $notice Notice to fetch a title for
  71. *
  72. * @return string title of the notice, or null if none
  73. */
  74. static function fromNotice($notice)
  75. {
  76. $nt = Notice_title::getKV('notice_id', $notice->id);
  77. if (empty($nt)) {
  78. return null;
  79. } else {
  80. return $nt->title;
  81. }
  82. }
  83. }