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

menus   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 43
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 16 2
A delete() 0 11 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 menus extends base_mapper
15
{
16
	/** @var string */
17
	protected $entity_class = 'blitze\sitemaker\model\entity\menu';
18
19
	/** @var string */
20
	protected $entity_pkey = 'menu_id';
21
22
	/**
23
	 * {@inheritdoc}
24
	 */
25 22
	public function load(array $condition = array())
26
	{
27
		/** @type \blitze\sitemaker\model\entity\menu|null $entity */
28 22
		$entity = parent::load($condition);
29
30
		if ($entity)
31 22
		{
32 16
			$items_mapper = $this->mapper_factory->create('items');
33
34
			/** @type \blitze\sitemaker\model\collections\items $collection */
35 16
			$collection = $items_mapper->find(array('%smenu_id', '=', $entity->get_menu_id()));
36 16
			$entity->set_items($collection);
37 16
		}
38
39 22
		return $entity;
40
	}
41
42
	/**
43
	 * @param array|\blitze\sitemaker\model\entity\menu $condition
44
	 */
45 3
	public function delete($condition)
46
	{
47 3
		parent::delete($condition);
48
49
		// delete menu items associated with this menu
50 3
		if ($condition instanceof $this->entity_class)
51 3
		{
52 2
			$items_mapper = $this->mapper_factory->create('items');
53 2
			$items_mapper->delete(array('menu_id', '=', $condition->get_menu_id()));
54 2
		}
55 3
	}
56
}
57