From ff6df8061b1b1cdd2685246ed238818ed46c959f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 18 Jan 2011 13:12:08 -0800 Subject: [PATCH] Refactor profile sidebar stats generation: factor out giant chunk of repeated method calls --- lib/profileaction.php | 55 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/lib/profileaction.php b/lib/profileaction.php index fd2b73f6f2..ae70ad560b 100644 --- a/lib/profileaction.php +++ b/lib/profileaction.php @@ -200,52 +200,39 @@ class ProfileAction extends OwnerDesignAction $this->element('h2', null, _('Statistics')); // Other stats...? - $this->elementStart('dl', 'entity_user-id'); - $this->element('dt', null, _('User ID')); - $this->element('dd', null, $this->profile->id); - $this->elementEnd('dl'); + $this->showStatsRow('user-id', _('User ID'), $this->profile->id); - $this->elementStart('dl', 'entity_member-since'); - $this->element('dt', null, _('Member since')); - $this->element('dd', null, date('j M Y', + $this->showStatsRow('member-since', _('Member since'), date('j M Y', strtotime($this->profile->created))); - $this->elementEnd('dl'); - $this->elementStart('dl', 'entity_subscriptions'); - $this->elementStart('dt'); - $this->statsSectionLink('subscriptions', _('Subscriptions')); - $this->elementEnd('dt'); - $this->element('dd', null, $subs_count); - $this->elementEnd('dl'); + $this->showStatsRow('subscriptions', _('Subscriptions'), $subs_count, 'subscriptions'); - $this->elementStart('dl', 'entity_subscribers'); - $this->elementStart('dt'); - $this->statsSectionLink('subscribers', _('Subscribers')); - $this->elementEnd('dt'); - $this->element('dd', 'subscribers', $subbed_count); - $this->elementEnd('dl'); + $this->showStatsRow('subscribers', _('Subscribers'), $subbed_count, 'subscribed'); - $this->elementStart('dl', 'entity_groups'); - $this->elementStart('dt'); - $this->statsSectionLink('usergroups', _('Groups')); - $this->elementEnd('dt'); - $this->element('dd', 'groups', $group_count); - $this->elementEnd('dl'); + $this->showStatsRow('groups', _('Groups'), $group_count, 'usergroup'); - $this->elementStart('dl', 'entity_notices'); - $this->element('dt', null, _('Notices')); - $this->element('dd', null, $notice_count); - $this->elementEnd('dl'); + $this->showStatsRow('notices', _('Notices'), $notice_count); - $this->elementStart('dl', 'entity_daily_notices'); // TRANS: Average count of posts made per day since account registration - $this->element('dt', null, _('Daily average')); - $this->element('dd', null, $daily_count); - $this->elementEnd('dl'); + $this->showStatsRow('daily_notices', _('Daily average'), $daily_count); $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() { $groups = $this->profile->getGroups(0, GROUPS_PER_MINILIST + 1); -- 2.39.5