1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dealer\Model; |
4
|
|
|
|
5
|
|
|
use Dealer\Model\Base\Dealer as BaseDealer; |
6
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
7
|
|
|
use Propel\Runtime\Collection\Collection; |
8
|
|
|
use Propel\Runtime\Collection\ObjectCollection; |
9
|
|
|
use Propel\Runtime\Connection\ConnectionInterface; |
10
|
|
|
use Dealer\Model\DealerShedulesQuery as ChildDealerShedulesQuery; |
11
|
|
|
use Propel\Runtime\Exception\PropelException; |
12
|
|
|
use Dealer\Model\DealerShedules as ChildDealerShedules; |
13
|
|
|
|
14
|
|
|
class Dealer extends BaseDealer |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ObjectCollection|ChildDealerShedules[] Collection to store aggregation of ChildDealerShedules objects. |
19
|
|
|
*/ |
20
|
|
|
protected $collDealerDefaultSheduless; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var ObjectCollection|ChildDealerShedules[] Collection to store aggregation of ChildDealerShedules objects. |
24
|
|
|
*/ |
25
|
|
|
protected $collDealerExtraSheduless; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the collDealerSheduless collection. |
29
|
|
|
* |
30
|
|
|
* By default this just sets the collDealerSheduless collection to an empty array (like clearcollDealerSheduless()); |
31
|
|
|
* however, you may wish to override this method in your stub class to provide setting appropriate |
32
|
|
|
* to your application -- for example, setting the initial array to the values stored in database. |
33
|
|
|
* |
34
|
|
|
* @param boolean $overrideExisting If set to true, the method call initializes |
35
|
|
|
* the collection even if it is not empty |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function initDealerDefaultSheduless($overrideExisting = true) |
40
|
|
|
{ |
41
|
|
|
if (null !== $this->collDealerDefaultSheduless && !$overrideExisting) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
$this->collDealerDefaultSheduless = new ObjectCollection(); |
45
|
|
|
$this->collDealerDefaultSheduless->setModel('\Dealer\Model\DealerShedules'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Initializes the collDealerSheduless collection. |
50
|
|
|
* |
51
|
|
|
* By default this just sets the collDealerSheduless collection to an empty array (like clearcollDealerSheduless()); |
52
|
|
|
* however, you may wish to override this method in your stub class to provide setting appropriate |
53
|
|
|
* to your application -- for example, setting the initial array to the values stored in database. |
54
|
|
|
* |
55
|
|
|
* @param boolean $overrideExisting If set to true, the method call initializes |
56
|
|
|
* the collection even if it is not empty |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function initDealerExtraSheduless($overrideExisting = true) |
61
|
|
|
{ |
62
|
|
|
if (null !== $this->collDealerExtraSheduless && !$overrideExisting) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
$this->collDealerExtraSheduless = new ObjectCollection(); |
66
|
|
|
$this->collDealerExtraSheduless->setModel('\Dealer\Model\DealerShedules'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets an array of ChildDealerShedules objects which contain a foreign key that references this object. |
71
|
|
|
* |
72
|
|
|
* If the $criteria is not null, it is used to always fetch the results from the database. |
73
|
|
|
* Otherwise the results are fetched from the database the first time, then cached. |
74
|
|
|
* Next time the same method is called without $criteria, the cached collection is returned. |
75
|
|
|
* If this ChildDealer is new, it will return |
76
|
|
|
* an empty collection or the current collection; the criteria is ignored on a new object. |
77
|
|
|
* |
78
|
|
|
* @param Criteria $criteria optional Criteria object to narrow the query |
79
|
|
|
* @param ConnectionInterface $con optional connection object |
80
|
|
|
* @return Collection|ChildDealerShedules[] List of ChildDealerShedules objects |
81
|
|
|
* @throws PropelException |
82
|
|
|
*/ |
83
|
|
|
public function getDefaultSchedules($criteria = null, ConnectionInterface $con = null) |
84
|
|
|
{ |
85
|
|
|
$partial = $this->collDealerShedulessPartial && !$this->isNew(); |
86
|
|
|
if (null === $this->collDealerDefaultSheduless || null !== $criteria || $partial) { |
87
|
|
|
if ($this->isNew() && null === $this->collDealerDefaultSheduless) { |
88
|
|
|
// return empty collection |
89
|
|
|
$this->initDealerDefaultSheduless(); |
90
|
|
|
} else { |
91
|
|
|
$collDealerSheduless = ChildDealerShedulesQuery::create(null, $criteria) |
92
|
|
|
->filterByDealer($this) |
93
|
|
|
->filterByPeriodNull() |
94
|
|
|
->find($con); |
95
|
|
|
|
96
|
|
|
if (null !== $criteria) { |
97
|
|
|
if (false !== $this->collDealerShedulessPartial && count($collDealerSheduless)) { |
98
|
|
|
$this->initDealerDefaultSheduless(false); |
99
|
|
|
|
100
|
|
|
foreach ($collDealerSheduless as $obj) { |
101
|
|
|
if (false == $this->collDealerDefaultSheduless->contains($obj)) { |
102
|
|
|
$this->collDealerDefaultSheduless->append($obj); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->collDealerShedulessPartial = true; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
reset($collDealerSheduless); |
110
|
|
|
|
111
|
|
|
return $collDealerSheduless; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($partial && $this->collDealerDefaultSheduless) { |
115
|
|
|
foreach ($this->collDealerDefaultSheduless as $obj) { |
116
|
|
|
if ($obj->isNew()) { |
117
|
|
|
$collDealerSheduless[] = $obj; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$this->collDealerDefaultSheduless = $collDealerSheduless; |
123
|
|
|
$this->collDealerShedulessPartial = false; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $this->collDealerDefaultSheduless; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Gets an array of ChildDealerShedules objects which contain a foreign key that references this object. |
132
|
|
|
* |
133
|
|
|
* If the $criteria is not null, it is used to always fetch the results from the database. |
134
|
|
|
* Otherwise the results are fetched from the database the first time, then cached. |
135
|
|
|
* Next time the same method is called without $criteria, the cached collection is returned. |
136
|
|
|
* If this ChildDealer is new, it will return |
137
|
|
|
* an empty collection or the current collection; the criteria is ignored on a new object. |
138
|
|
|
* |
139
|
|
|
* @param Criteria $criteria optional Criteria object to narrow the query |
140
|
|
|
* @param ConnectionInterface $con optional connection object |
141
|
|
|
* @return Collection|ChildDealerShedules[] List of ChildDealerShedules objects |
142
|
|
|
* @throws PropelException |
143
|
|
|
*/ |
144
|
|
|
public function getExtraSchedules($criteria = null, ConnectionInterface $con = null) |
145
|
|
|
{ |
146
|
|
|
$partial = $this->collDealerShedulessPartial && !$this->isNew(); |
147
|
|
|
if (null === $this->collDealerExtraSheduless || null !== $criteria || $partial) { |
148
|
|
|
if ($this->isNew() && null === $this->collDealerSheduless) { |
149
|
|
|
// return empty collection |
150
|
|
|
$this->initDealerExtraSheduless(); |
151
|
|
|
} else { |
152
|
|
|
$collDealerSheduless = ChildDealerShedulesQuery::create(null, $criteria) |
153
|
|
|
->filterByDealer($this) |
154
|
|
|
->filterByPeriodNotNull() |
155
|
|
|
->find($con); |
156
|
|
|
|
157
|
|
|
if (null !== $criteria) { |
158
|
|
|
if (false !== $this->collDealerShedulessPartial && count($collDealerSheduless)) { |
159
|
|
|
$this->initDealerExtraSheduless(false); |
160
|
|
|
|
161
|
|
|
foreach ($collDealerSheduless as $obj) { |
162
|
|
|
if (false == $this->collDealerExtraSheduless->contains($obj)) { |
163
|
|
|
$this->collDealerExtraSheduless->append($obj); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$this->collDealerShedulessPartial = true; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
reset($collDealerSheduless); |
171
|
|
|
|
172
|
|
|
return $collDealerSheduless; |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
if ($partial && $this->collDealerSheduless) { |
176
|
|
|
foreach ($this->collDealerExtraSheduless as $obj) { |
177
|
|
|
if ($obj->isNew()) { |
178
|
|
|
$collDealerSheduless[] = $obj; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$this->collDealerExtraSheduless = $collDealerSheduless; |
184
|
|
|
$this->collDealerShedulessPartial = false; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return $this->collDealerExtraSheduless; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.