Steve F
Well-known member
I am trying to understand the pagination but having a difficult time getting anywhere. If someone could get me pointed in the right direction I would appreciate it.
No page nav is being displayed in the source
Template:
I have in my Controller
=================
Model
I do get a dump with what seems the right info.
No page nav is being displayed in the source
Template:
Code:
<xen:pagenav link="notepad" page="{$page}" perpage="{$maxNotes}" total="{$totalNotes}" />
I have in my Controller
Code:
class PixelExit_AdminCenter_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
// fetch the Scratchpad_Model_Note class
$noteModel = $this->_getNoteModel();
// get the maximum number of notes to fetch
$maxNotes = XenForo_Application::get('options')->peNotepadMaxNotes;
$page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
$notepadNotes = $noteModel->getLatestNotes(array('perPage' => $maxNotes, 'page' => $page));
$totalNotes = $noteModel->getAllNotes($maxNotes);
// get the most recent notes
$notes = $noteModel->getLatestNotes($maxNotes);
// read the date of the most recent note
if ($notes)
{
$date = $notes[0]['note_date'];
}
else
{
$date = 0;
}
// put the data into an array to be passed to the view so the template can use it
$viewParams = array(
'notes' => $notes,
'date' => $date,
'page' => $page,
'notepadNotes' => $notepadNotes,
'totalNotes' => $totalNotes,
);
Zend_Debug::dump($maxNotes, 'Max Notes: ');
Zend_Debug::dump($page, 'Page: ');
Zend_Debug::dump($notepadNotes, 'Notepad Notes: ');
Zend_Debug::dump($totalNotes, 'totalNotes: ');
// get permissions
$permissions = XenForo_Visitor::getInstance()->getPermissions();
$canCreateNotes = XenForo_Permission::hasPermission($permissions, "peAdminCenter", "createNotes");
$canViewNotes = XenForo_Permission::hasPermission($permissions, 'peAdminCenter', 'viewNotes');
// if canViewNotes is true send to template
if ($canViewNotes)
{
// return a View (PixelExit_AdminCenter_ViewPublic_Index) using template 'pe_admin_notepad_index'
return $this->responseView(
'PixelExit_AdminCenter_ViewPublic_Index',
'pe_admin_notepad_index',
$viewParams
);
}
else
{
// if canViewNotes is false display no permission response
throw $this->getNoPermissionResponseException();
}
}
}
=================
Model
Code:
public function getLatestNotes($maxNotes = 0)
{
$sql = '
SELECT
note.*,
user.*
FROM pe_admin_notepad_note AS note
LEFT JOIN xf_user AS user ON
(user.user_id = note.user_id)
ORDER BY note_date DESC
';
// ensure we have a meaningful value for $maxNotes
if ($maxNotes = max($maxNotes, 0))
{
// build our LIMIT (or equivalent) clause
$sql = $this->limitQueryResults($sql, $maxNotes);
}
return $this->_getDb()->fetchAll($sql);
}
/**
* Fetches all notes together with user info.
*
* @return array
*/
public function getAllNotes($totalNotes)
{
return $this->_getDb()->fetchOne('
SELECT COUNT(*)
FROM pe_admin_notepad_note AS notepad_note
ORDER BY notepad_note.note_date DESC
');
}
I do get a dump with what seems the right info.
Max Notes: string(2) "15"
Page: int(1)
Notepad Notes: array(1) {
[0] => array(33) {
["note_id"] => int(94)
["user_id"] => int(1)
["note_date"] => int(1404081188)
["message"] => string(1) "5"
["username"] => string(5) "Steve"
["email"] => string(17) "**********"
["gender"] => string(0) ""
["custom_title"] => string(0) ""
["language_id"] => int(1)
["style_id"] => int(1)
["timezone"] => string(13) "Europe/London"
["visible"] => int(1)
["user_group_id"] => int(2)
["secondary_group_ids"] => string(3) "3,4"
["display_style_group_id"] => int(3)
["permission_combination_id"] => int(5)
["message_count"] => int(0)
["conversations_unread"] => int(0)
["register_date"] => int(1401420303)
["last_activity"] => int(1404173037)
["trophy_points"] => int(0)
["alerts_unread"] => int(0)
["avatar_date"] => int(1404012555)
["avatar_width"] => int(192)
["avatar_height"] => int(192)
["gravatar"] => string(0) ""
["user_state"] => string(5) "valid"
["is_moderator"] => int(1)
["is_admin"] => int(1)
["is_banned"] => int(0)
["like_count"] => int(0)
["warning_points"] => int(0)
["is_staff"] => int(1)
}
}
totalNotes: int(94)