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