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.

2.1 Show recent discussions for one category using class.discussionsmodule.php?

I am using 2.1a35. Is there an easy way to modify the code in the file, class.discussionsmodule.php to show only a certain categories' recent discussions instead of all the categories.

class DiscussionsModule extends Gdn_Module {
public $Limit = 4;
public $Prefix = 'Discussion';

public function __construct() {
parent::__construct();
$this->_ApplicationFolder = 'vanilla';
}

public function GetData($Limit = FALSE) {
if (!$Limit)
$Limit = $this->Limit;

$DiscussionModel = new DiscussionModel();
$this->SetData('Discussions', $DiscussionModel->Get(0, $Limit, array('Announce' => 'all')));
}

public function AssetTarget() {
return 'Panel';
}

public function ToString() {
if (!$this->Data('Discussions')) {
$this->GetData();
}

require_once Gdn::Controller()->FetchViewLocation('helper_functions', 'Discussions', 'Vanilla');

return parent::ToString();
}
}

Comments

  • KasperKasper Vanilla Staff

    You don't have to edit any core files to do this. Simply use the DiscussionModel class to get the data you'd like:

    $DiscussionModel = new DiscussionModel();
    $DiscussionData = $DiscussionModel->GetWhere(array('CategoryID' => 100), 0, 20);
    

    The above example will get you the first 20 discussions from the category with the ID of 100.

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • @kasperisager Thank you very much, that does exactly what i need :D

  • KasperKasper Vanilla Staff
    edited February 2013

    Cool, glad I could be of help!

    P.S.: If you need help displaying the data, just say the word.

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

Sign In or Register to comment.