We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48777
    • 11 Posts
    Do you want to excledue data in the query already?

    Then you could handle it with the where method:

    $query->where(array('width:!=' => 15));


    More information in this documentation:
    http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where
      • 46220
      • 66 Posts
      Ok, I have tried a couple of things, but as said I am not a coder (not even close tongue). I want to exclude private messages at all times to show up, so I can only assume I want to place the code in the query.

          //Build main sql querys
      if($show_threads == '1'){
          $c = $modx->newQuery('disThread');
      }else{
          $c = $modx->newQuery('disPost');
      	$c->where(array('messages:!=' => '0'
      	));
      }


      But then I get:
      [2014-09-17 16:36:23] (ERROR @ /index.php) Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'disPost.messages' in 'where clause' )

      I'm wasn't expecting it to work right away, but any pointers where I am going wrong?
        • 46886
        • 1,154 Posts
        I think dommes89 had a better idea in this thread:

        http://forums.modx.com/thread/93077/embed-a-discuss-board-on-home-page#dis-post-508690

        Here he was just showing us one way to exclude some elements, but I don't think that this particular argument is suitable for our purposes.

        You have to use his example first, which changes some things fundamentally in the tool, then follow these instructions:

        That means you just want to get some Thread information of a post?!

        Then look at line 145 in my example.
        Here I get the thread of my post and then you can ask it for his private flag ...

        $thread = $modx->getObject('disThread', array('id' => $res->get('thread')));
        $thread_is_private = $thread->get('private');



        Or am I wrong? tongue

        I don't know if this will work directly, but its the right kind of command, grabbing the private flags of the threads of the posts...
          • 38314
          • 45 Posts
          Hi,

          I've just spent long hours to get lasts posts/threads in a snippet to get them in other place than Discuss. Don't know why it was such a marathon, but if it can help, I share here both snippet. They're light, and I assume they embed some html (dirty formating), so my next step is to use template chunck. Thanks to those who post in this thread, I get really inspired as you can see in the code :

          [[!Discuss.LastPosts? &limit=`10`]]

          <?php
          /*
          *
          * Lasts posts (default, 3)
          *
          *
          */
          
          if (!(isset($limit))){
              $limit = 3;
          }
          
          $discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
          if (!($discuss instanceof Discuss)) return true;
              
          $query = $modx->newQuery('disPost');
          $query->limit($limit);
          $query->sortby('createdon', 'DESC');
              
          $resources = $modx->getCollection('disPost', $query);
          
          
          //Start of output array
              $output = '';
          
          if ($resources) {
              foreach ($resources as $res) {
                   $extrait = 'title="'.mb_substr($res->get('message'), 0, $letters_limit).'" ';
                   $output .= '<a ' . $extrait . ' href="forums/thread/'.$res->get('thread').'/'.strtolower($res->get('title')).'#dis-post-'.$res->get('id').'">'.$res->get('title').'</a>';
                  $a = $modx->getObject('disUser', array('id' => $res->get('author')));
                  $output .= ' par '.$a->get('username');
                  $date = $res->get('createdon');
                  $date = strftime(', %A %d %B %Y à %H:%M',strtotime($date)); //french date, comment to EN
                  $output .= $date . ' <br />';
                  
                  $output .= '<hr />';
                  
                  //print_r($res->toArray());  //debug
              }
          } else {
              $output = 'No data !';
          }
          
          
          
          return $output;


          And
          [[!Discuss.LastThreads? &limit=`10`]]

          /*
          *
          * Last threads (default, 3)
          *
          */
          
          if (!(isset($limit))){
              $limit = 3;
          }
          
          $discuss = $modx->getService('discuss','Discuss',$modx->getOption('discuss.core_path',null,$modx->getOption('core_path').'components/discuss/').'model/discuss/');
          if (!($discuss instanceof Discuss)) return true;
              
          $query = $modx->newQuery('disThread');
          $query->limit($limit);
          $query->sortby('post_last_on', 'DESC');
              
          $resources = $modx->getCollection('disThread', $query);
          
          
          //Start of output array
              $output = '';
          
          if ($resources) {
              foreach ($resources as $res) {
                  
                      $a = $modx->getObject('disUser', array('id' => $res->get('author_last')));
                      $username = $a->get('username');
                      
                  $output .= '<a href="forums/thread/'.$res->get('id').'/'.strtolower($res->get('title')).'">'.$res->get('title').'</a>';
                  
                  $output .= ' par : ' . $username;
                  $date = $res->get('post_last_on');
                  $date = strftime(', %A %d %B %Y à %H:%M',strtotime($date)); //french date, comment to avoid
                  $output .= $date . ' <br />';
                  
                  //$output .= $res->get('post_last_on');
                  $output .= '<hr />';
                  
                  //print_r($res->toArray()); //debug
              }
          } else {
              $output = 'no data';
          }
          
          return $output;
          


          Hope it can help...
            • 46886
            • 1,154 Posts
            Wow thanks for this! Glad you got it working!

            To move the html out of the snippet isn't too hard I believe. Basically you get collection and get chunk and the proper placeholders get populated.
              • 46886
              • 1,154 Posts
              After implementing the new and improved tool (see below), I found the biggest weakness is that the limit is in the tool and *maybe* can't be changed in the snippet call. This is a pain as each time I must make a copy of the tool. Same for specifying the forums to search, that should be in the snippet call.

              So those are two important aspects that would make the tool better, along with pulling the html out. This newer tool begins that html process, he made a lot of improvements I think.

              Recently I was thinking I would like to be able to segregate hot posts into all-time popular and popular "recently", and I thought that it couldn't be done, but then something I saw today made me wonder if it could. But I already forgot what that was haha. I will see it again. But that would just be most views over a week or something.

              I may also consider asking Rimo to do a tool for users, like Vanilla, which has newest users data in one of their (few) views. Actually, no I don't need that at all.

              So squarou, I see you really improved the tool you made by adding in the isset statement at the beginning, quite brilliant that. Set the default to 3 and let the limit term of the snippet call handle the rest ;-)

              I still don't know why the tool doesn't work out of the box for everyone, this guy writes some good code, he jumped in and it worked perfectly just like that.
                • 46886
                • 1,154 Posts
                Ok, here is the new tool, adding in the ability to search specific forums, moving some stuff around.

                Notes: just make sure you use only 1 param on '1' value from multi configs, both works with general boards id's and fetch sub threads or subposts into the subthreads. Dynamic functionality is avoided when multy is used (it's kind of static compared to dynamic function)

                <?php
                    //POST SETTINGS BELOW
                	$show_posts = '1'; //Set to 1 if you want to show posts
                	$posts_last_added = '1'; //Set to 1 if you want to show last added posts
                	$posts_dynamic = '0'; //Set to 1 if you want to show dynamicly posts from current board
                	////////////////////////////////////////////////
                	$multi_posts = '1'; //Set to 1 if you want to show posts from exact thread
                	$posts_ids = Array(107,106); //Set this for threads from which you want to show posts
                	
                	
                	
                	//THREADS SETTINGS BELOW
                	$multi_boards = '1'; //Set to 1 if you want to show threads from exact boards
                	$boards_ids = Array(107,106); //Set this for boards from which you want to show threads
                	//////////////////////////////////////////////
                	$show_threads = '0'; //Set to 1 if you want to show threads
                	//SELECT ONLY 1 OF 3 OPTIONS BELOW
                	$threads_last_posted = '0'; //Set to 1 if you want to show lastly active threads
                	$threads_most_viewed = '1'; //Set to 1 if you want to show most viewed threads
                	$threads_most_reply = '0'; //Set to 1 if you want to show threads with most reply's
                
                	$order = 'DESC';  //Set ASC for A->Z or DESC for Z->A
                	$limit = '10'; //Set limit count for results outputed which to be showed
                	$letters_limit = '30'; //Set letters limit for description of posts messages
                	$user_real_name = '1'; //Set to 1 if you want to show First Last names, set to 0 for username
                	
                	//DONT EDIT BELOW THIS LINE
                	//COPYRIGHT RIMOTEVST KANEV
                	//DONT EDIT BELOW THIS LINE
                	
                	//Build main sql querys
                if($show_threads == '1'){
                	$c = $modx->newQuery('disThread');
                }else{
                	$c = $modx->newQuery('disPost');
                }
                	//Set filters
                	if(($show_posts == '1') AND ($posts_last_added == '1')){
                	$c->sortby('createdon',$order);
                	}else{}
                	if(($show_threads == '1') AND ($threads_last_posted == '1')){
                	$c->sortby('post_last_on',$order);
                	}else{}
                	if(($show_threads == '1') AND ($threads_most_viewed == '1')){
                	$c->sortby('views',$order);
                	}else{}
                	if(($show_threads == '1') AND ($threads_most_reply == '1')){
                	$c->sortby('replies',$order);
                	}else{}
                
                if($show_threads == '1'){
                    if($multi_boards == '1'){
                    		foreach($boards_ids as $bid){
                        		$c->where(array(
                        		    'OR:board:=' => $bid,
                    	            'AND:private:=' => '0',
                        		));    
                    		}
                    }else{
                    	//Exclude private threads
                    	$c->where(array(
                    	'private' => '0',
                    	));
                    }
                }else{
                    
                    if($multi_posts == '1'){
                    	foreach($posts_ids as $pid){
                        	$c->where(array(
                        	    'OR:board:=' => $pid,
                        	));    
                    	}
                    }else{
                	//If we are in main board page
                	if((strip_tags($_GET['board']) != '') AND ($posts_dynamic == '1')){
                	$c->where(array(
                	'board' => strip_tags($_GET['board']),
                	));
                	}else{}
                	//If we are in thread page
                	if((strip_tags($_GET['thread']) != '') AND ($posts_dynamic == '1')){
                	$t = $modx->newQuery('disThread');
                	$t->where(array(
                	'id' => strip_tags($_GET['thread']),
                	));
                	$t->limit(1,0);
                	$boards = $modx->getCollection('disThread',$t);
                	foreach ($boards as $board) {
                		$c->where(array(
                		'board' => $board->get('board'),
                		));
                	}
                	}else{}
                    }
                }
                	//Set limits
                	$c->limit($limit,0);
                
                	//Get the Collections fetchResults
                if($show_threads == '1'){
                	$resources = $modx->getCollection('disThread',$c);
                }else{
                	$resources = $modx->getCollection('disPost',$c);
                }
                	//Start of output array
                	$output = '';
                	
                	//Looping to fill the output
                foreach ($resources as $res) {
                	if($show_threads == '1'){
                		$output .= '<li class="rthread"><a href="forums/thread/'.$res->get('id').'/'.strtolower($res->get('title')).'">'.$res->get('title').'</a>';
                		$a = $modx->getObject('disUser', array('id' => $res->get('author_first')));
                		$output .= ' by <a class="rauthor" href="forums/u/'.$a->get('username').'/">';
                	if($user_real_name == '1'){
                		$output .= $a->get('name_first').' '.$a->get('name_last').'</a>';
                	}else{
                		$output .= $a->get('username').'</a>';
                	}
                		$output .= '</li>';
                	}else{
                		$output .= '<li class="rpost"><a href="forums/thread/'.$res->get('thread').'/'.strtolower($res->get('title')).'#dis-post-'.$res->get('id').'">'.$res->get('title').'</a>';
                		$output .= '<p>'.mb_substr($res->get('message'), 0, $letters_limit).'</p>';
                		$a = $modx->getObject('disUser', array('id' => $res->get('author')));
                		$output .= ' by <a class="rauthor" href="forums/u/'.$a->get('username').'/">';
                	if($user_real_name == '1'){
                		$output .= $a->get('name_first').' '.$a->get('name_last').'</a>';
                	}else{
                		$output .= $a->get('username').'</a>';
                	}
                		$output .= '</li>';
                	}
                }
                	//Print the output
                return $output;