public function Award($Sender, $User, $Criteria) { $Args = $Sender->EventArguments; // Check to see if the submitted action is a target $Prop = 'ActionID_' . $Sender->EventArguments['ActionID']; if (property_exists($Criteria, $Prop)) { $Value = $Criteria->{$Prop}; if ($Value <= 0 || $Value == FALSE) { return FALSE; } } else { return FALSE; } // Get the reaction counts for this parent item $ReactionModel = Yaga::ReactionModel(); $Reactions = $ReactionModel->GetList($Args['ParentID'], $Args['ParentType']); // Squash the dataset into an array $Counts = array(); foreach ($Reactions as $Reaction) { $Counts['ActionID_' . $Reaction->ActionID] = $Reaction->Count; } // Actually check for the reaction counts foreach ($Criteria as $ActionID => $Target) { if ($Counts[$ActionID] < $Target) { return FALSE; } } // The owner should be awarded return $Args['ParentUserID']; }
/** * Renders the reaction record for a specific item * * @param int $ID * @param string $Type 'discussion', 'activity', or 'comment' */ function RenderReactionRecord($ID, $Type) { $Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type); $Limit = C('Yaga.Reactions.RecordLimit'); $ReactionCount = count($Reactions); $i = 0; foreach ($Reactions as $Reaction) { $i++; // 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')); $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); echo Wrap($String, 'span', $Wrapttributes); } if ($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) { echo Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural'); } } }
/** * This method shows the latest discussions/comments a user has posted that * received the specified action * * @param ProfileController $Sender * @param int $UserReference * @param string $Username * @param int $ActionID * @param int $Page */ public function ProfileController_Reactions_Create($Sender, $UserReference = '', $Username = '', $ActionID = '', $Page = 0) { if (!C('Yaga.Reactions.Enabled')) { return; } list($Offset, $Limit) = OffsetLimit($Page, C('Yaga.ReactedContent.PerPage', 5)); if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $Sender->EditMode(FALSE); // Tell the ProfileController what tab to load $Sender->GetUserInfo($UserReference, $Username); $Sender->_SetBreadcrumbs(T('Yaga.Reactions'), UserUrl($Sender->User, '', 'reactions')); $Sender->SetTabView(T('Yaga.Reactions'), 'reactions', 'profile', 'Yaga'); $Sender->AddJsFile('jquery.expander.js'); $Sender->AddJsFile('reactions.js', 'yaga'); $Sender->AddDefinition('ExpandText', T('(more)')); $Sender->AddDefinition('CollapseText', T('(less)')); $Model = new ActedModel(); $Data = $Model->Get($Sender->User->UserID, $ActionID, $Limit, $Offset); $Sender->SetData('Content', $Data); // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views $Sender->HandlerType = HANDLER_TYPE_NORMAL; // Do not show discussion options $Sender->ShowOptions = FALSE; if ($Sender->Head) { $Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive')); } $ReactionModel = Yaga::ReactionModel(); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $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/'); // Render the ProfileController $Sender->Render(); }