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.

Where do I put this code?

edited August 2015 in Vanilla 2.0 - 2.8

I would like to show if a topic was resolved or not. Here is the code. I cannot figure out where to put it.
/** * Show Unresolved meta tag. */ public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) { $Resolved = GetValue('Resolved', GetValue('Discussion', $Args)); // if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) { if (!$Resolved) { echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> '; } } /** * Show [RESOLVED] in discussion title when viewing single. */ public function DiscussionController_BeforeDiscussionOptions_Handler($Sender, $Args) { $Discussion = $Sender->Data('Discussion'); // if (CheckPermission('Plugins.Resolved.Manage') && $Discussion->Resolved) { if ($Discussion->Resolved) {

Thanks, have a nice night!

Tagged:

Comments

  • if you are referring to this discussion.

    http://vanillaforums.org/discussion/comment/218808/#Comment_218808

    then make the appropriate changes in

    class.resolved.plugin.php

    search for the function and cut and paste and modify.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Yes thanks. What exactly do i replace? I think something went wrong because I can no longer load my forum.
    I replaced /** * Show Unresolved meta tag. */ public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) { $Resolved = GetValue('Resolved', GetValue('Discussion', $Args)); if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) { echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> ';
    with /** * Show Unresolved meta tag. */ public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) { $Resolved = GetValue('Resolved', GetValue('Discussion', $Args)); // if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) { if (!$Resolved) { echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> '; } } /** * Show [RESOLVED] in discussion title when viewing single. */ public function DiscussionController_BeforeDiscussionOptions_Handler($Sender, $Args) { $Discussion = $Sender->Data('Discussion'); // if (CheckPermission('Plugins.Resolved.Manage') && $Discussion->Resolved) { if ($Discussion->Resolved) {

  • essentially all you need to do is replace

    if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) {

    with

     if (!$Resolved) {
    

    in the two functions.

    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 have changed the code and it still does not show.

    Link: forums.yourtechadvisors.com

  • peregrineperegrine MVP
    edited August 2015

    correction to above regarding

    if you want to see [RESOLVED] in discussion title when viewing the individual discussion.

    change in

    public function DiscussionController_BeforeDiscussionOptions_Handler($Sender, $Args) {

    change

    if (CheckPermission('Plugins.Resolved.Manage') && $Discussion->Resolved) {

    to

    // if (CheckPermission('Plugins.Resolved.Manage') && $Discussion->Resolved) {
                      if ($Discussion->Resolved) {
    

    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 really do thank you for your help. I have changed the code, and it still does not show up.

    What am i doing wrong? It would be nice if this was already done.

  • peregrineperegrine MVP
    edited August 2015

    it is already done. =) . just cut and paste in the correct places. it helps you learn.

    what exactly doesn't show up?

    you just have to explain more expicitly step by step what you want to see with more detail as well as screenshots of what you expect to show where.

    also provide the code changes your made.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited August 2015

    I would like to see a Resolved badge where the unresolved badge is when a topic is resolved. As of now, there is nothing that says Resolved when a topic is Resolved other than you cannot post a reply.

    Here is my code.

    <?php if (!defined('APPLICATION')) exit();
    
    $PluginInfo['Resolved'] = array(
       'Name' => 'Resolved Discussions',
       'Description' => "Adds an option to mark discussions as Resolved with custom permission. Resolved discussions are Closed to new participants, however additional posts by the OP unresolve it. Only users with the custom permission see its Resolved status.",
       'Version' => '1.0',
       'RequiredApplications' => array('Vanilla' => '2.1'),
       'RegisterPermissions' => array('Plugins.Resolved.Manage'),
       'MobileFriendly' => TRUE,
       'Author' => "Matt Lincoln Russell",
       'AuthorEmail' => 'lincolnwebs@gmail.com',
       'AuthorUrl' => 'http://lincolnwebs.com'
    );
    
    class ResolvedPlugin extends Gdn_Plugin {
       /**
        * Add 'Resolved' columns
        */
       public function Setup() {
          Gdn::Structure()
             ->Table('Discussion')
             ->Column('Resolved', 'int', '0')
             ->Column('DateResolved', 'datetime', TRUE)
             ->Column('ResolvedUserID', 'int', TRUE)
             ->Set();
       }
    
       /**
        * Allow staff to Resolve via checkbox under comment form.
        */
       public function Base_AfterBodyField_Handler($Sender, $Args) {
          if (CheckPermission('Plugins.Resolved.Manage'))
             echo '<span class="ResolvedCheckbox">'.
                $Sender->Form->CheckBox('Resolved', T('Resolved'), array('value' => '1')).'</span>';
       }
    
       /**
        * Allow staff to Resolve via discussion options.
        */
       public function Base_DiscussionOptions_Handler($Sender, $Args) {
          $Discussion = $Args['Discussion'];
          $Resolved = GetValue('Resolved', $Discussion);
          $NewResolved = (int)!$Resolved; 
          if (CheckPermission('Plugins.Resolved.Manage')) {
             $Label = T($Resolved ? 'Unresolve' : 'Resolve');
             $Url = "/discussion/resolve?discussionid={$Discussion->DiscussionID}&resolve=$NewResolved";
             // Deal with inconsistencies in how options are passed
             if (isset($Sender->Options)) {
                $Sender->Options .= Wrap(Anchor($Label, $Url, 'ResolveDiscussion Hijack'), 'li');
             }
             else {
                $Args['DiscussionOptions']['ResolveDiscussion'] = array(
                   'Label' => $Label,
                   'Url' => $Url,
                   'Class' => 'ResolveDiscussion Hijack'
                );
             }
          }
       }
    
       /**
        * Show Unresolved meta tag.
        */
       public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) {
          $Resolved = GetValue('Resolved', GetValue('Discussion', $Args));
        // if (CheckPermission('Plugins.Resolved.Manage') && $Discussion->Resolved) {
                          if ($Discussion->Resolved) {         echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> ';
          }
       }
    
       /**
        * Show [RESOLVED] in discussion title when viewing single.
        */
       public function DiscussionController_BeforeDiscussionOptions_Handler($Sender, $Args) {
          $Discussion = $Sender->Data('Discussion');
    if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) {         SetValue('Name', $Discussion, $NewName);
             $Sender->SetData('Discussion', $Discussion);
          }
       }
    
       /**
        * Handle discussion option menu Resolve action.
        */
       public function DiscussionController_Resolve_Create($Sender, $Args) {
          $Sender->Permission('Plugins.Resolved.Manage');  
          $DiscussionID = $Sender->Request->Get('discussionid');
          $Resolve = $Sender->Request->Get('resolve');
    
          // Make sure we are posting back.
          if (!$Sender->Request->IsPostBack())
             throw PermissionException('Javascript');
    
          $Discussion = $Sender->DiscussionModel->GetID($DiscussionID);
    
          if (!$Discussion)
             throw NotFoundException('Discussion');
    
          // Resolve the discussion.
          $Sender->DiscussionModel->SetField($DiscussionID, 'Resolved', $Resolve);
          $Discussion->Resolved = $Resolve;
    
          $Sender->SendOptions($Discussion);
    
          if (!$Resolve) {
             require_once $Sender->FetchViewLocation('helper_functions', 'Discussions');
             $Sender->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Meta-Discussion", 
                '<span class="Tag Tag-Unresolved" title="Unresolved">'.T('Unresolved').'</span>', 'Prepend');
             $Sender->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID", 'Unresolved', 'AddClass');
          } else {
             $Sender->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Tag-Unresolved", NULL, 'Remove');
             $Sender->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID", 'Unresolved', 'RemoveClass');
          }
    
          $Sender->JsonTarget("#Discussion_$DiscussionID", NULL, 'Highlight');
          $Sender->JsonTarget(".Discussion #Item_0", NULL, 'Highlight');
    
          $Sender->Render('Blank', 'Utility', 'Dashboard');
       }
    
       /**
        * Handle comment form Resolved checkbox & new user comments.
        */
       public function CommentModel_AfterSaveComment_Handler($Sender, $Args) {
          $Resolved = GetValueR('FormPostValues.Resolved', $Args);
          if (!CheckPermission('Plugins.Resolved.Manage')) {
             // Unset Resolved flag
             $DiscussionModel = new DiscussionModel();
             $DiscussionID = GetValue('DiscussionID', $Args['FormPostValues']);
             $DiscussionModel->SetField($DiscussionID, 'Resolved', 0);
          }
          else if ($Resolved) {
             // Set Resolved flag
             $DiscussionModel = new DiscussionModel();
             $DiscussionID = GetValue('DiscussionID', $Args['FormPostValues']);
             $DiscussionModel->SetField($DiscussionID, 'Resolved', 1);
          }
       }
    
       /**
        * Disallow comments in Resolved discussions by new participants.
        * 
        * @param DiscussionController $Sender
        */
       public function DiscussionController_BeforeDiscussionRender_Handler($Sender, $Args) {
          $Discussion = $Sender->Data('Discussion');
          $Resolved = GetValue('Resolved', $Discussion);
          $IsStarter = (GetValue('InsertUserID', $Discussion) == Gdn::Session()->UserID);
          if (!CheckPermission('Plugins.Resolved.Manage') && $Resolved && !$IsStarter) {
             // Pretend we're closed 
             SetValue('Closed', $Discussion, 1);  
             $Sender->SetData('Discussion', $Discussion);
          }
       }
    
       /**
        * Add 'Unresolved' discussions filter to menu.
        */
       public function Base_AfterDiscussionFilters_Handler($Sender) {
          if (CheckPermission('Plugins.Resolved.Manage')) {
             $Unresolved .= T('Unresolved') . FilterCountString(self::CountUnresolved());
             echo '<li class="Unresolved">'.Anchor(Sprite('SpUnresolved').' '.$Unresolved, '/discussions/unresolved').'</li>';
          }
       }
    
       /**
        * Count the number of unresolved discussions.
        *
        * @return int
        */
       public static function CountUnresolved() {
          $NumUnresolved = Gdn::SQL()
             ->Select('count(DISTINCT d.DiscussionID)', '', 'NumUnresolved')
             ->From('Discussion d')
             ->Where('d.Resolved', 0)
             ->Get()
             ->FirstRow()
             ->NumUnresolved;
    
          return $NumUnresolved;
       }
    
       /**
        * Discussions filter: Unresolved.
        */
       public function DiscussionsController_Unresolved_Create($Sender, $Args) {
          $Sender->Permission('Plugins.Resolved.Manage');
          $Page = ArrayValue(0, $Args, 0);
    
          // Determine offset from $Page
          list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
    
          // Validate $Page
          if (!is_numeric($Page) || $Page < 0)
             $Page = 0;
    
          $DiscussionModel = new DiscussionModel();
          $Wheres = array('d.Resolved' => '0');
    
          $Sender->DiscussionData = $DiscussionModel->Get($Page, $Limit, $Wheres);
          $Sender->SetData('Discussions', $Sender->DiscussionData);
          $CountDiscussions = $DiscussionModel->GetCount($Wheres);
          $Sender->SetData('CountDiscussions', $CountDiscussions);
          $Sender->Category = FALSE;
    
          $Sender->SetJson('Loading', $Page . ' to ' . $Limit);
    
          // Build a pager
          $PagerFactory = new Gdn_PagerFactory();
          $Sender->EventArguments['PagerType'] = 'Pager';
          $Sender->FireEvent('BeforeBuildBookmarkedPager');
          $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
          $Sender->Pager->ClientID = 'Pager';
          $Sender->Pager->Configure(
             $Page,
             $Limit,
             $CountDiscussions,
             'discussions/unresolved/%1$s'
          );
    
          if (!$Sender->Data('_PagerUrl'))
             $Sender->SetData('_PagerUrl', 'discussions/unresolved/{Page}');
          $Sender->SetData('_Page', $Page);
          $Sender->SetData('_Limit', $Limit);
          $Sender->FireEvent('AfterBuildBookmarkedPager');
    
          // Deliver JSON data if necessary
          if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
             $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
             $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
             $Sender->View = 'discussions';
          }
    
          // Add modules
          $Sender->AddModule('DiscussionFilterModule');
          $Sender->AddModule('NewDiscussionModule');
          $Sender->AddModule('CategoriesModule');
    
          // Render default view
          $Sender->SetData('Title', T('Unresolved'));
          $Sender->SetData('Breadcrumbs', array(array('Name' => T('Unresolved'), 'Url' => '/discussions/unresolved')));
          $Sender->Render('index');
       }
    }
    

    Link: forums.yourtechadvisors.com`

  • peregrineperegrine MVP
    edited August 2015

    I would like to see a Resolved badge where the unresolved badge is when a topic is resolved.

    Your wish is my command.

    ok. change

       /**
        * Show Unresolved meta tag.
        */
       public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) {
          $Resolved = GetValue('Resolved', GetValue('Discussion', $Args));
       //  if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) {
         if (!$Resolved) {
             echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> ';
          }
       }
    

    to

       /**
        * Show Unresolved and Resolved meta tag.
        */
       public function Base_BeforeDiscussionMeta_Handler($Sender, $Args) {
          $Resolved = GetValue('Resolved', GetValue('Discussion', $Args));
       //  if (CheckPermission('Plugins.Resolved.Manage') && !$Resolved) {
         if (!$Resolved) {
             echo ' <span class="Tag Tag-Unresolved">'.T('Unresolved').'</span> ';
          }  else {
             echo ' <span class="Tag Tag-Resolved">'.T('Resolved').'</span> ';
       }
    
       }
    

    sometimes links are good. sometimes images are better with circles around what you want or expect to see. thats why I asked for image.

    I rarely click on web page links unless trying to solve a js or css problem.

    please click here

    or press 9 to continue.

    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 help. It is now showing a resolved badge.

    (Topic Closed)

Sign In or Register to comment.