Fix getBirthdays()
- explicit create an array for the template
This commit is contained in:
parent
1239ce1e7e
commit
6eab7d9f14
|
@ -479,7 +479,6 @@ class Profile
|
||||||
|
|
||||||
public static function getBirthdays()
|
public static function getBirthdays()
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
|
||||||
$o = '';
|
$o = '';
|
||||||
|
|
||||||
if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
|
if (!local_user() || DI::mode()->isMobile() || DI::mode()->isMobile()) {
|
||||||
|
@ -493,13 +492,12 @@ class Profile
|
||||||
* return $o;
|
* return $o;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$bd_format = DI::l10n()->t('g A l F d'); // 8 AM Friday January 18
|
|
||||||
$bd_short = DI::l10n()->t('F d');
|
$bd_short = DI::l10n()->t('F d');
|
||||||
|
|
||||||
$cachekey = 'get_birthdays:' . local_user();
|
$cachekey = 'get_birthdays:' . local_user();
|
||||||
$r = DI::cache()->get($cachekey);
|
$events = DI::cache()->get($cachekey);
|
||||||
if (is_null($r)) {
|
if (is_null($events)) {
|
||||||
$s = DBA::p(
|
$result = DBA::p(
|
||||||
"SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
|
"SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
|
||||||
INNER JOIN `contact`
|
INNER JOIN `contact`
|
||||||
ON `contact`.`id` = `event`.`cid`
|
ON `contact`.`id` = `event`.`cid`
|
||||||
|
@ -517,20 +515,21 @@ class Profile
|
||||||
DateTimeFormat::utc('now + 6 days'),
|
DateTimeFormat::utc('now + 6 days'),
|
||||||
DateTimeFormat::utcNow()
|
DateTimeFormat::utcNow()
|
||||||
);
|
);
|
||||||
if (DBA::isResult($s)) {
|
if (DBA::isResult($result)) {
|
||||||
$r = DBA::toArray($s);
|
$events = DBA::toArray($result);
|
||||||
DI::cache()->set($cachekey, $r, Duration::HOUR);
|
DI::cache()->set($cachekey, $events, Duration::HOUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$classtoday = '';
|
$classtoday = '';
|
||||||
if (DBA::isResult($r)) {
|
$tpl_events = [];
|
||||||
|
if (DBA::isResult($events)) {
|
||||||
$now = strtotime('now');
|
$now = strtotime('now');
|
||||||
$cids = [];
|
$cids = [];
|
||||||
|
|
||||||
$istoday = false;
|
$istoday = false;
|
||||||
foreach ($r as $rr) {
|
foreach ($events as $rr) {
|
||||||
if (strlen($rr['name'])) {
|
if (strlen($rr['name'])) {
|
||||||
$total ++;
|
$total ++;
|
||||||
}
|
}
|
||||||
|
@ -540,13 +539,12 @@ class Profile
|
||||||
}
|
}
|
||||||
$classtoday = $istoday ? ' birthday-today ' : '';
|
$classtoday = $istoday ? ' birthday-today ' : '';
|
||||||
if ($total) {
|
if ($total) {
|
||||||
foreach ($r as &$rr) {
|
foreach ($events as $rr) {
|
||||||
if (!strlen($rr['name'])) {
|
if (!strlen($rr['name'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid duplicates
|
// avoid duplicates
|
||||||
|
|
||||||
if (in_array($rr['cid'], $cids)) {
|
if (in_array($rr['cid'], $cids)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -554,11 +552,12 @@ class Profile
|
||||||
|
|
||||||
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
|
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
|
||||||
|
|
||||||
$rr['link'] = Contact::magicLinkById($rr['cid']);
|
$tpl_events[] = [
|
||||||
$rr['title'] = $rr['name'];
|
'id' => $rr['id'],
|
||||||
$rr['date'] = DI::l10n()->getDay(DateTimeFormat::local($rr['start'], $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
|
'link' => Contact::magicLinkById($rr['cid']),
|
||||||
$rr['startime'] = null;
|
'title' => $rr['name'],
|
||||||
$rr['today'] = $today;
|
'date' => DI::l10n()->getDay(DateTimeFormat::local($rr['start'], $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '')
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,7 +567,7 @@ class Profile
|
||||||
'$count' => $total,
|
'$count' => $total,
|
||||||
'$event_reminders' => DI::l10n()->t('Birthday Reminders'),
|
'$event_reminders' => DI::l10n()->t('Birthday Reminders'),
|
||||||
'$event_title' => DI::l10n()->t('Birthdays this week:'),
|
'$event_title' => DI::l10n()->t('Birthdays this week:'),
|
||||||
'$events' => $r,
|
'$events' => $tpl_events,
|
||||||
'$lbr' => '{', // raw brackets mess up if/endif macro processing
|
'$lbr' => '{', // raw brackets mess up if/endif macro processing
|
||||||
'$rbr' => '}'
|
'$rbr' => '}'
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue