2 namespace wcf\data\notice
;
3 use wcf\data\condition\Condition
;
4 use wcf\data\DatabaseObject
;
5 use wcf\system\condition\ConditionHandler
;
6 use wcf\system\request\IRouteController
;
7 use wcf\system\user\storage\UserStorageHandler
;
11 * Represents a notice.
13 * @author Matthias Schmidt
14 * @copyright 2001-2016 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage data.notice
18 * @category Community Framework
20 * @property-read integer $noticeID
21 * @property-read string $noticeName
22 * @property-read string $notice
23 * @property-read integer $noticeUseHtml
24 * @property-read string $cssClassName
25 * @property-read integer $showOrder
26 * @property-read integer $isDisabled
27 * @property-read integer $isDismissible
29 class Notice
extends DatabaseObject
implements IRouteController
{
31 * true if the active user has dismissed the notice
34 protected $isDismissed = null;
39 protected static $databaseTableName = 'notice';
44 protected static $databaseTableIndexName = 'noticeID';
47 * Returns the textual representation of the notice.
52 public function __toString() {
53 // replace `{$username}` with the active user's name and `{$email}`
54 // with the active user's email address
55 $text = strtr(WCF
::getLanguage()->get($this->notice
), [
56 '{$username}' => WCF
::getUser()->username
,
57 '{$email}' => WCF
::getUser()->email
60 if (!$this->noticeUseHtml
) {
61 $text = nl2br(htmlspecialchars($text), false);
68 * Returns the conditions of the notice.
72 public function getConditions() {
73 return ConditionHandler
::getInstance()->getConditions('com.woltlab.wcf.condition.notice', $this->noticeID
);
79 public function getTitle() {
80 return $this->noticeName
;
84 * Returns true if the active user has dismissed the notice.
88 public function isDismissed() {
89 if (!$this->isDismissible
) return false;
91 if ($this->isDismissed
=== null) {
92 if (WCF
::getUser()->userID
) {
93 $dismissedNotices = UserStorageHandler
::getInstance()->getField('dismissedNotices');
94 if ($dismissedNotices === null) {
95 $sql = "SELECT noticeID
96 FROM wcf".WCF_N
."_notice_dismissed
98 $statement = WCF
::getDB()->prepareStatement($sql);
100 WCF
::getUser()->userID
104 while ($noticeID = $statement->fetchColumn()) {
105 $noticeIDs[] = $noticeID;
107 if ($noticeID == $this->noticeID
) {
108 $this->isDismissed
= true;
112 UserStorageHandler
::getInstance()->update(WCF
::getUser()->userID
, 'dismissedNotices', serialize($noticeIDs));
115 $dismissedNoticeIDs = @unserialize
($dismissedNotices);
116 $this->isDismissed
= in_array($this->noticeID
, $dismissedNoticeIDs);
120 $dismissedNotices = WCF
::getSession()->getVar('dismissedNotices');
121 if ($dismissedNotices !== null) {
122 $dismissedNotices = @unserialize
($dismissedNotices);
123 $this->isDismissed
= in_array($this->noticeID
, $dismissedNotices);
126 $this->isDismissed
= false;
131 return $this->isDismissed
;