This repository has been archived on 2024-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
mybb-digest/activethreads.php

42 lines
1.4 KiB
PHP
Raw Normal View History

2017-05-04 09:11:59 +03:00
<?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')
2017-05-04 09:39:07 +03:00
->leftJoin(MYBB_PREFIX.'forums', MYBB_PREFIX.'forums.fid', '=', MYBB_PREFIX.'threads.fid')
2017-05-04 09:11:59 +03:00
->whereMany($condition, '=')
2017-05-04 09:39:07 +03:00
->orderBy(MYBB_PREFIX.'threads.lastpost', 'DESC')
2017-05-04 09:11:59 +03:00
->limit(intval($limit), 0)
->execute();
return $query->fetchAll();
}