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.

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

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

Thanks

There was an error rendering this rich post.

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.

«1

Answers

  • ToddTodd Chief Product Officer Vanilla Staff
    Please stop mentioning us on all of your questions. I don't understand your question.
  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    m sorry Todd. its only you guys who develop the framework know about it inside out. so thats y i used to tag it on ur name. i wont do that again.
    cheers

    There was an error rendering this rich post.

  • camocamo New
    edited October 2011
    sahotataran quite simply wants to hide discussions from a given single category, so they don't appear on the 'all discussions' page.

    Not sure how that could be done, but I'm assuming when the query is made to mysql, to display all discussions, it must be specified to omit the specific category, with some kind of 'if' clause.
  • UnderDogUnderDog MVP
    edited October 2011
    I've edited camo's post a bit.
    If the mysql query needs to be altered to omit a specific category, it's not that easy to resolve. I'll give it some thought, sahotataran.

    There was an error rendering this rich post.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    actually the thing is i am using NillaBlog to display my one category as Blog. so i want in all discussions, that Category is removed from there and rest all posts from categories are displayed in all discussions.

    Thanks guys

    There was an error rendering this rich post.

  • Oh man... so abstract...
    sahotataran can you give me 2 examples please? Let's do an example with PHP scripts.
    Your category on NillaBlog is "Forum Scripts". The forums are "Vanilla", "PhpBB" and "SMF". Tell what you need in which situation :-)

    There was an error rendering this rich post.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    so let me explain my situation.
    say -> i have 4 categories named NEWS, ARTICLES, FEATURED, OTHER
    using NillaBlog i have Displayed ARTICLES category page as BLOG and its url categories/articles - i am using as home page.

    u know how on discussions page /DISCUSSIONS - all the discussions are listed - which are from NEWS, ARTICLES, FEATURED, OTHER

    but i dont want to display ARTICLES in this list of DISCUSSIONS

    so i wanted to know if that is possible

    There was an error rendering this rich post.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    Oh man... so abstract...
    and for me underdog experimenting is never an abstract :D

    There was an error rendering this rich post.

  • but i dont want to display ARTICLES in this list of DISCUSSIONS
    Select * from Discussions where categoryId not IN (Select * from Categories where CategoryName = "Articles")

    Experiment with this SQL a bit, it's not the most perfect SQL I've written.
    You can hardcode the category ID of the Articles category. You can replace the "NOT IN" with something else.

    There was an error rendering this rich post.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    sorry underdog but where do i put this in? shall i use something like DiscussionsController_Render_Before - in my template as a hook ??????

    There was an error rendering this rich post.

  • 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.

  • x00x00 MVP
    edited October 2011
    Hmm the above won't work perfectly with the pager, for that you will have to dance around using the DiscussionModel

    get the category id before the discussions query is built. Then add the where clause to the query builder (no join). Then this will return the results you want.

    grep is your friend.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    thanks @x00 i will try these and see how far i can go

    There was an error rendering this rich post.

  • x00x00 MVP
    edited October 2011
    To be honest best hook the

    DiscussionController_Index_Before

    store the category Id in a class variable then with

    DiscussionModel_BeforeGet_Handler

    add the where

    $Sender->SQL->Where('d.CategoryID <>', $this->BlogCategoryID);

    This would produce better results. This all stimulates on if(strtolower($Sender->RequestMethod) != 'index') return;

    if (!isset($this->BlogCategoryID)) return;

    respectively

    grep is your friend.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    edited November 2011
    hi @x00

    i did something like this on my home page
    <?php $DiscussModel = new DiscussionModel();
    $whereas = array('CategoryID <>' => $catid);
    $discussions = $DiscussModel -> Get(0, 10, $whereas)->Result();
    $discussionController = new DiscussionsController();
    $discussionController->DiscussionData = $discussions;
    $discussionController->View = 'discussions';
    $discussionController->Render();
    //$DiscussModel->ToString();
    ?>
    but its not loading DISCUSSIONS VIEW and gives error as
    Fatal Error in DiscussionsController.FetchViewLocation();
    Could not find a 'discussions' view for the 'discussions' controller in the '' application.
    The error occurred on or near: C:\xampp\htdocs\vanilla2\library\core\class.controller.php

    776: $this->_ViewLocations[$LocationName] = $ViewPath;

    777: }

    778: // echo '['.$LocationName.'] RETURNS ['.$ViewPath.']';

    779: if ($ViewPath === FALSE && $ThrowError)

    780: trigger_error(ErrorMessage("Could not find a '$View' view for the '$ControllerName' controller in the '$ApplicationFolder' application.", $this->ClassName, 'FetchViewLocation'), E_USER_ERROR);

    781:

    782: return $ViewPath;

    783: }

    784:

    can you please help me with it????
    Thanks in advance

    There was an error rendering this rich post.

  • What are you trying to do? Embed?

    grep is your friend.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    no i have this in my default.master.php which trigers only if its home page.
    i check if the URL is my home page and if its home page then
    line wise explanation
    1.new discussion model
    2. whereas option which we pass to Get method in DiscussionModel (i am displaying all discussions except a particular category categoryID)
    3. get result from Get function in DiscussionModel which returns me recently posted 10 discussions which are not from particular CATEGORY and save its result in variable $discussions
    4. create a new controller for discussionsController
    5. i pass its DiscussionsData as result from my above DiscussionModel resultset
    6. then i try to load view 'discussions'
    7. render it - but the above error

    There was an error rendering this rich post.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    fixed it guys. was just lost and got to right track after lunch :)
    Thanks x00

    There was an error rendering this rich post.

  • @sahotataran
    Please consider contributing this as a feature to the NillaBlog project. I suspect others may want this functionality as well.

    If you don't know how to pull the code and submit a patch, try to come up with a working example plugin for your forum where you have it working and submit the working code as part of a ticket. I'll see if I can work it into the settings of the project so that others may benefit.

    There was an error rendering this rich post.

Sign In or Register to comment.