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