Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

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

sahotataransahotataran Rare Visitor ✭✭
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 Don't PM about development, I'm not currently taking on clients MVP
    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);
    }

    Don't PM about development, I'm not currently taking on clients.

    grep is your friend.

  • x00x00 Don't PM about development, I'm not currently taking on clients 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);
    }

    Don't PM about development, I'm not currently taking on clients.

    grep is your friend.

Answers

Sign In or Register to comment.