Now, I know Mentioning is an option in the choices for creating badges, but that makes a rule that assigns the badge if the user mentions somebody, but, there is no option for assigning a badge for something saying "Hi" in a discussion, for example.
You want a rule that parses the message for a word? Maybe a keyword rule?
You should write it up as an exercise. I will get you started.
<?php if(!defined('APPLICATION')) exit();
/**
* This rule awards badges when a user uses a specific keyword in a discussion,
* comment, or activity
*/
class KeywordUsed implements YagaRule{
public function Award($Sender, $User, $Criteria) {
// insert logic here
return FALSE;
}
public function Form($Form) {
$String = $Form->Label('Keyword', 'KeywordUsed');
$String .= $Form->Textbox('Keyword');
return $String;
}
public function Validate($Criteria, $Form) {
$Validation = new Gdn_Validation();
$Validation->ApplyRules(
array(
'Name' => 'Keyword', 'Validation' => 'Required'
));
$Validation->Validate($Criteria);
$Form->SetValidationResults($Validation->Results());
}
public function Hooks() {
return array('CommentModel_BeforeNotification', 'DiscussionModel_BeforeNotification');
}
public function Description() {
$Description = T('Yaga.Rules.KeywordUsed.Desc');
return Wrap($Description, 'div', array('class' => 'InfoMessage'));
}
public function Name() {
return T('Yaga.Rules.KeywordUsed');
}
}
I got around it by renaming class.keyword.php to class.keywordused.php, and got it setup, but now, when I say "Hi" in a comment / discussion, it doesn't award it to me automatically
Comments
You want a rule that parses the message for a word? Maybe a keyword rule?
You should write it up as an exercise. I will get you started.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Let me introduce myself: Hi, I'm a cheater.
I will try that @hgtonight
@hgtonight After saving the code as class.keyword.php and saved it in /applications/yaga/library/rules, it gives me a "Rule Not Found" error
I got around it by renaming class.keyword.php to class.keywordused.php, and got it setup, but now, when I say "Hi" in a comment / discussion, it doesn't award it to me automatically
You will have to write the actual parsing code yourself as an exercise. Line 10 of your rule file should read
// insert logic here
.Have at it.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@hgtonight Just one thing: What does $SQL do? How does it connect to the database if it does? I need the parsing code to pull data from the database.
EDIT: Nvm about the above question. What table does Vanilla store comments?
$SQL is generally a Gdn_SQLDriver object.
Read through
/library/database/class.sqldriver.php
to learn what it can do.Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Maybe this?
public function Award($Sender, $User, $Criteria) {
$connect = mysqli_connect("localhost","*******","******","*******")
$result = mysqli_query($connect,"SELECT * FROM GDN_Comment")
if $result includes "Hi" then
return TRUE;
else
return FALSE
Maybe not complete, but is this ok for the base, before the award assigning code adds on?
You don't need to deal with connecting to the db at all. The comment or discussion is already loaded in the calling object ($Sender).
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I need to change my password... Can you edit that to delete the password and personal info please @hgtonight?
What about this?
public function Award($Sender, $User, $Criteria) {
if $Sender include "Hi" then
return TRUE;
@hgtonight Did you add the code to automatically give out badges yet?
EDIT: Along with the parsing code I did