-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbusinessdirectory.php
More file actions
69 lines (62 loc) · 1.3 KB
/
businessdirectory.php
File metadata and controls
69 lines (62 loc) · 1.3 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
<?php
namespace KVSun\KVSAPI;
use \PDO;
use \PDOStatement;
final class BusinessDirectory extends Abstracts\Content
{
const TYPE = 'businessdirectory';
const DEFAULTS = [
'categories' => [],
'title' => 'Business Directory',
'keywords' => [
'businesses',
'directory',
'kvsun',
'lake isabella',
'kern valley',
'kern river valley',
],
];
public function __construct(PDO $pdo, String $url)
{
$this->_init($pdo, $url);
}
/**
* Required method to get query to execute
* @return String SQL query
*/
protected function _getSQL(): String
{
return 'SELECT
`name`,
`category`,
`description` AS `text`,
`start`,
`end`,
`img` AS `image`
FROM `businessDirectory`
WHERE `start` <= CURRENT_DATE
AND (
`end` IS NULL
OR `end` >= CURRENT_DATE
);';
}
/**
* Required method for setting data
* @param PDOStatement $stm A prepared statment using `\PDO::prepare`
*/
protected function _setData(PDOStatement $stm)
{
$stm->execute();
$cats = [];
$results = $stm->fetchAll(PDO::FETCH_CLASS);
foreach ($results as $result) {
if (! array_key_exists($result->category, $cats)) {
$cats[$result->category] = [];
}
$cats[$result->category][] = $result;
unset($cats[$result->category]->category);
}
$this->_set('categories', $cats);
}
}