1: <?php
2:
3: namespace cli_db\propel\om;
4:
5: use \BaseObject;
6: use \BasePeer;
7: use \Criteria;
8: use \Exception;
9: use \PDO;
10: use \Persistent;
11: use \Propel;
12: use \PropelException;
13: use \PropelPDO;
14: use cli_db\propel\Pub;
15: use cli_db\propel\PubQuery;
16: use cli_db\propel\Pubauthor;
17: use cli_db\propel\PubauthorPeer;
18: use cli_db\propel\PubauthorQuery;
19:
20: /**
21: * Base class that represents a row from the 'pubauthor' table.
22: *
23: *
24: *
25: * @package propel.generator.cli_db.om
26: */
27: abstract class BasePubauthor extends BaseObject implements Persistent
28: {
29: /**
30: * Peer class name
31: */
32: const PEER = 'cli_db\\propel\\PubauthorPeer';
33:
34: /**
35: * The Peer class.
36: * Instance provides a convenient way of calling static methods on a class
37: * that calling code may not be able to identify.
38: * @var PubauthorPeer
39: */
40: protected static $peer;
41:
42: /**
43: * The flag var to prevent infinit loop in deep copy
44: * @var boolean
45: */
46: protected $startCopy = false;
47:
48: /**
49: * The value for the pubauthor_id field.
50: * @var int
51: */
52: protected $pubauthor_id;
53:
54: /**
55: * The value for the pub_id field.
56: * @var int
57: */
58: protected $pub_id;
59:
60: /**
61: * The value for the rank field.
62: * @var int
63: */
64: protected $rank;
65:
66: /**
67: * The value for the editor field.
68: * Note: this column has a database default value of: false
69: * @var boolean
70: */
71: protected $editor;
72:
73: /**
74: * The value for the surname field.
75: * @var string
76: */
77: protected $surname;
78:
79: /**
80: * The value for the givennames field.
81: * @var string
82: */
83: protected $givennames;
84:
85: /**
86: * The value for the suffix field.
87: * @var string
88: */
89: protected $suffix;
90:
91: /**
92: * @var Pub
93: */
94: protected $aPub;
95:
96: /**
97: * Flag to prevent endless save loop, if this object is referenced
98: * by another object which falls in this transaction.
99: * @var boolean
100: */
101: protected $alreadyInSave = false;
102:
103: /**
104: * Flag to prevent endless validation loop, if this object is referenced
105: * by another object which falls in this transaction.
106: * @var boolean
107: */
108: protected $alreadyInValidation = false;
109:
110: /**
111: * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
112: * @var boolean
113: */
114: protected $alreadyInClearAllReferencesDeep = false;
115:
116: /**
117: * Applies default values to this object.
118: * This method should be called from the object's constructor (or
119: * equivalent initialization method).
120: * @see __construct()
121: */
122: public function applyDefaultValues()
123: {
124: $this->editor = false;
125: }
126:
127: /**
128: * Initializes internal state of BasePubauthor object.
129: * @see applyDefaults()
130: */
131: public function __construct()
132: {
133: parent::__construct();
134: $this->applyDefaultValues();
135: }
136:
137: /**
138: * Get the [pubauthor_id] column value.
139: *
140: * @return int
141: */
142: public function getPubauthorId()
143: {
144: return $this->pubauthor_id;
145: }
146:
147: /**
148: * Get the [pub_id] column value.
149: *
150: * @return int
151: */
152: public function getPubId()
153: {
154: return $this->pub_id;
155: }
156:
157: /**
158: * Get the [rank] column value.
159: *
160: * @return int
161: */
162: public function getRank()
163: {
164: return $this->rank;
165: }
166:
167: /**
168: * Get the [editor] column value.
169: *
170: * @return boolean
171: */
172: public function getEditor()
173: {
174: return $this->editor;
175: }
176:
177: /**
178: * Get the [surname] column value.
179: *
180: * @return string
181: */
182: public function getSurname()
183: {
184: return $this->surname;
185: }
186:
187: /**
188: * Get the [givennames] column value.
189: *
190: * @return string
191: */
192: public function getGivennames()
193: {
194: return $this->givennames;
195: }
196:
197: /**
198: * Get the [suffix] column value.
199: *
200: * @return string
201: */
202: public function getSuffix()
203: {
204: return $this->suffix;
205: }
206:
207: /**
208: * Set the value of [pubauthor_id] column.
209: *
210: * @param int $v new value
211: * @return Pubauthor The current object (for fluent API support)
212: */
213: public function setPubauthorId($v)
214: {
215: if ($v !== null && is_numeric($v)) {
216: $v = (int) $v;
217: }
218:
219: if ($this->pubauthor_id !== $v) {
220: $this->pubauthor_id = $v;
221: $this->modifiedColumns[] = PubauthorPeer::PUBAUTHOR_ID;
222: }
223:
224:
225: return $this;
226: } // setPubauthorId()
227:
228: /**
229: * Set the value of [pub_id] column.
230: *
231: * @param int $v new value
232: * @return Pubauthor The current object (for fluent API support)
233: */
234: public function setPubId($v)
235: {
236: if ($v !== null && is_numeric($v)) {
237: $v = (int) $v;
238: }
239:
240: if ($this->pub_id !== $v) {
241: $this->pub_id = $v;
242: $this->modifiedColumns[] = PubauthorPeer::PUB_ID;
243: }
244:
245: if ($this->aPub !== null && $this->aPub->getPubId() !== $v) {
246: $this->aPub = null;
247: }
248:
249:
250: return $this;
251: } // setPubId()
252:
253: /**
254: * Set the value of [rank] column.
255: *
256: * @param int $v new value
257: * @return Pubauthor The current object (for fluent API support)
258: */
259: public function setRank($v)
260: {
261: if ($v !== null && is_numeric($v)) {
262: $v = (int) $v;
263: }
264:
265: if ($this->rank !== $v) {
266: $this->rank = $v;
267: $this->modifiedColumns[] = PubauthorPeer::RANK;
268: }
269:
270:
271: return $this;
272: } // setRank()
273:
274: /**
275: * Sets the value of the [editor] column.
276: * Non-boolean arguments are converted using the following rules:
277: * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
278: * * 0, '0', 'false', 'off', and 'no' are converted to boolean false
279: * Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
280: *
281: * @param boolean|integer|string $v The new value
282: * @return Pubauthor The current object (for fluent API support)
283: */
284: public function setEditor($v)
285: {
286: if ($v !== null) {
287: if (is_string($v)) {
288: $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
289: } else {
290: $v = (boolean) $v;
291: }
292: }
293:
294: if ($this->editor !== $v) {
295: $this->editor = $v;
296: $this->modifiedColumns[] = PubauthorPeer::EDITOR;
297: }
298:
299:
300: return $this;
301: } // setEditor()
302:
303: /**
304: * Set the value of [surname] column.
305: *
306: * @param string $v new value
307: * @return Pubauthor The current object (for fluent API support)
308: */
309: public function setSurname($v)
310: {
311: if ($v !== null && is_numeric($v)) {
312: $v = (string) $v;
313: }
314:
315: if ($this->surname !== $v) {
316: $this->surname = $v;
317: $this->modifiedColumns[] = PubauthorPeer::SURNAME;
318: }
319:
320:
321: return $this;
322: } // setSurname()
323:
324: /**
325: * Set the value of [givennames] column.
326: *
327: * @param string $v new value
328: * @return Pubauthor The current object (for fluent API support)
329: */
330: public function setGivennames($v)
331: {
332: if ($v !== null && is_numeric($v)) {
333: $v = (string) $v;
334: }
335:
336: if ($this->givennames !== $v) {
337: $this->givennames = $v;
338: $this->modifiedColumns[] = PubauthorPeer::GIVENNAMES;
339: }
340:
341:
342: return $this;
343: } // setGivennames()
344:
345: /**
346: * Set the value of [suffix] column.
347: *
348: * @param string $v new value
349: * @return Pubauthor The current object (for fluent API support)
350: */
351: public function setSuffix($v)
352: {
353: if ($v !== null && is_numeric($v)) {
354: $v = (string) $v;
355: }
356:
357: if ($this->suffix !== $v) {
358: $this->suffix = $v;
359: $this->modifiedColumns[] = PubauthorPeer::SUFFIX;
360: }
361:
362:
363: return $this;
364: } // setSuffix()
365:
366: /**
367: * Indicates whether the columns in this object are only set to default values.
368: *
369: * This method can be used in conjunction with isModified() to indicate whether an object is both
370: * modified _and_ has some values set which are non-default.
371: *
372: * @return boolean Whether the columns in this object are only been set with default values.
373: */
374: public function hasOnlyDefaultValues()
375: {
376: if ($this->editor !== false) {
377: return false;
378: }
379:
380: // otherwise, everything was equal, so return true
381: return true;
382: } // hasOnlyDefaultValues()
383:
384: /**
385: * Hydrates (populates) the object variables with values from the database resultset.
386: *
387: * An offset (0-based "start column") is specified so that objects can be hydrated
388: * with a subset of the columns in the resultset rows. This is needed, for example,
389: * for results of JOIN queries where the resultset row includes columns from two or
390: * more tables.
391: *
392: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
393: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
394: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
395: * @return int next starting column
396: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
397: */
398: public function hydrate($row, $startcol = 0, $rehydrate = false)
399: {
400: try {
401:
402: $this->pubauthor_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
403: $this->pub_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
404: $this->rank = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
405: $this->editor = ($row[$startcol + 3] !== null) ? (boolean) $row[$startcol + 3] : null;
406: $this->surname = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
407: $this->givennames = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
408: $this->suffix = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
409: $this->resetModified();
410:
411: $this->setNew(false);
412:
413: if ($rehydrate) {
414: $this->ensureConsistency();
415: }
416: $this->postHydrate($row, $startcol, $rehydrate);
417: return $startcol + 7; // 7 = PubauthorPeer::NUM_HYDRATE_COLUMNS.
418:
419: } catch (Exception $e) {
420: throw new PropelException("Error populating Pubauthor object", $e);
421: }
422: }
423:
424: /**
425: * Checks and repairs the internal consistency of the object.
426: *
427: * This method is executed after an already-instantiated object is re-hydrated
428: * from the database. It exists to check any foreign keys to make sure that
429: * the objects related to the current object are correct based on foreign key.
430: *
431: * You can override this method in the stub class, but you should always invoke
432: * the base method from the overridden method (i.e. parent::ensureConsistency()),
433: * in case your model changes.
434: *
435: * @throws PropelException
436: */
437: public function ensureConsistency()
438: {
439:
440: if ($this->aPub !== null && $this->pub_id !== $this->aPub->getPubId()) {
441: $this->aPub = null;
442: }
443: } // ensureConsistency
444:
445: /**
446: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
447: *
448: * This will only work if the object has been saved and has a valid primary key set.
449: *
450: * @param boolean $deep (optional) Whether to also de-associated any related objects.
451: * @param PropelPDO $con (optional) The PropelPDO connection to use.
452: * @return void
453: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
454: */
455: public function reload($deep = false, PropelPDO $con = null)
456: {
457: if ($this->isDeleted()) {
458: throw new PropelException("Cannot reload a deleted object.");
459: }
460:
461: if ($this->isNew()) {
462: throw new PropelException("Cannot reload an unsaved object.");
463: }
464:
465: if ($con === null) {
466: $con = Propel::getConnection(PubauthorPeer::DATABASE_NAME, Propel::CONNECTION_READ);
467: }
468:
469: // We don't need to alter the object instance pool; we're just modifying this instance
470: // already in the pool.
471:
472: $stmt = PubauthorPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
473: $row = $stmt->fetch(PDO::FETCH_NUM);
474: $stmt->closeCursor();
475: if (!$row) {
476: throw new PropelException('Cannot find matching row in the database to reload object values.');
477: }
478: $this->hydrate($row, 0, true); // rehydrate
479:
480: if ($deep) { // also de-associate any related objects?
481:
482: $this->aPub = null;
483: } // if (deep)
484: }
485:
486: /**
487: * Removes this object from datastore and sets delete attribute.
488: *
489: * @param PropelPDO $con
490: * @return void
491: * @throws PropelException
492: * @throws Exception
493: * @see BaseObject::setDeleted()
494: * @see BaseObject::isDeleted()
495: */
496: public function delete(PropelPDO $con = null)
497: {
498: if ($this->isDeleted()) {
499: throw new PropelException("This object has already been deleted.");
500: }
501:
502: if ($con === null) {
503: $con = Propel::getConnection(PubauthorPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
504: }
505:
506: $con->beginTransaction();
507: try {
508: $deleteQuery = PubauthorQuery::create()
509: ->filterByPrimaryKey($this->getPrimaryKey());
510: $ret = $this->preDelete($con);
511: if ($ret) {
512: $deleteQuery->delete($con);
513: $this->postDelete($con);
514: $con->commit();
515: $this->setDeleted(true);
516: } else {
517: $con->commit();
518: }
519: } catch (Exception $e) {
520: $con->rollBack();
521: throw $e;
522: }
523: }
524:
525: /**
526: * Persists this object to the database.
527: *
528: * If the object is new, it inserts it; otherwise an update is performed.
529: * All modified related objects will also be persisted in the doSave()
530: * method. This method wraps all precipitate database operations in a
531: * single transaction.
532: *
533: * @param PropelPDO $con
534: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
535: * @throws PropelException
536: * @throws Exception
537: * @see doSave()
538: */
539: public function save(PropelPDO $con = null)
540: {
541: if ($this->isDeleted()) {
542: throw new PropelException("You cannot save an object that has been deleted.");
543: }
544:
545: if ($con === null) {
546: $con = Propel::getConnection(PubauthorPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
547: }
548:
549: $con->beginTransaction();
550: $isInsert = $this->isNew();
551: try {
552: $ret = $this->preSave($con);
553: if ($isInsert) {
554: $ret = $ret && $this->preInsert($con);
555: } else {
556: $ret = $ret && $this->preUpdate($con);
557: }
558: if ($ret) {
559: $affectedRows = $this->doSave($con);
560: if ($isInsert) {
561: $this->postInsert($con);
562: } else {
563: $this->postUpdate($con);
564: }
565: $this->postSave($con);
566: PubauthorPeer::addInstanceToPool($this);
567: } else {
568: $affectedRows = 0;
569: }
570: $con->commit();
571:
572: return $affectedRows;
573: } catch (Exception $e) {
574: $con->rollBack();
575: throw $e;
576: }
577: }
578:
579: /**
580: * Performs the work of inserting or updating the row in the database.
581: *
582: * If the object is new, it inserts it; otherwise an update is performed.
583: * All related objects are also updated in this method.
584: *
585: * @param PropelPDO $con
586: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
587: * @throws PropelException
588: * @see save()
589: */
590: protected function doSave(PropelPDO $con)
591: {
592: $affectedRows = 0; // initialize var to track total num of affected rows
593: if (!$this->alreadyInSave) {
594: $this->alreadyInSave = true;
595:
596: // We call the save method on the following object(s) if they
597: // were passed to this object by their coresponding set
598: // method. This object relates to these object(s) by a
599: // foreign key reference.
600:
601: if ($this->aPub !== null) {
602: if ($this->aPub->isModified() || $this->aPub->isNew()) {
603: $affectedRows += $this->aPub->save($con);
604: }
605: $this->setPub($this->aPub);
606: }
607:
608: if ($this->isNew() || $this->isModified()) {
609: // persist changes
610: if ($this->isNew()) {
611: $this->doInsert($con);
612: } else {
613: $this->doUpdate($con);
614: }
615: $affectedRows += 1;
616: $this->resetModified();
617: }
618:
619: $this->alreadyInSave = false;
620:
621: }
622:
623: return $affectedRows;
624: } // doSave()
625:
626: /**
627: * Insert the row in the database.
628: *
629: * @param PropelPDO $con
630: *
631: * @throws PropelException
632: * @see doSave()
633: */
634: protected function doInsert(PropelPDO $con)
635: {
636: $modifiedColumns = array();
637: $index = 0;
638:
639: $this->modifiedColumns[] = PubauthorPeer::PUBAUTHOR_ID;
640: if (null !== $this->pubauthor_id) {
641: throw new PropelException('Cannot insert a value for auto-increment primary key (' . PubauthorPeer::PUBAUTHOR_ID . ')');
642: }
643: if (null === $this->pubauthor_id) {
644: try {
645: $stmt = $con->query("SELECT nextval('pubauthor_pubauthor_id_seq')");
646: $row = $stmt->fetch(PDO::FETCH_NUM);
647: $this->pubauthor_id = $row[0];
648: } catch (Exception $e) {
649: throw new PropelException('Unable to get sequence id.', $e);
650: }
651: }
652:
653:
654: // check the columns in natural order for more readable SQL queries
655: if ($this->isColumnModified(PubauthorPeer::PUBAUTHOR_ID)) {
656: $modifiedColumns[':p' . $index++] = '"pubauthor_id"';
657: }
658: if ($this->isColumnModified(PubauthorPeer::PUB_ID)) {
659: $modifiedColumns[':p' . $index++] = '"pub_id"';
660: }
661: if ($this->isColumnModified(PubauthorPeer::RANK)) {
662: $modifiedColumns[':p' . $index++] = '"rank"';
663: }
664: if ($this->isColumnModified(PubauthorPeer::EDITOR)) {
665: $modifiedColumns[':p' . $index++] = '"editor"';
666: }
667: if ($this->isColumnModified(PubauthorPeer::SURNAME)) {
668: $modifiedColumns[':p' . $index++] = '"surname"';
669: }
670: if ($this->isColumnModified(PubauthorPeer::GIVENNAMES)) {
671: $modifiedColumns[':p' . $index++] = '"givennames"';
672: }
673: if ($this->isColumnModified(PubauthorPeer::SUFFIX)) {
674: $modifiedColumns[':p' . $index++] = '"suffix"';
675: }
676:
677: $sql = sprintf(
678: 'INSERT INTO "pubauthor" (%s) VALUES (%s)',
679: implode(', ', $modifiedColumns),
680: implode(', ', array_keys($modifiedColumns))
681: );
682:
683: try {
684: $stmt = $con->prepare($sql);
685: foreach ($modifiedColumns as $identifier => $columnName) {
686: switch ($columnName) {
687: case '"pubauthor_id"':
688: $stmt->bindValue($identifier, $this->pubauthor_id, PDO::PARAM_INT);
689: break;
690: case '"pub_id"':
691: $stmt->bindValue($identifier, $this->pub_id, PDO::PARAM_INT);
692: break;
693: case '"rank"':
694: $stmt->bindValue($identifier, $this->rank, PDO::PARAM_INT);
695: break;
696: case '"editor"':
697: $stmt->bindValue($identifier, $this->editor, PDO::PARAM_BOOL);
698: break;
699: case '"surname"':
700: $stmt->bindValue($identifier, $this->surname, PDO::PARAM_STR);
701: break;
702: case '"givennames"':
703: $stmt->bindValue($identifier, $this->givennames, PDO::PARAM_STR);
704: break;
705: case '"suffix"':
706: $stmt->bindValue($identifier, $this->suffix, PDO::PARAM_STR);
707: break;
708: }
709: }
710: $stmt->execute();
711: } catch (Exception $e) {
712: Propel::log($e->getMessage(), Propel::LOG_ERR);
713: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
714: }
715:
716: $this->setNew(false);
717: }
718:
719: /**
720: * Update the row in the database.
721: *
722: * @param PropelPDO $con
723: *
724: * @see doSave()
725: */
726: protected function doUpdate(PropelPDO $con)
727: {
728: $selectCriteria = $this->buildPkeyCriteria();
729: $valuesCriteria = $this->buildCriteria();
730: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
731: }
732:
733: /**
734: * Array of ValidationFailed objects.
735: * @var array ValidationFailed[]
736: */
737: protected $validationFailures = array();
738:
739: /**
740: * Gets any ValidationFailed objects that resulted from last call to validate().
741: *
742: *
743: * @return array ValidationFailed[]
744: * @see validate()
745: */
746: public function getValidationFailures()
747: {
748: return $this->validationFailures;
749: }
750:
751: /**
752: * Validates the objects modified field values and all objects related to this table.
753: *
754: * If $columns is either a column name or an array of column names
755: * only those columns are validated.
756: *
757: * @param mixed $columns Column name or an array of column names.
758: * @return boolean Whether all columns pass validation.
759: * @see doValidate()
760: * @see getValidationFailures()
761: */
762: public function validate($columns = null)
763: {
764: $res = $this->doValidate($columns);
765: if ($res === true) {
766: $this->validationFailures = array();
767:
768: return true;
769: }
770:
771: $this->validationFailures = $res;
772:
773: return false;
774: }
775:
776: /**
777: * This function performs the validation work for complex object models.
778: *
779: * In addition to checking the current object, all related objects will
780: * also be validated. If all pass then <code>true</code> is returned; otherwise
781: * an aggreagated array of ValidationFailed objects will be returned.
782: *
783: * @param array $columns Array of column names to validate.
784: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
785: */
786: protected function doValidate($columns = null)
787: {
788: if (!$this->alreadyInValidation) {
789: $this->alreadyInValidation = true;
790: $retval = null;
791:
792: $failureMap = array();
793:
794:
795: // We call the validate method on the following object(s) if they
796: // were passed to this object by their coresponding set
797: // method. This object relates to these object(s) by a
798: // foreign key reference.
799:
800: if ($this->aPub !== null) {
801: if (!$this->aPub->validate($columns)) {
802: $failureMap = array_merge($failureMap, $this->aPub->getValidationFailures());
803: }
804: }
805:
806:
807: if (($retval = PubauthorPeer::doValidate($this, $columns)) !== true) {
808: $failureMap = array_merge($failureMap, $retval);
809: }
810:
811:
812:
813: $this->alreadyInValidation = false;
814: }
815:
816: return (!empty($failureMap) ? $failureMap : true);
817: }
818:
819: /**
820: * Retrieves a field from the object by name passed in as a string.
821: *
822: * @param string $name name
823: * @param string $type The type of fieldname the $name is of:
824: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
825: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
826: * Defaults to BasePeer::TYPE_PHPNAME
827: * @return mixed Value of field.
828: */
829: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
830: {
831: $pos = PubauthorPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
832: $field = $this->getByPosition($pos);
833:
834: return $field;
835: }
836:
837: /**
838: * Retrieves a field from the object by Position as specified in the xml schema.
839: * Zero-based.
840: *
841: * @param int $pos position in xml schema
842: * @return mixed Value of field at $pos
843: */
844: public function getByPosition($pos)
845: {
846: switch ($pos) {
847: case 0:
848: return $this->getPubauthorId();
849: break;
850: case 1:
851: return $this->getPubId();
852: break;
853: case 2:
854: return $this->getRank();
855: break;
856: case 3:
857: return $this->getEditor();
858: break;
859: case 4:
860: return $this->getSurname();
861: break;
862: case 5:
863: return $this->getGivennames();
864: break;
865: case 6:
866: return $this->getSuffix();
867: break;
868: default:
869: return null;
870: break;
871: } // switch()
872: }
873:
874: /**
875: * Exports the object as an array.
876: *
877: * You can specify the key type of the array by passing one of the class
878: * type constants.
879: *
880: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
881: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
882: * Defaults to BasePeer::TYPE_PHPNAME.
883: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
884: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
885: * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
886: *
887: * @return array an associative array containing the field names (as keys) and field values
888: */
889: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
890: {
891: if (isset($alreadyDumpedObjects['Pubauthor'][$this->getPrimaryKey()])) {
892: return '*RECURSION*';
893: }
894: $alreadyDumpedObjects['Pubauthor'][$this->getPrimaryKey()] = true;
895: $keys = PubauthorPeer::getFieldNames($keyType);
896: $result = array(
897: $keys[0] => $this->getPubauthorId(),
898: $keys[1] => $this->getPubId(),
899: $keys[2] => $this->getRank(),
900: $keys[3] => $this->getEditor(),
901: $keys[4] => $this->getSurname(),
902: $keys[5] => $this->getGivennames(),
903: $keys[6] => $this->getSuffix(),
904: );
905: if ($includeForeignObjects) {
906: if (null !== $this->aPub) {
907: $result['Pub'] = $this->aPub->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
908: }
909: }
910:
911: return $result;
912: }
913:
914: /**
915: * Sets a field from the object by name passed in as a string.
916: *
917: * @param string $name peer name
918: * @param mixed $value field value
919: * @param string $type The type of fieldname the $name is of:
920: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
921: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
922: * Defaults to BasePeer::TYPE_PHPNAME
923: * @return void
924: */
925: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
926: {
927: $pos = PubauthorPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
928:
929: $this->setByPosition($pos, $value);
930: }
931:
932: /**
933: * Sets a field from the object by Position as specified in the xml schema.
934: * Zero-based.
935: *
936: * @param int $pos position in xml schema
937: * @param mixed $value field value
938: * @return void
939: */
940: public function setByPosition($pos, $value)
941: {
942: switch ($pos) {
943: case 0:
944: $this->setPubauthorId($value);
945: break;
946: case 1:
947: $this->setPubId($value);
948: break;
949: case 2:
950: $this->setRank($value);
951: break;
952: case 3:
953: $this->setEditor($value);
954: break;
955: case 4:
956: $this->setSurname($value);
957: break;
958: case 5:
959: $this->setGivennames($value);
960: break;
961: case 6:
962: $this->setSuffix($value);
963: break;
964: } // switch()
965: }
966:
967: /**
968: * Populates the object using an array.
969: *
970: * This is particularly useful when populating an object from one of the
971: * request arrays (e.g. $_POST). This method goes through the column
972: * names, checking to see whether a matching key exists in populated
973: * array. If so the setByName() method is called for that column.
974: *
975: * You can specify the key type of the array by additionally passing one
976: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
977: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
978: * The default key type is the column's BasePeer::TYPE_PHPNAME
979: *
980: * @param array $arr An array to populate the object from.
981: * @param string $keyType The type of keys the array uses.
982: * @return void
983: */
984: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
985: {
986: $keys = PubauthorPeer::getFieldNames($keyType);
987:
988: if (array_key_exists($keys[0], $arr)) $this->setPubauthorId($arr[$keys[0]]);
989: if (array_key_exists($keys[1], $arr)) $this->setPubId($arr[$keys[1]]);
990: if (array_key_exists($keys[2], $arr)) $this->setRank($arr[$keys[2]]);
991: if (array_key_exists($keys[3], $arr)) $this->setEditor($arr[$keys[3]]);
992: if (array_key_exists($keys[4], $arr)) $this->setSurname($arr[$keys[4]]);
993: if (array_key_exists($keys[5], $arr)) $this->setGivennames($arr[$keys[5]]);
994: if (array_key_exists($keys[6], $arr)) $this->setSuffix($arr[$keys[6]]);
995: }
996:
997: /**
998: * Build a Criteria object containing the values of all modified columns in this object.
999: *
1000: * @return Criteria The Criteria object containing all modified values.
1001: */
1002: public function buildCriteria()
1003: {
1004: $criteria = new Criteria(PubauthorPeer::DATABASE_NAME);
1005:
1006: if ($this->isColumnModified(PubauthorPeer::PUBAUTHOR_ID)) $criteria->add(PubauthorPeer::PUBAUTHOR_ID, $this->pubauthor_id);
1007: if ($this->isColumnModified(PubauthorPeer::PUB_ID)) $criteria->add(PubauthorPeer::PUB_ID, $this->pub_id);
1008: if ($this->isColumnModified(PubauthorPeer::RANK)) $criteria->add(PubauthorPeer::RANK, $this->rank);
1009: if ($this->isColumnModified(PubauthorPeer::EDITOR)) $criteria->add(PubauthorPeer::EDITOR, $this->editor);
1010: if ($this->isColumnModified(PubauthorPeer::SURNAME)) $criteria->add(PubauthorPeer::SURNAME, $this->surname);
1011: if ($this->isColumnModified(PubauthorPeer::GIVENNAMES)) $criteria->add(PubauthorPeer::GIVENNAMES, $this->givennames);
1012: if ($this->isColumnModified(PubauthorPeer::SUFFIX)) $criteria->add(PubauthorPeer::SUFFIX, $this->suffix);
1013:
1014: return $criteria;
1015: }
1016:
1017: /**
1018: * Builds a Criteria object containing the primary key for this object.
1019: *
1020: * Unlike buildCriteria() this method includes the primary key values regardless
1021: * of whether or not they have been modified.
1022: *
1023: * @return Criteria The Criteria object containing value(s) for primary key(s).
1024: */
1025: public function buildPkeyCriteria()
1026: {
1027: $criteria = new Criteria(PubauthorPeer::DATABASE_NAME);
1028: $criteria->add(PubauthorPeer::PUBAUTHOR_ID, $this->pubauthor_id);
1029:
1030: return $criteria;
1031: }
1032:
1033: /**
1034: * Returns the primary key for this object (row).
1035: * @return int
1036: */
1037: public function getPrimaryKey()
1038: {
1039: return $this->getPubauthorId();
1040: }
1041:
1042: /**
1043: * Generic method to set the primary key (pubauthor_id column).
1044: *
1045: * @param int $key Primary key.
1046: * @return void
1047: */
1048: public function setPrimaryKey($key)
1049: {
1050: $this->setPubauthorId($key);
1051: }
1052:
1053: /**
1054: * Returns true if the primary key for this object is null.
1055: * @return boolean
1056: */
1057: public function isPrimaryKeyNull()
1058: {
1059:
1060: return null === $this->getPubauthorId();
1061: }
1062:
1063: /**
1064: * Sets contents of passed object to values from current object.
1065: *
1066: * If desired, this method can also make copies of all associated (fkey referrers)
1067: * objects.
1068: *
1069: * @param object $copyObj An object of Pubauthor (or compatible) type.
1070: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1071: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1072: * @throws PropelException
1073: */
1074: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1075: {
1076: $copyObj->setPubId($this->getPubId());
1077: $copyObj->setRank($this->getRank());
1078: $copyObj->setEditor($this->getEditor());
1079: $copyObj->setSurname($this->getSurname());
1080: $copyObj->setGivennames($this->getGivennames());
1081: $copyObj->setSuffix($this->getSuffix());
1082:
1083: if ($deepCopy && !$this->startCopy) {
1084: // important: temporarily setNew(false) because this affects the behavior of
1085: // the getter/setter methods for fkey referrer objects.
1086: $copyObj->setNew(false);
1087: // store object hash to prevent cycle
1088: $this->startCopy = true;
1089:
1090: //unflag object copy
1091: $this->startCopy = false;
1092: } // if ($deepCopy)
1093:
1094: if ($makeNew) {
1095: $copyObj->setNew(true);
1096: $copyObj->setPubauthorId(NULL); // this is a auto-increment column, so set to default value
1097: }
1098: }
1099:
1100: /**
1101: * Makes a copy of this object that will be inserted as a new row in table when saved.
1102: * It creates a new object filling in the simple attributes, but skipping any primary
1103: * keys that are defined for the table.
1104: *
1105: * If desired, this method can also make copies of all associated (fkey referrers)
1106: * objects.
1107: *
1108: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1109: * @return Pubauthor Clone of current object.
1110: * @throws PropelException
1111: */
1112: public function copy($deepCopy = false)
1113: {
1114: // we use get_class(), because this might be a subclass
1115: $clazz = get_class($this);
1116: $copyObj = new $clazz();
1117: $this->copyInto($copyObj, $deepCopy);
1118:
1119: return $copyObj;
1120: }
1121:
1122: /**
1123: * Returns a peer instance associated with this om.
1124: *
1125: * Since Peer classes are not to have any instance attributes, this method returns the
1126: * same instance for all member of this class. The method could therefore
1127: * be static, but this would prevent one from overriding the behavior.
1128: *
1129: * @return PubauthorPeer
1130: */
1131: public function getPeer()
1132: {
1133: if (self::$peer === null) {
1134: self::$peer = new PubauthorPeer();
1135: }
1136:
1137: return self::$peer;
1138: }
1139:
1140: /**
1141: * Declares an association between this object and a Pub object.
1142: *
1143: * @param Pub $v
1144: * @return Pubauthor The current object (for fluent API support)
1145: * @throws PropelException
1146: */
1147: public function setPub(Pub $v = null)
1148: {
1149: if ($v === null) {
1150: $this->setPubId(NULL);
1151: } else {
1152: $this->setPubId($v->getPubId());
1153: }
1154:
1155: $this->aPub = $v;
1156:
1157: // Add binding for other direction of this n:n relationship.
1158: // If this object has already been added to the Pub object, it will not be re-added.
1159: if ($v !== null) {
1160: $v->addPubauthor($this);
1161: }
1162:
1163:
1164: return $this;
1165: }
1166:
1167:
1168: /**
1169: * Get the associated Pub object
1170: *
1171: * @param PropelPDO $con Optional Connection object.
1172: * @param $doQuery Executes a query to get the object if required
1173: * @return Pub The associated Pub object.
1174: * @throws PropelException
1175: */
1176: public function getPub(PropelPDO $con = null, $doQuery = true)
1177: {
1178: if ($this->aPub === null && ($this->pub_id !== null) && $doQuery) {
1179: $this->aPub = PubQuery::create()->findPk($this->pub_id, $con);
1180: /* The following can be used additionally to
1181: guarantee the related object contains a reference
1182: to this object. This level of coupling may, however, be
1183: undesirable since it could result in an only partially populated collection
1184: in the referenced object.
1185: $this->aPub->addPubauthors($this);
1186: */
1187: }
1188:
1189: return $this->aPub;
1190: }
1191:
1192: /**
1193: * Clears the current object and sets all attributes to their default values
1194: */
1195: public function clear()
1196: {
1197: $this->pubauthor_id = null;
1198: $this->pub_id = null;
1199: $this->rank = null;
1200: $this->editor = null;
1201: $this->surname = null;
1202: $this->givennames = null;
1203: $this->suffix = null;
1204: $this->alreadyInSave = false;
1205: $this->alreadyInValidation = false;
1206: $this->alreadyInClearAllReferencesDeep = false;
1207: $this->clearAllReferences();
1208: $this->applyDefaultValues();
1209: $this->resetModified();
1210: $this->setNew(true);
1211: $this->setDeleted(false);
1212: }
1213:
1214: /**
1215: * Resets all references to other model objects or collections of model objects.
1216: *
1217: * This method is a user-space workaround for PHP's inability to garbage collect
1218: * objects with circular references (even in PHP 5.3). This is currently necessary
1219: * when using Propel in certain daemon or large-volumne/high-memory operations.
1220: *
1221: * @param boolean $deep Whether to also clear the references on all referrer objects.
1222: */
1223: public function clearAllReferences($deep = false)
1224: {
1225: if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1226: $this->alreadyInClearAllReferencesDeep = true;
1227: if ($this->aPub instanceof Persistent) {
1228: $this->aPub->clearAllReferences($deep);
1229: }
1230:
1231: $this->alreadyInClearAllReferencesDeep = false;
1232: } // if ($deep)
1233:
1234: $this->aPub = null;
1235: }
1236:
1237: /**
1238: * return the string representation of this object
1239: *
1240: * @return string
1241: */
1242: public function __toString()
1243: {
1244: return (string) $this->exportTo(PubauthorPeer::DEFAULT_STRING_FORMAT);
1245: }
1246:
1247: /**
1248: * return true is the object is in saving state
1249: *
1250: * @return boolean
1251: */
1252: public function isAlreadyInSave()
1253: {
1254: return $this->alreadyInSave;
1255: }
1256:
1257: }
1258: