This question has been answered by gormytorysh. See the first response.
<?php $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; $c = $modx->newQuery('disPost'); $c->where(array('private' => 0)); $c->limit(10); $c->orderby('createdon', 'DESC'); $posts = $modx->getCollection('disPost', $c); foreach ($posts as $post) { $temp = $post->toArray(); $temp['url'] = $post->getUrl(); // call chunks or what you want $out[] = $modx->getChunk('rowTpl', $temp); } return implode("\n", $out);
<?php $weghalen = array(",", "/", "?", "<", ">", ";", ":", "[", "]", "{", "}", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "="); $vervangen = array(" ", "."); $c = $modx->newQuery('modUser'); $c->leftJoin('modUserProfile','Profile'); $c->sortby('id','ASC'); // add column names that u want to show $c->select(array( 'modUser.*', 'Profile.fullname', 'Profile.email', )); $users = $modx->getCollection("modUser",$c); $naam[0] = 'Anoniem'; foreach($users as $user){ $usr = $user->toArray(); $naam[$usr['id']] = $usr['username']; $email[$usr['id']] = $usr['email']; } $tpl = $modx->getOption('tpl',$scriptProperties,'Forumthreads.Popular'); $package_path = $modx->getOption('core_path').'components/discuss/model/'; $modx->addPackage('discuss', $package_path); $vraag = $modx->newQuery('disThread'); $vraag->sortby('replies','DESC'); $vraag->where(array( )); $vraag->limit(6,0); $regels = $modx->getCollection('disThread',$vraag); $output = ''; foreach($regels as $regel){ $rglArray['post']= $regel->get('id'); $rglArray['thread']= $regel->get('thread'); $titel = strtolower($regel->get('title')); if(substr($titel, 0,4)=="re: "){$titel = substr($titel,4);} $titel= str_replace($vervangen, "-", str_replace($weghalen, "", $titel)); if(substr($titel,-1)=="-"){$titel = substr($titel,0,-1);} $rglArray['threadname'] = $titel; //$rglArray['threadname'] = $titel2; $rglArray['title']= $regel->get('title'); $rglArray['message']= $regel->get('message'); $rglArray['author'] = $naam[$regel->get('author')]; $rglArray['createdon']= $regel->get('createdon'); $rglArray['gravatar'] = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email[$regel->get('author')])))."?d=mm&s=50"; $rglArray['email'] = $email[$regel->get('author')]; $rglArray['nummer'] =$nummer; $output .= $modx->getChunk($tpl,$rglArray); } return $output;
<ul> <li> <h5><a href="/forums/thread/[[+thread]]/[[+threadname]]#dis-post-[[+post]]">[[+title]]</a></h5> <p style='margin-top:-15px'>[[+message:strip:stripTags:ellipsis=`50`]]</p> <div class="clear"></div> </li> </ul>
[[!Discuss.Popular]]
$tpl = $modx->getOption('tpl',$scriptProperties,'Forumthreads.Popular'); $package_path = $modx->getOption('core_path').'components/discuss/model/'; $modx->addPackage('discuss', $package_path); $vraag = $modx->newQuery('disThread'); $vraag->sortby('replies','DESC'); $vraag->where(array( )); $vraag->limit(6,0);
$vraag->sortby('most_replies_within_last_day','DESC');
$vraag = $modx->newQuery('disThread');
Wow! Its a huge step forward! Congrats on doing this!
I want to mention something I noticed when using mintnl's code directly, he had kept out boards 9 and 10 as they were private, and with no change private pms between users also are visible
I don't understand fully, and may get some parts wrong, (signified by ?) but it goes like this:
Go get popular threads's template and path to file ?
Addpackage - Go get discuss (remember, this is on a page outside discuss) part of database and path to file
Query the db - go get the Discuss threads for my query, pls,
Sort - Now get what I want, which is replies (going from most to least, DESC in other words)
Now give me top 6, pls.
Then finally, getCollection, is, ok, go really do it. For real now. Then output.
Which isn't how it would be, because most_replies_within_last_day here *should* be the name of the data column in the db, if that makes sense. So it would probably be some php to sort in this fashion.
$c = $modx->newQuery('disPost'); $c->where(array('private' => 0)); $c->limit(10); $c->orderby('createdon', 'DESC');
$modx->addPackage('discuss', $package_path); $vraag = $modx->newQuery('disThread'); $vraag->sortby('replies','DESC'); $vraag->where(array( )); $vraag->limit(6,0);
$modx->addPackage('discuss', $package_path); $vraag = $modx->newQuery('disThread'); $vraag->where(array('private' => 0)); $vraag->sortby('replies','DESC'); $vraag->where(array( )); $vraag->limit(6,0);