Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Awards a badge if the user has posted in a specific category. Compliments of Jan Hoos.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters