Completed
Push — develop ( 8387b5...1b51bd )
by Daniel
11:34
created

routes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 4
dl 0
loc 64
c 0
b 0
f 0
ccs 27
cts 27
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 19 2
A delete() 0 15 2
A find_sql() 0 6 2
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