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
|
20 |
|
public function load(array $condition = array()) |
29
|
|
|
{ |
30
|
|
|
/** @type \blitze\sitemaker\model\entity\route|null $entity */ |
31
|
20 |
|
$entity = parent::load($condition); |
32
|
|
|
|
33
|
|
|
if ($entity) |
34
|
20 |
|
{ |
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
|
20 |
|
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
|
48 |
|
protected function find_sql(array $sql_where) |
72
|
|
|
{ |
73
|
48 |
|
return 'SELECT * FROM ' . $this->entity_table . |
74
|
48 |
|
((sizeof($sql_where)) ? ' WHERE ' . join(' AND ', $sql_where) : '') . ' |
75
|
48 |
|
ORDER BY route ASC'; |
76
|
15 |
|
} |
77
|
|
|
} |
78
|
|
|
|