Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Input often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Input, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | abstract class Input implements ActiveRecordInterface |
||
38 | { |
||
39 | /** |
||
40 | * TableMap class name |
||
41 | */ |
||
42 | const TABLE_MAP = '\\Jalle19\\StatusManager\\Database\\Map\\InputTableMap'; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * attribute to determine if this object has previously been saved. |
||
47 | * @var boolean |
||
48 | */ |
||
49 | protected $new = true; |
||
50 | |||
51 | /** |
||
52 | * attribute to determine whether this object has been deleted. |
||
53 | * @var boolean |
||
54 | */ |
||
55 | protected $deleted = false; |
||
56 | |||
57 | /** |
||
58 | * The columns that have been modified in current object. |
||
59 | * Tracking modified columns allows us to only update modified columns. |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $modifiedColumns = array(); |
||
63 | |||
64 | /** |
||
65 | * The (virtual) columns that are added at runtime |
||
66 | * The formatters can add supplementary columns based on a resultset |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $virtualColumns = array(); |
||
70 | |||
71 | /** |
||
72 | * The value for the uuid field. |
||
73 | * |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $uuid; |
||
77 | |||
78 | /** |
||
79 | * The value for the instance_name field. |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $instance_name; |
||
84 | |||
85 | /** |
||
86 | * The value for the started field. |
||
87 | * |
||
88 | * @var \DateTime |
||
89 | */ |
||
90 | protected $started; |
||
91 | |||
92 | /** |
||
93 | * The value for the input field. |
||
94 | * |
||
95 | * @var string |
||
96 | */ |
||
97 | protected $input; |
||
98 | |||
99 | /** |
||
100 | * The value for the network field. |
||
101 | * |
||
102 | * @var string |
||
103 | */ |
||
104 | protected $network; |
||
105 | |||
106 | /** |
||
107 | * The value for the mux field. |
||
108 | * |
||
109 | * @var string |
||
110 | */ |
||
111 | protected $mux; |
||
112 | |||
113 | /** |
||
114 | * The value for the weight field. |
||
115 | * |
||
116 | * @var int |
||
117 | */ |
||
118 | protected $weight; |
||
119 | |||
120 | /** |
||
121 | * @var ChildInstance |
||
122 | */ |
||
123 | protected $aInstance; |
||
124 | |||
125 | /** |
||
126 | * @var ObjectCollection|ChildSubscription[] Collection to store aggregation of ChildSubscription objects. |
||
127 | */ |
||
128 | protected $collSubscriptions; |
||
129 | protected $collSubscriptionsPartial; |
||
130 | |||
131 | /** |
||
132 | * Flag to prevent endless save loop, if this object is referenced |
||
133 | * by another object which falls in this transaction. |
||
134 | * |
||
135 | * @var boolean |
||
136 | */ |
||
137 | protected $alreadyInSave = false; |
||
138 | |||
139 | /** |
||
140 | * An array of objects scheduled for deletion. |
||
141 | * @var ObjectCollection|ChildSubscription[] |
||
142 | */ |
||
143 | protected $subscriptionsScheduledForDeletion = null; |
||
144 | |||
145 | /** |
||
146 | * Initializes internal state of Jalle19\StatusManager\Database\Base\Input object. |
||
147 | */ |
||
148 | public function __construct() |
||
149 | { |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Returns whether the object has been modified. |
||
154 | * |
||
155 | * @return boolean True if the object has been modified. |
||
156 | */ |
||
157 | public function isModified() |
||
158 | { |
||
159 | return !!$this->modifiedColumns; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Has specified column been modified? |
||
164 | * |
||
165 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
166 | * @return boolean True if $col has been modified. |
||
167 | */ |
||
168 | public function isColumnModified($col) |
||
169 | { |
||
170 | return $this->modifiedColumns && isset($this->modifiedColumns[$col]); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Get the columns that have been modified in this object. |
||
175 | * @return array A unique list of the modified column names for this object. |
||
176 | */ |
||
177 | public function getModifiedColumns() |
||
178 | { |
||
179 | return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Returns whether the object has ever been saved. This will |
||
184 | * be false, if the object was retrieved from storage or was created |
||
185 | * and then saved. |
||
186 | * |
||
187 | * @return boolean true, if the object has never been persisted. |
||
188 | */ |
||
189 | public function isNew() |
||
190 | { |
||
191 | return $this->new; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Setter for the isNew attribute. This method will be called |
||
196 | * by Propel-generated children and objects. |
||
197 | * |
||
198 | * @param boolean $b the state of the object. |
||
199 | */ |
||
200 | public function setNew($b) |
||
201 | { |
||
202 | $this->new = (boolean) $b; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Whether this object has been deleted. |
||
207 | * @return boolean The deleted state of this object. |
||
208 | */ |
||
209 | public function isDeleted() |
||
210 | { |
||
211 | return $this->deleted; |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Specify whether this object has been deleted. |
||
216 | * @param boolean $b The deleted state of this object. |
||
217 | * @return void |
||
218 | */ |
||
219 | public function setDeleted($b) |
||
220 | { |
||
221 | $this->deleted = (boolean) $b; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * Sets the modified state for the object to be false. |
||
226 | * @param string $col If supplied, only the specified column is reset. |
||
227 | * @return void |
||
228 | */ |
||
229 | public function resetModified($col = null) |
||
230 | { |
||
231 | if (null !== $col) { |
||
232 | if (isset($this->modifiedColumns[$col])) { |
||
233 | unset($this->modifiedColumns[$col]); |
||
234 | } |
||
235 | } else { |
||
236 | $this->modifiedColumns = array(); |
||
237 | } |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Compares this with another <code>Input</code> instance. If |
||
242 | * <code>obj</code> is an instance of <code>Input</code>, delegates to |
||
243 | * <code>equals(Input)</code>. Otherwise, returns <code>false</code>. |
||
244 | * |
||
245 | * @param mixed $obj The object to compare to. |
||
246 | * @return boolean Whether equal to the object specified. |
||
247 | */ |
||
248 | public function equals($obj) |
||
249 | { |
||
250 | if (!$obj instanceof static) { |
||
251 | return false; |
||
252 | } |
||
253 | |||
254 | if ($this === $obj) { |
||
255 | return true; |
||
256 | } |
||
257 | |||
258 | if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { |
||
259 | return false; |
||
260 | } |
||
261 | |||
262 | return $this->getPrimaryKey() === $obj->getPrimaryKey(); |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Get the associative array of the virtual columns in this object |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | public function getVirtualColumns() |
||
271 | { |
||
272 | return $this->virtualColumns; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Checks the existence of a virtual column in this object |
||
277 | * |
||
278 | * @param string $name The virtual column name |
||
279 | * @return boolean |
||
280 | */ |
||
281 | public function hasVirtualColumn($name) |
||
282 | { |
||
283 | return array_key_exists($name, $this->virtualColumns); |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Get the value of a virtual column in this object |
||
288 | * |
||
289 | * @param string $name The virtual column name |
||
290 | * @return mixed |
||
291 | * |
||
292 | * @throws PropelException |
||
293 | */ |
||
294 | public function getVirtualColumn($name) |
||
295 | { |
||
296 | if (!$this->hasVirtualColumn($name)) { |
||
297 | throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); |
||
298 | } |
||
299 | |||
300 | return $this->virtualColumns[$name]; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * Set the value of a virtual column in this object |
||
305 | * |
||
306 | * @param string $name The virtual column name |
||
307 | * @param mixed $value The value to give to the virtual column |
||
308 | * |
||
309 | * @return $this|Input The current object, for fluid interface |
||
310 | */ |
||
311 | public function setVirtualColumn($name, $value) |
||
312 | { |
||
313 | $this->virtualColumns[$name] = $value; |
||
314 | |||
315 | return $this; |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * Logs a message using Propel::log(). |
||
320 | * |
||
321 | * @param string $msg |
||
322 | * @param int $priority One of the Propel::LOG_* logging levels |
||
323 | * @return boolean |
||
324 | */ |
||
325 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
326 | { |
||
327 | return Propel::log(get_class($this) . ': ' . $msg, $priority); |
||
328 | } |
||
329 | |||
330 | /** |
||
331 | * Export the current object properties to a string, using a given parser format |
||
332 | * <code> |
||
333 | * $book = BookQuery::create()->findPk(9012); |
||
334 | * echo $book->exportTo('JSON'); |
||
335 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
336 | * </code> |
||
337 | * |
||
338 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
339 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
340 | * @return string The exported data |
||
341 | */ |
||
342 | public function exportTo($parser, $includeLazyLoadColumns = true) |
||
343 | { |
||
344 | if (!$parser instanceof AbstractParser) { |
||
345 | $parser = AbstractParser::getParser($parser); |
||
346 | } |
||
347 | |||
348 | return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * Clean up internal collections prior to serializing |
||
353 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
354 | */ |
||
355 | public function __sleep() |
||
356 | { |
||
357 | $this->clearAllReferences(); |
||
358 | |||
359 | $cls = new \ReflectionClass($this); |
||
360 | $propertyNames = []; |
||
361 | $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); |
||
362 | |||
363 | foreach($serializableProperties as $property) { |
||
364 | $propertyNames[] = $property->getName(); |
||
365 | } |
||
366 | |||
367 | return $propertyNames; |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * Get the [uuid] column value. |
||
372 | * |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getUuid() |
||
376 | { |
||
377 | return $this->uuid; |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Get the [instance_name] column value. |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | public function getInstanceName() |
||
386 | { |
||
387 | return $this->instance_name; |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * Get the [optionally formatted] temporal [started] column value. |
||
392 | * |
||
393 | * |
||
394 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
395 | * If format is NULL, then the raw DateTime object will be returned. |
||
396 | * |
||
397 | * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL |
||
398 | * |
||
399 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
400 | */ |
||
401 | public function getStarted($format = NULL) |
||
402 | { |
||
403 | if ($format === null) { |
||
404 | return $this->started; |
||
405 | } else { |
||
406 | return $this->started instanceof \DateTime ? $this->started->format($format) : null; |
||
407 | } |
||
408 | } |
||
409 | |||
410 | /** |
||
411 | * Get the [input] column value. |
||
412 | * |
||
413 | * @return string |
||
414 | */ |
||
415 | public function getInput() |
||
416 | { |
||
417 | return $this->input; |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * Get the [network] column value. |
||
422 | * |
||
423 | * @return string |
||
424 | */ |
||
425 | public function getNetwork() |
||
426 | { |
||
427 | return $this->network; |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * Get the [mux] column value. |
||
432 | * |
||
433 | * @return string |
||
434 | */ |
||
435 | public function getMux() |
||
436 | { |
||
437 | return $this->mux; |
||
438 | } |
||
439 | |||
440 | /** |
||
441 | * Get the [weight] column value. |
||
442 | * |
||
443 | * @return int |
||
444 | */ |
||
445 | public function getWeight() |
||
446 | { |
||
447 | return $this->weight; |
||
448 | } |
||
449 | |||
450 | /** |
||
451 | * Set the value of [uuid] column. |
||
452 | * |
||
453 | * @param string $v new value |
||
454 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
455 | */ |
||
456 | public function setUuid($v) |
||
457 | { |
||
458 | if ($v !== null) { |
||
459 | $v = (string) $v; |
||
460 | } |
||
461 | |||
462 | if ($this->uuid !== $v) { |
||
463 | $this->uuid = $v; |
||
464 | $this->modifiedColumns[InputTableMap::COL_UUID] = true; |
||
465 | } |
||
466 | |||
467 | return $this; |
||
468 | } // setUuid() |
||
469 | |||
470 | /** |
||
471 | * Set the value of [instance_name] column. |
||
472 | * |
||
473 | * @param string $v new value |
||
474 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
475 | */ |
||
476 | public function setInstanceName($v) |
||
477 | { |
||
478 | if ($v !== null) { |
||
479 | $v = (string) $v; |
||
480 | } |
||
481 | |||
482 | if ($this->instance_name !== $v) { |
||
483 | $this->instance_name = $v; |
||
484 | $this->modifiedColumns[InputTableMap::COL_INSTANCE_NAME] = true; |
||
485 | } |
||
486 | |||
487 | if ($this->aInstance !== null && $this->aInstance->getName() !== $v) { |
||
488 | $this->aInstance = null; |
||
489 | } |
||
490 | |||
491 | return $this; |
||
492 | } // setInstanceName() |
||
493 | |||
494 | /** |
||
495 | * Sets the value of [started] column to a normalized version of the date/time value specified. |
||
496 | * |
||
497 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
498 | * Empty strings are treated as NULL. |
||
499 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
500 | */ |
||
501 | public function setStarted($v) |
||
502 | { |
||
503 | $dt = PropelDateTime::newInstance($v, null, 'DateTime'); |
||
504 | if ($this->started !== null || $dt !== null) { |
||
505 | if ($this->started === null || $dt === null || $dt->format("Y-m-d H:i:s") !== $this->started->format("Y-m-d H:i:s")) { |
||
506 | $this->started = $dt === null ? null : clone $dt; |
||
507 | $this->modifiedColumns[InputTableMap::COL_STARTED] = true; |
||
508 | } |
||
509 | } // if either are not null |
||
510 | |||
511 | return $this; |
||
512 | } // setStarted() |
||
513 | |||
514 | /** |
||
515 | * Set the value of [input] column. |
||
516 | * |
||
517 | * @param string $v new value |
||
518 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
519 | */ |
||
520 | public function setInput($v) |
||
521 | { |
||
522 | if ($v !== null) { |
||
523 | $v = (string) $v; |
||
524 | } |
||
525 | |||
526 | if ($this->input !== $v) { |
||
527 | $this->input = $v; |
||
528 | $this->modifiedColumns[InputTableMap::COL_INPUT] = true; |
||
529 | } |
||
530 | |||
531 | return $this; |
||
532 | } // setInput() |
||
533 | |||
534 | /** |
||
535 | * Set the value of [network] column. |
||
536 | * |
||
537 | * @param string $v new value |
||
538 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
539 | */ |
||
540 | public function setNetwork($v) |
||
541 | { |
||
542 | if ($v !== null) { |
||
543 | $v = (string) $v; |
||
544 | } |
||
545 | |||
546 | if ($this->network !== $v) { |
||
547 | $this->network = $v; |
||
548 | $this->modifiedColumns[InputTableMap::COL_NETWORK] = true; |
||
549 | } |
||
550 | |||
551 | return $this; |
||
552 | } // setNetwork() |
||
553 | |||
554 | /** |
||
555 | * Set the value of [mux] column. |
||
556 | * |
||
557 | * @param string $v new value |
||
558 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
559 | */ |
||
560 | public function setMux($v) |
||
561 | { |
||
562 | if ($v !== null) { |
||
563 | $v = (string) $v; |
||
564 | } |
||
565 | |||
566 | if ($this->mux !== $v) { |
||
567 | $this->mux = $v; |
||
568 | $this->modifiedColumns[InputTableMap::COL_MUX] = true; |
||
569 | } |
||
570 | |||
571 | return $this; |
||
572 | } // setMux() |
||
573 | |||
574 | /** |
||
575 | * Set the value of [weight] column. |
||
576 | * |
||
577 | * @param int $v new value |
||
578 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
579 | */ |
||
580 | public function setWeight($v) |
||
581 | { |
||
582 | if ($v !== null) { |
||
583 | $v = (int) $v; |
||
584 | } |
||
585 | |||
586 | if ($this->weight !== $v) { |
||
587 | $this->weight = $v; |
||
588 | $this->modifiedColumns[InputTableMap::COL_WEIGHT] = true; |
||
589 | } |
||
590 | |||
591 | return $this; |
||
592 | } // setWeight() |
||
593 | |||
594 | /** |
||
595 | * Indicates whether the columns in this object are only set to default values. |
||
596 | * |
||
597 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
598 | * modified _and_ has some values set which are non-default. |
||
599 | * |
||
600 | * @return boolean Whether the columns in this object are only been set with default values. |
||
601 | */ |
||
602 | public function hasOnlyDefaultValues() |
||
603 | { |
||
604 | // otherwise, everything was equal, so return TRUE |
||
605 | return true; |
||
606 | } // hasOnlyDefaultValues() |
||
607 | |||
608 | /** |
||
609 | * Hydrates (populates) the object variables with values from the database resultset. |
||
610 | * |
||
611 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
612 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
613 | * for results of JOIN queries where the resultset row includes columns from two or |
||
614 | * more tables. |
||
615 | * |
||
616 | * @param array $row The row returned by DataFetcher->fetch(). |
||
617 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
618 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
619 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
620 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
621 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
622 | * |
||
623 | * @return int next starting column |
||
624 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
625 | */ |
||
626 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
627 | { |
||
628 | try { |
||
629 | |||
630 | $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : InputTableMap::translateFieldName('Uuid', TableMap::TYPE_PHPNAME, $indexType)]; |
||
631 | $this->uuid = (null !== $col) ? (string) $col : null; |
||
632 | |||
633 | $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : InputTableMap::translateFieldName('InstanceName', TableMap::TYPE_PHPNAME, $indexType)]; |
||
634 | $this->instance_name = (null !== $col) ? (string) $col : null; |
||
635 | |||
636 | $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : InputTableMap::translateFieldName('Started', TableMap::TYPE_PHPNAME, $indexType)]; |
||
637 | $this->started = (null !== $col) ? PropelDateTime::newInstance($col, null, 'DateTime') : null; |
||
638 | |||
639 | $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : InputTableMap::translateFieldName('Input', TableMap::TYPE_PHPNAME, $indexType)]; |
||
640 | $this->input = (null !== $col) ? (string) $col : null; |
||
641 | |||
642 | $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : InputTableMap::translateFieldName('Network', TableMap::TYPE_PHPNAME, $indexType)]; |
||
643 | $this->network = (null !== $col) ? (string) $col : null; |
||
644 | |||
645 | $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : InputTableMap::translateFieldName('Mux', TableMap::TYPE_PHPNAME, $indexType)]; |
||
646 | $this->mux = (null !== $col) ? (string) $col : null; |
||
647 | |||
648 | $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : InputTableMap::translateFieldName('Weight', TableMap::TYPE_PHPNAME, $indexType)]; |
||
649 | $this->weight = (null !== $col) ? (int) $col : null; |
||
650 | $this->resetModified(); |
||
651 | |||
652 | $this->setNew(false); |
||
653 | |||
654 | if ($rehydrate) { |
||
655 | $this->ensureConsistency(); |
||
656 | } |
||
657 | |||
658 | return $startcol + 7; // 7 = InputTableMap::NUM_HYDRATE_COLUMNS. |
||
659 | |||
660 | } catch (Exception $e) { |
||
661 | throw new PropelException(sprintf('Error populating %s object', '\\Jalle19\\StatusManager\\Database\\Input'), 0, $e); |
||
662 | } |
||
663 | } |
||
664 | |||
665 | /** |
||
666 | * Checks and repairs the internal consistency of the object. |
||
667 | * |
||
668 | * This method is executed after an already-instantiated object is re-hydrated |
||
669 | * from the database. It exists to check any foreign keys to make sure that |
||
670 | * the objects related to the current object are correct based on foreign key. |
||
671 | * |
||
672 | * You can override this method in the stub class, but you should always invoke |
||
673 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
674 | * in case your model changes. |
||
675 | * |
||
676 | * @throws PropelException |
||
677 | */ |
||
678 | public function ensureConsistency() |
||
679 | { |
||
680 | if ($this->aInstance !== null && $this->instance_name !== $this->aInstance->getName()) { |
||
681 | $this->aInstance = null; |
||
682 | } |
||
683 | } // ensureConsistency |
||
684 | |||
685 | /** |
||
686 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
687 | * |
||
688 | * This will only work if the object has been saved and has a valid primary key set. |
||
689 | * |
||
690 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
691 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
692 | * @return void |
||
693 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
694 | */ |
||
695 | public function reload($deep = false, ConnectionInterface $con = null) |
||
696 | { |
||
697 | if ($this->isDeleted()) { |
||
698 | throw new PropelException("Cannot reload a deleted object."); |
||
699 | } |
||
700 | |||
701 | if ($this->isNew()) { |
||
702 | throw new PropelException("Cannot reload an unsaved object."); |
||
703 | } |
||
704 | |||
705 | if ($con === null) { |
||
706 | $con = Propel::getServiceContainer()->getReadConnection(InputTableMap::DATABASE_NAME); |
||
707 | } |
||
708 | |||
709 | // We don't need to alter the object instance pool; we're just modifying this instance |
||
710 | // already in the pool. |
||
711 | |||
712 | $dataFetcher = ChildInputQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); |
||
713 | $row = $dataFetcher->fetch(); |
||
714 | $dataFetcher->close(); |
||
715 | if (!$row) { |
||
716 | throw new PropelException('Cannot find matching row in the database to reload object values.'); |
||
717 | } |
||
718 | $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate |
||
719 | |||
720 | if ($deep) { // also de-associate any related objects? |
||
721 | |||
722 | $this->aInstance = null; |
||
723 | $this->collSubscriptions = null; |
||
724 | |||
725 | } // if (deep) |
||
726 | } |
||
727 | |||
728 | /** |
||
729 | * Removes this object from datastore and sets delete attribute. |
||
730 | * |
||
731 | * @param ConnectionInterface $con |
||
732 | * @return void |
||
733 | * @throws PropelException |
||
734 | * @see Input::setDeleted() |
||
735 | * @see Input::isDeleted() |
||
736 | */ |
||
737 | public function delete(ConnectionInterface $con = null) |
||
738 | { |
||
739 | if ($this->isDeleted()) { |
||
740 | throw new PropelException("This object has already been deleted."); |
||
741 | } |
||
742 | |||
743 | if ($con === null) { |
||
744 | $con = Propel::getServiceContainer()->getWriteConnection(InputTableMap::DATABASE_NAME); |
||
745 | } |
||
746 | |||
747 | $con->transaction(function () use ($con) { |
||
748 | $deleteQuery = ChildInputQuery::create() |
||
749 | ->filterByPrimaryKey($this->getPrimaryKey()); |
||
750 | $ret = $this->preDelete($con); |
||
751 | if ($ret) { |
||
752 | $deleteQuery->delete($con); |
||
753 | $this->postDelete($con); |
||
754 | $this->setDeleted(true); |
||
755 | } |
||
756 | }); |
||
757 | } |
||
758 | |||
759 | /** |
||
760 | * Persists this object to the database. |
||
761 | * |
||
762 | * If the object is new, it inserts it; otherwise an update is performed. |
||
763 | * All modified related objects will also be persisted in the doSave() |
||
764 | * method. This method wraps all precipitate database operations in a |
||
765 | * single transaction. |
||
766 | * |
||
767 | * @param ConnectionInterface $con |
||
768 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
769 | * @throws PropelException |
||
770 | * @see doSave() |
||
771 | */ |
||
772 | public function save(ConnectionInterface $con = null) |
||
773 | { |
||
774 | if ($this->isDeleted()) { |
||
775 | throw new PropelException("You cannot save an object that has been deleted."); |
||
776 | } |
||
777 | |||
778 | if ($con === null) { |
||
779 | $con = Propel::getServiceContainer()->getWriteConnection(InputTableMap::DATABASE_NAME); |
||
780 | } |
||
781 | |||
782 | return $con->transaction(function () use ($con) { |
||
783 | $isInsert = $this->isNew(); |
||
784 | $ret = $this->preSave($con); |
||
785 | if ($isInsert) { |
||
786 | $ret = $ret && $this->preInsert($con); |
||
787 | } else { |
||
788 | $ret = $ret && $this->preUpdate($con); |
||
789 | } |
||
790 | if ($ret) { |
||
791 | $affectedRows = $this->doSave($con); |
||
792 | if ($isInsert) { |
||
793 | $this->postInsert($con); |
||
794 | } else { |
||
795 | $this->postUpdate($con); |
||
796 | } |
||
797 | $this->postSave($con); |
||
798 | InputTableMap::addInstanceToPool($this); |
||
799 | } else { |
||
800 | $affectedRows = 0; |
||
801 | } |
||
802 | |||
803 | return $affectedRows; |
||
804 | }); |
||
805 | } |
||
806 | |||
807 | /** |
||
808 | * Performs the work of inserting or updating the row in the database. |
||
809 | * |
||
810 | * If the object is new, it inserts it; otherwise an update is performed. |
||
811 | * All related objects are also updated in this method. |
||
812 | * |
||
813 | * @param ConnectionInterface $con |
||
814 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
815 | * @throws PropelException |
||
816 | * @see save() |
||
817 | */ |
||
818 | protected function doSave(ConnectionInterface $con) |
||
819 | { |
||
820 | $affectedRows = 0; // initialize var to track total num of affected rows |
||
821 | if (!$this->alreadyInSave) { |
||
822 | $this->alreadyInSave = true; |
||
823 | |||
824 | // We call the save method on the following object(s) if they |
||
825 | // were passed to this object by their corresponding set |
||
826 | // method. This object relates to these object(s) by a |
||
827 | // foreign key reference. |
||
828 | |||
829 | if ($this->aInstance !== null) { |
||
830 | if ($this->aInstance->isModified() || $this->aInstance->isNew()) { |
||
831 | $affectedRows += $this->aInstance->save($con); |
||
832 | } |
||
833 | $this->setInstance($this->aInstance); |
||
834 | } |
||
835 | |||
836 | if ($this->isNew() || $this->isModified()) { |
||
837 | // persist changes |
||
838 | if ($this->isNew()) { |
||
839 | $this->doInsert($con); |
||
840 | $affectedRows += 1; |
||
841 | } else { |
||
842 | $affectedRows += $this->doUpdate($con); |
||
843 | } |
||
844 | $this->resetModified(); |
||
845 | } |
||
846 | |||
847 | if ($this->subscriptionsScheduledForDeletion !== null) { |
||
848 | if (!$this->subscriptionsScheduledForDeletion->isEmpty()) { |
||
849 | foreach ($this->subscriptionsScheduledForDeletion as $subscription) { |
||
850 | // need to save related object because we set the relation to null |
||
851 | $subscription->save($con); |
||
852 | } |
||
853 | $this->subscriptionsScheduledForDeletion = null; |
||
854 | } |
||
855 | } |
||
856 | |||
857 | if ($this->collSubscriptions !== null) { |
||
858 | foreach ($this->collSubscriptions as $referrerFK) { |
||
859 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
860 | $affectedRows += $referrerFK->save($con); |
||
861 | } |
||
862 | } |
||
863 | } |
||
864 | |||
865 | $this->alreadyInSave = false; |
||
866 | |||
867 | } |
||
868 | |||
869 | return $affectedRows; |
||
870 | } // doSave() |
||
871 | |||
872 | /** |
||
873 | * Insert the row in the database. |
||
874 | * |
||
875 | * @param ConnectionInterface $con |
||
876 | * |
||
877 | * @throws PropelException |
||
878 | * @see doSave() |
||
879 | */ |
||
880 | protected function doInsert(ConnectionInterface $con) |
||
881 | { |
||
882 | $modifiedColumns = array(); |
||
883 | $index = 0; |
||
884 | |||
885 | |||
886 | // check the columns in natural order for more readable SQL queries |
||
887 | if ($this->isColumnModified(InputTableMap::COL_UUID)) { |
||
888 | $modifiedColumns[':p' . $index++] = 'uuid'; |
||
889 | } |
||
890 | if ($this->isColumnModified(InputTableMap::COL_INSTANCE_NAME)) { |
||
891 | $modifiedColumns[':p' . $index++] = 'instance_name'; |
||
892 | } |
||
893 | if ($this->isColumnModified(InputTableMap::COL_STARTED)) { |
||
894 | $modifiedColumns[':p' . $index++] = 'started'; |
||
895 | } |
||
896 | if ($this->isColumnModified(InputTableMap::COL_INPUT)) { |
||
897 | $modifiedColumns[':p' . $index++] = 'input'; |
||
898 | } |
||
899 | if ($this->isColumnModified(InputTableMap::COL_NETWORK)) { |
||
900 | $modifiedColumns[':p' . $index++] = 'network'; |
||
901 | } |
||
902 | if ($this->isColumnModified(InputTableMap::COL_MUX)) { |
||
903 | $modifiedColumns[':p' . $index++] = 'mux'; |
||
904 | } |
||
905 | if ($this->isColumnModified(InputTableMap::COL_WEIGHT)) { |
||
906 | $modifiedColumns[':p' . $index++] = 'weight'; |
||
907 | } |
||
908 | |||
909 | $sql = sprintf( |
||
910 | 'INSERT INTO input (%s) VALUES (%s)', |
||
911 | implode(', ', $modifiedColumns), |
||
912 | implode(', ', array_keys($modifiedColumns)) |
||
913 | ); |
||
914 | |||
915 | try { |
||
916 | $stmt = $con->prepare($sql); |
||
917 | foreach ($modifiedColumns as $identifier => $columnName) { |
||
918 | switch ($columnName) { |
||
919 | case 'uuid': |
||
920 | $stmt->bindValue($identifier, $this->uuid, PDO::PARAM_STR); |
||
921 | break; |
||
922 | case 'instance_name': |
||
923 | $stmt->bindValue($identifier, $this->instance_name, PDO::PARAM_STR); |
||
924 | break; |
||
925 | case 'started': |
||
926 | $stmt->bindValue($identifier, $this->started ? $this->started->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); |
||
927 | break; |
||
928 | case 'input': |
||
929 | $stmt->bindValue($identifier, $this->input, PDO::PARAM_STR); |
||
930 | break; |
||
931 | case 'network': |
||
932 | $stmt->bindValue($identifier, $this->network, PDO::PARAM_STR); |
||
933 | break; |
||
934 | case 'mux': |
||
935 | $stmt->bindValue($identifier, $this->mux, PDO::PARAM_STR); |
||
936 | break; |
||
937 | case 'weight': |
||
938 | $stmt->bindValue($identifier, $this->weight, PDO::PARAM_INT); |
||
939 | break; |
||
940 | } |
||
941 | } |
||
942 | $stmt->execute(); |
||
943 | } catch (Exception $e) { |
||
944 | Propel::log($e->getMessage(), Propel::LOG_ERR); |
||
945 | throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); |
||
946 | } |
||
947 | |||
948 | $this->setNew(false); |
||
949 | } |
||
950 | |||
951 | /** |
||
952 | * Update the row in the database. |
||
953 | * |
||
954 | * @param ConnectionInterface $con |
||
955 | * |
||
956 | * @return Integer Number of updated rows |
||
957 | * @see doSave() |
||
958 | */ |
||
959 | protected function doUpdate(ConnectionInterface $con) |
||
960 | { |
||
961 | $selectCriteria = $this->buildPkeyCriteria(); |
||
962 | $valuesCriteria = $this->buildCriteria(); |
||
963 | |||
964 | return $selectCriteria->doUpdate($valuesCriteria, $con); |
||
965 | } |
||
966 | |||
967 | /** |
||
968 | * Retrieves a field from the object by name passed in as a string. |
||
969 | * |
||
970 | * @param string $name name |
||
971 | * @param string $type The type of fieldname the $name is of: |
||
972 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
973 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
974 | * Defaults to TableMap::TYPE_PHPNAME. |
||
975 | * @return mixed Value of field. |
||
976 | */ |
||
977 | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
||
978 | { |
||
979 | $pos = InputTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
980 | $field = $this->getByPosition($pos); |
||
981 | |||
982 | return $field; |
||
983 | } |
||
984 | |||
985 | /** |
||
986 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
987 | * Zero-based. |
||
988 | * |
||
989 | * @param int $pos position in xml schema |
||
990 | * @return mixed Value of field at $pos |
||
991 | */ |
||
992 | public function getByPosition($pos) |
||
993 | { |
||
994 | switch ($pos) { |
||
995 | case 0: |
||
996 | return $this->getUuid(); |
||
997 | break; |
||
998 | case 1: |
||
999 | return $this->getInstanceName(); |
||
1000 | break; |
||
1001 | case 2: |
||
1002 | return $this->getStarted(); |
||
1003 | break; |
||
1004 | case 3: |
||
1005 | return $this->getInput(); |
||
1006 | break; |
||
1007 | case 4: |
||
1008 | return $this->getNetwork(); |
||
1009 | break; |
||
1010 | case 5: |
||
1011 | return $this->getMux(); |
||
1012 | break; |
||
1013 | case 6: |
||
1014 | return $this->getWeight(); |
||
1015 | break; |
||
1016 | default: |
||
1017 | return null; |
||
1018 | break; |
||
1019 | } // switch() |
||
1020 | } |
||
1021 | |||
1022 | /** |
||
1023 | * Exports the object as an array. |
||
1024 | * |
||
1025 | * You can specify the key type of the array by passing one of the class |
||
1026 | * type constants. |
||
1027 | * |
||
1028 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
1029 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
1030 | * Defaults to TableMap::TYPE_PHPNAME. |
||
1031 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
1032 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
1033 | * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. |
||
1034 | * |
||
1035 | * @return array an associative array containing the field names (as keys) and field values |
||
1036 | */ |
||
1037 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) |
||
1038 | { |
||
1039 | |||
1040 | if (isset($alreadyDumpedObjects['Input'][$this->hashCode()])) { |
||
1041 | return '*RECURSION*'; |
||
1042 | } |
||
1043 | $alreadyDumpedObjects['Input'][$this->hashCode()] = true; |
||
1044 | $keys = InputTableMap::getFieldNames($keyType); |
||
1045 | $result = array( |
||
1046 | $keys[0] => $this->getUuid(), |
||
1047 | $keys[1] => $this->getInstanceName(), |
||
1048 | $keys[2] => $this->getStarted(), |
||
1049 | $keys[3] => $this->getInput(), |
||
1050 | $keys[4] => $this->getNetwork(), |
||
1051 | $keys[5] => $this->getMux(), |
||
1052 | $keys[6] => $this->getWeight(), |
||
1053 | ); |
||
1054 | if ($result[$keys[2]] instanceof \DateTime) { |
||
1055 | $result[$keys[2]] = $result[$keys[2]]->format('c'); |
||
1056 | } |
||
1057 | |||
1058 | $virtualColumns = $this->virtualColumns; |
||
1059 | foreach ($virtualColumns as $key => $virtualColumn) { |
||
1060 | $result[$key] = $virtualColumn; |
||
1061 | } |
||
1062 | |||
1063 | if ($includeForeignObjects) { |
||
1064 | if (null !== $this->aInstance) { |
||
1065 | |||
1066 | switch ($keyType) { |
||
1067 | case TableMap::TYPE_CAMELNAME: |
||
1068 | $key = 'instance'; |
||
1069 | break; |
||
1070 | case TableMap::TYPE_FIELDNAME: |
||
1071 | $key = 'instance'; |
||
1072 | break; |
||
1073 | default: |
||
1074 | $key = 'Instance'; |
||
1075 | } |
||
1076 | |||
1077 | $result[$key] = $this->aInstance->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); |
||
1078 | } |
||
1079 | if (null !== $this->collSubscriptions) { |
||
1080 | |||
1081 | switch ($keyType) { |
||
1082 | case TableMap::TYPE_CAMELNAME: |
||
1083 | $key = 'subscriptions'; |
||
1084 | break; |
||
1085 | case TableMap::TYPE_FIELDNAME: |
||
1086 | $key = 'subscriptions'; |
||
1087 | break; |
||
1088 | default: |
||
1089 | $key = 'Subscriptions'; |
||
1090 | } |
||
1091 | |||
1092 | $result[$key] = $this->collSubscriptions->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
1093 | } |
||
1094 | } |
||
1095 | |||
1096 | return $result; |
||
1097 | } |
||
1098 | |||
1099 | /** |
||
1100 | * Sets a field from the object by name passed in as a string. |
||
1101 | * |
||
1102 | * @param string $name |
||
1103 | * @param mixed $value field value |
||
1104 | * @param string $type The type of fieldname the $name is of: |
||
1105 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
1106 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
1107 | * Defaults to TableMap::TYPE_PHPNAME. |
||
1108 | * @return $this|\Jalle19\StatusManager\Database\Input |
||
1109 | */ |
||
1110 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
1111 | { |
||
1112 | $pos = InputTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
1113 | |||
1114 | return $this->setByPosition($pos, $value); |
||
1115 | } |
||
1116 | |||
1117 | /** |
||
1118 | * Sets a field from the object by Position as specified in the xml schema. |
||
1119 | * Zero-based. |
||
1120 | * |
||
1121 | * @param int $pos position in xml schema |
||
1122 | * @param mixed $value field value |
||
1123 | * @return $this|\Jalle19\StatusManager\Database\Input |
||
1124 | */ |
||
1125 | public function setByPosition($pos, $value) |
||
1126 | { |
||
1127 | switch ($pos) { |
||
1128 | case 0: |
||
1129 | $this->setUuid($value); |
||
1130 | break; |
||
1131 | case 1: |
||
1132 | $this->setInstanceName($value); |
||
1133 | break; |
||
1134 | case 2: |
||
1135 | $this->setStarted($value); |
||
1136 | break; |
||
1137 | case 3: |
||
1138 | $this->setInput($value); |
||
1139 | break; |
||
1140 | case 4: |
||
1141 | $this->setNetwork($value); |
||
1142 | break; |
||
1143 | case 5: |
||
1144 | $this->setMux($value); |
||
1145 | break; |
||
1146 | case 6: |
||
1147 | $this->setWeight($value); |
||
1148 | break; |
||
1149 | } // switch() |
||
1150 | |||
1151 | return $this; |
||
1152 | } |
||
1153 | |||
1154 | /** |
||
1155 | * Populates the object using an array. |
||
1156 | * |
||
1157 | * This is particularly useful when populating an object from one of the |
||
1158 | * request arrays (e.g. $_POST). This method goes through the column |
||
1159 | * names, checking to see whether a matching key exists in populated |
||
1160 | * array. If so the setByName() method is called for that column. |
||
1161 | * |
||
1162 | * You can specify the key type of the array by additionally passing one |
||
1163 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
1164 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
1165 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
1166 | * |
||
1167 | * @param array $arr An array to populate the object from. |
||
1168 | * @param string $keyType The type of keys the array uses. |
||
1169 | * @return void |
||
1170 | */ |
||
1171 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
1172 | { |
||
1173 | $keys = InputTableMap::getFieldNames($keyType); |
||
1174 | |||
1175 | if (array_key_exists($keys[0], $arr)) { |
||
1176 | $this->setUuid($arr[$keys[0]]); |
||
1177 | } |
||
1178 | if (array_key_exists($keys[1], $arr)) { |
||
1179 | $this->setInstanceName($arr[$keys[1]]); |
||
1180 | } |
||
1181 | if (array_key_exists($keys[2], $arr)) { |
||
1182 | $this->setStarted($arr[$keys[2]]); |
||
1183 | } |
||
1184 | if (array_key_exists($keys[3], $arr)) { |
||
1185 | $this->setInput($arr[$keys[3]]); |
||
1186 | } |
||
1187 | if (array_key_exists($keys[4], $arr)) { |
||
1188 | $this->setNetwork($arr[$keys[4]]); |
||
1189 | } |
||
1190 | if (array_key_exists($keys[5], $arr)) { |
||
1191 | $this->setMux($arr[$keys[5]]); |
||
1192 | } |
||
1193 | if (array_key_exists($keys[6], $arr)) { |
||
1194 | $this->setWeight($arr[$keys[6]]); |
||
1195 | } |
||
1196 | } |
||
1197 | |||
1198 | /** |
||
1199 | * Populate the current object from a string, using a given parser format |
||
1200 | * <code> |
||
1201 | * $book = new Book(); |
||
1202 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
1203 | * </code> |
||
1204 | * |
||
1205 | * You can specify the key type of the array by additionally passing one |
||
1206 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
1207 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
1208 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
1209 | * |
||
1210 | * @param mixed $parser A AbstractParser instance, |
||
1211 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
1212 | * @param string $data The source data to import from |
||
1213 | * @param string $keyType The type of keys the array uses. |
||
1214 | * |
||
1215 | * @return $this|\Jalle19\StatusManager\Database\Input The current object, for fluid interface |
||
1216 | */ |
||
1217 | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
||
1218 | { |
||
1219 | if (!$parser instanceof AbstractParser) { |
||
1220 | $parser = AbstractParser::getParser($parser); |
||
1221 | } |
||
1222 | |||
1223 | $this->fromArray($parser->toArray($data), $keyType); |
||
1224 | |||
1225 | return $this; |
||
1226 | } |
||
1227 | |||
1228 | /** |
||
1229 | * Build a Criteria object containing the values of all modified columns in this object. |
||
1230 | * |
||
1231 | * @return Criteria The Criteria object containing all modified values. |
||
1232 | */ |
||
1233 | public function buildCriteria() |
||
1234 | { |
||
1235 | $criteria = new Criteria(InputTableMap::DATABASE_NAME); |
||
1236 | |||
1237 | if ($this->isColumnModified(InputTableMap::COL_UUID)) { |
||
1238 | $criteria->add(InputTableMap::COL_UUID, $this->uuid); |
||
1239 | } |
||
1240 | if ($this->isColumnModified(InputTableMap::COL_INSTANCE_NAME)) { |
||
1241 | $criteria->add(InputTableMap::COL_INSTANCE_NAME, $this->instance_name); |
||
1242 | } |
||
1243 | if ($this->isColumnModified(InputTableMap::COL_STARTED)) { |
||
1244 | $criteria->add(InputTableMap::COL_STARTED, $this->started); |
||
1245 | } |
||
1246 | if ($this->isColumnModified(InputTableMap::COL_INPUT)) { |
||
1247 | $criteria->add(InputTableMap::COL_INPUT, $this->input); |
||
1248 | } |
||
1249 | if ($this->isColumnModified(InputTableMap::COL_NETWORK)) { |
||
1250 | $criteria->add(InputTableMap::COL_NETWORK, $this->network); |
||
1251 | } |
||
1252 | if ($this->isColumnModified(InputTableMap::COL_MUX)) { |
||
1253 | $criteria->add(InputTableMap::COL_MUX, $this->mux); |
||
1254 | } |
||
1255 | if ($this->isColumnModified(InputTableMap::COL_WEIGHT)) { |
||
1256 | $criteria->add(InputTableMap::COL_WEIGHT, $this->weight); |
||
1257 | } |
||
1258 | |||
1259 | return $criteria; |
||
1260 | } |
||
1261 | |||
1262 | /** |
||
1263 | * Builds a Criteria object containing the primary key for this object. |
||
1264 | * |
||
1265 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
1266 | * of whether or not they have been modified. |
||
1267 | * |
||
1268 | * @throws LogicException if no primary key is defined |
||
1269 | * |
||
1270 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
1271 | */ |
||
1272 | public function buildPkeyCriteria() |
||
1273 | { |
||
1274 | $criteria = ChildInputQuery::create(); |
||
1275 | $criteria->add(InputTableMap::COL_UUID, $this->uuid); |
||
1276 | |||
1277 | return $criteria; |
||
1278 | } |
||
1279 | |||
1280 | /** |
||
1281 | * If the primary key is not null, return the hashcode of the |
||
1282 | * primary key. Otherwise, return the hash code of the object. |
||
1283 | * |
||
1284 | * @return int Hashcode |
||
1285 | */ |
||
1286 | public function hashCode() |
||
1287 | { |
||
1288 | $validPk = null !== $this->getUuid(); |
||
1289 | |||
1290 | $validPrimaryKeyFKs = 0; |
||
1291 | $primaryKeyFKs = []; |
||
1292 | |||
1293 | if ($validPk) { |
||
1294 | return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); |
||
1295 | } elseif ($validPrimaryKeyFKs) { |
||
1296 | return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); |
||
1297 | } |
||
1298 | |||
1299 | return spl_object_hash($this); |
||
1300 | } |
||
1301 | |||
1302 | /** |
||
1303 | * Returns the primary key for this object (row). |
||
1304 | * @return string |
||
1305 | */ |
||
1306 | public function getPrimaryKey() |
||
1307 | { |
||
1308 | return $this->getUuid(); |
||
1309 | } |
||
1310 | |||
1311 | /** |
||
1312 | * Generic method to set the primary key (uuid column). |
||
1313 | * |
||
1314 | * @param string $key Primary key. |
||
1315 | * @return void |
||
1316 | */ |
||
1317 | public function setPrimaryKey($key) |
||
1318 | { |
||
1319 | $this->setUuid($key); |
||
1320 | } |
||
1321 | |||
1322 | /** |
||
1323 | * Returns true if the primary key for this object is null. |
||
1324 | * @return boolean |
||
1325 | */ |
||
1326 | public function isPrimaryKeyNull() |
||
1327 | { |
||
1328 | return null === $this->getUuid(); |
||
1329 | } |
||
1330 | |||
1331 | /** |
||
1332 | * Sets contents of passed object to values from current object. |
||
1333 | * |
||
1334 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1335 | * objects. |
||
1336 | * |
||
1337 | * @param object $copyObj An object of \Jalle19\StatusManager\Database\Input (or compatible) type. |
||
1338 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1339 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
1340 | * @throws PropelException |
||
1341 | */ |
||
1342 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
1343 | { |
||
1344 | $copyObj->setUuid($this->getUuid()); |
||
1345 | $copyObj->setInstanceName($this->getInstanceName()); |
||
1346 | $copyObj->setStarted($this->getStarted()); |
||
1347 | $copyObj->setInput($this->getInput()); |
||
1348 | $copyObj->setNetwork($this->getNetwork()); |
||
1349 | $copyObj->setMux($this->getMux()); |
||
1350 | $copyObj->setWeight($this->getWeight()); |
||
1351 | |||
1352 | if ($deepCopy) { |
||
1353 | // important: temporarily setNew(false) because this affects the behavior of |
||
1354 | // the getter/setter methods for fkey referrer objects. |
||
1355 | $copyObj->setNew(false); |
||
1356 | |||
1357 | foreach ($this->getSubscriptions() as $relObj) { |
||
1358 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
1359 | $copyObj->addSubscription($relObj->copy($deepCopy)); |
||
1360 | } |
||
1361 | } |
||
1362 | |||
1363 | } // if ($deepCopy) |
||
1364 | |||
1365 | if ($makeNew) { |
||
1366 | $copyObj->setNew(true); |
||
1367 | } |
||
1368 | } |
||
1369 | |||
1370 | /** |
||
1371 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
1372 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
1373 | * keys that are defined for the table. |
||
1374 | * |
||
1375 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
1376 | * objects. |
||
1377 | * |
||
1378 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
1379 | * @return \Jalle19\StatusManager\Database\Input Clone of current object. |
||
1380 | * @throws PropelException |
||
1381 | */ |
||
1382 | public function copy($deepCopy = false) |
||
1383 | { |
||
1384 | // we use get_class(), because this might be a subclass |
||
1385 | $clazz = get_class($this); |
||
1386 | $copyObj = new $clazz(); |
||
1387 | $this->copyInto($copyObj, $deepCopy); |
||
1388 | |||
1389 | return $copyObj; |
||
1390 | } |
||
1391 | |||
1392 | /** |
||
1393 | * Declares an association between this object and a ChildInstance object. |
||
1394 | * |
||
1395 | * @param ChildInstance $v |
||
1396 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
1397 | * @throws PropelException |
||
1398 | */ |
||
1399 | public function setInstance(ChildInstance $v = null) |
||
1400 | { |
||
1401 | if ($v === null) { |
||
1402 | $this->setInstanceName(NULL); |
||
1403 | } else { |
||
1404 | $this->setInstanceName($v->getName()); |
||
1405 | } |
||
1406 | |||
1407 | $this->aInstance = $v; |
||
1408 | |||
1409 | // Add binding for other direction of this n:n relationship. |
||
1410 | // If this object has already been added to the ChildInstance object, it will not be re-added. |
||
1411 | if ($v !== null) { |
||
1412 | $v->addInput($this); |
||
1413 | } |
||
1414 | |||
1415 | |||
1416 | return $this; |
||
1417 | } |
||
1418 | |||
1419 | |||
1420 | /** |
||
1421 | * Get the associated ChildInstance object |
||
1422 | * |
||
1423 | * @param ConnectionInterface $con Optional Connection object. |
||
1424 | * @return ChildInstance The associated ChildInstance object. |
||
1425 | * @throws PropelException |
||
1426 | */ |
||
1427 | public function getInstance(ConnectionInterface $con = null) |
||
1428 | { |
||
1429 | if ($this->aInstance === null && (($this->instance_name !== "" && $this->instance_name !== null))) { |
||
1430 | $this->aInstance = ChildInstanceQuery::create()->findPk($this->instance_name, $con); |
||
1431 | /* The following can be used additionally to |
||
1432 | guarantee the related object contains a reference |
||
1433 | to this object. This level of coupling may, however, be |
||
1434 | undesirable since it could result in an only partially populated collection |
||
1435 | in the referenced object. |
||
1436 | $this->aInstance->addInputs($this); |
||
1437 | */ |
||
1438 | } |
||
1439 | |||
1440 | return $this->aInstance; |
||
1441 | } |
||
1442 | |||
1443 | |||
1444 | /** |
||
1445 | * Initializes a collection based on the name of a relation. |
||
1446 | * Avoids crafting an 'init[$relationName]s' method name |
||
1447 | * that wouldn't work when StandardEnglishPluralizer is used. |
||
1448 | * |
||
1449 | * @param string $relationName The name of the relation to initialize |
||
1450 | * @return void |
||
1451 | */ |
||
1452 | public function initRelation($relationName) |
||
1453 | { |
||
1454 | if ('Subscription' == $relationName) { |
||
1455 | return $this->initSubscriptions(); |
||
1456 | } |
||
1457 | } |
||
1458 | |||
1459 | /** |
||
1460 | * Clears out the collSubscriptions collection |
||
1461 | * |
||
1462 | * This does not modify the database; however, it will remove any associated objects, causing |
||
1463 | * them to be refetched by subsequent calls to accessor method. |
||
1464 | * |
||
1465 | * @return void |
||
1466 | * @see addSubscriptions() |
||
1467 | */ |
||
1468 | public function clearSubscriptions() |
||
1469 | { |
||
1470 | $this->collSubscriptions = null; // important to set this to NULL since that means it is uninitialized |
||
1471 | } |
||
1472 | |||
1473 | /** |
||
1474 | * Reset is the collSubscriptions collection loaded partially. |
||
1475 | */ |
||
1476 | public function resetPartialSubscriptions($v = true) |
||
1477 | { |
||
1478 | $this->collSubscriptionsPartial = $v; |
||
1479 | } |
||
1480 | |||
1481 | /** |
||
1482 | * Initializes the collSubscriptions collection. |
||
1483 | * |
||
1484 | * By default this just sets the collSubscriptions collection to an empty array (like clearcollSubscriptions()); |
||
1485 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
1486 | * to your application -- for example, setting the initial array to the values stored in database. |
||
1487 | * |
||
1488 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
1489 | * the collection even if it is not empty |
||
1490 | * |
||
1491 | * @return void |
||
1492 | */ |
||
1493 | public function initSubscriptions($overrideExisting = true) |
||
1494 | { |
||
1495 | if (null !== $this->collSubscriptions && !$overrideExisting) { |
||
1496 | return; |
||
1497 | } |
||
1498 | |||
1499 | $collectionClassName = SubscriptionTableMap::getTableMap()->getCollectionClassName(); |
||
1500 | |||
1501 | $this->collSubscriptions = new $collectionClassName; |
||
1502 | $this->collSubscriptions->setModel('\Jalle19\StatusManager\Database\Subscription'); |
||
1503 | } |
||
1504 | |||
1505 | /** |
||
1506 | * Gets an array of ChildSubscription objects which contain a foreign key that references this object. |
||
1507 | * |
||
1508 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
1509 | * Otherwise the results are fetched from the database the first time, then cached. |
||
1510 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
1511 | * If this ChildInput is new, it will return |
||
1512 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
1513 | * |
||
1514 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
1515 | * @param ConnectionInterface $con optional connection object |
||
1516 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
1517 | * @throws PropelException |
||
1518 | */ |
||
1519 | public function getSubscriptions(Criteria $criteria = null, ConnectionInterface $con = null) |
||
1520 | { |
||
1521 | $partial = $this->collSubscriptionsPartial && !$this->isNew(); |
||
1522 | if (null === $this->collSubscriptions || null !== $criteria || $partial) { |
||
1523 | if ($this->isNew() && null === $this->collSubscriptions) { |
||
1524 | // return empty collection |
||
1525 | $this->initSubscriptions(); |
||
1526 | } else { |
||
1527 | $collSubscriptions = ChildSubscriptionQuery::create(null, $criteria) |
||
1528 | ->filterByInput($this) |
||
1529 | ->find($con); |
||
1530 | |||
1531 | if (null !== $criteria) { |
||
1532 | if (false !== $this->collSubscriptionsPartial && count($collSubscriptions)) { |
||
1533 | $this->initSubscriptions(false); |
||
1534 | |||
1535 | foreach ($collSubscriptions as $obj) { |
||
1536 | if (false == $this->collSubscriptions->contains($obj)) { |
||
1537 | $this->collSubscriptions->append($obj); |
||
1538 | } |
||
1539 | } |
||
1540 | |||
1541 | $this->collSubscriptionsPartial = true; |
||
1542 | } |
||
1543 | |||
1544 | return $collSubscriptions; |
||
1545 | } |
||
1546 | |||
1547 | if ($partial && $this->collSubscriptions) { |
||
1548 | foreach ($this->collSubscriptions as $obj) { |
||
1549 | if ($obj->isNew()) { |
||
1550 | $collSubscriptions[] = $obj; |
||
1551 | } |
||
1552 | } |
||
1553 | } |
||
1554 | |||
1555 | $this->collSubscriptions = $collSubscriptions; |
||
1556 | $this->collSubscriptionsPartial = false; |
||
1557 | } |
||
1558 | } |
||
1559 | |||
1560 | return $this->collSubscriptions; |
||
1561 | } |
||
1562 | |||
1563 | /** |
||
1564 | * Sets a collection of ChildSubscription objects related by a one-to-many relationship |
||
1565 | * to the current object. |
||
1566 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
1567 | * and new objects from the given Propel collection. |
||
1568 | * |
||
1569 | * @param Collection $subscriptions A Propel collection. |
||
1570 | * @param ConnectionInterface $con Optional connection object |
||
1571 | * @return $this|ChildInput The current object (for fluent API support) |
||
1572 | */ |
||
1573 | public function setSubscriptions(Collection $subscriptions, ConnectionInterface $con = null) |
||
1574 | { |
||
1575 | /** @var ChildSubscription[] $subscriptionsToDelete */ |
||
1576 | $subscriptionsToDelete = $this->getSubscriptions(new Criteria(), $con)->diff($subscriptions); |
||
1577 | |||
1578 | |||
1579 | $this->subscriptionsScheduledForDeletion = $subscriptionsToDelete; |
||
1580 | |||
1581 | foreach ($subscriptionsToDelete as $subscriptionRemoved) { |
||
1582 | $subscriptionRemoved->setInput(null); |
||
1583 | } |
||
1584 | |||
1585 | $this->collSubscriptions = null; |
||
1586 | foreach ($subscriptions as $subscription) { |
||
1587 | $this->addSubscription($subscription); |
||
1588 | } |
||
1589 | |||
1590 | $this->collSubscriptions = $subscriptions; |
||
1591 | $this->collSubscriptionsPartial = false; |
||
1592 | |||
1593 | return $this; |
||
1594 | } |
||
1595 | |||
1596 | /** |
||
1597 | * Returns the number of related Subscription objects. |
||
1598 | * |
||
1599 | * @param Criteria $criteria |
||
1600 | * @param boolean $distinct |
||
1601 | * @param ConnectionInterface $con |
||
1602 | * @return int Count of related Subscription objects. |
||
1603 | * @throws PropelException |
||
1604 | */ |
||
1605 | public function countSubscriptions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
1606 | { |
||
1607 | $partial = $this->collSubscriptionsPartial && !$this->isNew(); |
||
1608 | if (null === $this->collSubscriptions || null !== $criteria || $partial) { |
||
1609 | if ($this->isNew() && null === $this->collSubscriptions) { |
||
1610 | return 0; |
||
1611 | } |
||
1612 | |||
1613 | if ($partial && !$criteria) { |
||
1614 | return count($this->getSubscriptions()); |
||
1615 | } |
||
1616 | |||
1617 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
1618 | if ($distinct) { |
||
1619 | $query->distinct(); |
||
1620 | } |
||
1621 | |||
1622 | return $query |
||
1623 | ->filterByInput($this) |
||
1624 | ->count($con); |
||
1625 | } |
||
1626 | |||
1627 | return count($this->collSubscriptions); |
||
1628 | } |
||
1629 | |||
1630 | /** |
||
1631 | * Method called to associate a ChildSubscription object to this object |
||
1632 | * through the ChildSubscription foreign key attribute. |
||
1633 | * |
||
1634 | * @param ChildSubscription $l ChildSubscription |
||
1635 | * @return $this|\Jalle19\StatusManager\Database\Input The current object (for fluent API support) |
||
1636 | */ |
||
1637 | public function addSubscription(ChildSubscription $l) |
||
1638 | { |
||
1639 | if ($this->collSubscriptions === null) { |
||
1640 | $this->initSubscriptions(); |
||
1641 | $this->collSubscriptionsPartial = true; |
||
1642 | } |
||
1643 | |||
1644 | if (!$this->collSubscriptions->contains($l)) { |
||
1645 | $this->doAddSubscription($l); |
||
1646 | |||
1647 | if ($this->subscriptionsScheduledForDeletion and $this->subscriptionsScheduledForDeletion->contains($l)) { |
||
1648 | $this->subscriptionsScheduledForDeletion->remove($this->subscriptionsScheduledForDeletion->search($l)); |
||
1649 | } |
||
1650 | } |
||
1651 | |||
1652 | return $this; |
||
1653 | } |
||
1654 | |||
1655 | /** |
||
1656 | * @param ChildSubscription $subscription The ChildSubscription object to add. |
||
1657 | */ |
||
1658 | protected function doAddSubscription(ChildSubscription $subscription) |
||
1659 | { |
||
1660 | $this->collSubscriptions[]= $subscription; |
||
1661 | $subscription->setInput($this); |
||
1662 | } |
||
1663 | |||
1664 | /** |
||
1665 | * @param ChildSubscription $subscription The ChildSubscription object to remove. |
||
1666 | * @return $this|ChildInput The current object (for fluent API support) |
||
1667 | */ |
||
1668 | public function removeSubscription(ChildSubscription $subscription) |
||
1669 | { |
||
1670 | if ($this->getSubscriptions()->contains($subscription)) { |
||
1671 | $pos = $this->collSubscriptions->search($subscription); |
||
1672 | $this->collSubscriptions->remove($pos); |
||
1673 | if (null === $this->subscriptionsScheduledForDeletion) { |
||
1674 | $this->subscriptionsScheduledForDeletion = clone $this->collSubscriptions; |
||
1675 | $this->subscriptionsScheduledForDeletion->clear(); |
||
1676 | } |
||
1677 | $this->subscriptionsScheduledForDeletion[]= $subscription; |
||
1678 | $subscription->setInput(null); |
||
1679 | } |
||
1680 | |||
1681 | return $this; |
||
1682 | } |
||
1683 | |||
1684 | |||
1685 | /** |
||
1686 | * If this collection has already been initialized with |
||
1687 | * an identical criteria, it returns the collection. |
||
1688 | * Otherwise if this Input is new, it will return |
||
1689 | * an empty collection; or if this Input has previously |
||
1690 | * been saved, it will retrieve related Subscriptions from storage. |
||
1691 | * |
||
1692 | * This method is protected by default in order to keep the public |
||
1693 | * api reasonable. You can provide public methods for those you |
||
1694 | * actually need in Input. |
||
1695 | * |
||
1696 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
1697 | * @param ConnectionInterface $con optional connection object |
||
1698 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
1699 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
1700 | */ |
||
1701 | public function getSubscriptionsJoinInstance(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
1702 | { |
||
1703 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
1704 | $query->joinWith('Instance', $joinBehavior); |
||
1705 | |||
1706 | return $this->getSubscriptions($query, $con); |
||
1707 | } |
||
1708 | |||
1709 | |||
1710 | /** |
||
1711 | * If this collection has already been initialized with |
||
1712 | * an identical criteria, it returns the collection. |
||
1713 | * Otherwise if this Input is new, it will return |
||
1714 | * an empty collection; or if this Input has previously |
||
1715 | * been saved, it will retrieve related Subscriptions from storage. |
||
1716 | * |
||
1717 | * This method is protected by default in order to keep the public |
||
1718 | * api reasonable. You can provide public methods for those you |
||
1719 | * actually need in Input. |
||
1720 | * |
||
1721 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
1722 | * @param ConnectionInterface $con optional connection object |
||
1723 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
1724 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
1725 | */ |
||
1726 | public function getSubscriptionsJoinUser(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
1727 | { |
||
1728 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
1729 | $query->joinWith('User', $joinBehavior); |
||
1730 | |||
1731 | return $this->getSubscriptions($query, $con); |
||
1732 | } |
||
1733 | |||
1734 | |||
1735 | /** |
||
1736 | * If this collection has already been initialized with |
||
1737 | * an identical criteria, it returns the collection. |
||
1738 | * Otherwise if this Input is new, it will return |
||
1739 | * an empty collection; or if this Input has previously |
||
1740 | * been saved, it will retrieve related Subscriptions from storage. |
||
1741 | * |
||
1742 | * This method is protected by default in order to keep the public |
||
1743 | * api reasonable. You can provide public methods for those you |
||
1744 | * actually need in Input. |
||
1745 | * |
||
1746 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
1747 | * @param ConnectionInterface $con optional connection object |
||
1748 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
1749 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
1750 | */ |
||
1751 | public function getSubscriptionsJoinChannel(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
1752 | { |
||
1753 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
1754 | $query->joinWith('Channel', $joinBehavior); |
||
1755 | |||
1756 | return $this->getSubscriptions($query, $con); |
||
1757 | } |
||
1758 | |||
1759 | /** |
||
1760 | * Clears the current object, sets all attributes to their default values and removes |
||
1761 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
1762 | * change of those foreign objects when you call `save` there). |
||
1763 | */ |
||
1764 | public function clear() |
||
1765 | { |
||
1766 | if (null !== $this->aInstance) { |
||
1767 | $this->aInstance->removeInput($this); |
||
1768 | } |
||
1769 | $this->uuid = null; |
||
1770 | $this->instance_name = null; |
||
1771 | $this->started = null; |
||
1772 | $this->input = null; |
||
1773 | $this->network = null; |
||
1774 | $this->mux = null; |
||
1775 | $this->weight = null; |
||
1776 | $this->alreadyInSave = false; |
||
1777 | $this->clearAllReferences(); |
||
1778 | $this->resetModified(); |
||
1779 | $this->setNew(true); |
||
1780 | $this->setDeleted(false); |
||
1781 | } |
||
1782 | |||
1783 | /** |
||
1784 | * Resets all references and back-references to other model objects or collections of model objects. |
||
1785 | * |
||
1786 | * This method is used to reset all php object references (not the actual reference in the database). |
||
1787 | * Necessary for object serialisation. |
||
1788 | * |
||
1789 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
1790 | */ |
||
1791 | public function clearAllReferences($deep = false) |
||
1792 | { |
||
1793 | if ($deep) { |
||
1794 | if ($this->collSubscriptions) { |
||
1795 | foreach ($this->collSubscriptions as $o) { |
||
1796 | $o->clearAllReferences($deep); |
||
1797 | } |
||
1798 | } |
||
1799 | } // if ($deep) |
||
1800 | |||
1801 | $this->collSubscriptions = null; |
||
1802 | $this->aInstance = null; |
||
1803 | } |
||
1804 | |||
1805 | /** |
||
1806 | * Return the string representation of this object |
||
1807 | * |
||
1808 | * @return string |
||
1809 | */ |
||
1810 | public function __toString() |
||
1811 | { |
||
1812 | return (string) $this->exportTo(InputTableMap::DEFAULT_STRING_FORMAT); |
||
1813 | } |
||
1814 | |||
1815 | /** |
||
1816 | * Code to be run before persisting the object |
||
1817 | * @param ConnectionInterface $con |
||
1818 | * @return boolean |
||
1819 | */ |
||
1820 | public function preSave(ConnectionInterface $con = null) |
||
1821 | { |
||
1822 | return true; |
||
1823 | } |
||
1824 | |||
1825 | /** |
||
1826 | * Code to be run after persisting the object |
||
1827 | * @param ConnectionInterface $con |
||
1828 | */ |
||
1829 | public function postSave(ConnectionInterface $con = null) |
||
1830 | { |
||
1831 | |||
1832 | } |
||
1833 | |||
1834 | /** |
||
1835 | * Code to be run before inserting to database |
||
1836 | * @param ConnectionInterface $con |
||
1837 | * @return boolean |
||
1838 | */ |
||
1839 | public function preInsert(ConnectionInterface $con = null) |
||
1840 | { |
||
1841 | return true; |
||
1842 | } |
||
1843 | |||
1844 | /** |
||
1845 | * Code to be run after inserting to database |
||
1846 | * @param ConnectionInterface $con |
||
1847 | */ |
||
1848 | public function postInsert(ConnectionInterface $con = null) |
||
1849 | { |
||
1850 | |||
1851 | } |
||
1852 | |||
1853 | /** |
||
1854 | * Code to be run before updating the object in database |
||
1855 | * @param ConnectionInterface $con |
||
1856 | * @return boolean |
||
1857 | */ |
||
1858 | public function preUpdate(ConnectionInterface $con = null) |
||
1859 | { |
||
1860 | return true; |
||
1861 | } |
||
1862 | |||
1863 | /** |
||
1864 | * Code to be run after updating the object in database |
||
1865 | * @param ConnectionInterface $con |
||
1866 | */ |
||
1867 | public function postUpdate(ConnectionInterface $con = null) |
||
1868 | { |
||
1869 | |||
1870 | } |
||
1871 | |||
1872 | /** |
||
1873 | * Code to be run before deleting the object in database |
||
1874 | * @param ConnectionInterface $con |
||
1875 | * @return boolean |
||
1876 | */ |
||
1877 | public function preDelete(ConnectionInterface $con = null) |
||
1878 | { |
||
1879 | return true; |
||
1880 | } |
||
1881 | |||
1882 | /** |
||
1883 | * Code to be run after deleting the object in database |
||
1884 | * @param ConnectionInterface $con |
||
1885 | */ |
||
1886 | public function postDelete(ConnectionInterface $con = null) |
||
1887 | { |
||
1888 | |||
1889 | } |
||
1890 | |||
1891 | |||
1892 | /** |
||
1893 | * Derived method to catches calls to undefined methods. |
||
1894 | * |
||
1895 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
1896 | * Allows to define default __call() behavior if you overwrite __call() |
||
1897 | * |
||
1898 | * @param string $name |
||
1899 | * @param mixed $params |
||
1900 | * |
||
1901 | * @return array|string |
||
1902 | */ |
||
1903 | public function __call($name, $params) |
||
1904 | { |
||
1905 | if (0 === strpos($name, 'get')) { |
||
1906 | $virtualColumn = substr($name, 3); |
||
1907 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
1908 | return $this->getVirtualColumn($virtualColumn); |
||
1909 | } |
||
1910 | |||
1911 | $virtualColumn = lcfirst($virtualColumn); |
||
1912 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
1913 | return $this->getVirtualColumn($virtualColumn); |
||
1914 | } |
||
1915 | } |
||
1916 | |||
1917 | if (0 === strpos($name, 'from')) { |
||
1918 | $format = substr($name, 4); |
||
1919 | |||
1920 | return $this->importFrom($format, reset($params)); |
||
1921 | } |
||
1922 | |||
1923 | if (0 === strpos($name, 'to')) { |
||
1924 | $format = substr($name, 2); |
||
1925 | $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; |
||
1926 | |||
1927 | return $this->exportTo($format, $includeLazyLoadColumns); |
||
1928 | } |
||
1929 | |||
1930 | throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); |
||
1931 | } |
||
1932 | |||
1933 | } |
||
1934 |