Completed
Push — master ( c7b947...966759 )
by Thomas
08:09
created

Relationships::getManyToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace keeko\tools\model;
3
4
use phootwork\collection\Map;
5
use Propel\Generator\Model\Table;
6
7
class Relationships {
8
	
9
	/** @var Map */
10
	private $all;
11
	
12
	/** @var Map */
13
	private $oneToOne;
14
	
15
	/** @var Map */
16
	private $oneToMany;
17
	
18
	/** @var Map */
19
	private $manyToMany;
20
	
21
	/** @var Table */
22
	private $model;
23
	
24
	public function __construct(Table $model) {
25
		$this->model = $model;
26
		$this->all = new Map();
27
		$this->oneToOne = new Map();
28
		$this->oneToMany = new Map();
29
		$this->manyToMany = new Map();
30
	}
31
	
32
	/**
33
	 * @return Table
34
	 */
35
	public function getModel() {
36
		return $this->model;
37
	}
38
	
39
	/**
40
	 * Adds a relationships to this collection
41
	 * 
42
	 * @param Relationship $relationship
43
	 */
44
	public function add(Relationship $relationship) {
45
		switch ($relationship->getType()) {
46
			case Relationship::ONE_TO_ONE:
47
				$this->oneToOne->set($relationship->getRelatedTypeName(), $relationship);
48
				break;
49
				
50
			case Relationship::ONE_TO_MANY:
51
				$this->oneToMany->set($relationship->getRelatedTypeName(), $relationship);
52
				break;
53
				
54
			case Relationship::MANY_TO_MANY:
55
				$this->manyToMany->set($relationship->getRelatedTypeName(), $relationship);
56
				break;
57
		}
58
		
59
		$this->all->set($relationship->getRelatedTypeName(), $relationship);
60
	}
61
	
62
	/**
63
	 * Return all relationships
64
	 * 
65
	 * @return Map
66
	 */
67
	public function getAll() {
68
		return $this->all;
69
	}
70
	
71
	/**
72
	 * Return one-to-one relationships
73
	 * 
74
	 * @return Map
75
	 */
76
	public function getOneToOne() {
77
		return $this->oneToOne;
78
	}
79
	
80
	/**
81
	 * Return one-to-many relationships
82
	 * 
83
	 * @return Map
84
	 */
85
	public function getOneToMany() {
86
		return $this->oneToMany;
87
	}
88
	
89
	/**
90
	 * Return many-to-many relationships
91
	 * 
92
	 * @return Map
93
	 */
94
	public function getManyToMany() {
95
		return $this->manyToMany;
96
	}
97
	
98
	/**
99
	 * The number of all relationships
100
	 * 
101
	 * @return int
102
	 */
103
	public function size() {
104
		return $this->all->size();
105
	}
106
	
107
	/**
108
	 * Checks whether a relationship with the given related type name exists
109
	 * 
110
	 * @param string $relatedTypeName
111
	 * @return boolean
112
	 */
113
	public function has($relatedTypeName) {
114
		return $this->all->has($relatedTypeName);
115
	}
116
	
117
	/**
118
	 * Returns a relationship with the given related type name
119
	 * 
120
	 * @param string $relatedTypeName
121
	 * @return Relationship
122
	 */
123
	public function get($relatedTypeName) {
124
		return $this->all->get($relatedTypeName);
125
	}
126
}