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
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


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

  • 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

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

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

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

  • 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 :-)
  • 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

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

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

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

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

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

  • 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

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

  • 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

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

  • 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

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

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

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

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

    My addons: NillaBlog | Vanoogle

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    sure @ddumont - i will be submitting the working example and also the demo URL soon - as soon as i finish out with the layout and stuff - CSS. i will send you the whole code i had used and then you can consider it putting into your working example of NillaBlog.

    Thanks

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

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    @ddumont i had a quick question - is there anyway i can set the number of discussions to be displayed on the BLOG category page?
    e.g generally we set the number of discussions we can show on category page through Dashboard->Forum->Advanced
    but suppose if it choose 50 there and if we try to display 50 posts in NillaBlog Category then the page is going to get very very long.
    so is there anyway we can restrict the BLOG category page discussions count to only 10 or 15?????
    Thanks

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

  • NillaBlog has an option in the plugin config that lets you say how many posts you want to display instead of the global number, yes.

    My addons: NillaBlog | Vanoogle

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    Thanks ddumont i just downloaded the latest version. thanks again.
    i have a hack to display images if a user attaches an image with the post. shall i pm to u?

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

  • This is not very MVC, You are using a view for your logic. Views should be kept clean and should only concern display issues (and some formatting issues too). There are some forgiveable exceptions but this is way overboard.

    Likely there is better way to do this.

    grep is your friend.

  • x00x00 MVP
    edited November 2011
    DisscussionModel_BeforeGet_Handler

    You should be able to set

    $Sender->SQL->Limit($Limit, $Offset); over-riding the default.

    also wheres

    You can use if(strtolower($Sender->RequestMethod) != 'index') return; before that.

    Have a look a class.discussionmodel.php Get you see the BeforeGet event, you even have wheres event args

    grep is your friend.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭
    @ddumont
    i restricted my home page to display only 10 latest posts which are not from my BLOG category using the hook in themes as below:
     public function DiscussionsController_Render_Before($Sender) {
    $this->_AddButton($Sender, 'NewDiscussionModule');
    $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; }
    if ($pageURL == 'MY HOME PAGE URL') {
    $Offset = 0;
    $Limit = 10;
    $Whereas = array("CategoryID <>" => 'MY BLOG CATEGORY ID' );
    $DiscussionModel = new DiscussionModel();
    $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, $Whereas);
    $CountDiscussions = count($DiscussionModel->Get($Offset, $Limit, $Whereas));
    $Sender->Data('Discussions', $Sender->DiscussionData);
    $Sender->SetData('CountDiscussions', $CountDiscussions);
    /* ======= this was the code given by x00 =========
    list($Page, $Limit) = OffsetLimit(10, 0);
    $Discussions = $Sender->Data('Discussions');
    $DiscussionsFiltered =array();
    foreach($Discussions As $Discussion ){
    if($Discussion->Category!=='articles'){
    $DiscussionsFiltered[]=$Discussion;
    }
    }
    $DiscussionsLeft = count($DiscussionsFiltered);
    //$DiscussionsFiltered = new Gdn_DataSet($DiscussionsFiltered);
    $Sender->DiscussionData =$DiscussionsFiltered;
    $Sender->Data('Discussions',$DiscussionsFiltered);
    ===============================*/
    }

    }

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

Sign In or Register to comment.