41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Return the latest threads of one forum, where a post has been posted
|
||
|
*
|
||
|
* @param integer $forum_id Forum ID to fetch threads from
|
||
|
* @param integer $limit Amount of threads to get
|
||
|
* @param boolean $excluse_invisible Shall we also get invisible threads?
|
||
|
* @return array
|
||
|
*/
|
||
|
function getLatestActiveThreads($forum_id = 0, $limit = 7, $exclude_invisible = true)
|
||
|
{
|
||
|
global $pdo, $prefix;
|
||
|
// This will be the array, where we can save the threads
|
||
|
$threads = array();
|
||
|
|
||
|
/**
|
||
|
* If defined forum id is 0, we do not fetch threads from only one forum,
|
||
|
* but we fetch the latest threads of all forums
|
||
|
* Therefore we add the forum_id in the where condition
|
||
|
* We only fetch visible threads, if there is anything we want to hide ;)
|
||
|
* However we can also define that we want the invisible threads as well
|
||
|
*/
|
||
|
$fetch_invisible_threads = ($exclude_invisible == true) ? '1' : '0';
|
||
|
$condition = [];
|
||
|
$condition['visible'] = $fetch_invisible_threads;
|
||
|
if ($forum_id != 0){
|
||
|
$condition['fid'] = intval($forum_id);
|
||
|
}
|
||
|
|
||
|
// Run the Query
|
||
|
$query = $pdo->select()
|
||
|
->from(MYBB_PREFIX.'threads')
|
||
|
->whereMany($condition, '=')
|
||
|
->orderBy('lastpost', 'DESC')
|
||
|
->limit(intval($limit), 0)
|
||
|
->execute();
|
||
|
|
||
|
return $query->fetchAll();
|
||
|
}
|
||
|
|