Refactor profile sidebar stats generation: factor out giant chunk of repeated method calls

This commit is contained in:
Brion Vibber 2011-01-18 13:12:08 -08:00
parent 9be770e609
commit ff6df8061b

View File

@ -200,52 +200,39 @@ class ProfileAction extends OwnerDesignAction
$this->element('h2', null, _('Statistics')); $this->element('h2', null, _('Statistics'));
// Other stats...? // Other stats...?
$this->elementStart('dl', 'entity_user-id'); $this->showStatsRow('user-id', _('User ID'), $this->profile->id);
$this->element('dt', null, _('User ID'));
$this->element('dd', null, $this->profile->id);
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_member-since'); $this->showStatsRow('member-since', _('Member since'), date('j M Y',
$this->element('dt', null, _('Member since'));
$this->element('dd', null, date('j M Y',
strtotime($this->profile->created))); strtotime($this->profile->created)));
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_subscriptions'); $this->showStatsRow('subscriptions', _('Subscriptions'), $subs_count, 'subscriptions');
$this->elementStart('dt');
$this->statsSectionLink('subscriptions', _('Subscriptions'));
$this->elementEnd('dt');
$this->element('dd', null, $subs_count);
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_subscribers'); $this->showStatsRow('subscribers', _('Subscribers'), $subbed_count, 'subscribed');
$this->elementStart('dt');
$this->statsSectionLink('subscribers', _('Subscribers'));
$this->elementEnd('dt');
$this->element('dd', 'subscribers', $subbed_count);
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_groups'); $this->showStatsRow('groups', _('Groups'), $group_count, 'usergroup');
$this->elementStart('dt');
$this->statsSectionLink('usergroups', _('Groups'));
$this->elementEnd('dt');
$this->element('dd', 'groups', $group_count);
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_notices'); $this->showStatsRow('notices', _('Notices'), $notice_count);
$this->element('dt', null, _('Notices'));
$this->element('dd', null, $notice_count);
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_daily_notices');
// TRANS: Average count of posts made per day since account registration // TRANS: Average count of posts made per day since account registration
$this->element('dt', null, _('Daily average')); $this->showStatsRow('daily_notices', _('Daily average'), $daily_count);
$this->element('dd', null, $daily_count);
$this->elementEnd('dl');
$this->elementEnd('div'); $this->elementEnd('div');
} }
function showStatsRow($id, $label, $content, $labelAction=false)
{
$this->elementStart('dl', 'entity_' . $id);
$this->elementStart('dt');
if ($labelAction) {
$this->statsSectionLink($labelAction, $label);
} else {
$this->text($label);
}
$this->elementEnd('dt');
$this->element('dd', null, $content);
$this->elementEnd('dl');
}
function showGroups() function showGroups()
{ {
$groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1); $groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1);