|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package sitemaker |
|
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\model\mapper; |
|
11
|
|
|
|
|
12
|
|
|
use blitze\sitemaker\model\base_mapper; |
|
13
|
|
|
|
|
14
|
|
|
class routes extends base_mapper |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \blitze\sitemaker\model\mapper\blocks */ |
|
17
|
|
|
protected $block_mapper; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
protected $entity_class = 'blitze\sitemaker\model\entity\route'; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $entity_pkey = 'route_id'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
21 |
|
public function load(array $condition = array()) |
|
29
|
|
|
{ |
|
30
|
|
|
/** @type \blitze\sitemaker\model\entity\route|null $entity */ |
|
31
|
21 |
|
$entity = parent::load($condition); |
|
32
|
|
|
|
|
33
|
|
|
if ($entity) |
|
34
|
21 |
|
{ |
|
35
|
18 |
|
$block_mapper = $this->mapper_factory->create('blocks'); |
|
36
|
|
|
|
|
37
|
|
|
/** @type \blitze\sitemaker\model\collections\blocks $collection */ |
|
38
|
18 |
|
$collection = $block_mapper->find(array( |
|
39
|
18 |
|
array('style', '=', $entity->get_style()), |
|
40
|
18 |
|
array('route_id', '=', $entity->get_route_id()), |
|
41
|
18 |
|
)); |
|
42
|
18 |
|
$entity->set_blocks($collection); |
|
43
|
18 |
|
} |
|
44
|
|
|
|
|
45
|
21 |
|
return $entity; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param array|\blitze\sitemaker\model\entity\route $condition |
|
50
|
|
|
*/ |
|
51
|
8 |
|
public function delete($condition) |
|
52
|
|
|
{ |
|
53
|
8 |
|
parent::delete($condition); |
|
54
|
|
|
|
|
55
|
|
|
// delete blocks associated with this route and style |
|
56
|
8 |
|
if ($condition instanceof $this->entity_class) |
|
57
|
8 |
|
{ |
|
58
|
6 |
|
$block_mapper = $this->mapper_factory->create('blocks'); |
|
59
|
|
|
|
|
60
|
6 |
|
$block_mapper->delete(array( |
|
61
|
6 |
|
array('style', '=', $condition->get_style()), |
|
62
|
6 |
|
array('route_id', '=', $condition->get_route_id()), |
|
63
|
6 |
|
)); |
|
64
|
6 |
|
} |
|
65
|
8 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param array $sql_where |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
53 |
|
protected function find_sql(array $sql_where) |
|
72
|
|
|
{ |
|
73
|
53 |
|
return 'SELECT * FROM ' . $this->entity_table . |
|
74
|
53 |
|
((sizeof($sql_where)) ? ' WHERE ' . join(' AND ', $sql_where) : '') . ' |
|
75
|
53 |
|
ORDER BY route ASC'; |
|
76
|
15 |
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|