c0d11cf91e
Added an Interacts method on the yagarule interface. Any badges using interactive rules will be checked regardless of the calling user's award status. Fixes issue #15
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php if(!defined('APPLICATION')) exit();
|
|
|
|
/**
|
|
* This rule awards badges when a user comments on a dead discussion.
|
|
*
|
|
* @author Zachary Doll
|
|
* @since 0.3.4
|
|
* @package Yaga
|
|
*/
|
|
class NecroPost implements YagaRule {
|
|
|
|
public function Award($Sender, $User, $Criteria) {
|
|
$NecroDate = strtotime($Criteria->Duration . ' ' . $Criteria->Period . ' ago');
|
|
|
|
// Get the last comment date from the parent discussion
|
|
$Args = $Sender->EventArguments;
|
|
$DiscussionID = $Args['FormPostValues']['DiscussionID'];
|
|
$DiscussionModel = new DiscussionModel();
|
|
$Discussion = $DiscussionModel->GetID($DiscussionID);
|
|
$LastCommentDate = strtotime($Discussion->DateLastComment);
|
|
|
|
if($LastCommentDate < $NecroDate) {
|
|
return TRUE;
|
|
}
|
|
else {
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
public function Form($Form) {
|
|
$Lengths = array(
|
|
'day' => T('Days'),
|
|
'week' => T('Weeks'),
|
|
'year' => T('Years')
|
|
);
|
|
|
|
$String = $Form->Label('Yaga.Rules.NecroPost.Criteria.Head', 'NecroPost');
|
|
$String .= $Form->Textbox('Duration', array('class' => 'SmallInput')) . ' ';
|
|
$String .= $Form->DropDown('Period', $Lengths);
|
|
|
|
return $String;
|
|
}
|
|
|
|
public function Validate($Criteria, $Form) {
|
|
$Validation = new Gdn_Validation();
|
|
$Validation->ApplyRules(array(
|
|
array(
|
|
'Name' => 'Duration', 'Validation' => array('Required', 'Integer')
|
|
),
|
|
array(
|
|
'Name' => 'Period', 'Validation' => 'Required'
|
|
)
|
|
));
|
|
$Validation->Validate($Criteria);
|
|
$Form->SetValidationResults($Validation->Results());
|
|
}
|
|
|
|
public function Hooks() {
|
|
return array('CommentModel_AfterSaveComment');
|
|
}
|
|
|
|
public function Description() {
|
|
$Description = T('Yaga.Rules.NecroPost.Desc');
|
|
return Wrap($Description, 'div', array('class' => 'InfoMessage'));
|
|
}
|
|
|
|
public function Name() {
|
|
return T('Yaga.Rules.NecroPost');
|
|
}
|
|
|
|
public function Interacts() {
|
|
return FALSE;
|
|
}
|
|
}
|