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->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID);
$this->JsonTarget($Anchor . ' .ReactMenu', RenderReactionList($ID, $Type), 'ReplaceWith'); $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 // Don't render anything
$this->Render('Blank', 'Utility', 'Dashboard'); $this->Render('Blank', 'Utility', 'Dashboard');

View File

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

View File

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

View File

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

View File

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

View File

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