Return an object from ActedModel instead of an array.

This object contains the total record count after a security check. This ensures the pager gets the right data while preventing a duplicate query.
This commit is contained in:
Zachary Doll 2015-01-19 09:44:19 -06:00
parent b44a695437
commit 39f55f6803
3 changed files with 11 additions and 11 deletions

View File

@ -92,7 +92,7 @@ class ActedModel extends Gdn_Model {
}
$this->Security($Content);
$this->Condense($Content, $Limit, $Offset);
$this->CondenseAndPrep($Content, $Limit, $Offset);
return $Content;
}
@ -147,7 +147,7 @@ class ActedModel extends Gdn_Model {
}
$this->Security($Content);
$this->Condense($Content, $Limit, $Offset);
$this->CondenseAndPrep($Content, $Limit, $Offset);
return $Content;
}
@ -199,7 +199,7 @@ class ActedModel extends Gdn_Model {
}
$this->Security($Content);
$this->Condense($Content, $Limit, $Offset);
$this->CondenseAndPrep($Content, $Limit, $Offset);
return $Content;
}
@ -244,7 +244,7 @@ class ActedModel extends Gdn_Model {
}
$this->Security($Content);
$this->Condense($Content, $Limit, $Offset);
$this->CondenseAndPrep($Content, $Limit, $Offset);
return $Content;
}
@ -293,7 +293,7 @@ class ActedModel extends Gdn_Model {
}
$this->Security($Content);
$this->Condense($Content, $Limit, $Offset);
$this->CondenseAndPrep($Content, $Limit, $Offset);
return $Content;
}
@ -433,8 +433,8 @@ class ActedModel extends Gdn_Model {
* @param int $Limit
* @param int $Offset
*/
protected function Condense(&$Content, $Limit, $Offset) {
$Content = array_slice($Content, $Offset, $Limit);
protected function CondenseAndPrep(&$Content, $Limit, $Offset) {
$Content = (object) array('TotalRecords' => count($Content), 'Content' => array_slice($Content, $Offset, $Limit));
}
}

View File

@ -165,7 +165,7 @@ class YagaHooks implements Gdn_IPlugin {
$Model = Yaga::ActedModel();
$Data = $Model->Get($Sender->User->UserID, $ActionID, $Limit, $Offset);
$Sender->SetData('Content', $Data);
$Sender->SetData('Content', $Data->Content);
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;
@ -184,7 +184,7 @@ class YagaHooks implements Gdn_IPlugin {
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset, $Limit, $ReactionModel->GetUserCount($Sender->User->UserID, $ActionID), 'profile/reactions/' . $Sender->User->UserID . '/' . Gdn_Format::Url($Sender->User->Name) . '/' . $ActionID . '/%1$s/'
$Offset, $Limit, $Data->TotalRecords, 'profile/reactions/' . $Sender->User->UserID . '/' . Gdn_Format::Url($Sender->User->Name) . '/' . $ActionID . '/%1$s/'
);
// Render the ProfileController
@ -224,7 +224,7 @@ class YagaHooks implements Gdn_IPlugin {
$Model = Yaga::ActedModel();
$Data = $Model->GetBest($Sender->User->UserID, $Limit, $Offset);
$Sender->SetData('Content', $Data);
$Sender->SetData('Content', $Data->Content);
// Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
$Sender->HandlerType = HANDLER_TYPE_NORMAL;

View File

@ -1,7 +1,7 @@
<?php if(!defined('APPLICATION')) exit();
/* Copyright 2014 Zachary Doll */
$Contents = $this->_Content;
$Contents = $this->_Content->Content;
echo '<ul class="DataList Compact BlogList">';
foreach ($Contents as $Content) {