Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Linking a custom PostController Form to ->object->insert $sql
SonicNebula
New
Normally I would just try to figure out this stuff on my own. But I am running out of time and any help would be greatly appreciated.
I'm trying to write a plugin. The Effect: a user rates their own post before submitting the Post Form. The user ratings show next to the DiscussionOptions. I've worked out all the css, HTML, Js( maybe). What I am having trouble with is the methods required to store a value('0-4') in a column('rating') of the table gdn_discussion taken from the xhtml radio selector structure... or if that is even the correct solution.
Here is the code I have so far: (oh boy...)
default.php
<?php if (!defined('APPLICATION')) exit(); $PluginInfo['PersonalRating'] = array( 'Name' => 'Personal Rating', 'Description' => "Add a special form, which allows user to rate thier own 'Post'", 'Version' => '0.1', 'RequiredApplications' => array('Vanilla' => '>=2.0.18'), 'Author' => 'Drew Billings', 'AuthorEmail' => 'andrewandroid@gmail.com', 'AuthorUrl' => 'http://www.vanillaforums.org/profile/SonicNebula' ); class PersonalRating extends Gdn_Plugin { public function setup(){ return TRUE; } public function Base_Render_Before($Sender) { $Sender->AddCssFile($this->GetResource('design/jquery.rating.css', FALSE, FALSE)); $Sender->AddJsFile($this->GetResource('js/jquery.rating.js', FALSE, FALSE)); $Sender->AddJsFile($this->GetResource('js/OnLoad.js', FALSE, FALSE)); } public function DiscussionsController_DiscussionOptions_Handler($Sender){ echo '<div class="PRateReadOnly">'; echo '<input class="rate2 PRate0" type="radio" class="star" />'; echo '<input class="rate2 PRate1" type="radio" class="star" />'; echo '<input class="rate2 PRate2" type="radio" class="star" />'; echo '<input class="rate2 PRate3" type="radio" class="star" />'; echo '<input class="rate2 PRate4" type="radio" class="star" />'; echo '</div>'; } public function PostController_BeforeFormButtons_Handler($Sender){ echo '<h3>Rate Your Customer:</h3>'; echo '<div class="PRate">'; echo '<input class="rate2 PRate0" type="radio" class="star" checked=""/>'; echo '<input class="rate2 PRate1" type="radio" class="star" checked=""/>'; echo '<input class="rate2 PRate2" type="radio" class="star" checked=""/>'; echo '<input class="rate2 PRate3" type="radio" class="star" checked=""/>'; echo '<input class="rate2 PRate4" type="radio" class="star" checked="checked"/>'; echo '</div>'; } public function PostController_BeforeFormSave_Handler($Sender){ GetID(); Set(); } /*public function Setup() { $this->Structure(); } public function Structure() { Gdn::Structure() ->Table('discussion') ->Column('Rating', 'varchar(255)', NULL) SaveToConfig('Plugins.PersonalRating.Version',$this->PluginInfo['Version']); } */ public function OnDisable(){ } }
class.PersonalRatingModel.php
<?php if (!defined('APPLICATION')) exit(); class LinkRatingsModel extends VanillaModel{ public function __construct() { parent::__construct('PersonlRating'); } public function GetID($DiscussionID){ $UserID = Gdn::Session()->UserID; return $this->SQL ->Select('Rating.*') ->From('Discussion Rating ') ->Where( array( 'Discussion.DiscussionID'=>$DiscussionID, ) ) ->Get() ->FirstRow() ->Rating; } public function Set($DiscussionID, $Rating){ $ExitingRating = $this->GetID($DiscussionID); if($ExitingRating) return FALSE; $UserID = Gdn::Session()->UserID; $Date=Gdn_Format::ToDateTime(); $this->SQL ->Insert('Discussion', array( 'Rating'=>$Rating, ) ->Where array( 'Discussion.DiscussionID'=>$DiscussionID, ) ); }
0
Comments
Also, I thought this statement would set up a new column. It doesn't appear that it does. I am almost sure I am way off base with this stuff right now....
if you post other 3 file .css and .js too. Then people can test it too.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Here is the plugin package. Thanks again, and of course the plugin will be posted back to the community.
try adding this to your default.php
also make sure references to Discussions table are Discussions not lowercase discussions.
one step further on your way. I think there may be other issues for you to solve, but you are on your way.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I'm not sure you need the NULL , I think it is TRUE or FALSE, but if it works like you want it works.
->Column('Rating', 'varchar(255)', NULL)
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I suspect following x00's ratemylink more closely as a model will help you immensely.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Is what I have been trying to do. Vanilla and Garden are just so rich and deep. It is hard to wrap my head around so quickly.
SonicNebula said:
Yea, I have the same problem. each time you go back in you hold your breath and see some new thing, then you have to come back to the surface and rest. Then dive back in.
BTW - the above writes the Rating column to the Discussions table.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Thanks for the sound advice. Your analogy perfectly describes my experience thus far. I am taking notes to hopefully and eventually help improve the documentation. I also noticed you have a tutorial plugin! I am working through that now. Thanks a ton for your help man. Some times it just takes either a life preserver and other times just a little nudge into the deep end. Even though I cannot possibly have the whole Vanilla and Gdn system figured out yet I can tell it's well worth the time. It appears highly modularized and well written regarding other good coding strategies.
Also, I am posting this particular project for hire. I need it done by Monday. I figured I would give you and @x00 first dibs if you want it:
80 USD
Needs to be done to specs by Monday Morning PST.
http://testing.gulpu.com has the scratch concept.
You will have to sign up for an account to see it if your interested. There is no spam or anything like that.
I think once I get this done I will be less stressed and more able to be in the beginners mind mode...
Thanks again and please let me know if you are interested.
It sounds right up @x00's alley. At this point in time I am not doing anything for hire and especially a 36 hour deadline - but thanks for the consideration.
I'm sure there are others if @x00 doesn't pick it up for you.
If you decide to drag it out and muddle through it I can try to help on this forum debugging specific stumbling blocks if I know the answer.
You might also look at ignoreuser and ignore plugin as well as replyto plugin and x00's other plugins - all write to database
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Awesome. Yes I will continue to muddle through it until either it is done or someone accepts the job!
also the flagging plugin or split merge plugins might be worth looking at for ideas.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Ok. Table updates upon instalation of plugin with the "Rating" Column. I have added this code to render the list of "stars" in the Post View:
In Default.php
Works pretty good.
Now the XHTML is changed during Parse via javaScript to this:
Notice the inputs are switched to hidden.
If a DIV is "checked" by the user, the a class .star-rating-on is added. Alternatively the hidden input associated with the DIV is given an XHTML property of 'Checked="checked"'
i.e.
I can't figure out how to send the 'value=n' to be stored in the database under Discussion.Rating where discussionID = this.DiscussionID
My latest feeble attempt:
I relaize I also need (In bad sudocode):
Any Ideas, docs, ManPages(lol) you can point me to?
updated package
@SonicNebula -- I know this is a dead thread, but how does the handler know the DiscussionID? is this a global?
public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) {
$DiscussionData = $DiscussionModel->GetWhere(array('DiscussionID' => $DiscussionID));
$Discussion = $DiscussionData->FirstRow('', DATASET_TYPE_ARRAY);
$Discussioin['Rating'] = 3;
$DiscussionModel->Save($Discussion);
}
No, it must be retrieved from the event arguments (it's contained in
$Sender->EventArguments['DiscussionID']
).If the purpose of the code is to add a rating to the values before saving the Discussion, the handler can be rewritten as follows:
That's it. The model will automatically save the value to
Rating
fields.My shop | About Me
thanks @businessdad