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