Add DiscussionCategory rule
Awards a badge if the user has posted in a specific category. Compliments of Jan Hoos.
This commit is contained in:
parent
9e6bd014d7
commit
fcb166abb6
55
library/rules/class.discussioncategory.php
Normal file
55
library/rules/class.discussioncategory.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php if(!defined('APPLICATION')) exit();
|
||||||
|
/**
|
||||||
|
* This rule awards badges if a discussion is posted in the right category
|
||||||
|
*
|
||||||
|
* @author Jan Hoos
|
||||||
|
* @since 1.0
|
||||||
|
* @package Yaga
|
||||||
|
*/
|
||||||
|
class DiscussionCategory implements YagaRule {
|
||||||
|
|
||||||
|
public function Award($Sender, $User, $Criteria) {
|
||||||
|
$Discussion = $Sender->EventArguments['Discussion'];
|
||||||
|
$ID = ($Discussion->CategoryID);
|
||||||
|
if($ID == $Criteria->CategoryID) {
|
||||||
|
return $Discussion->InsertUserID;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Form($Form) {
|
||||||
|
$String = $Form->Label('Yaga.Rules.DiscussionCategory.Criteria.Head', 'DiscussionCategory');
|
||||||
|
$String .= $Form->CategoryDropDown('CategoryID');
|
||||||
|
return $String;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Validate($Criteria, $Form) {
|
||||||
|
$Validation = new Gdn_Validation();
|
||||||
|
$Validation->ApplyRules(array(
|
||||||
|
array(
|
||||||
|
'Name' => 'CategoryID', 'Validation' => array('Required', 'Integer')
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$Validation->Validate($Criteria);
|
||||||
|
$Form->SetValidationResults($Validation->Results());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Hooks() {
|
||||||
|
return array('DiscussionModel_AfterSaveDiscussion');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Description() {
|
||||||
|
return Wrap(T('Yaga.Rules.DiscussionCategory.Desc'), 'div', array('class' => 'InfoMessage'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Name() {
|
||||||
|
return T('Yaga.Rules.DiscussionCategory');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Interacts() {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -154,6 +154,9 @@ $Definition['Yaga.Rules.CommentMarathon.Criteria.Head'] = 'Number of Comments';
|
|||||||
$Definition['Yaga.Rules.DiscussionBodyLength'] = 'OP Length';
|
$Definition['Yaga.Rules.DiscussionBodyLength'] = 'OP Length';
|
||||||
$Definition['Yaga.Rules.DiscussionBodyLength.Desc'] = 'Award this badge if the user has a discussion that reaches the target number of characters. Make sure you enter a number less than or equal to %s.';
|
$Definition['Yaga.Rules.DiscussionBodyLength.Desc'] = 'Award this badge if the user has a discussion that reaches the target number of characters. Make sure you enter a number less than or equal to %s.';
|
||||||
$Definition['Yaga.Rules.DiscussionBodyLength.Criteria.Head'] = 'How many characters?';
|
$Definition['Yaga.Rules.DiscussionBodyLength.Criteria.Head'] = 'How many characters?';
|
||||||
|
$Definition['Yaga.Rules.DiscussionCategory'] = 'Post in category';
|
||||||
|
$Definition['Yaga.Rules.DiscussionCategory.Desc'] = 'Award this badge if the user has started a discussion in the specified category.';
|
||||||
|
$Definition['Yaga.Rules.DiscussionCategory.Criteria.Head'] = 'Select Category:';
|
||||||
$Definition['Yaga.Rules.DiscussionCount'] = 'Discussion Count Total';
|
$Definition['Yaga.Rules.DiscussionCount'] = 'Discussion Count Total';
|
||||||
$Definition['Yaga.Rules.DiscussionCount.Desc'] = 'Award this badges if the total count of discussions a user has ever started meets the specified comparison.';
|
$Definition['Yaga.Rules.DiscussionCount.Desc'] = 'Award this badges if the total count of discussions a user has ever started meets the specified comparison.';
|
||||||
$Definition['Yaga.Rules.DiscussionCount.Criteria.Head'] = 'Total Discussions';
|
$Definition['Yaga.Rules.DiscussionCount.Criteria.Head'] = 'Total Discussions';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user