Fork me on GitHub
Current Releases are 2.1 stable (major release) and 2.0.18.11 (security patch for 2.0)
We've also rebooted our GitHub repo, docs, and more!

How to Display Discussion from all the Categories except one on Discussions page?

sahotataransahotataran Developer, Bay Area - CA ✭✭✭
edited October 2011 in Questions
Can anybody help with that?
@Todd @Lincoln @Tim @Underdog

Thanks

Theme Charcha for great desktop and mobile experience! - drop me a message :)

Best Answers

  • x00x00 MVP
    edited October 2011 Answer ✓
    Nested sql is rarely a good idea especial in an IN very slow, and often not configured in mySQL, also if you look in the discussion model they are not using an JOIN instead they zip the categories data to the discussion data programmatically after the discussion dat has bee got. This will be for performance reasons.

    SO for this reason, it would be better to simply remove the offending data before it is renderered.

    Something like:
    public function DiscussionsController_Render_Before(&$Sender){
    if (strtolower($Sender->RequestMethod) != 'index') return;
    foreach (CategoryModel::Categories() As $Category) {
    if ($Category['Name'] == 'Blog'){
    $ID = $Category['CategoryID'];
    break;
    }
    }
    if(!$ID) return;
    $Discussions = $Sender->Data('Discussions');

    foreach($Discussions As &$Discussion){
    if($Discussion['CategoryID']==$ID){
    $Discussion = null;
    }
    }
    $Discussions = array_filter($Discussions);
    $Sender->SetData('Discussions',$Discussions);
    }

    grep is your friend.

  • x00x00 MVP
    Answer ✓
    Sorry this is more like it
    public function DiscussionsController_Render_Before(&$Sender){
    if (strtolower($Sender->RequestMethod) != 'index') return;
    $Discussions = $Sender->Data('Discussions');

    $DiscussionsFiltered =array();
    foreach($Discussions As $Discussion ){
    if($Discussion->Category!=='Blog'){
    $DiscussionsFiltered[]=$Discussion;
    }
    }
    $DiscussionsFiltered = new Gdn_DataSet($DiscussionsFiltered);
    $Sender->DiscussionData =$DiscussionsFiltered;
    $Sender->Data('Discussions',$DiscussionsFiltered);
    }

    grep is your friend.

Answers

Sign In or Register to comment.