Remove echo option from RenderReactionRecord()

This commit is contained in:
Zachary Doll 2015-01-12 09:15:38 -06:00
parent 4a396e1ca6
commit 1d2349ef4b
6 changed files with 15 additions and 35 deletions

View File

@ -99,7 +99,7 @@ class ReactController extends Gdn_Controller {
$this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID);
$this->JsonTarget($Anchor . ' .ReactMenu', RenderReactionList($ID, $Type), 'ReplaceWith');
$this->JsonTarget($Anchor . ' .ReactionRecord', RenderReactionRecord($ID, $Type, FALSE), 'ReplaceWith');
$this->JsonTarget($Anchor . ' .ReactionRecord', RenderReactionRecord($ID, $Type), 'ReplaceWith');
// Don't render anything
$this->Render('Blank', 'Utility', 'Dashboard');

View File

@ -14,7 +14,7 @@ if(!function_exists('RenderReactionList')) {
*
* @param int $ID
* @param string $Type 'discussion', 'activity', or 'comment'
* @return string Rendered list of reactions
* @return string Rendered list of actions available
*/
function RenderReactionList($ID, $Type) {
$Reactions = Yaga::ReactionModel()->GetList($ID, $Type);
@ -46,51 +46,31 @@ if(!function_exists('RenderReactionRecord')) {
*
* @param int $ID
* @param string $Type 'discussion', 'activity', or 'comment'
* @param bool $Echo Should it be echoed?
* @return mixed String if $Echo is false, TRUE otherwise
* @return string Rendered list of existing reactions
*/
function RenderReactionRecord($ID, $Type, $Echo = TRUE) {
function RenderReactionRecord($ID, $Type) {
$Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type);
$Limit = C('Yaga.Reactions.RecordLimit');
$ReactionCount = count($Reactions);
$RecordsString = '';
$i = 0;
foreach($Reactions as $Reaction) {
$i++;
foreach($Reactions as $i => $Reaction) {
// Limit the record if there are a lot of reactions
if($i <= $Limit || $Limit <= 0) {
$User = Gdn::UserModel()->GetID($Reaction->UserID);
$DateTitle = sprintf(
T('Yaga.Reactions.RecordFormat'),
$User->Name,
$Reaction->Name,
Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y')
);
$DateTitle = sprintf(T('Yaga.Reactions.RecordFormat'), $User->Name, $Reaction->Name, Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y'));
$String = UserPhoto($User, array('Size' => 'Small', 'title' => $DateTitle));
$String .= '<span class="ReactSprite Reaction-' . $Reaction->ActionID . ' ' . $Reaction->CssClass . '"></span>';
$Wrapttributes = array(
'class' => 'UserReactionWrap',
'data-userid' => $User->UserID,
'title' => $DateTitle
);
$Wrapttributes = array('class' => 'UserReactionWrap', 'data-userid' => $User->UserID, 'title' => $DateTitle);
$RecordsString .= Wrap($String, 'span', $Wrapttributes);
}
// Display the 'and x more' message if there is a limit
if($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) {
$RecordsString .= Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural');
}
}
$AllRecordsString = Wrap($RecordsString, 'div', array('class' => 'ReactionRecord'));
if($Echo) {
echo $AllRecordsString;
return true;
}
else {
return $AllRecordsString;
}
return Wrap($RecordsString, 'div', array('class' => 'ReactionRecord'));
}
}

View File

@ -360,7 +360,7 @@ class YagaHooks implements Gdn_IPlugin {
}
$Type = 'discussion';
$ID = $Sender->DiscussionID;
RenderReactionRecord($ID, $Type);
echo RenderReactionRecord($ID, $Type);
}
/**
@ -373,7 +373,7 @@ class YagaHooks implements Gdn_IPlugin {
}
$Type = 'comment';
$ID = $Sender->EventArguments['Comment']->CommentID;
RenderReactionRecord($ID, $Type);
echo RenderReactionRecord($ID, $Type);
}
/**

View File

@ -58,7 +58,7 @@ foreach ($Contents as $Content) {
</div>
<?php
if(C('Yaga.Reactions.Enabled') && Gdn::Session()->CheckPermission('Yaga.Reactions.View')) {
RenderReactionRecord($ContentID, strtolower($ContentType));
echo RenderReactionRecord($ContentID, strtolower($ContentType));
}
?>
</div>

View File

@ -58,7 +58,7 @@ foreach ($Contents as $Content) {
</div>
<?php
if(C('Yaga.Reactions.Enabled') && Gdn::Session()->CheckPermission('Yaga.Reactions.View')) {
RenderReactionRecord($ContentID, strtolower($ContentType));
echo RenderReactionRecord($ContentID, strtolower($ContentType));
}
?>
</div>

View File

@ -58,7 +58,7 @@ foreach ($Contents as $Content) {
</div>
<?php
if(C('Yaga.Reactions.Enabled') && Gdn::Session()->CheckPermission('Yaga.Reactions.View')) {
RenderReactionRecord($ContentID, strtolower($ContentType));
echo RenderReactionRecord($ContentID, strtolower($ContentType));
}
?>
</div>