Created
June 21, 2019 10:59
-
-
Save cgi-caesar/8a494323c3b4262ab67c6819980a8fc7 to your computer and use it in GitHub Desktop.
aMember (site.php): Add new Widget (Upcoming Expirations) to Admin Dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Am_Di::getInstance()->hook->add(Am_Event::LOAD_ADMIN_DASHBOARD_WIDGETS, function(Am_Event $e) { | |
$e->addReturn(new Am_AdminDashboardWidget('upcoming-expire', ___('Upcoming Expirations'), | |
function(Am_View $v, $config = null) { | |
$lookahead = sqlDate('+7 days'); | |
$now = sqlDate('now'); | |
$data = Am_Di::getInstance()->db->select(<<<CUT | |
SELECT u.login, u.email, u.name_f, u.name_l, product_id, MAX(expire_date) AS exp | |
FROM ?_user u | |
LEFT JOIN ?_access a USING (user_id) | |
GROUP BY user_id, product_id | |
HAVING exp BETWEEN ? AND ? | |
ORDER BY exp ASC; | |
CUT | |
, $now, $lookahead); | |
$pMap = Am_Di::getInstance()->productTable->getOptions(); | |
$out = ''; | |
foreach ($data as $_) { | |
$out .= sprintf('<tr class="grid-row am-grid-row"><td><strong>%s</strong> (%s)<br/>%s</td><td>%s</td><td>%s</td></tr>', | |
$v->escape("{$_['name_f']} {$_['name_l']}"), | |
$v->escape($_['login']), | |
$v->escape($_['email']), | |
$v->escape($pMap[$_['product_id']]), | |
amDate($_['exp']) | |
); | |
} | |
return <<<CUT | |
<div class="admin-last"> | |
<h2>Upcoming Expirations</h2> | |
<div class="grid-container am-grid-container"> | |
<table class="am-grid grid-no-highlight"> | |
<tr> | |
<th class="helper-corner-left" nowrap="nowrap">Customer</th> | |
<th>Product</th> | |
<th class="helper-corner-right">Expires</th> | |
</tr> | |
{$out} | |
</table> | |
</div> | |
</div> | |
CUT; | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment