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