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 Instance 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 Instance, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | abstract class Instance implements ActiveRecordInterface |
||
| 46 | { |
||
| 47 | /** |
||
| 48 | * TableMap class name |
||
| 49 | */ |
||
| 50 | const TABLE_MAP = '\\Jalle19\\StatusManager\\Database\\Map\\InstanceTableMap'; |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * attribute to determine if this object has previously been saved. |
||
| 55 | * @var boolean |
||
| 56 | */ |
||
| 57 | protected $new = true; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * attribute to determine whether this object has been deleted. |
||
| 61 | * @var boolean |
||
| 62 | */ |
||
| 63 | protected $deleted = false; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The columns that have been modified in current object. |
||
| 67 | * Tracking modified columns allows us to only update modified columns. |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $modifiedColumns = array(); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The (virtual) columns that are added at runtime |
||
| 74 | * The formatters can add supplementary columns based on a resultset |
||
| 75 | * @var array |
||
| 76 | */ |
||
| 77 | protected $virtualColumns = array(); |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The value for the name field. |
||
| 81 | * |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | protected $name; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var ObjectCollection|ChildUser[] Collection to store aggregation of ChildUser objects. |
||
| 88 | */ |
||
| 89 | protected $collUsers; |
||
| 90 | protected $collUsersPartial; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var ObjectCollection|ChildConnection[] Collection to store aggregation of ChildConnection objects. |
||
| 94 | */ |
||
| 95 | protected $collConnections; |
||
| 96 | protected $collConnectionsPartial; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var ObjectCollection|ChildInput[] Collection to store aggregation of ChildInput objects. |
||
| 100 | */ |
||
| 101 | protected $collInputs; |
||
| 102 | protected $collInputsPartial; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var ObjectCollection|ChildChannel[] Collection to store aggregation of ChildChannel objects. |
||
| 106 | */ |
||
| 107 | protected $collChannels; |
||
| 108 | protected $collChannelsPartial; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var ObjectCollection|ChildSubscription[] Collection to store aggregation of ChildSubscription objects. |
||
| 112 | */ |
||
| 113 | protected $collSubscriptions; |
||
| 114 | protected $collSubscriptionsPartial; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Flag to prevent endless save loop, if this object is referenced |
||
| 118 | * by another object which falls in this transaction. |
||
| 119 | * |
||
| 120 | * @var boolean |
||
| 121 | */ |
||
| 122 | protected $alreadyInSave = false; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * An array of objects scheduled for deletion. |
||
| 126 | * @var ObjectCollection|ChildUser[] |
||
| 127 | */ |
||
| 128 | protected $usersScheduledForDeletion = null; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * An array of objects scheduled for deletion. |
||
| 132 | * @var ObjectCollection|ChildConnection[] |
||
| 133 | */ |
||
| 134 | protected $connectionsScheduledForDeletion = null; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * An array of objects scheduled for deletion. |
||
| 138 | * @var ObjectCollection|ChildInput[] |
||
| 139 | */ |
||
| 140 | protected $inputsScheduledForDeletion = null; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * An array of objects scheduled for deletion. |
||
| 144 | * @var ObjectCollection|ChildChannel[] |
||
| 145 | */ |
||
| 146 | protected $channelsScheduledForDeletion = null; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * An array of objects scheduled for deletion. |
||
| 150 | * @var ObjectCollection|ChildSubscription[] |
||
| 151 | */ |
||
| 152 | protected $subscriptionsScheduledForDeletion = null; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Initializes internal state of Jalle19\StatusManager\Database\Base\Instance object. |
||
| 156 | */ |
||
| 157 | public function __construct() |
||
| 158 | { |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Returns whether the object has been modified. |
||
| 163 | * |
||
| 164 | * @return boolean True if the object has been modified. |
||
| 165 | */ |
||
| 166 | public function isModified() |
||
| 167 | { |
||
| 168 | return !!$this->modifiedColumns; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Has specified column been modified? |
||
| 173 | * |
||
| 174 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
| 175 | * @return boolean True if $col has been modified. |
||
| 176 | */ |
||
| 177 | public function isColumnModified($col) |
||
| 178 | { |
||
| 179 | return $this->modifiedColumns && isset($this->modifiedColumns[$col]); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Get the columns that have been modified in this object. |
||
| 184 | * @return array A unique list of the modified column names for this object. |
||
| 185 | */ |
||
| 186 | public function getModifiedColumns() |
||
| 187 | { |
||
| 188 | return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Returns whether the object has ever been saved. This will |
||
| 193 | * be false, if the object was retrieved from storage or was created |
||
| 194 | * and then saved. |
||
| 195 | * |
||
| 196 | * @return boolean true, if the object has never been persisted. |
||
| 197 | */ |
||
| 198 | public function isNew() |
||
| 199 | { |
||
| 200 | return $this->new; |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Setter for the isNew attribute. This method will be called |
||
| 205 | * by Propel-generated children and objects. |
||
| 206 | * |
||
| 207 | * @param boolean $b the state of the object. |
||
| 208 | */ |
||
| 209 | public function setNew($b) |
||
| 210 | { |
||
| 211 | $this->new = (boolean) $b; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Whether this object has been deleted. |
||
| 216 | * @return boolean The deleted state of this object. |
||
| 217 | */ |
||
| 218 | public function isDeleted() |
||
| 219 | { |
||
| 220 | return $this->deleted; |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Specify whether this object has been deleted. |
||
| 225 | * @param boolean $b The deleted state of this object. |
||
| 226 | * @return void |
||
| 227 | */ |
||
| 228 | public function setDeleted($b) |
||
| 229 | { |
||
| 230 | $this->deleted = (boolean) $b; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Sets the modified state for the object to be false. |
||
| 235 | * @param string $col If supplied, only the specified column is reset. |
||
| 236 | * @return void |
||
| 237 | */ |
||
| 238 | public function resetModified($col = null) |
||
| 239 | { |
||
| 240 | if (null !== $col) { |
||
| 241 | if (isset($this->modifiedColumns[$col])) { |
||
| 242 | unset($this->modifiedColumns[$col]); |
||
| 243 | } |
||
| 244 | } else { |
||
| 245 | $this->modifiedColumns = array(); |
||
| 246 | } |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Compares this with another <code>Instance</code> instance. If |
||
| 251 | * <code>obj</code> is an instance of <code>Instance</code>, delegates to |
||
| 252 | * <code>equals(Instance)</code>. Otherwise, returns <code>false</code>. |
||
| 253 | * |
||
| 254 | * @param mixed $obj The object to compare to. |
||
| 255 | * @return boolean Whether equal to the object specified. |
||
| 256 | */ |
||
| 257 | public function equals($obj) |
||
| 258 | { |
||
| 259 | if (!$obj instanceof static) { |
||
| 260 | return false; |
||
| 261 | } |
||
| 262 | |||
| 263 | if ($this === $obj) { |
||
| 264 | return true; |
||
| 265 | } |
||
| 266 | |||
| 267 | if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { |
||
| 268 | return false; |
||
| 269 | } |
||
| 270 | |||
| 271 | return $this->getPrimaryKey() === $obj->getPrimaryKey(); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Get the associative array of the virtual columns in this object |
||
| 276 | * |
||
| 277 | * @return array |
||
| 278 | */ |
||
| 279 | public function getVirtualColumns() |
||
| 280 | { |
||
| 281 | return $this->virtualColumns; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Checks the existence of a virtual column in this object |
||
| 286 | * |
||
| 287 | * @param string $name The virtual column name |
||
| 288 | * @return boolean |
||
| 289 | */ |
||
| 290 | public function hasVirtualColumn($name) |
||
| 291 | { |
||
| 292 | return array_key_exists($name, $this->virtualColumns); |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Get the value of a virtual column in this object |
||
| 297 | * |
||
| 298 | * @param string $name The virtual column name |
||
| 299 | * @return mixed |
||
| 300 | * |
||
| 301 | * @throws PropelException |
||
| 302 | */ |
||
| 303 | public function getVirtualColumn($name) |
||
| 304 | { |
||
| 305 | if (!$this->hasVirtualColumn($name)) { |
||
| 306 | throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); |
||
| 307 | } |
||
| 308 | |||
| 309 | return $this->virtualColumns[$name]; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Set the value of a virtual column in this object |
||
| 314 | * |
||
| 315 | * @param string $name The virtual column name |
||
| 316 | * @param mixed $value The value to give to the virtual column |
||
| 317 | * |
||
| 318 | * @return $this|Instance The current object, for fluid interface |
||
| 319 | */ |
||
| 320 | public function setVirtualColumn($name, $value) |
||
| 321 | { |
||
| 322 | $this->virtualColumns[$name] = $value; |
||
| 323 | |||
| 324 | return $this; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Logs a message using Propel::log(). |
||
| 329 | * |
||
| 330 | * @param string $msg |
||
| 331 | * @param int $priority One of the Propel::LOG_* logging levels |
||
| 332 | * @return boolean |
||
| 333 | */ |
||
| 334 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
| 335 | { |
||
| 336 | return Propel::log(get_class($this) . ': ' . $msg, $priority); |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Export the current object properties to a string, using a given parser format |
||
| 341 | * <code> |
||
| 342 | * $book = BookQuery::create()->findPk(9012); |
||
| 343 | * echo $book->exportTo('JSON'); |
||
| 344 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 345 | * </code> |
||
| 346 | * |
||
| 347 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 348 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
| 349 | * @return string The exported data |
||
| 350 | */ |
||
| 351 | public function exportTo($parser, $includeLazyLoadColumns = true) |
||
| 352 | { |
||
| 353 | if (!$parser instanceof AbstractParser) { |
||
| 354 | $parser = AbstractParser::getParser($parser); |
||
| 355 | } |
||
| 356 | |||
| 357 | return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Clean up internal collections prior to serializing |
||
| 362 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
| 363 | */ |
||
| 364 | public function __sleep() |
||
| 365 | { |
||
| 366 | $this->clearAllReferences(); |
||
| 367 | |||
| 368 | $cls = new \ReflectionClass($this); |
||
| 369 | $propertyNames = []; |
||
| 370 | $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); |
||
| 371 | |||
| 372 | foreach($serializableProperties as $property) { |
||
| 373 | $propertyNames[] = $property->getName(); |
||
| 374 | } |
||
| 375 | |||
| 376 | return $propertyNames; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get the [name] column value. |
||
| 381 | * |
||
| 382 | * @return string |
||
| 383 | */ |
||
| 384 | public function getName() |
||
| 385 | { |
||
| 386 | return $this->name; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Set the value of [name] column. |
||
| 391 | * |
||
| 392 | * @param string $v new value |
||
| 393 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 394 | */ |
||
| 395 | public function setName($v) |
||
| 396 | { |
||
| 397 | if ($v !== null) { |
||
| 398 | $v = (string) $v; |
||
| 399 | } |
||
| 400 | |||
| 401 | if ($this->name !== $v) { |
||
| 402 | $this->name = $v; |
||
| 403 | $this->modifiedColumns[InstanceTableMap::COL_NAME] = true; |
||
| 404 | } |
||
| 405 | |||
| 406 | return $this; |
||
| 407 | } // setName() |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Indicates whether the columns in this object are only set to default values. |
||
| 411 | * |
||
| 412 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
| 413 | * modified _and_ has some values set which are non-default. |
||
| 414 | * |
||
| 415 | * @return boolean Whether the columns in this object are only been set with default values. |
||
| 416 | */ |
||
| 417 | public function hasOnlyDefaultValues() |
||
| 418 | { |
||
| 419 | // otherwise, everything was equal, so return TRUE |
||
| 420 | return true; |
||
| 421 | } // hasOnlyDefaultValues() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Hydrates (populates) the object variables with values from the database resultset. |
||
| 425 | * |
||
| 426 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
| 427 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
| 428 | * for results of JOIN queries where the resultset row includes columns from two or |
||
| 429 | * more tables. |
||
| 430 | * |
||
| 431 | * @param array $row The row returned by DataFetcher->fetch(). |
||
| 432 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
| 433 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
| 434 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
| 435 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 436 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 437 | * |
||
| 438 | * @return int next starting column |
||
| 439 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
| 440 | */ |
||
| 441 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
| 442 | { |
||
| 443 | try { |
||
| 444 | |||
| 445 | $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : InstanceTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; |
||
| 446 | $this->name = (null !== $col) ? (string) $col : null; |
||
| 447 | $this->resetModified(); |
||
| 448 | |||
| 449 | $this->setNew(false); |
||
| 450 | |||
| 451 | if ($rehydrate) { |
||
| 452 | $this->ensureConsistency(); |
||
| 453 | } |
||
| 454 | |||
| 455 | return $startcol + 1; // 1 = InstanceTableMap::NUM_HYDRATE_COLUMNS. |
||
| 456 | |||
| 457 | } catch (Exception $e) { |
||
| 458 | throw new PropelException(sprintf('Error populating %s object', '\\Jalle19\\StatusManager\\Database\\Instance'), 0, $e); |
||
| 459 | } |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Checks and repairs the internal consistency of the object. |
||
| 464 | * |
||
| 465 | * This method is executed after an already-instantiated object is re-hydrated |
||
| 466 | * from the database. It exists to check any foreign keys to make sure that |
||
| 467 | * the objects related to the current object are correct based on foreign key. |
||
| 468 | * |
||
| 469 | * You can override this method in the stub class, but you should always invoke |
||
| 470 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
| 471 | * in case your model changes. |
||
| 472 | * |
||
| 473 | * @throws PropelException |
||
| 474 | */ |
||
| 475 | public function ensureConsistency() |
||
| 476 | { |
||
| 477 | } // ensureConsistency |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
| 481 | * |
||
| 482 | * This will only work if the object has been saved and has a valid primary key set. |
||
| 483 | * |
||
| 484 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
| 485 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
| 486 | * @return void |
||
| 487 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
| 488 | */ |
||
| 489 | public function reload($deep = false, ConnectionInterface $con = null) |
||
| 490 | { |
||
| 491 | if ($this->isDeleted()) { |
||
| 492 | throw new PropelException("Cannot reload a deleted object."); |
||
| 493 | } |
||
| 494 | |||
| 495 | if ($this->isNew()) { |
||
| 496 | throw new PropelException("Cannot reload an unsaved object."); |
||
| 497 | } |
||
| 498 | |||
| 499 | if ($con === null) { |
||
| 500 | $con = Propel::getServiceContainer()->getReadConnection(InstanceTableMap::DATABASE_NAME); |
||
| 501 | } |
||
| 502 | |||
| 503 | // We don't need to alter the object instance pool; we're just modifying this instance |
||
| 504 | // already in the pool. |
||
| 505 | |||
| 506 | $dataFetcher = ChildInstanceQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); |
||
| 507 | $row = $dataFetcher->fetch(); |
||
| 508 | $dataFetcher->close(); |
||
| 509 | if (!$row) { |
||
| 510 | throw new PropelException('Cannot find matching row in the database to reload object values.'); |
||
| 511 | } |
||
| 512 | $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate |
||
| 513 | |||
| 514 | if ($deep) { // also de-associate any related objects? |
||
| 515 | |||
| 516 | $this->collUsers = null; |
||
| 517 | |||
| 518 | $this->collConnections = null; |
||
| 519 | |||
| 520 | $this->collInputs = null; |
||
| 521 | |||
| 522 | $this->collChannels = null; |
||
| 523 | |||
| 524 | $this->collSubscriptions = null; |
||
| 525 | |||
| 526 | } // if (deep) |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Removes this object from datastore and sets delete attribute. |
||
| 531 | * |
||
| 532 | * @param ConnectionInterface $con |
||
| 533 | * @return void |
||
| 534 | * @throws PropelException |
||
| 535 | * @see Instance::setDeleted() |
||
| 536 | * @see Instance::isDeleted() |
||
| 537 | */ |
||
| 538 | public function delete(ConnectionInterface $con = null) |
||
| 539 | { |
||
| 540 | if ($this->isDeleted()) { |
||
| 541 | throw new PropelException("This object has already been deleted."); |
||
| 542 | } |
||
| 543 | |||
| 544 | if ($con === null) { |
||
| 545 | $con = Propel::getServiceContainer()->getWriteConnection(InstanceTableMap::DATABASE_NAME); |
||
| 546 | } |
||
| 547 | |||
| 548 | $con->transaction(function () use ($con) { |
||
| 549 | $deleteQuery = ChildInstanceQuery::create() |
||
| 550 | ->filterByPrimaryKey($this->getPrimaryKey()); |
||
| 551 | $ret = $this->preDelete($con); |
||
| 552 | if ($ret) { |
||
| 553 | $deleteQuery->delete($con); |
||
| 554 | $this->postDelete($con); |
||
| 555 | $this->setDeleted(true); |
||
| 556 | } |
||
| 557 | }); |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Persists this object to the database. |
||
| 562 | * |
||
| 563 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 564 | * All modified related objects will also be persisted in the doSave() |
||
| 565 | * method. This method wraps all precipitate database operations in a |
||
| 566 | * single transaction. |
||
| 567 | * |
||
| 568 | * @param ConnectionInterface $con |
||
| 569 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 570 | * @throws PropelException |
||
| 571 | * @see doSave() |
||
| 572 | */ |
||
| 573 | public function save(ConnectionInterface $con = null) |
||
| 574 | { |
||
| 575 | if ($this->isDeleted()) { |
||
| 576 | throw new PropelException("You cannot save an object that has been deleted."); |
||
| 577 | } |
||
| 578 | |||
| 579 | if ($con === null) { |
||
| 580 | $con = Propel::getServiceContainer()->getWriteConnection(InstanceTableMap::DATABASE_NAME); |
||
| 581 | } |
||
| 582 | |||
| 583 | return $con->transaction(function () use ($con) { |
||
| 584 | $isInsert = $this->isNew(); |
||
| 585 | $ret = $this->preSave($con); |
||
| 586 | if ($isInsert) { |
||
| 587 | $ret = $ret && $this->preInsert($con); |
||
| 588 | } else { |
||
| 589 | $ret = $ret && $this->preUpdate($con); |
||
| 590 | } |
||
| 591 | if ($ret) { |
||
| 592 | $affectedRows = $this->doSave($con); |
||
| 593 | if ($isInsert) { |
||
| 594 | $this->postInsert($con); |
||
| 595 | } else { |
||
| 596 | $this->postUpdate($con); |
||
| 597 | } |
||
| 598 | $this->postSave($con); |
||
| 599 | InstanceTableMap::addInstanceToPool($this); |
||
| 600 | } else { |
||
| 601 | $affectedRows = 0; |
||
| 602 | } |
||
| 603 | |||
| 604 | return $affectedRows; |
||
| 605 | }); |
||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Performs the work of inserting or updating the row in the database. |
||
| 610 | * |
||
| 611 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 612 | * All related objects are also updated in this method. |
||
| 613 | * |
||
| 614 | * @param ConnectionInterface $con |
||
| 615 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 616 | * @throws PropelException |
||
| 617 | * @see save() |
||
| 618 | */ |
||
| 619 | protected function doSave(ConnectionInterface $con) |
||
| 620 | { |
||
| 621 | $affectedRows = 0; // initialize var to track total num of affected rows |
||
| 622 | if (!$this->alreadyInSave) { |
||
| 623 | $this->alreadyInSave = true; |
||
| 624 | |||
| 625 | if ($this->isNew() || $this->isModified()) { |
||
| 626 | // persist changes |
||
| 627 | if ($this->isNew()) { |
||
| 628 | $this->doInsert($con); |
||
| 629 | $affectedRows += 1; |
||
| 630 | } else { |
||
| 631 | $affectedRows += $this->doUpdate($con); |
||
| 632 | } |
||
| 633 | $this->resetModified(); |
||
| 634 | } |
||
| 635 | |||
| 636 | if ($this->usersScheduledForDeletion !== null) { |
||
| 637 | if (!$this->usersScheduledForDeletion->isEmpty()) { |
||
| 638 | \Jalle19\StatusManager\Database\UserQuery::create() |
||
| 639 | ->filterByPrimaryKeys($this->usersScheduledForDeletion->getPrimaryKeys(false)) |
||
| 640 | ->delete($con); |
||
| 641 | $this->usersScheduledForDeletion = null; |
||
| 642 | } |
||
| 643 | } |
||
| 644 | |||
| 645 | if ($this->collUsers !== null) { |
||
| 646 | foreach ($this->collUsers as $referrerFK) { |
||
| 647 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
| 648 | $affectedRows += $referrerFK->save($con); |
||
| 649 | } |
||
| 650 | } |
||
| 651 | } |
||
| 652 | |||
| 653 | if ($this->connectionsScheduledForDeletion !== null) { |
||
| 654 | if (!$this->connectionsScheduledForDeletion->isEmpty()) { |
||
| 655 | \Jalle19\StatusManager\Database\ConnectionQuery::create() |
||
| 656 | ->filterByPrimaryKeys($this->connectionsScheduledForDeletion->getPrimaryKeys(false)) |
||
| 657 | ->delete($con); |
||
| 658 | $this->connectionsScheduledForDeletion = null; |
||
| 659 | } |
||
| 660 | } |
||
| 661 | |||
| 662 | if ($this->collConnections !== null) { |
||
| 663 | foreach ($this->collConnections as $referrerFK) { |
||
| 664 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
| 665 | $affectedRows += $referrerFK->save($con); |
||
| 666 | } |
||
| 667 | } |
||
| 668 | } |
||
| 669 | |||
| 670 | if ($this->inputsScheduledForDeletion !== null) { |
||
| 671 | if (!$this->inputsScheduledForDeletion->isEmpty()) { |
||
| 672 | \Jalle19\StatusManager\Database\InputQuery::create() |
||
| 673 | ->filterByPrimaryKeys($this->inputsScheduledForDeletion->getPrimaryKeys(false)) |
||
| 674 | ->delete($con); |
||
| 675 | $this->inputsScheduledForDeletion = null; |
||
| 676 | } |
||
| 677 | } |
||
| 678 | |||
| 679 | if ($this->collInputs !== null) { |
||
| 680 | foreach ($this->collInputs as $referrerFK) { |
||
| 681 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
| 682 | $affectedRows += $referrerFK->save($con); |
||
| 683 | } |
||
| 684 | } |
||
| 685 | } |
||
| 686 | |||
| 687 | if ($this->channelsScheduledForDeletion !== null) { |
||
| 688 | if (!$this->channelsScheduledForDeletion->isEmpty()) { |
||
| 689 | \Jalle19\StatusManager\Database\ChannelQuery::create() |
||
| 690 | ->filterByPrimaryKeys($this->channelsScheduledForDeletion->getPrimaryKeys(false)) |
||
| 691 | ->delete($con); |
||
| 692 | $this->channelsScheduledForDeletion = null; |
||
| 693 | } |
||
| 694 | } |
||
| 695 | |||
| 696 | if ($this->collChannels !== null) { |
||
| 697 | foreach ($this->collChannels as $referrerFK) { |
||
| 698 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
| 699 | $affectedRows += $referrerFK->save($con); |
||
| 700 | } |
||
| 701 | } |
||
| 702 | } |
||
| 703 | |||
| 704 | if ($this->subscriptionsScheduledForDeletion !== null) { |
||
| 705 | if (!$this->subscriptionsScheduledForDeletion->isEmpty()) { |
||
| 706 | \Jalle19\StatusManager\Database\SubscriptionQuery::create() |
||
| 707 | ->filterByPrimaryKeys($this->subscriptionsScheduledForDeletion->getPrimaryKeys(false)) |
||
| 708 | ->delete($con); |
||
| 709 | $this->subscriptionsScheduledForDeletion = null; |
||
| 710 | } |
||
| 711 | } |
||
| 712 | |||
| 713 | if ($this->collSubscriptions !== null) { |
||
| 714 | foreach ($this->collSubscriptions as $referrerFK) { |
||
| 715 | if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { |
||
| 716 | $affectedRows += $referrerFK->save($con); |
||
| 717 | } |
||
| 718 | } |
||
| 719 | } |
||
| 720 | |||
| 721 | $this->alreadyInSave = false; |
||
| 722 | |||
| 723 | } |
||
| 724 | |||
| 725 | return $affectedRows; |
||
| 726 | } // doSave() |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Insert the row in the database. |
||
| 730 | * |
||
| 731 | * @param ConnectionInterface $con |
||
| 732 | * |
||
| 733 | * @throws PropelException |
||
| 734 | * @see doSave() |
||
| 735 | */ |
||
| 736 | protected function doInsert(ConnectionInterface $con) |
||
| 737 | { |
||
| 738 | $modifiedColumns = array(); |
||
| 739 | $index = 0; |
||
| 740 | |||
| 741 | |||
| 742 | // check the columns in natural order for more readable SQL queries |
||
| 743 | if ($this->isColumnModified(InstanceTableMap::COL_NAME)) { |
||
| 744 | $modifiedColumns[':p' . $index++] = 'name'; |
||
| 745 | } |
||
| 746 | |||
| 747 | $sql = sprintf( |
||
| 748 | 'INSERT INTO instance (%s) VALUES (%s)', |
||
| 749 | implode(', ', $modifiedColumns), |
||
| 750 | implode(', ', array_keys($modifiedColumns)) |
||
| 751 | ); |
||
| 752 | |||
| 753 | try { |
||
| 754 | $stmt = $con->prepare($sql); |
||
| 755 | foreach ($modifiedColumns as $identifier => $columnName) { |
||
| 756 | switch ($columnName) { |
||
| 757 | case 'name': |
||
| 758 | $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); |
||
| 759 | break; |
||
| 760 | } |
||
| 761 | } |
||
| 762 | $stmt->execute(); |
||
| 763 | } catch (Exception $e) { |
||
| 764 | Propel::log($e->getMessage(), Propel::LOG_ERR); |
||
| 765 | throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); |
||
| 766 | } |
||
| 767 | |||
| 768 | $this->setNew(false); |
||
| 769 | } |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Update the row in the database. |
||
| 773 | * |
||
| 774 | * @param ConnectionInterface $con |
||
| 775 | * |
||
| 776 | * @return Integer Number of updated rows |
||
| 777 | * @see doSave() |
||
| 778 | */ |
||
| 779 | protected function doUpdate(ConnectionInterface $con) |
||
| 780 | { |
||
| 781 | $selectCriteria = $this->buildPkeyCriteria(); |
||
| 782 | $valuesCriteria = $this->buildCriteria(); |
||
| 783 | |||
| 784 | return $selectCriteria->doUpdate($valuesCriteria, $con); |
||
| 785 | } |
||
| 786 | |||
| 787 | /** |
||
| 788 | * Retrieves a field from the object by name passed in as a string. |
||
| 789 | * |
||
| 790 | * @param string $name name |
||
| 791 | * @param string $type The type of fieldname the $name is of: |
||
| 792 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 793 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 794 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 795 | * @return mixed Value of field. |
||
| 796 | */ |
||
| 797 | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
||
| 798 | { |
||
| 799 | $pos = InstanceTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
| 800 | $field = $this->getByPosition($pos); |
||
| 801 | |||
| 802 | return $field; |
||
| 803 | } |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
| 807 | * Zero-based. |
||
| 808 | * |
||
| 809 | * @param int $pos position in xml schema |
||
| 810 | * @return mixed Value of field at $pos |
||
| 811 | */ |
||
| 812 | public function getByPosition($pos) |
||
| 813 | { |
||
| 814 | switch ($pos) { |
||
| 815 | case 0: |
||
| 816 | return $this->getName(); |
||
| 817 | break; |
||
| 818 | default: |
||
| 819 | return null; |
||
| 820 | break; |
||
| 821 | } // switch() |
||
| 822 | } |
||
| 823 | |||
| 824 | /** |
||
| 825 | * Exports the object as an array. |
||
| 826 | * |
||
| 827 | * You can specify the key type of the array by passing one of the class |
||
| 828 | * type constants. |
||
| 829 | * |
||
| 830 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 831 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 832 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 833 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
| 834 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
| 835 | * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. |
||
| 836 | * |
||
| 837 | * @return array an associative array containing the field names (as keys) and field values |
||
| 838 | */ |
||
| 839 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) |
||
| 840 | { |
||
| 841 | |||
| 842 | if (isset($alreadyDumpedObjects['Instance'][$this->hashCode()])) { |
||
| 843 | return '*RECURSION*'; |
||
| 844 | } |
||
| 845 | $alreadyDumpedObjects['Instance'][$this->hashCode()] = true; |
||
| 846 | $keys = InstanceTableMap::getFieldNames($keyType); |
||
| 847 | $result = array( |
||
| 848 | $keys[0] => $this->getName(), |
||
| 849 | ); |
||
| 850 | $virtualColumns = $this->virtualColumns; |
||
| 851 | foreach ($virtualColumns as $key => $virtualColumn) { |
||
| 852 | $result[$key] = $virtualColumn; |
||
| 853 | } |
||
| 854 | |||
| 855 | if ($includeForeignObjects) { |
||
| 856 | if (null !== $this->collUsers) { |
||
| 857 | |||
| 858 | switch ($keyType) { |
||
| 859 | case TableMap::TYPE_CAMELNAME: |
||
| 860 | $key = 'users'; |
||
| 861 | break; |
||
| 862 | case TableMap::TYPE_FIELDNAME: |
||
| 863 | $key = 'users'; |
||
| 864 | break; |
||
| 865 | default: |
||
| 866 | $key = 'Users'; |
||
| 867 | } |
||
| 868 | |||
| 869 | $result[$key] = $this->collUsers->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
| 870 | } |
||
| 871 | if (null !== $this->collConnections) { |
||
| 872 | |||
| 873 | switch ($keyType) { |
||
| 874 | case TableMap::TYPE_CAMELNAME: |
||
| 875 | $key = 'connections'; |
||
| 876 | break; |
||
| 877 | case TableMap::TYPE_FIELDNAME: |
||
| 878 | $key = 'connections'; |
||
| 879 | break; |
||
| 880 | default: |
||
| 881 | $key = 'Connections'; |
||
| 882 | } |
||
| 883 | |||
| 884 | $result[$key] = $this->collConnections->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
| 885 | } |
||
| 886 | if (null !== $this->collInputs) { |
||
| 887 | |||
| 888 | switch ($keyType) { |
||
| 889 | case TableMap::TYPE_CAMELNAME: |
||
| 890 | $key = 'inputs'; |
||
| 891 | break; |
||
| 892 | case TableMap::TYPE_FIELDNAME: |
||
| 893 | $key = 'inputs'; |
||
| 894 | break; |
||
| 895 | default: |
||
| 896 | $key = 'Inputs'; |
||
| 897 | } |
||
| 898 | |||
| 899 | $result[$key] = $this->collInputs->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
| 900 | } |
||
| 901 | if (null !== $this->collChannels) { |
||
| 902 | |||
| 903 | switch ($keyType) { |
||
| 904 | case TableMap::TYPE_CAMELNAME: |
||
| 905 | $key = 'channels'; |
||
| 906 | break; |
||
| 907 | case TableMap::TYPE_FIELDNAME: |
||
| 908 | $key = 'channels'; |
||
| 909 | break; |
||
| 910 | default: |
||
| 911 | $key = 'Channels'; |
||
| 912 | } |
||
| 913 | |||
| 914 | $result[$key] = $this->collChannels->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
| 915 | } |
||
| 916 | if (null !== $this->collSubscriptions) { |
||
| 917 | |||
| 918 | switch ($keyType) { |
||
| 919 | case TableMap::TYPE_CAMELNAME: |
||
| 920 | $key = 'subscriptions'; |
||
| 921 | break; |
||
| 922 | case TableMap::TYPE_FIELDNAME: |
||
| 923 | $key = 'subscriptions'; |
||
| 924 | break; |
||
| 925 | default: |
||
| 926 | $key = 'Subscriptions'; |
||
| 927 | } |
||
| 928 | |||
| 929 | $result[$key] = $this->collSubscriptions->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); |
||
| 930 | } |
||
| 931 | } |
||
| 932 | |||
| 933 | return $result; |
||
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Sets a field from the object by name passed in as a string. |
||
| 938 | * |
||
| 939 | * @param string $name |
||
| 940 | * @param mixed $value field value |
||
| 941 | * @param string $type The type of fieldname the $name is of: |
||
| 942 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 943 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 944 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 945 | * @return $this|\Jalle19\StatusManager\Database\Instance |
||
| 946 | */ |
||
| 947 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
| 948 | { |
||
| 949 | $pos = InstanceTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); |
||
| 950 | |||
| 951 | return $this->setByPosition($pos, $value); |
||
| 952 | } |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Sets a field from the object by Position as specified in the xml schema. |
||
| 956 | * Zero-based. |
||
| 957 | * |
||
| 958 | * @param int $pos position in xml schema |
||
| 959 | * @param mixed $value field value |
||
| 960 | * @return $this|\Jalle19\StatusManager\Database\Instance |
||
| 961 | */ |
||
| 962 | public function setByPosition($pos, $value) |
||
| 963 | { |
||
| 964 | switch ($pos) { |
||
| 965 | case 0: |
||
| 966 | $this->setName($value); |
||
| 967 | break; |
||
| 968 | } // switch() |
||
| 969 | |||
| 970 | return $this; |
||
| 971 | } |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Populates the object using an array. |
||
| 975 | * |
||
| 976 | * This is particularly useful when populating an object from one of the |
||
| 977 | * request arrays (e.g. $_POST). This method goes through the column |
||
| 978 | * names, checking to see whether a matching key exists in populated |
||
| 979 | * array. If so the setByName() method is called for that column. |
||
| 980 | * |
||
| 981 | * You can specify the key type of the array by additionally passing one |
||
| 982 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 983 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 984 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 985 | * |
||
| 986 | * @param array $arr An array to populate the object from. |
||
| 987 | * @param string $keyType The type of keys the array uses. |
||
| 988 | * @return void |
||
| 989 | */ |
||
| 990 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
| 991 | { |
||
| 992 | $keys = InstanceTableMap::getFieldNames($keyType); |
||
| 993 | |||
| 994 | if (array_key_exists($keys[0], $arr)) { |
||
| 995 | $this->setName($arr[$keys[0]]); |
||
| 996 | } |
||
| 997 | } |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Populate the current object from a string, using a given parser format |
||
| 1001 | * <code> |
||
| 1002 | * $book = new Book(); |
||
| 1003 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 1004 | * </code> |
||
| 1005 | * |
||
| 1006 | * You can specify the key type of the array by additionally passing one |
||
| 1007 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1008 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1009 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1010 | * |
||
| 1011 | * @param mixed $parser A AbstractParser instance, |
||
| 1012 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 1013 | * @param string $data The source data to import from |
||
| 1014 | * @param string $keyType The type of keys the array uses. |
||
| 1015 | * |
||
| 1016 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object, for fluid interface |
||
| 1017 | */ |
||
| 1018 | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
||
| 1019 | { |
||
| 1020 | if (!$parser instanceof AbstractParser) { |
||
| 1021 | $parser = AbstractParser::getParser($parser); |
||
| 1022 | } |
||
| 1023 | |||
| 1024 | $this->fromArray($parser->toArray($data), $keyType); |
||
| 1025 | |||
| 1026 | return $this; |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Build a Criteria object containing the values of all modified columns in this object. |
||
| 1031 | * |
||
| 1032 | * @return Criteria The Criteria object containing all modified values. |
||
| 1033 | */ |
||
| 1034 | public function buildCriteria() |
||
| 1035 | { |
||
| 1036 | $criteria = new Criteria(InstanceTableMap::DATABASE_NAME); |
||
| 1037 | |||
| 1038 | if ($this->isColumnModified(InstanceTableMap::COL_NAME)) { |
||
| 1039 | $criteria->add(InstanceTableMap::COL_NAME, $this->name); |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | return $criteria; |
||
| 1043 | } |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Builds a Criteria object containing the primary key for this object. |
||
| 1047 | * |
||
| 1048 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
| 1049 | * of whether or not they have been modified. |
||
| 1050 | * |
||
| 1051 | * @throws LogicException if no primary key is defined |
||
| 1052 | * |
||
| 1053 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
| 1054 | */ |
||
| 1055 | public function buildPkeyCriteria() |
||
| 1056 | { |
||
| 1057 | $criteria = ChildInstanceQuery::create(); |
||
| 1058 | $criteria->add(InstanceTableMap::COL_NAME, $this->name); |
||
| 1059 | |||
| 1060 | return $criteria; |
||
| 1061 | } |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * If the primary key is not null, return the hashcode of the |
||
| 1065 | * primary key. Otherwise, return the hash code of the object. |
||
| 1066 | * |
||
| 1067 | * @return int Hashcode |
||
| 1068 | */ |
||
| 1069 | public function hashCode() |
||
| 1070 | { |
||
| 1071 | $validPk = null !== $this->getName(); |
||
| 1072 | |||
| 1073 | $validPrimaryKeyFKs = 0; |
||
| 1074 | $primaryKeyFKs = []; |
||
| 1075 | |||
| 1076 | if ($validPk) { |
||
| 1077 | return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); |
||
| 1078 | } elseif ($validPrimaryKeyFKs) { |
||
| 1079 | return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | return spl_object_hash($this); |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Returns the primary key for this object (row). |
||
| 1087 | * @return string |
||
| 1088 | */ |
||
| 1089 | public function getPrimaryKey() |
||
| 1090 | { |
||
| 1091 | return $this->getName(); |
||
| 1092 | } |
||
| 1093 | |||
| 1094 | /** |
||
| 1095 | * Generic method to set the primary key (name column). |
||
| 1096 | * |
||
| 1097 | * @param string $key Primary key. |
||
| 1098 | * @return void |
||
| 1099 | */ |
||
| 1100 | public function setPrimaryKey($key) |
||
| 1101 | { |
||
| 1102 | $this->setName($key); |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Returns true if the primary key for this object is null. |
||
| 1107 | * @return boolean |
||
| 1108 | */ |
||
| 1109 | public function isPrimaryKeyNull() |
||
| 1110 | { |
||
| 1111 | return null === $this->getName(); |
||
| 1112 | } |
||
| 1113 | |||
| 1114 | /** |
||
| 1115 | * Sets contents of passed object to values from current object. |
||
| 1116 | * |
||
| 1117 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1118 | * objects. |
||
| 1119 | * |
||
| 1120 | * @param object $copyObj An object of \Jalle19\StatusManager\Database\Instance (or compatible) type. |
||
| 1121 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1122 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
| 1123 | * @throws PropelException |
||
| 1124 | */ |
||
| 1125 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
| 1126 | { |
||
| 1127 | $copyObj->setName($this->getName()); |
||
| 1128 | |||
| 1129 | if ($deepCopy) { |
||
| 1130 | // important: temporarily setNew(false) because this affects the behavior of |
||
| 1131 | // the getter/setter methods for fkey referrer objects. |
||
| 1132 | $copyObj->setNew(false); |
||
| 1133 | |||
| 1134 | foreach ($this->getUsers() as $relObj) { |
||
| 1135 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
| 1136 | $copyObj->addUser($relObj->copy($deepCopy)); |
||
| 1137 | } |
||
| 1138 | } |
||
| 1139 | |||
| 1140 | foreach ($this->getConnections() as $relObj) { |
||
| 1141 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
| 1142 | $copyObj->addConnection($relObj->copy($deepCopy)); |
||
| 1143 | } |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | foreach ($this->getInputs() as $relObj) { |
||
| 1147 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
| 1148 | $copyObj->addInput($relObj->copy($deepCopy)); |
||
| 1149 | } |
||
| 1150 | } |
||
| 1151 | |||
| 1152 | foreach ($this->getChannels() as $relObj) { |
||
| 1153 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
| 1154 | $copyObj->addChannel($relObj->copy($deepCopy)); |
||
| 1155 | } |
||
| 1156 | } |
||
| 1157 | |||
| 1158 | foreach ($this->getSubscriptions() as $relObj) { |
||
| 1159 | if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves |
||
| 1160 | $copyObj->addSubscription($relObj->copy($deepCopy)); |
||
| 1161 | } |
||
| 1162 | } |
||
| 1163 | |||
| 1164 | } // if ($deepCopy) |
||
| 1165 | |||
| 1166 | if ($makeNew) { |
||
| 1167 | $copyObj->setNew(true); |
||
| 1168 | } |
||
| 1169 | } |
||
| 1170 | |||
| 1171 | /** |
||
| 1172 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
| 1173 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
| 1174 | * keys that are defined for the table. |
||
| 1175 | * |
||
| 1176 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1177 | * objects. |
||
| 1178 | * |
||
| 1179 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1180 | * @return \Jalle19\StatusManager\Database\Instance Clone of current object. |
||
| 1181 | * @throws PropelException |
||
| 1182 | */ |
||
| 1183 | public function copy($deepCopy = false) |
||
| 1184 | { |
||
| 1185 | // we use get_class(), because this might be a subclass |
||
| 1186 | $clazz = get_class($this); |
||
| 1187 | $copyObj = new $clazz(); |
||
| 1188 | $this->copyInto($copyObj, $deepCopy); |
||
| 1189 | |||
| 1190 | return $copyObj; |
||
| 1191 | } |
||
| 1192 | |||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Initializes a collection based on the name of a relation. |
||
| 1196 | * Avoids crafting an 'init[$relationName]s' method name |
||
| 1197 | * that wouldn't work when StandardEnglishPluralizer is used. |
||
| 1198 | * |
||
| 1199 | * @param string $relationName The name of the relation to initialize |
||
| 1200 | * @return void |
||
| 1201 | */ |
||
| 1202 | public function initRelation($relationName) |
||
| 1203 | { |
||
| 1204 | if ('User' == $relationName) { |
||
| 1205 | return $this->initUsers(); |
||
| 1206 | } |
||
| 1207 | if ('Connection' == $relationName) { |
||
| 1208 | return $this->initConnections(); |
||
| 1209 | } |
||
| 1210 | if ('Input' == $relationName) { |
||
| 1211 | return $this->initInputs(); |
||
| 1212 | } |
||
| 1213 | if ('Channel' == $relationName) { |
||
| 1214 | return $this->initChannels(); |
||
| 1215 | } |
||
| 1216 | if ('Subscription' == $relationName) { |
||
| 1217 | return $this->initSubscriptions(); |
||
| 1218 | } |
||
| 1219 | } |
||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Clears out the collUsers collection |
||
| 1223 | * |
||
| 1224 | * This does not modify the database; however, it will remove any associated objects, causing |
||
| 1225 | * them to be refetched by subsequent calls to accessor method. |
||
| 1226 | * |
||
| 1227 | * @return void |
||
| 1228 | * @see addUsers() |
||
| 1229 | */ |
||
| 1230 | public function clearUsers() |
||
| 1231 | { |
||
| 1232 | $this->collUsers = null; // important to set this to NULL since that means it is uninitialized |
||
| 1233 | } |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Reset is the collUsers collection loaded partially. |
||
| 1237 | */ |
||
| 1238 | public function resetPartialUsers($v = true) |
||
| 1239 | { |
||
| 1240 | $this->collUsersPartial = $v; |
||
| 1241 | } |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Initializes the collUsers collection. |
||
| 1245 | * |
||
| 1246 | * By default this just sets the collUsers collection to an empty array (like clearcollUsers()); |
||
| 1247 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
| 1248 | * to your application -- for example, setting the initial array to the values stored in database. |
||
| 1249 | * |
||
| 1250 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
| 1251 | * the collection even if it is not empty |
||
| 1252 | * |
||
| 1253 | * @return void |
||
| 1254 | */ |
||
| 1255 | public function initUsers($overrideExisting = true) |
||
| 1256 | { |
||
| 1257 | if (null !== $this->collUsers && !$overrideExisting) { |
||
| 1258 | return; |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | $collectionClassName = UserTableMap::getTableMap()->getCollectionClassName(); |
||
| 1262 | |||
| 1263 | $this->collUsers = new $collectionClassName; |
||
| 1264 | $this->collUsers->setModel('\Jalle19\StatusManager\Database\User'); |
||
| 1265 | } |
||
| 1266 | |||
| 1267 | /** |
||
| 1268 | * Gets an array of ChildUser objects which contain a foreign key that references this object. |
||
| 1269 | * |
||
| 1270 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
| 1271 | * Otherwise the results are fetched from the database the first time, then cached. |
||
| 1272 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
| 1273 | * If this ChildInstance is new, it will return |
||
| 1274 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
| 1275 | * |
||
| 1276 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 1277 | * @param ConnectionInterface $con optional connection object |
||
| 1278 | * @return ObjectCollection|ChildUser[] List of ChildUser objects |
||
| 1279 | * @throws PropelException |
||
| 1280 | */ |
||
| 1281 | public function getUsers(Criteria $criteria = null, ConnectionInterface $con = null) |
||
| 1282 | { |
||
| 1283 | $partial = $this->collUsersPartial && !$this->isNew(); |
||
| 1284 | if (null === $this->collUsers || null !== $criteria || $partial) { |
||
| 1285 | if ($this->isNew() && null === $this->collUsers) { |
||
| 1286 | // return empty collection |
||
| 1287 | $this->initUsers(); |
||
| 1288 | } else { |
||
| 1289 | $collUsers = ChildUserQuery::create(null, $criteria) |
||
| 1290 | ->filterByInstance($this) |
||
| 1291 | ->find($con); |
||
| 1292 | |||
| 1293 | if (null !== $criteria) { |
||
| 1294 | if (false !== $this->collUsersPartial && count($collUsers)) { |
||
| 1295 | $this->initUsers(false); |
||
| 1296 | |||
| 1297 | foreach ($collUsers as $obj) { |
||
| 1298 | if (false == $this->collUsers->contains($obj)) { |
||
| 1299 | $this->collUsers->append($obj); |
||
| 1300 | } |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | $this->collUsersPartial = true; |
||
| 1304 | } |
||
| 1305 | |||
| 1306 | return $collUsers; |
||
| 1307 | } |
||
| 1308 | |||
| 1309 | if ($partial && $this->collUsers) { |
||
| 1310 | foreach ($this->collUsers as $obj) { |
||
| 1311 | if ($obj->isNew()) { |
||
| 1312 | $collUsers[] = $obj; |
||
| 1313 | } |
||
| 1314 | } |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | $this->collUsers = $collUsers; |
||
| 1318 | $this->collUsersPartial = false; |
||
| 1319 | } |
||
| 1320 | } |
||
| 1321 | |||
| 1322 | return $this->collUsers; |
||
| 1323 | } |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Sets a collection of ChildUser objects related by a one-to-many relationship |
||
| 1327 | * to the current object. |
||
| 1328 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
| 1329 | * and new objects from the given Propel collection. |
||
| 1330 | * |
||
| 1331 | * @param Collection $users A Propel collection. |
||
| 1332 | * @param ConnectionInterface $con Optional connection object |
||
| 1333 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1334 | */ |
||
| 1335 | public function setUsers(Collection $users, ConnectionInterface $con = null) |
||
| 1336 | { |
||
| 1337 | /** @var ChildUser[] $usersToDelete */ |
||
| 1338 | $usersToDelete = $this->getUsers(new Criteria(), $con)->diff($users); |
||
| 1339 | |||
| 1340 | |||
| 1341 | $this->usersScheduledForDeletion = $usersToDelete; |
||
| 1342 | |||
| 1343 | foreach ($usersToDelete as $userRemoved) { |
||
| 1344 | $userRemoved->setInstance(null); |
||
| 1345 | } |
||
| 1346 | |||
| 1347 | $this->collUsers = null; |
||
| 1348 | foreach ($users as $user) { |
||
| 1349 | $this->addUser($user); |
||
| 1350 | } |
||
| 1351 | |||
| 1352 | $this->collUsers = $users; |
||
| 1353 | $this->collUsersPartial = false; |
||
| 1354 | |||
| 1355 | return $this; |
||
| 1356 | } |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Returns the number of related User objects. |
||
| 1360 | * |
||
| 1361 | * @param Criteria $criteria |
||
| 1362 | * @param boolean $distinct |
||
| 1363 | * @param ConnectionInterface $con |
||
| 1364 | * @return int Count of related User objects. |
||
| 1365 | * @throws PropelException |
||
| 1366 | */ |
||
| 1367 | public function countUsers(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
| 1368 | { |
||
| 1369 | $partial = $this->collUsersPartial && !$this->isNew(); |
||
| 1370 | if (null === $this->collUsers || null !== $criteria || $partial) { |
||
| 1371 | if ($this->isNew() && null === $this->collUsers) { |
||
| 1372 | return 0; |
||
| 1373 | } |
||
| 1374 | |||
| 1375 | if ($partial && !$criteria) { |
||
| 1376 | return count($this->getUsers()); |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | $query = ChildUserQuery::create(null, $criteria); |
||
| 1380 | if ($distinct) { |
||
| 1381 | $query->distinct(); |
||
| 1382 | } |
||
| 1383 | |||
| 1384 | return $query |
||
| 1385 | ->filterByInstance($this) |
||
| 1386 | ->count($con); |
||
| 1387 | } |
||
| 1388 | |||
| 1389 | return count($this->collUsers); |
||
| 1390 | } |
||
| 1391 | |||
| 1392 | /** |
||
| 1393 | * Method called to associate a ChildUser object to this object |
||
| 1394 | * through the ChildUser foreign key attribute. |
||
| 1395 | * |
||
| 1396 | * @param ChildUser $l ChildUser |
||
| 1397 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 1398 | */ |
||
| 1399 | public function addUser(ChildUser $l) |
||
| 1400 | { |
||
| 1401 | if ($this->collUsers === null) { |
||
| 1402 | $this->initUsers(); |
||
| 1403 | $this->collUsersPartial = true; |
||
| 1404 | } |
||
| 1405 | |||
| 1406 | if (!$this->collUsers->contains($l)) { |
||
| 1407 | $this->doAddUser($l); |
||
| 1408 | |||
| 1409 | if ($this->usersScheduledForDeletion and $this->usersScheduledForDeletion->contains($l)) { |
||
| 1410 | $this->usersScheduledForDeletion->remove($this->usersScheduledForDeletion->search($l)); |
||
| 1411 | } |
||
| 1412 | } |
||
| 1413 | |||
| 1414 | return $this; |
||
| 1415 | } |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * @param ChildUser $user The ChildUser object to add. |
||
| 1419 | */ |
||
| 1420 | protected function doAddUser(ChildUser $user) |
||
| 1421 | { |
||
| 1422 | $this->collUsers[]= $user; |
||
| 1423 | $user->setInstance($this); |
||
| 1424 | } |
||
| 1425 | |||
| 1426 | /** |
||
| 1427 | * @param ChildUser $user The ChildUser object to remove. |
||
| 1428 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1429 | */ |
||
| 1430 | public function removeUser(ChildUser $user) |
||
| 1431 | { |
||
| 1432 | if ($this->getUsers()->contains($user)) { |
||
| 1433 | $pos = $this->collUsers->search($user); |
||
| 1434 | $this->collUsers->remove($pos); |
||
| 1435 | if (null === $this->usersScheduledForDeletion) { |
||
| 1436 | $this->usersScheduledForDeletion = clone $this->collUsers; |
||
| 1437 | $this->usersScheduledForDeletion->clear(); |
||
| 1438 | } |
||
| 1439 | $this->usersScheduledForDeletion[]= clone $user; |
||
| 1440 | $user->setInstance(null); |
||
| 1441 | } |
||
| 1442 | |||
| 1443 | return $this; |
||
| 1444 | } |
||
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Clears out the collConnections collection |
||
| 1448 | * |
||
| 1449 | * This does not modify the database; however, it will remove any associated objects, causing |
||
| 1450 | * them to be refetched by subsequent calls to accessor method. |
||
| 1451 | * |
||
| 1452 | * @return void |
||
| 1453 | * @see addConnections() |
||
| 1454 | */ |
||
| 1455 | public function clearConnections() |
||
| 1456 | { |
||
| 1457 | $this->collConnections = null; // important to set this to NULL since that means it is uninitialized |
||
| 1458 | } |
||
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Reset is the collConnections collection loaded partially. |
||
| 1462 | */ |
||
| 1463 | public function resetPartialConnections($v = true) |
||
| 1464 | { |
||
| 1465 | $this->collConnectionsPartial = $v; |
||
| 1466 | } |
||
| 1467 | |||
| 1468 | /** |
||
| 1469 | * Initializes the collConnections collection. |
||
| 1470 | * |
||
| 1471 | * By default this just sets the collConnections collection to an empty array (like clearcollConnections()); |
||
| 1472 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
| 1473 | * to your application -- for example, setting the initial array to the values stored in database. |
||
| 1474 | * |
||
| 1475 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
| 1476 | * the collection even if it is not empty |
||
| 1477 | * |
||
| 1478 | * @return void |
||
| 1479 | */ |
||
| 1480 | public function initConnections($overrideExisting = true) |
||
| 1481 | { |
||
| 1482 | if (null !== $this->collConnections && !$overrideExisting) { |
||
| 1483 | return; |
||
| 1484 | } |
||
| 1485 | |||
| 1486 | $collectionClassName = ConnectionTableMap::getTableMap()->getCollectionClassName(); |
||
| 1487 | |||
| 1488 | $this->collConnections = new $collectionClassName; |
||
| 1489 | $this->collConnections->setModel('\Jalle19\StatusManager\Database\Connection'); |
||
| 1490 | } |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Gets an array of ChildConnection objects which contain a foreign key that references this object. |
||
| 1494 | * |
||
| 1495 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
| 1496 | * Otherwise the results are fetched from the database the first time, then cached. |
||
| 1497 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
| 1498 | * If this ChildInstance is new, it will return |
||
| 1499 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
| 1500 | * |
||
| 1501 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 1502 | * @param ConnectionInterface $con optional connection object |
||
| 1503 | * @return ObjectCollection|ChildConnection[] List of ChildConnection objects |
||
| 1504 | * @throws PropelException |
||
| 1505 | */ |
||
| 1506 | public function getConnections(Criteria $criteria = null, ConnectionInterface $con = null) |
||
| 1507 | { |
||
| 1508 | $partial = $this->collConnectionsPartial && !$this->isNew(); |
||
| 1509 | if (null === $this->collConnections || null !== $criteria || $partial) { |
||
| 1510 | if ($this->isNew() && null === $this->collConnections) { |
||
| 1511 | // return empty collection |
||
| 1512 | $this->initConnections(); |
||
| 1513 | } else { |
||
| 1514 | $collConnections = ChildConnectionQuery::create(null, $criteria) |
||
| 1515 | ->filterByInstance($this) |
||
| 1516 | ->find($con); |
||
| 1517 | |||
| 1518 | if (null !== $criteria) { |
||
| 1519 | if (false !== $this->collConnectionsPartial && count($collConnections)) { |
||
| 1520 | $this->initConnections(false); |
||
| 1521 | |||
| 1522 | foreach ($collConnections as $obj) { |
||
| 1523 | if (false == $this->collConnections->contains($obj)) { |
||
| 1524 | $this->collConnections->append($obj); |
||
| 1525 | } |
||
| 1526 | } |
||
| 1527 | |||
| 1528 | $this->collConnectionsPartial = true; |
||
| 1529 | } |
||
| 1530 | |||
| 1531 | return $collConnections; |
||
| 1532 | } |
||
| 1533 | |||
| 1534 | if ($partial && $this->collConnections) { |
||
| 1535 | foreach ($this->collConnections as $obj) { |
||
| 1536 | if ($obj->isNew()) { |
||
| 1537 | $collConnections[] = $obj; |
||
| 1538 | } |
||
| 1539 | } |
||
| 1540 | } |
||
| 1541 | |||
| 1542 | $this->collConnections = $collConnections; |
||
| 1543 | $this->collConnectionsPartial = false; |
||
| 1544 | } |
||
| 1545 | } |
||
| 1546 | |||
| 1547 | return $this->collConnections; |
||
| 1548 | } |
||
| 1549 | |||
| 1550 | /** |
||
| 1551 | * Sets a collection of ChildConnection objects related by a one-to-many relationship |
||
| 1552 | * to the current object. |
||
| 1553 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
| 1554 | * and new objects from the given Propel collection. |
||
| 1555 | * |
||
| 1556 | * @param Collection $connections A Propel collection. |
||
| 1557 | * @param ConnectionInterface $con Optional connection object |
||
| 1558 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1559 | */ |
||
| 1560 | public function setConnections(Collection $connections, ConnectionInterface $con = null) |
||
| 1561 | { |
||
| 1562 | /** @var ChildConnection[] $connectionsToDelete */ |
||
| 1563 | $connectionsToDelete = $this->getConnections(new Criteria(), $con)->diff($connections); |
||
| 1564 | |||
| 1565 | |||
| 1566 | $this->connectionsScheduledForDeletion = $connectionsToDelete; |
||
| 1567 | |||
| 1568 | foreach ($connectionsToDelete as $connectionRemoved) { |
||
| 1569 | $connectionRemoved->setInstance(null); |
||
| 1570 | } |
||
| 1571 | |||
| 1572 | $this->collConnections = null; |
||
| 1573 | foreach ($connections as $connection) { |
||
| 1574 | $this->addConnection($connection); |
||
| 1575 | } |
||
| 1576 | |||
| 1577 | $this->collConnections = $connections; |
||
| 1578 | $this->collConnectionsPartial = false; |
||
| 1579 | |||
| 1580 | return $this; |
||
| 1581 | } |
||
| 1582 | |||
| 1583 | /** |
||
| 1584 | * Returns the number of related Connection objects. |
||
| 1585 | * |
||
| 1586 | * @param Criteria $criteria |
||
| 1587 | * @param boolean $distinct |
||
| 1588 | * @param ConnectionInterface $con |
||
| 1589 | * @return int Count of related Connection objects. |
||
| 1590 | * @throws PropelException |
||
| 1591 | */ |
||
| 1592 | public function countConnections(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
| 1593 | { |
||
| 1594 | $partial = $this->collConnectionsPartial && !$this->isNew(); |
||
| 1595 | if (null === $this->collConnections || null !== $criteria || $partial) { |
||
| 1596 | if ($this->isNew() && null === $this->collConnections) { |
||
| 1597 | return 0; |
||
| 1598 | } |
||
| 1599 | |||
| 1600 | if ($partial && !$criteria) { |
||
| 1601 | return count($this->getConnections()); |
||
| 1602 | } |
||
| 1603 | |||
| 1604 | $query = ChildConnectionQuery::create(null, $criteria); |
||
| 1605 | if ($distinct) { |
||
| 1606 | $query->distinct(); |
||
| 1607 | } |
||
| 1608 | |||
| 1609 | return $query |
||
| 1610 | ->filterByInstance($this) |
||
| 1611 | ->count($con); |
||
| 1612 | } |
||
| 1613 | |||
| 1614 | return count($this->collConnections); |
||
| 1615 | } |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Method called to associate a ChildConnection object to this object |
||
| 1619 | * through the ChildConnection foreign key attribute. |
||
| 1620 | * |
||
| 1621 | * @param ChildConnection $l ChildConnection |
||
| 1622 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 1623 | */ |
||
| 1624 | public function addConnection(ChildConnection $l) |
||
| 1625 | { |
||
| 1626 | if ($this->collConnections === null) { |
||
| 1627 | $this->initConnections(); |
||
| 1628 | $this->collConnectionsPartial = true; |
||
| 1629 | } |
||
| 1630 | |||
| 1631 | if (!$this->collConnections->contains($l)) { |
||
| 1632 | $this->doAddConnection($l); |
||
| 1633 | |||
| 1634 | if ($this->connectionsScheduledForDeletion and $this->connectionsScheduledForDeletion->contains($l)) { |
||
| 1635 | $this->connectionsScheduledForDeletion->remove($this->connectionsScheduledForDeletion->search($l)); |
||
| 1636 | } |
||
| 1637 | } |
||
| 1638 | |||
| 1639 | return $this; |
||
| 1640 | } |
||
| 1641 | |||
| 1642 | /** |
||
| 1643 | * @param ChildConnection $connection The ChildConnection object to add. |
||
| 1644 | */ |
||
| 1645 | protected function doAddConnection(ChildConnection $connection) |
||
| 1646 | { |
||
| 1647 | $this->collConnections[]= $connection; |
||
| 1648 | $connection->setInstance($this); |
||
| 1649 | } |
||
| 1650 | |||
| 1651 | /** |
||
| 1652 | * @param ChildConnection $connection The ChildConnection object to remove. |
||
| 1653 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1654 | */ |
||
| 1655 | public function removeConnection(ChildConnection $connection) |
||
| 1656 | { |
||
| 1657 | if ($this->getConnections()->contains($connection)) { |
||
| 1658 | $pos = $this->collConnections->search($connection); |
||
| 1659 | $this->collConnections->remove($pos); |
||
| 1660 | if (null === $this->connectionsScheduledForDeletion) { |
||
| 1661 | $this->connectionsScheduledForDeletion = clone $this->collConnections; |
||
| 1662 | $this->connectionsScheduledForDeletion->clear(); |
||
| 1663 | } |
||
| 1664 | $this->connectionsScheduledForDeletion[]= clone $connection; |
||
| 1665 | $connection->setInstance(null); |
||
| 1666 | } |
||
| 1667 | |||
| 1668 | return $this; |
||
| 1669 | } |
||
| 1670 | |||
| 1671 | |||
| 1672 | /** |
||
| 1673 | * If this collection has already been initialized with |
||
| 1674 | * an identical criteria, it returns the collection. |
||
| 1675 | * Otherwise if this Instance is new, it will return |
||
| 1676 | * an empty collection; or if this Instance has previously |
||
| 1677 | * been saved, it will retrieve related Connections from storage. |
||
| 1678 | * |
||
| 1679 | * This method is protected by default in order to keep the public |
||
| 1680 | * api reasonable. You can provide public methods for those you |
||
| 1681 | * actually need in Instance. |
||
| 1682 | * |
||
| 1683 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 1684 | * @param ConnectionInterface $con optional connection object |
||
| 1685 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
| 1686 | * @return ObjectCollection|ChildConnection[] List of ChildConnection objects |
||
| 1687 | */ |
||
| 1688 | public function getConnectionsJoinUser(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
| 1689 | { |
||
| 1690 | $query = ChildConnectionQuery::create(null, $criteria); |
||
| 1691 | $query->joinWith('User', $joinBehavior); |
||
| 1692 | |||
| 1693 | return $this->getConnections($query, $con); |
||
| 1694 | } |
||
| 1695 | |||
| 1696 | /** |
||
| 1697 | * Clears out the collInputs collection |
||
| 1698 | * |
||
| 1699 | * This does not modify the database; however, it will remove any associated objects, causing |
||
| 1700 | * them to be refetched by subsequent calls to accessor method. |
||
| 1701 | * |
||
| 1702 | * @return void |
||
| 1703 | * @see addInputs() |
||
| 1704 | */ |
||
| 1705 | public function clearInputs() |
||
| 1706 | { |
||
| 1707 | $this->collInputs = null; // important to set this to NULL since that means it is uninitialized |
||
| 1708 | } |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * Reset is the collInputs collection loaded partially. |
||
| 1712 | */ |
||
| 1713 | public function resetPartialInputs($v = true) |
||
| 1714 | { |
||
| 1715 | $this->collInputsPartial = $v; |
||
| 1716 | } |
||
| 1717 | |||
| 1718 | /** |
||
| 1719 | * Initializes the collInputs collection. |
||
| 1720 | * |
||
| 1721 | * By default this just sets the collInputs collection to an empty array (like clearcollInputs()); |
||
| 1722 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
| 1723 | * to your application -- for example, setting the initial array to the values stored in database. |
||
| 1724 | * |
||
| 1725 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
| 1726 | * the collection even if it is not empty |
||
| 1727 | * |
||
| 1728 | * @return void |
||
| 1729 | */ |
||
| 1730 | public function initInputs($overrideExisting = true) |
||
| 1731 | { |
||
| 1732 | if (null !== $this->collInputs && !$overrideExisting) { |
||
| 1733 | return; |
||
| 1734 | } |
||
| 1735 | |||
| 1736 | $collectionClassName = InputTableMap::getTableMap()->getCollectionClassName(); |
||
| 1737 | |||
| 1738 | $this->collInputs = new $collectionClassName; |
||
| 1739 | $this->collInputs->setModel('\Jalle19\StatusManager\Database\Input'); |
||
| 1740 | } |
||
| 1741 | |||
| 1742 | /** |
||
| 1743 | * Gets an array of ChildInput objects which contain a foreign key that references this object. |
||
| 1744 | * |
||
| 1745 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
| 1746 | * Otherwise the results are fetched from the database the first time, then cached. |
||
| 1747 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
| 1748 | * If this ChildInstance is new, it will return |
||
| 1749 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
| 1750 | * |
||
| 1751 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 1752 | * @param ConnectionInterface $con optional connection object |
||
| 1753 | * @return ObjectCollection|ChildInput[] List of ChildInput objects |
||
| 1754 | * @throws PropelException |
||
| 1755 | */ |
||
| 1756 | public function getInputs(Criteria $criteria = null, ConnectionInterface $con = null) |
||
| 1757 | { |
||
| 1758 | $partial = $this->collInputsPartial && !$this->isNew(); |
||
| 1759 | if (null === $this->collInputs || null !== $criteria || $partial) { |
||
| 1760 | if ($this->isNew() && null === $this->collInputs) { |
||
| 1761 | // return empty collection |
||
| 1762 | $this->initInputs(); |
||
| 1763 | } else { |
||
| 1764 | $collInputs = ChildInputQuery::create(null, $criteria) |
||
| 1765 | ->filterByInstance($this) |
||
| 1766 | ->find($con); |
||
| 1767 | |||
| 1768 | if (null !== $criteria) { |
||
| 1769 | if (false !== $this->collInputsPartial && count($collInputs)) { |
||
| 1770 | $this->initInputs(false); |
||
| 1771 | |||
| 1772 | foreach ($collInputs as $obj) { |
||
| 1773 | if (false == $this->collInputs->contains($obj)) { |
||
| 1774 | $this->collInputs->append($obj); |
||
| 1775 | } |
||
| 1776 | } |
||
| 1777 | |||
| 1778 | $this->collInputsPartial = true; |
||
| 1779 | } |
||
| 1780 | |||
| 1781 | return $collInputs; |
||
| 1782 | } |
||
| 1783 | |||
| 1784 | if ($partial && $this->collInputs) { |
||
| 1785 | foreach ($this->collInputs as $obj) { |
||
| 1786 | if ($obj->isNew()) { |
||
| 1787 | $collInputs[] = $obj; |
||
| 1788 | } |
||
| 1789 | } |
||
| 1790 | } |
||
| 1791 | |||
| 1792 | $this->collInputs = $collInputs; |
||
| 1793 | $this->collInputsPartial = false; |
||
| 1794 | } |
||
| 1795 | } |
||
| 1796 | |||
| 1797 | return $this->collInputs; |
||
| 1798 | } |
||
| 1799 | |||
| 1800 | /** |
||
| 1801 | * Sets a collection of ChildInput objects related by a one-to-many relationship |
||
| 1802 | * to the current object. |
||
| 1803 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
| 1804 | * and new objects from the given Propel collection. |
||
| 1805 | * |
||
| 1806 | * @param Collection $inputs A Propel collection. |
||
| 1807 | * @param ConnectionInterface $con Optional connection object |
||
| 1808 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1809 | */ |
||
| 1810 | public function setInputs(Collection $inputs, ConnectionInterface $con = null) |
||
| 1811 | { |
||
| 1812 | /** @var ChildInput[] $inputsToDelete */ |
||
| 1813 | $inputsToDelete = $this->getInputs(new Criteria(), $con)->diff($inputs); |
||
| 1814 | |||
| 1815 | |||
| 1816 | $this->inputsScheduledForDeletion = $inputsToDelete; |
||
| 1817 | |||
| 1818 | foreach ($inputsToDelete as $inputRemoved) { |
||
| 1819 | $inputRemoved->setInstance(null); |
||
| 1820 | } |
||
| 1821 | |||
| 1822 | $this->collInputs = null; |
||
| 1823 | foreach ($inputs as $input) { |
||
| 1824 | $this->addInput($input); |
||
| 1825 | } |
||
| 1826 | |||
| 1827 | $this->collInputs = $inputs; |
||
| 1828 | $this->collInputsPartial = false; |
||
| 1829 | |||
| 1830 | return $this; |
||
| 1831 | } |
||
| 1832 | |||
| 1833 | /** |
||
| 1834 | * Returns the number of related Input objects. |
||
| 1835 | * |
||
| 1836 | * @param Criteria $criteria |
||
| 1837 | * @param boolean $distinct |
||
| 1838 | * @param ConnectionInterface $con |
||
| 1839 | * @return int Count of related Input objects. |
||
| 1840 | * @throws PropelException |
||
| 1841 | */ |
||
| 1842 | public function countInputs(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
| 1843 | { |
||
| 1844 | $partial = $this->collInputsPartial && !$this->isNew(); |
||
| 1845 | if (null === $this->collInputs || null !== $criteria || $partial) { |
||
| 1846 | if ($this->isNew() && null === $this->collInputs) { |
||
| 1847 | return 0; |
||
| 1848 | } |
||
| 1849 | |||
| 1850 | if ($partial && !$criteria) { |
||
| 1851 | return count($this->getInputs()); |
||
| 1852 | } |
||
| 1853 | |||
| 1854 | $query = ChildInputQuery::create(null, $criteria); |
||
| 1855 | if ($distinct) { |
||
| 1856 | $query->distinct(); |
||
| 1857 | } |
||
| 1858 | |||
| 1859 | return $query |
||
| 1860 | ->filterByInstance($this) |
||
| 1861 | ->count($con); |
||
| 1862 | } |
||
| 1863 | |||
| 1864 | return count($this->collInputs); |
||
| 1865 | } |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Method called to associate a ChildInput object to this object |
||
| 1869 | * through the ChildInput foreign key attribute. |
||
| 1870 | * |
||
| 1871 | * @param ChildInput $l ChildInput |
||
| 1872 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 1873 | */ |
||
| 1874 | public function addInput(ChildInput $l) |
||
| 1875 | { |
||
| 1876 | if ($this->collInputs === null) { |
||
| 1877 | $this->initInputs(); |
||
| 1878 | $this->collInputsPartial = true; |
||
| 1879 | } |
||
| 1880 | |||
| 1881 | if (!$this->collInputs->contains($l)) { |
||
| 1882 | $this->doAddInput($l); |
||
| 1883 | |||
| 1884 | if ($this->inputsScheduledForDeletion and $this->inputsScheduledForDeletion->contains($l)) { |
||
| 1885 | $this->inputsScheduledForDeletion->remove($this->inputsScheduledForDeletion->search($l)); |
||
| 1886 | } |
||
| 1887 | } |
||
| 1888 | |||
| 1889 | return $this; |
||
| 1890 | } |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * @param ChildInput $input The ChildInput object to add. |
||
| 1894 | */ |
||
| 1895 | protected function doAddInput(ChildInput $input) |
||
| 1896 | { |
||
| 1897 | $this->collInputs[]= $input; |
||
| 1898 | $input->setInstance($this); |
||
| 1899 | } |
||
| 1900 | |||
| 1901 | /** |
||
| 1902 | * @param ChildInput $input The ChildInput object to remove. |
||
| 1903 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 1904 | */ |
||
| 1905 | public function removeInput(ChildInput $input) |
||
| 1906 | { |
||
| 1907 | if ($this->getInputs()->contains($input)) { |
||
| 1908 | $pos = $this->collInputs->search($input); |
||
| 1909 | $this->collInputs->remove($pos); |
||
| 1910 | if (null === $this->inputsScheduledForDeletion) { |
||
| 1911 | $this->inputsScheduledForDeletion = clone $this->collInputs; |
||
| 1912 | $this->inputsScheduledForDeletion->clear(); |
||
| 1913 | } |
||
| 1914 | $this->inputsScheduledForDeletion[]= clone $input; |
||
| 1915 | $input->setInstance(null); |
||
| 1916 | } |
||
| 1917 | |||
| 1918 | return $this; |
||
| 1919 | } |
||
| 1920 | |||
| 1921 | /** |
||
| 1922 | * Clears out the collChannels collection |
||
| 1923 | * |
||
| 1924 | * This does not modify the database; however, it will remove any associated objects, causing |
||
| 1925 | * them to be refetched by subsequent calls to accessor method. |
||
| 1926 | * |
||
| 1927 | * @return void |
||
| 1928 | * @see addChannels() |
||
| 1929 | */ |
||
| 1930 | public function clearChannels() |
||
| 1931 | { |
||
| 1932 | $this->collChannels = null; // important to set this to NULL since that means it is uninitialized |
||
| 1933 | } |
||
| 1934 | |||
| 1935 | /** |
||
| 1936 | * Reset is the collChannels collection loaded partially. |
||
| 1937 | */ |
||
| 1938 | public function resetPartialChannels($v = true) |
||
| 1939 | { |
||
| 1940 | $this->collChannelsPartial = $v; |
||
| 1941 | } |
||
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Initializes the collChannels collection. |
||
| 1945 | * |
||
| 1946 | * By default this just sets the collChannels collection to an empty array (like clearcollChannels()); |
||
| 1947 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
| 1948 | * to your application -- for example, setting the initial array to the values stored in database. |
||
| 1949 | * |
||
| 1950 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
| 1951 | * the collection even if it is not empty |
||
| 1952 | * |
||
| 1953 | * @return void |
||
| 1954 | */ |
||
| 1955 | public function initChannels($overrideExisting = true) |
||
| 1956 | { |
||
| 1957 | if (null !== $this->collChannels && !$overrideExisting) { |
||
| 1958 | return; |
||
| 1959 | } |
||
| 1960 | |||
| 1961 | $collectionClassName = ChannelTableMap::getTableMap()->getCollectionClassName(); |
||
| 1962 | |||
| 1963 | $this->collChannels = new $collectionClassName; |
||
| 1964 | $this->collChannels->setModel('\Jalle19\StatusManager\Database\Channel'); |
||
| 1965 | } |
||
| 1966 | |||
| 1967 | /** |
||
| 1968 | * Gets an array of ChildChannel objects which contain a foreign key that references this object. |
||
| 1969 | * |
||
| 1970 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
| 1971 | * Otherwise the results are fetched from the database the first time, then cached. |
||
| 1972 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
| 1973 | * If this ChildInstance is new, it will return |
||
| 1974 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
| 1975 | * |
||
| 1976 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 1977 | * @param ConnectionInterface $con optional connection object |
||
| 1978 | * @return ObjectCollection|ChildChannel[] List of ChildChannel objects |
||
| 1979 | * @throws PropelException |
||
| 1980 | */ |
||
| 1981 | public function getChannels(Criteria $criteria = null, ConnectionInterface $con = null) |
||
| 1982 | { |
||
| 1983 | $partial = $this->collChannelsPartial && !$this->isNew(); |
||
| 1984 | if (null === $this->collChannels || null !== $criteria || $partial) { |
||
| 1985 | if ($this->isNew() && null === $this->collChannels) { |
||
| 1986 | // return empty collection |
||
| 1987 | $this->initChannels(); |
||
| 1988 | } else { |
||
| 1989 | $collChannels = ChildChannelQuery::create(null, $criteria) |
||
| 1990 | ->filterByInstance($this) |
||
| 1991 | ->find($con); |
||
| 1992 | |||
| 1993 | if (null !== $criteria) { |
||
| 1994 | if (false !== $this->collChannelsPartial && count($collChannels)) { |
||
| 1995 | $this->initChannels(false); |
||
| 1996 | |||
| 1997 | foreach ($collChannels as $obj) { |
||
| 1998 | if (false == $this->collChannels->contains($obj)) { |
||
| 1999 | $this->collChannels->append($obj); |
||
| 2000 | } |
||
| 2001 | } |
||
| 2002 | |||
| 2003 | $this->collChannelsPartial = true; |
||
| 2004 | } |
||
| 2005 | |||
| 2006 | return $collChannels; |
||
| 2007 | } |
||
| 2008 | |||
| 2009 | if ($partial && $this->collChannels) { |
||
| 2010 | foreach ($this->collChannels as $obj) { |
||
| 2011 | if ($obj->isNew()) { |
||
| 2012 | $collChannels[] = $obj; |
||
| 2013 | } |
||
| 2014 | } |
||
| 2015 | } |
||
| 2016 | |||
| 2017 | $this->collChannels = $collChannels; |
||
| 2018 | $this->collChannelsPartial = false; |
||
| 2019 | } |
||
| 2020 | } |
||
| 2021 | |||
| 2022 | return $this->collChannels; |
||
| 2023 | } |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Sets a collection of ChildChannel objects related by a one-to-many relationship |
||
| 2027 | * to the current object. |
||
| 2028 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
| 2029 | * and new objects from the given Propel collection. |
||
| 2030 | * |
||
| 2031 | * @param Collection $channels A Propel collection. |
||
| 2032 | * @param ConnectionInterface $con Optional connection object |
||
| 2033 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 2034 | */ |
||
| 2035 | public function setChannels(Collection $channels, ConnectionInterface $con = null) |
||
| 2036 | { |
||
| 2037 | /** @var ChildChannel[] $channelsToDelete */ |
||
| 2038 | $channelsToDelete = $this->getChannels(new Criteria(), $con)->diff($channels); |
||
| 2039 | |||
| 2040 | |||
| 2041 | $this->channelsScheduledForDeletion = $channelsToDelete; |
||
| 2042 | |||
| 2043 | foreach ($channelsToDelete as $channelRemoved) { |
||
| 2044 | $channelRemoved->setInstance(null); |
||
| 2045 | } |
||
| 2046 | |||
| 2047 | $this->collChannels = null; |
||
| 2048 | foreach ($channels as $channel) { |
||
| 2049 | $this->addChannel($channel); |
||
| 2050 | } |
||
| 2051 | |||
| 2052 | $this->collChannels = $channels; |
||
| 2053 | $this->collChannelsPartial = false; |
||
| 2054 | |||
| 2055 | return $this; |
||
| 2056 | } |
||
| 2057 | |||
| 2058 | /** |
||
| 2059 | * Returns the number of related Channel objects. |
||
| 2060 | * |
||
| 2061 | * @param Criteria $criteria |
||
| 2062 | * @param boolean $distinct |
||
| 2063 | * @param ConnectionInterface $con |
||
| 2064 | * @return int Count of related Channel objects. |
||
| 2065 | * @throws PropelException |
||
| 2066 | */ |
||
| 2067 | public function countChannels(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
| 2068 | { |
||
| 2069 | $partial = $this->collChannelsPartial && !$this->isNew(); |
||
| 2070 | if (null === $this->collChannels || null !== $criteria || $partial) { |
||
| 2071 | if ($this->isNew() && null === $this->collChannels) { |
||
| 2072 | return 0; |
||
| 2073 | } |
||
| 2074 | |||
| 2075 | if ($partial && !$criteria) { |
||
| 2076 | return count($this->getChannels()); |
||
| 2077 | } |
||
| 2078 | |||
| 2079 | $query = ChildChannelQuery::create(null, $criteria); |
||
| 2080 | if ($distinct) { |
||
| 2081 | $query->distinct(); |
||
| 2082 | } |
||
| 2083 | |||
| 2084 | return $query |
||
| 2085 | ->filterByInstance($this) |
||
| 2086 | ->count($con); |
||
| 2087 | } |
||
| 2088 | |||
| 2089 | return count($this->collChannels); |
||
| 2090 | } |
||
| 2091 | |||
| 2092 | /** |
||
| 2093 | * Method called to associate a ChildChannel object to this object |
||
| 2094 | * through the ChildChannel foreign key attribute. |
||
| 2095 | * |
||
| 2096 | * @param ChildChannel $l ChildChannel |
||
| 2097 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 2098 | */ |
||
| 2099 | public function addChannel(ChildChannel $l) |
||
| 2100 | { |
||
| 2101 | if ($this->collChannels === null) { |
||
| 2102 | $this->initChannels(); |
||
| 2103 | $this->collChannelsPartial = true; |
||
| 2104 | } |
||
| 2105 | |||
| 2106 | if (!$this->collChannels->contains($l)) { |
||
| 2107 | $this->doAddChannel($l); |
||
| 2108 | |||
| 2109 | if ($this->channelsScheduledForDeletion and $this->channelsScheduledForDeletion->contains($l)) { |
||
| 2110 | $this->channelsScheduledForDeletion->remove($this->channelsScheduledForDeletion->search($l)); |
||
| 2111 | } |
||
| 2112 | } |
||
| 2113 | |||
| 2114 | return $this; |
||
| 2115 | } |
||
| 2116 | |||
| 2117 | /** |
||
| 2118 | * @param ChildChannel $channel The ChildChannel object to add. |
||
| 2119 | */ |
||
| 2120 | protected function doAddChannel(ChildChannel $channel) |
||
| 2121 | { |
||
| 2122 | $this->collChannels[]= $channel; |
||
| 2123 | $channel->setInstance($this); |
||
| 2124 | } |
||
| 2125 | |||
| 2126 | /** |
||
| 2127 | * @param ChildChannel $channel The ChildChannel object to remove. |
||
| 2128 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 2129 | */ |
||
| 2130 | public function removeChannel(ChildChannel $channel) |
||
| 2131 | { |
||
| 2132 | if ($this->getChannels()->contains($channel)) { |
||
| 2133 | $pos = $this->collChannels->search($channel); |
||
| 2134 | $this->collChannels->remove($pos); |
||
| 2135 | if (null === $this->channelsScheduledForDeletion) { |
||
| 2136 | $this->channelsScheduledForDeletion = clone $this->collChannels; |
||
| 2137 | $this->channelsScheduledForDeletion->clear(); |
||
| 2138 | } |
||
| 2139 | $this->channelsScheduledForDeletion[]= clone $channel; |
||
| 2140 | $channel->setInstance(null); |
||
| 2141 | } |
||
| 2142 | |||
| 2143 | return $this; |
||
| 2144 | } |
||
| 2145 | |||
| 2146 | /** |
||
| 2147 | * Clears out the collSubscriptions collection |
||
| 2148 | * |
||
| 2149 | * This does not modify the database; however, it will remove any associated objects, causing |
||
| 2150 | * them to be refetched by subsequent calls to accessor method. |
||
| 2151 | * |
||
| 2152 | * @return void |
||
| 2153 | * @see addSubscriptions() |
||
| 2154 | */ |
||
| 2155 | public function clearSubscriptions() |
||
| 2156 | { |
||
| 2157 | $this->collSubscriptions = null; // important to set this to NULL since that means it is uninitialized |
||
| 2158 | } |
||
| 2159 | |||
| 2160 | /** |
||
| 2161 | * Reset is the collSubscriptions collection loaded partially. |
||
| 2162 | */ |
||
| 2163 | public function resetPartialSubscriptions($v = true) |
||
| 2164 | { |
||
| 2165 | $this->collSubscriptionsPartial = $v; |
||
| 2166 | } |
||
| 2167 | |||
| 2168 | /** |
||
| 2169 | * Initializes the collSubscriptions collection. |
||
| 2170 | * |
||
| 2171 | * By default this just sets the collSubscriptions collection to an empty array (like clearcollSubscriptions()); |
||
| 2172 | * however, you may wish to override this method in your stub class to provide setting appropriate |
||
| 2173 | * to your application -- for example, setting the initial array to the values stored in database. |
||
| 2174 | * |
||
| 2175 | * @param boolean $overrideExisting If set to true, the method call initializes |
||
| 2176 | * the collection even if it is not empty |
||
| 2177 | * |
||
| 2178 | * @return void |
||
| 2179 | */ |
||
| 2180 | public function initSubscriptions($overrideExisting = true) |
||
| 2181 | { |
||
| 2182 | if (null !== $this->collSubscriptions && !$overrideExisting) { |
||
| 2183 | return; |
||
| 2184 | } |
||
| 2185 | |||
| 2186 | $collectionClassName = SubscriptionTableMap::getTableMap()->getCollectionClassName(); |
||
| 2187 | |||
| 2188 | $this->collSubscriptions = new $collectionClassName; |
||
| 2189 | $this->collSubscriptions->setModel('\Jalle19\StatusManager\Database\Subscription'); |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | /** |
||
| 2193 | * Gets an array of ChildSubscription objects which contain a foreign key that references this object. |
||
| 2194 | * |
||
| 2195 | * If the $criteria is not null, it is used to always fetch the results from the database. |
||
| 2196 | * Otherwise the results are fetched from the database the first time, then cached. |
||
| 2197 | * Next time the same method is called without $criteria, the cached collection is returned. |
||
| 2198 | * If this ChildInstance is new, it will return |
||
| 2199 | * an empty collection or the current collection; the criteria is ignored on a new object. |
||
| 2200 | * |
||
| 2201 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 2202 | * @param ConnectionInterface $con optional connection object |
||
| 2203 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
| 2204 | * @throws PropelException |
||
| 2205 | */ |
||
| 2206 | public function getSubscriptions(Criteria $criteria = null, ConnectionInterface $con = null) |
||
| 2207 | { |
||
| 2208 | $partial = $this->collSubscriptionsPartial && !$this->isNew(); |
||
| 2209 | if (null === $this->collSubscriptions || null !== $criteria || $partial) { |
||
| 2210 | if ($this->isNew() && null === $this->collSubscriptions) { |
||
| 2211 | // return empty collection |
||
| 2212 | $this->initSubscriptions(); |
||
| 2213 | } else { |
||
| 2214 | $collSubscriptions = ChildSubscriptionQuery::create(null, $criteria) |
||
| 2215 | ->filterByInstance($this) |
||
| 2216 | ->find($con); |
||
| 2217 | |||
| 2218 | if (null !== $criteria) { |
||
| 2219 | if (false !== $this->collSubscriptionsPartial && count($collSubscriptions)) { |
||
| 2220 | $this->initSubscriptions(false); |
||
| 2221 | |||
| 2222 | foreach ($collSubscriptions as $obj) { |
||
| 2223 | if (false == $this->collSubscriptions->contains($obj)) { |
||
| 2224 | $this->collSubscriptions->append($obj); |
||
| 2225 | } |
||
| 2226 | } |
||
| 2227 | |||
| 2228 | $this->collSubscriptionsPartial = true; |
||
| 2229 | } |
||
| 2230 | |||
| 2231 | return $collSubscriptions; |
||
| 2232 | } |
||
| 2233 | |||
| 2234 | if ($partial && $this->collSubscriptions) { |
||
| 2235 | foreach ($this->collSubscriptions as $obj) { |
||
| 2236 | if ($obj->isNew()) { |
||
| 2237 | $collSubscriptions[] = $obj; |
||
| 2238 | } |
||
| 2239 | } |
||
| 2240 | } |
||
| 2241 | |||
| 2242 | $this->collSubscriptions = $collSubscriptions; |
||
| 2243 | $this->collSubscriptionsPartial = false; |
||
| 2244 | } |
||
| 2245 | } |
||
| 2246 | |||
| 2247 | return $this->collSubscriptions; |
||
| 2248 | } |
||
| 2249 | |||
| 2250 | /** |
||
| 2251 | * Sets a collection of ChildSubscription objects related by a one-to-many relationship |
||
| 2252 | * to the current object. |
||
| 2253 | * It will also schedule objects for deletion based on a diff between old objects (aka persisted) |
||
| 2254 | * and new objects from the given Propel collection. |
||
| 2255 | * |
||
| 2256 | * @param Collection $subscriptions A Propel collection. |
||
| 2257 | * @param ConnectionInterface $con Optional connection object |
||
| 2258 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 2259 | */ |
||
| 2260 | public function setSubscriptions(Collection $subscriptions, ConnectionInterface $con = null) |
||
| 2261 | { |
||
| 2262 | /** @var ChildSubscription[] $subscriptionsToDelete */ |
||
| 2263 | $subscriptionsToDelete = $this->getSubscriptions(new Criteria(), $con)->diff($subscriptions); |
||
| 2264 | |||
| 2265 | |||
| 2266 | $this->subscriptionsScheduledForDeletion = $subscriptionsToDelete; |
||
| 2267 | |||
| 2268 | foreach ($subscriptionsToDelete as $subscriptionRemoved) { |
||
| 2269 | $subscriptionRemoved->setInstance(null); |
||
| 2270 | } |
||
| 2271 | |||
| 2272 | $this->collSubscriptions = null; |
||
| 2273 | foreach ($subscriptions as $subscription) { |
||
| 2274 | $this->addSubscription($subscription); |
||
| 2275 | } |
||
| 2276 | |||
| 2277 | $this->collSubscriptions = $subscriptions; |
||
| 2278 | $this->collSubscriptionsPartial = false; |
||
| 2279 | |||
| 2280 | return $this; |
||
| 2281 | } |
||
| 2282 | |||
| 2283 | /** |
||
| 2284 | * Returns the number of related Subscription objects. |
||
| 2285 | * |
||
| 2286 | * @param Criteria $criteria |
||
| 2287 | * @param boolean $distinct |
||
| 2288 | * @param ConnectionInterface $con |
||
| 2289 | * @return int Count of related Subscription objects. |
||
| 2290 | * @throws PropelException |
||
| 2291 | */ |
||
| 2292 | public function countSubscriptions(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) |
||
| 2293 | { |
||
| 2294 | $partial = $this->collSubscriptionsPartial && !$this->isNew(); |
||
| 2295 | if (null === $this->collSubscriptions || null !== $criteria || $partial) { |
||
| 2296 | if ($this->isNew() && null === $this->collSubscriptions) { |
||
| 2297 | return 0; |
||
| 2298 | } |
||
| 2299 | |||
| 2300 | if ($partial && !$criteria) { |
||
| 2301 | return count($this->getSubscriptions()); |
||
| 2302 | } |
||
| 2303 | |||
| 2304 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
| 2305 | if ($distinct) { |
||
| 2306 | $query->distinct(); |
||
| 2307 | } |
||
| 2308 | |||
| 2309 | return $query |
||
| 2310 | ->filterByInstance($this) |
||
| 2311 | ->count($con); |
||
| 2312 | } |
||
| 2313 | |||
| 2314 | return count($this->collSubscriptions); |
||
| 2315 | } |
||
| 2316 | |||
| 2317 | /** |
||
| 2318 | * Method called to associate a ChildSubscription object to this object |
||
| 2319 | * through the ChildSubscription foreign key attribute. |
||
| 2320 | * |
||
| 2321 | * @param ChildSubscription $l ChildSubscription |
||
| 2322 | * @return $this|\Jalle19\StatusManager\Database\Instance The current object (for fluent API support) |
||
| 2323 | */ |
||
| 2324 | public function addSubscription(ChildSubscription $l) |
||
| 2325 | { |
||
| 2326 | if ($this->collSubscriptions === null) { |
||
| 2327 | $this->initSubscriptions(); |
||
| 2328 | $this->collSubscriptionsPartial = true; |
||
| 2329 | } |
||
| 2330 | |||
| 2331 | if (!$this->collSubscriptions->contains($l)) { |
||
| 2332 | $this->doAddSubscription($l); |
||
| 2333 | |||
| 2334 | if ($this->subscriptionsScheduledForDeletion and $this->subscriptionsScheduledForDeletion->contains($l)) { |
||
| 2335 | $this->subscriptionsScheduledForDeletion->remove($this->subscriptionsScheduledForDeletion->search($l)); |
||
| 2336 | } |
||
| 2337 | } |
||
| 2338 | |||
| 2339 | return $this; |
||
| 2340 | } |
||
| 2341 | |||
| 2342 | /** |
||
| 2343 | * @param ChildSubscription $subscription The ChildSubscription object to add. |
||
| 2344 | */ |
||
| 2345 | protected function doAddSubscription(ChildSubscription $subscription) |
||
| 2346 | { |
||
| 2347 | $this->collSubscriptions[]= $subscription; |
||
| 2348 | $subscription->setInstance($this); |
||
| 2349 | } |
||
| 2350 | |||
| 2351 | /** |
||
| 2352 | * @param ChildSubscription $subscription The ChildSubscription object to remove. |
||
| 2353 | * @return $this|ChildInstance The current object (for fluent API support) |
||
| 2354 | */ |
||
| 2355 | public function removeSubscription(ChildSubscription $subscription) |
||
| 2356 | { |
||
| 2357 | if ($this->getSubscriptions()->contains($subscription)) { |
||
| 2358 | $pos = $this->collSubscriptions->search($subscription); |
||
| 2359 | $this->collSubscriptions->remove($pos); |
||
| 2360 | if (null === $this->subscriptionsScheduledForDeletion) { |
||
| 2361 | $this->subscriptionsScheduledForDeletion = clone $this->collSubscriptions; |
||
| 2362 | $this->subscriptionsScheduledForDeletion->clear(); |
||
| 2363 | } |
||
| 2364 | $this->subscriptionsScheduledForDeletion[]= clone $subscription; |
||
| 2365 | $subscription->setInstance(null); |
||
| 2366 | } |
||
| 2367 | |||
| 2368 | return $this; |
||
| 2369 | } |
||
| 2370 | |||
| 2371 | |||
| 2372 | /** |
||
| 2373 | * If this collection has already been initialized with |
||
| 2374 | * an identical criteria, it returns the collection. |
||
| 2375 | * Otherwise if this Instance is new, it will return |
||
| 2376 | * an empty collection; or if this Instance has previously |
||
| 2377 | * been saved, it will retrieve related Subscriptions from storage. |
||
| 2378 | * |
||
| 2379 | * This method is protected by default in order to keep the public |
||
| 2380 | * api reasonable. You can provide public methods for those you |
||
| 2381 | * actually need in Instance. |
||
| 2382 | * |
||
| 2383 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 2384 | * @param ConnectionInterface $con optional connection object |
||
| 2385 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
| 2386 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
| 2387 | */ |
||
| 2388 | public function getSubscriptionsJoinInput(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
| 2389 | { |
||
| 2390 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
| 2391 | $query->joinWith('Input', $joinBehavior); |
||
| 2392 | |||
| 2393 | return $this->getSubscriptions($query, $con); |
||
| 2394 | } |
||
| 2395 | |||
| 2396 | |||
| 2397 | /** |
||
| 2398 | * If this collection has already been initialized with |
||
| 2399 | * an identical criteria, it returns the collection. |
||
| 2400 | * Otherwise if this Instance is new, it will return |
||
| 2401 | * an empty collection; or if this Instance has previously |
||
| 2402 | * been saved, it will retrieve related Subscriptions from storage. |
||
| 2403 | * |
||
| 2404 | * This method is protected by default in order to keep the public |
||
| 2405 | * api reasonable. You can provide public methods for those you |
||
| 2406 | * actually need in Instance. |
||
| 2407 | * |
||
| 2408 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 2409 | * @param ConnectionInterface $con optional connection object |
||
| 2410 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
| 2411 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
| 2412 | */ |
||
| 2413 | public function getSubscriptionsJoinUser(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
| 2414 | { |
||
| 2415 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
| 2416 | $query->joinWith('User', $joinBehavior); |
||
| 2417 | |||
| 2418 | return $this->getSubscriptions($query, $con); |
||
| 2419 | } |
||
| 2420 | |||
| 2421 | |||
| 2422 | /** |
||
| 2423 | * If this collection has already been initialized with |
||
| 2424 | * an identical criteria, it returns the collection. |
||
| 2425 | * Otherwise if this Instance is new, it will return |
||
| 2426 | * an empty collection; or if this Instance has previously |
||
| 2427 | * been saved, it will retrieve related Subscriptions from storage. |
||
| 2428 | * |
||
| 2429 | * This method is protected by default in order to keep the public |
||
| 2430 | * api reasonable. You can provide public methods for those you |
||
| 2431 | * actually need in Instance. |
||
| 2432 | * |
||
| 2433 | * @param Criteria $criteria optional Criteria object to narrow the query |
||
| 2434 | * @param ConnectionInterface $con optional connection object |
||
| 2435 | * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) |
||
| 2436 | * @return ObjectCollection|ChildSubscription[] List of ChildSubscription objects |
||
| 2437 | */ |
||
| 2438 | public function getSubscriptionsJoinChannel(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) |
||
| 2439 | { |
||
| 2440 | $query = ChildSubscriptionQuery::create(null, $criteria); |
||
| 2441 | $query->joinWith('Channel', $joinBehavior); |
||
| 2442 | |||
| 2443 | return $this->getSubscriptions($query, $con); |
||
| 2444 | } |
||
| 2445 | |||
| 2446 | /** |
||
| 2447 | * Clears the current object, sets all attributes to their default values and removes |
||
| 2448 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
| 2449 | * change of those foreign objects when you call `save` there). |
||
| 2450 | */ |
||
| 2451 | public function clear() |
||
| 2452 | { |
||
| 2453 | $this->name = null; |
||
| 2454 | $this->alreadyInSave = false; |
||
| 2455 | $this->clearAllReferences(); |
||
| 2456 | $this->resetModified(); |
||
| 2457 | $this->setNew(true); |
||
| 2458 | $this->setDeleted(false); |
||
| 2459 | } |
||
| 2460 | |||
| 2461 | /** |
||
| 2462 | * Resets all references and back-references to other model objects or collections of model objects. |
||
| 2463 | * |
||
| 2464 | * This method is used to reset all php object references (not the actual reference in the database). |
||
| 2465 | * Necessary for object serialisation. |
||
| 2466 | * |
||
| 2467 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
| 2468 | */ |
||
| 2469 | public function clearAllReferences($deep = false) |
||
| 2470 | { |
||
| 2471 | if ($deep) { |
||
| 2472 | if ($this->collUsers) { |
||
| 2473 | foreach ($this->collUsers as $o) { |
||
| 2474 | $o->clearAllReferences($deep); |
||
| 2475 | } |
||
| 2476 | } |
||
| 2477 | if ($this->collConnections) { |
||
| 2478 | foreach ($this->collConnections as $o) { |
||
| 2479 | $o->clearAllReferences($deep); |
||
| 2480 | } |
||
| 2481 | } |
||
| 2482 | if ($this->collInputs) { |
||
| 2483 | foreach ($this->collInputs as $o) { |
||
| 2484 | $o->clearAllReferences($deep); |
||
| 2485 | } |
||
| 2486 | } |
||
| 2487 | if ($this->collChannels) { |
||
| 2488 | foreach ($this->collChannels as $o) { |
||
| 2489 | $o->clearAllReferences($deep); |
||
| 2490 | } |
||
| 2491 | } |
||
| 2492 | if ($this->collSubscriptions) { |
||
| 2493 | foreach ($this->collSubscriptions as $o) { |
||
| 2494 | $o->clearAllReferences($deep); |
||
| 2495 | } |
||
| 2496 | } |
||
| 2497 | } // if ($deep) |
||
| 2498 | |||
| 2499 | $this->collUsers = null; |
||
| 2500 | $this->collConnections = null; |
||
| 2501 | $this->collInputs = null; |
||
| 2502 | $this->collChannels = null; |
||
| 2503 | $this->collSubscriptions = null; |
||
| 2504 | } |
||
| 2505 | |||
| 2506 | /** |
||
| 2507 | * Return the string representation of this object |
||
| 2508 | * |
||
| 2509 | * @return string |
||
| 2510 | */ |
||
| 2511 | public function __toString() |
||
| 2512 | { |
||
| 2513 | return (string) $this->exportTo(InstanceTableMap::DEFAULT_STRING_FORMAT); |
||
| 2514 | } |
||
| 2515 | |||
| 2516 | /** |
||
| 2517 | * Code to be run before persisting the object |
||
| 2518 | * @param ConnectionInterface $con |
||
| 2519 | * @return boolean |
||
| 2520 | */ |
||
| 2521 | public function preSave(ConnectionInterface $con = null) |
||
| 2522 | { |
||
| 2523 | return true; |
||
| 2524 | } |
||
| 2525 | |||
| 2526 | /** |
||
| 2527 | * Code to be run after persisting the object |
||
| 2528 | * @param ConnectionInterface $con |
||
| 2529 | */ |
||
| 2530 | public function postSave(ConnectionInterface $con = null) |
||
| 2531 | { |
||
| 2532 | |||
| 2533 | } |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Code to be run before inserting to database |
||
| 2537 | * @param ConnectionInterface $con |
||
| 2538 | * @return boolean |
||
| 2539 | */ |
||
| 2540 | public function preInsert(ConnectionInterface $con = null) |
||
| 2541 | { |
||
| 2542 | return true; |
||
| 2543 | } |
||
| 2544 | |||
| 2545 | /** |
||
| 2546 | * Code to be run after inserting to database |
||
| 2547 | * @param ConnectionInterface $con |
||
| 2548 | */ |
||
| 2549 | public function postInsert(ConnectionInterface $con = null) |
||
| 2550 | { |
||
| 2551 | |||
| 2552 | } |
||
| 2553 | |||
| 2554 | /** |
||
| 2555 | * Code to be run before updating the object in database |
||
| 2556 | * @param ConnectionInterface $con |
||
| 2557 | * @return boolean |
||
| 2558 | */ |
||
| 2559 | public function preUpdate(ConnectionInterface $con = null) |
||
| 2560 | { |
||
| 2561 | return true; |
||
| 2562 | } |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * Code to be run after updating the object in database |
||
| 2566 | * @param ConnectionInterface $con |
||
| 2567 | */ |
||
| 2568 | public function postUpdate(ConnectionInterface $con = null) |
||
| 2569 | { |
||
| 2570 | |||
| 2571 | } |
||
| 2572 | |||
| 2573 | /** |
||
| 2574 | * Code to be run before deleting the object in database |
||
| 2575 | * @param ConnectionInterface $con |
||
| 2576 | * @return boolean |
||
| 2577 | */ |
||
| 2578 | public function preDelete(ConnectionInterface $con = null) |
||
| 2579 | { |
||
| 2580 | return true; |
||
| 2581 | } |
||
| 2582 | |||
| 2583 | /** |
||
| 2584 | * Code to be run after deleting the object in database |
||
| 2585 | * @param ConnectionInterface $con |
||
| 2586 | */ |
||
| 2587 | public function postDelete(ConnectionInterface $con = null) |
||
| 2588 | { |
||
| 2589 | |||
| 2590 | } |
||
| 2591 | |||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Derived method to catches calls to undefined methods. |
||
| 2595 | * |
||
| 2596 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
| 2597 | * Allows to define default __call() behavior if you overwrite __call() |
||
| 2598 | * |
||
| 2599 | * @param string $name |
||
| 2600 | * @param mixed $params |
||
| 2601 | * |
||
| 2602 | * @return array|string |
||
| 2603 | */ |
||
| 2604 | public function __call($name, $params) |
||
| 2605 | { |
||
| 2606 | if (0 === strpos($name, 'get')) { |
||
| 2607 | $virtualColumn = substr($name, 3); |
||
| 2608 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
| 2609 | return $this->getVirtualColumn($virtualColumn); |
||
| 2610 | } |
||
| 2611 | |||
| 2612 | $virtualColumn = lcfirst($virtualColumn); |
||
| 2613 | if ($this->hasVirtualColumn($virtualColumn)) { |
||
| 2614 | return $this->getVirtualColumn($virtualColumn); |
||
| 2615 | } |
||
| 2616 | } |
||
| 2617 | |||
| 2618 | if (0 === strpos($name, 'from')) { |
||
| 2619 | $format = substr($name, 4); |
||
| 2620 | |||
| 2621 | return $this->importFrom($format, reset($params)); |
||
| 2622 | } |
||
| 2623 | |||
| 2624 | if (0 === strpos($name, 'to')) { |
||
| 2625 | $format = substr($name, 2); |
||
| 2626 | $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; |
||
| 2627 | |||
| 2628 | return $this->exportTo($format, $includeLazyLoadColumns); |
||
| 2629 | } |
||
| 2630 | |||
| 2631 | throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); |
||
| 2632 | } |
||
| 2633 | |||
| 2634 | } |
||
| 2635 |