SimpleDesk

SimpleDesk! => SimpleDesk Support => Topic started by: venguard223 on August 09, 2013, 12:48:19 AM

Title: Pagination in the profile area log
Post by: venguard223 on August 09, 2013, 12:48:19 AM
The profile area showing the entire editing history of someone can be pretty cool. Not so cool if you get a white screen of death because too much memory got eaten in PHP.

So, let's fix that with some pagination. Bit more complex a fix this, two files needed.

Firstly, SimpleDesk-Profile.php

Code (find) Select
function shd_profile_actionlog($memID)
{
global $context, $txt, $scripturl, $sourcedir, $user_info, $settings;

loadTemplate('sd_template/SimpleDesk-Profile');
shd_load_language('sd_language/SimpleDeskProfile');

require_once($sourcedir . '/sd_source/Subs-SimpleDeskAdmin.php');
$context['action_log'] = shd_load_action_log_entries(0, 10, '', '', 'la.id_member = ' . $memID);
$context['action_log_count'] = shd_count_action_log_entries('la.id_member = ' . $memID);
$context['action_full_log'] = allowedTo('admin_forum') || shd_allowed_to('admin_helpdesk', 0);

$context['page_title'] = $txt['shd_profile_area'] . ' - ' . $txt['shd_profile_actionlog'];
$context['sub_template'] = 'shd_profile_actionlog';

}


(your copy may or may not have that odd empty line... just replace the entire function definition)

Code (replace) Select
function shd_profile_actionlog($memID)
{
global $context, $txt, $scripturl, $sourcedir, $user_info, $settings;

loadTemplate('sd_template/SimpleDesk-Profile');
shd_load_language('sd_language/SimpleDeskProfile');

require_once($sourcedir . '/sd_source/Subs-SimpleDeskAdmin.php');
$context['action_log_count'] = shd_count_action_log_entries('la.id_member = ' . $memID);
$context['displaypage'] = 30;
$context['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
if ($context['start'] < 0 || $context['start'] >= $context['action_log_count'])
$context['start'] = 0;
$context['action_log'] = shd_load_action_log_entries($context['start'], $context['displaypage'], '', '', 'la.id_member = ' . $memID);
$context['action_full_log'] = allowedTo('admin_forum') || shd_allowed_to('admin_helpdesk', 0);
$context['page_index'] = shd_no_expand_pageindex($scripturl . '?action=profile;area=hd_actionlog;u=' . $memID, $context['start'], $context['action_log_count'], $context['displaypage']);
$context['page_title'] = $txt['shd_profile_area'] . ' - ' . $txt['shd_profile_actionlog'];
$context['sub_template'] = 'shd_profile_actionlog';
}


This does the actual pagination under the hood. Now we have to display it.

SimpleDesk-Profile.template.php

function template_shd_profile_actionlog()
{
global $context, $settings, $txt, $scripturl;

echo '
<div class="tborder">
<div class="cat_bar grid_header">
<h3 class="catbg" id="ticket_log_header">
<img src="', $settings['default_images_url'], '/simpledesk/log.png" class="icon" alt="*" />
', sprintf($txt['shd_profile_log'], $context['member']['name']), '
<span class="smalltext">(', $context['action_log_count'] == 1 ? $txt['shd_profile_log_count_one'] : sprintf($txt['shd_profile_log_count_more'], $context['action_log_count']) , ')</span>
</h3>
</div>


Code (replace) Select
function template_shd_profile_actionlog()
{
global $context, $settings, $txt, $scripturl;

echo '
<div class="title_bar">
<h3 class="titlebg">
<span class="smalltext">', $txt['pages'], ': ', $context['page_index'], '</span>
</h3>
</div>
<div class="tborder">
<div class="cat_bar grid_header">
<h3 class="catbg" id="ticket_log_header">
<img src="', $settings['default_images_url'], '/simpledesk/log.png" class="icon" alt="*" />
', sprintf($txt['shd_profile_log'], $context['member']['name']), '
<span class="smalltext">(', $context['action_log_count'] == 1 ? $txt['shd_profile_log_count_one'] : sprintf($txt['shd_profile_log_count_more'], $context['action_log_count']) , ')</span>
</h3>
</div>


It's not pretty but it should give you pagination on the profile area log.
Title: Re: Pagination in the profile area log
Post by: tfs on August 11, 2013, 10:17:27 PM
Excellent!  Thank you.  This issue just wasn't something we were going to catch as beta testers since it took the buildup of thousands of entries before I started getting the WSOD.  And then for the longest time I thought it was due to some screwy high ASCII character sneaking into a ticket.

Only thing I changed was...

$context['displaypage'] = 30;

...changed to...

$context['displaypage'] = 500;

I prefer a large page of items.  I'm assuming that was the only change necessary to have a different count per page?  It seems to work fine.
Title: Re: Pagination in the profile area log
Post by: venguard223 on August 11, 2013, 11:24:32 PM
Yeah, that's the only thing you'd have to change, everything else around that number. I initially had it at 50 but that seemed too many for my liking.

Good that it all works for you.