-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMyBBModel.php
More file actions
75 lines (64 loc) · 1.96 KB
/
MyBBModel.php
File metadata and controls
75 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace App\Models;
use CodeIgniter\Model;
/**
* Class MyBBModel
*
* Interacts with the fx_threads table on either
* a local MyBB installation, or a local database
* to simulate a MyBB install.
*/
class MyBBModel extends Model
{
protected $table = 'fx_threads';
protected $primaryKey = 'tid';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $allowedFields = [
'fid', 'tid', 'subject', 'username', 'lastpost', 'lastposter', 'visible', 'deletetime',
];
/**
* Grabs the most recently active threads from the forums.
*
* @return array|null
*/
public function getRecentPosts(int $limit = 5, string $order = 'desc')
{
$forumId = config('MyBB')->newsForumId;
$where = [
'visible' => 1,
'deletetime' => 0,
];
$builder = $this->db->table('fx_threads');
$query = $builder->select('tid, subject, username, lastpost, lastposter')
->where($where)
->where('fid != ' . $forumId)
->limit($limit, 0)
->orderBy('lastpost', $order)
->get();
return $query->getResultArray();
}
/**
* Grabs the most recent announcements from the forums.
*
* @return array
*/
public function getRecentNews(int $limit = 5, string $order = 'desc')
{
$admins = config('MyBB')->newsUsernames;
$forumId = config('MyBB')->newsForumId;
$where = [
'fid' => $forumId,
'visible' => 1,
'deletetime' => 0,
];
$builder = $this->db->table('fx_threads');
$query = $builder->select('tid, subject, username, lastpost, lastposter')
->where($where)
->whereIn('username', $admins)
->limit($limit, 0)
->orderBy('lastpost', $order)
->get();
return $query->getResultArray();
}
}