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