PreviewRepository.php
1.36 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
<?php
namespace FootyRoom\Repositories;
use Illuminate\Database\Connection;
class PreviewRepository
{
/**
* @var \Illuminate\Database\Connection
*/
protected $mysql;
/**
* Constructor.
*
* @param \Illuminate\Database\Connection $mysql
*/
public function __construct(Connection $mysql)
{
$this->mysql = $mysql;
}
/**
* Find published preview posts for matches that have not finished.
*
* @param int $offset
* @param int $limit
*
* @return object[];
*/
public function findPosts($offset = 0, $limit = 20): array
{
return $this->mysql
->select(
'SELECT
m.match_id as matchId,
pm.post_id as postId,
p.post_date as postDate,
t1.nice_name as homeTeamName,
t2.nice_name as awayTeamName,
t1.team_id as homeTeamId,
t2.team_id as awayTeamId
FROM wp_posts AS p
JOIN wp_postmeta AS pm ON pm.meta_key = "match_id_preview" AND pm.post_id = p.id
JOIN matches AS m ON m.match_id = pm.meta_value
JOIN teams AS t1 ON t1.team_id = home_team
JOIN teams AS t2 ON t2.team_id = away_team
WHERE m.status_type != "finished" AND m.status_type != "interrupted"
AND p.post_status = "publish" AND p.post_type = "preview"
ORDER BY p.post_date DESC
LIMIT ?, ?',
[$offset, $limit]
);
}
}