Commit | Line | Data |
---|---|---|
8444b115 | 1 | <?php |
a9229942 | 2 | |
ea42130c | 3 | namespace wcf\system\box; |
a9229942 | 4 | |
4279653c | 5 | use wcf\data\DatabaseObject; |
ea42130c | 6 | use wcf\data\user\option\UserOption; |
25bb9d92 | 7 | use wcf\system\cache\builder\UserOptionCacheBuilder; |
9a66ae92 | 8 | use wcf\system\cache\runtime\UserProfileRuntimeCache; |
324aa486 | 9 | use wcf\system\condition\IObjectCondition; |
8444b115 MW |
10 | use wcf\system\user\UserBirthdayCache; |
11 | use wcf\system\WCF; | |
12 | use wcf\util\DateUtil; | |
13 | ||
14 | /** | |
15 | * Shows today's birthdays. | |
ea42130c | 16 | * |
a9229942 TD |
17 | * @author Marcel Werk |
18 | * @copyright 2001-2019 WoltLab GmbH | |
19 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
20 | * @package WoltLabSuite\Core\System\Box | |
21 | * @since 3.0 | |
8444b115 | 22 | */ |
a9229942 TD |
23 | class TodaysBirthdaysBoxController extends AbstractDatabaseObjectListBoxController |
24 | { | |
25 | /** | |
26 | * @inheritDoc | |
27 | */ | |
28 | protected static $supportedPositions = ['sidebarLeft', 'sidebarRight']; | |
29 | ||
30 | /** | |
31 | * @inheritDoc | |
32 | * @since 5.3 | |
33 | */ | |
34 | protected $conditionDefinition = 'com.woltlab.wcf.box.todaysBirthdays.condition'; | |
35 | ||
36 | /** | |
37 | * template name | |
38 | * @var string | |
39 | */ | |
40 | protected $templateName = 'boxTodaysBirthdays'; | |
41 | ||
42 | /** | |
43 | * @inheritDoc | |
44 | */ | |
45 | public $defaultLimit = 5; | |
46 | ||
47 | /** | |
48 | * @inheritDoc | |
49 | */ | |
50 | protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField'; | |
51 | ||
52 | /** | |
53 | * @inheritDoc | |
54 | */ | |
55 | public $validSortFields = [ | |
56 | 'username', | |
57 | 'activityPoints', | |
58 | 'registrationDate', | |
59 | ]; | |
60 | ||
61 | /** | |
62 | * @inheritDoc | |
63 | */ | |
64 | protected function getObjectList() | |
65 | { | |
66 | } | |
67 | ||
68 | /** | |
69 | * @inheritDoc | |
70 | */ | |
71 | protected function getTemplate() | |
72 | { | |
73 | } | |
74 | ||
75 | /** | |
76 | * @inheritDoc | |
77 | */ | |
78 | public function hasContent() | |
79 | { | |
80 | parent::hasContent(); | |
81 | ||
82 | return AbstractBoxController::hasContent(); | |
83 | } | |
84 | ||
85 | /** | |
86 | * @inheritDoc | |
87 | */ | |
88 | protected function loadContent() | |
89 | { | |
90 | // get current date | |
91 | $currentDay = DateUtil::format(null, 'm-d'); | |
92 | $date = \explode('-', DateUtil::format(null, 'Y-n-j')); | |
93 | ||
94 | // get user ids | |
95 | $userIDs = UserBirthdayCache::getInstance()->getBirthdays($date[1], $date[2]); | |
96 | $this->filterUserIDs($userIDs); | |
97 | ||
98 | if (!empty($userIDs)) { | |
99 | $userOptions = UserOptionCacheBuilder::getInstance()->getData([], 'options'); | |
100 | if (isset($userOptions['birthday'])) { | |
101 | /** @var UserOption $birthdayUserOption */ | |
102 | $birthdayUserOption = $userOptions['birthday']; | |
103 | ||
104 | $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($userIDs); | |
105 | $visibleUserProfiles = []; | |
106 | ||
107 | $i = 0; | |
108 | foreach ($userProfiles as $userProfile) { | |
109 | // ignore deleted users | |
110 | if ($userProfile === null) { | |
111 | continue; | |
112 | } | |
113 | ||
114 | // show a maximum of x users | |
115 | if ($i == $this->limit) { | |
116 | break; | |
117 | } | |
118 | ||
119 | foreach ($this->box->getConditions() as $condition) { | |
120 | /** @var IObjectCondition $processor */ | |
121 | $processor = $condition->getObjectType()->getProcessor(); | |
122 | if (!$processor->checkObject($userProfile->getDecoratedObject(), $condition->conditionData)) { | |
123 | continue 2; | |
124 | } | |
125 | } | |
126 | ||
127 | $birthdayUserOption->setUser($userProfile->getDecoratedObject()); | |
128 | ||
129 | if ( | |
130 | !$userProfile->isProtected() && $birthdayUserOption->isVisible() && \substr( | |
131 | $userProfile->birthday, | |
132 | 5 | |
133 | ) == $currentDay | |
134 | ) { | |
135 | $visibleUserProfiles[] = $userProfile; | |
136 | $i++; | |
137 | } | |
138 | } | |
139 | ||
140 | if (!empty($visibleUserProfiles)) { | |
141 | // sort users | |
142 | DatabaseObject::sort($visibleUserProfiles, $this->sortField, $this->sortOrder); | |
143 | ||
144 | $this->content = WCF::getTPL()->fetch($this->templateName, 'wcf', [ | |
145 | 'birthdayUserProfiles' => $visibleUserProfiles, | |
146 | 'sortField' => $this->sortField, | |
147 | 'sortOrder' => $this->sortOrder, | |
148 | ], true); | |
149 | } | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | /** | |
155 | * Filters given user ids. | |
156 | * | |
157 | * @param int[] $userIDs | |
158 | */ | |
159 | protected function filterUserIDs(&$userIDs) | |
160 | { | |
161 | // does nothing, can be overwritten by child classes | |
162 | } | |
8444b115 | 163 | } |