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\Biomaterial;
17: use cli_db\propel\BiomaterialQuery;
18: use cli_db\propel\Feature;
19: use cli_db\propel\FeatureQuery;
20: use cli_db\propel\Organism;
21: use cli_db\propel\OrganismPeer;
22: use cli_db\propel\OrganismQuery;
23:
24: /**
25: * Base class that represents a row from the 'organism' table.
26: *
27: *
28: *
29: * @package propel.generator.cli_db.om
30: */
31: abstract class BaseOrganism extends BaseObject implements Persistent
32: {
33: /**
34: * Peer class name
35: */
36: const PEER = 'cli_db\\propel\\OrganismPeer';
37:
38: /**
39: * The Peer class.
40: * Instance provides a convenient way of calling static methods on a class
41: * that calling code may not be able to identify.
42: * @var OrganismPeer
43: */
44: protected static $peer;
45:
46: /**
47: * The flag var to prevent infinit loop in deep copy
48: * @var boolean
49: */
50: protected $startCopy = false;
51:
52: /**
53: * The value for the organism_id field.
54: * @var int
55: */
56: protected $organism_id;
57:
58: /**
59: * The value for the abbreviation field.
60: * @var string
61: */
62: protected $abbreviation;
63:
64: /**
65: * The value for the genus field.
66: * @var string
67: */
68: protected $genus;
69:
70: /**
71: * The value for the species field.
72: * @var string
73: */
74: protected $species;
75:
76: /**
77: * The value for the common_name field.
78: * @var string
79: */
80: protected $common_name;
81:
82: /**
83: * The value for the comment field.
84: * @var string
85: */
86: protected $comment;
87:
88: /**
89: * @var PropelObjectCollection|Biomaterial[] Collection to store aggregation of Biomaterial objects.
90: */
91: protected $collBiomaterials;
92: protected $collBiomaterialsPartial;
93:
94: /**
95: * @var PropelObjectCollection|Feature[] Collection to store aggregation of Feature objects.
96: */
97: protected $collFeatures;
98: protected $collFeaturesPartial;
99:
100: /**
101: * Flag to prevent endless save loop, if this object is referenced
102: * by another object which falls in this transaction.
103: * @var boolean
104: */
105: protected $alreadyInSave = false;
106:
107: /**
108: * Flag to prevent endless validation loop, if this object is referenced
109: * by another object which falls in this transaction.
110: * @var boolean
111: */
112: protected $alreadyInValidation = false;
113:
114: /**
115: * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
116: * @var boolean
117: */
118: protected $alreadyInClearAllReferencesDeep = false;
119:
120: /**
121: * An array of objects scheduled for deletion.
122: * @var PropelObjectCollection
123: */
124: protected $biomaterialsScheduledForDeletion = null;
125:
126: /**
127: * An array of objects scheduled for deletion.
128: * @var PropelObjectCollection
129: */
130: protected $featuresScheduledForDeletion = null;
131:
132: /**
133: * Get the [organism_id] column value.
134: *
135: * @return int
136: */
137: public function getOrganismId()
138: {
139: return $this->organism_id;
140: }
141:
142: /**
143: * Get the [abbreviation] column value.
144: *
145: * @return string
146: */
147: public function getAbbreviation()
148: {
149: return $this->abbreviation;
150: }
151:
152: /**
153: * Get the [genus] column value.
154: *
155: * @return string
156: */
157: public function getGenus()
158: {
159: return $this->genus;
160: }
161:
162: /**
163: * Get the [species] column value.
164: *
165: * @return string
166: */
167: public function getSpecies()
168: {
169: return $this->species;
170: }
171:
172: /**
173: * Get the [common_name] column value.
174: *
175: * @return string
176: */
177: public function getCommonName()
178: {
179: return $this->common_name;
180: }
181:
182: /**
183: * Get the [comment] column value.
184: *
185: * @return string
186: */
187: public function getComment()
188: {
189: return $this->comment;
190: }
191:
192: /**
193: * Set the value of [organism_id] column.
194: *
195: * @param int $v new value
196: * @return Organism The current object (for fluent API support)
197: */
198: public function setOrganismId($v)
199: {
200: if ($v !== null && is_numeric($v)) {
201: $v = (int) $v;
202: }
203:
204: if ($this->organism_id !== $v) {
205: $this->organism_id = $v;
206: $this->modifiedColumns[] = OrganismPeer::ORGANISM_ID;
207: }
208:
209:
210: return $this;
211: } // setOrganismId()
212:
213: /**
214: * Set the value of [abbreviation] column.
215: *
216: * @param string $v new value
217: * @return Organism The current object (for fluent API support)
218: */
219: public function setAbbreviation($v)
220: {
221: if ($v !== null && is_numeric($v)) {
222: $v = (string) $v;
223: }
224:
225: if ($this->abbreviation !== $v) {
226: $this->abbreviation = $v;
227: $this->modifiedColumns[] = OrganismPeer::ABBREVIATION;
228: }
229:
230:
231: return $this;
232: } // setAbbreviation()
233:
234: /**
235: * Set the value of [genus] column.
236: *
237: * @param string $v new value
238: * @return Organism The current object (for fluent API support)
239: */
240: public function setGenus($v)
241: {
242: if ($v !== null && is_numeric($v)) {
243: $v = (string) $v;
244: }
245:
246: if ($this->genus !== $v) {
247: $this->genus = $v;
248: $this->modifiedColumns[] = OrganismPeer::GENUS;
249: }
250:
251:
252: return $this;
253: } // setGenus()
254:
255: /**
256: * Set the value of [species] column.
257: *
258: * @param string $v new value
259: * @return Organism The current object (for fluent API support)
260: */
261: public function setSpecies($v)
262: {
263: if ($v !== null && is_numeric($v)) {
264: $v = (string) $v;
265: }
266:
267: if ($this->species !== $v) {
268: $this->species = $v;
269: $this->modifiedColumns[] = OrganismPeer::SPECIES;
270: }
271:
272:
273: return $this;
274: } // setSpecies()
275:
276: /**
277: * Set the value of [common_name] column.
278: *
279: * @param string $v new value
280: * @return Organism The current object (for fluent API support)
281: */
282: public function setCommonName($v)
283: {
284: if ($v !== null && is_numeric($v)) {
285: $v = (string) $v;
286: }
287:
288: if ($this->common_name !== $v) {
289: $this->common_name = $v;
290: $this->modifiedColumns[] = OrganismPeer::COMMON_NAME;
291: }
292:
293:
294: return $this;
295: } // setCommonName()
296:
297: /**
298: * Set the value of [comment] column.
299: *
300: * @param string $v new value
301: * @return Organism The current object (for fluent API support)
302: */
303: public function setComment($v)
304: {
305: if ($v !== null && is_numeric($v)) {
306: $v = (string) $v;
307: }
308:
309: if ($this->comment !== $v) {
310: $this->comment = $v;
311: $this->modifiedColumns[] = OrganismPeer::COMMENT;
312: }
313:
314:
315: return $this;
316: } // setComment()
317:
318: /**
319: * Indicates whether the columns in this object are only set to default values.
320: *
321: * This method can be used in conjunction with isModified() to indicate whether an object is both
322: * modified _and_ has some values set which are non-default.
323: *
324: * @return boolean Whether the columns in this object are only been set with default values.
325: */
326: public function hasOnlyDefaultValues()
327: {
328: // otherwise, everything was equal, so return true
329: return true;
330: } // hasOnlyDefaultValues()
331:
332: /**
333: * Hydrates (populates) the object variables with values from the database resultset.
334: *
335: * An offset (0-based "start column") is specified so that objects can be hydrated
336: * with a subset of the columns in the resultset rows. This is needed, for example,
337: * for results of JOIN queries where the resultset row includes columns from two or
338: * more tables.
339: *
340: * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
341: * @param int $startcol 0-based offset column which indicates which restultset column to start with.
342: * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
343: * @return int next starting column
344: * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
345: */
346: public function hydrate($row, $startcol = 0, $rehydrate = false)
347: {
348: try {
349:
350: $this->organism_id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
351: $this->abbreviation = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;
352: $this->genus = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
353: $this->species = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
354: $this->common_name = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
355: $this->comment = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
356: $this->resetModified();
357:
358: $this->setNew(false);
359:
360: if ($rehydrate) {
361: $this->ensureConsistency();
362: }
363: $this->postHydrate($row, $startcol, $rehydrate);
364: return $startcol + 6; // 6 = OrganismPeer::NUM_HYDRATE_COLUMNS.
365:
366: } catch (Exception $e) {
367: throw new PropelException("Error populating Organism object", $e);
368: }
369: }
370:
371: /**
372: * Checks and repairs the internal consistency of the object.
373: *
374: * This method is executed after an already-instantiated object is re-hydrated
375: * from the database. It exists to check any foreign keys to make sure that
376: * the objects related to the current object are correct based on foreign key.
377: *
378: * You can override this method in the stub class, but you should always invoke
379: * the base method from the overridden method (i.e. parent::ensureConsistency()),
380: * in case your model changes.
381: *
382: * @throws PropelException
383: */
384: public function ensureConsistency()
385: {
386:
387: } // ensureConsistency
388:
389: /**
390: * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
391: *
392: * This will only work if the object has been saved and has a valid primary key set.
393: *
394: * @param boolean $deep (optional) Whether to also de-associated any related objects.
395: * @param PropelPDO $con (optional) The PropelPDO connection to use.
396: * @return void
397: * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
398: */
399: public function reload($deep = false, PropelPDO $con = null)
400: {
401: if ($this->isDeleted()) {
402: throw new PropelException("Cannot reload a deleted object.");
403: }
404:
405: if ($this->isNew()) {
406: throw new PropelException("Cannot reload an unsaved object.");
407: }
408:
409: if ($con === null) {
410: $con = Propel::getConnection(OrganismPeer::DATABASE_NAME, Propel::CONNECTION_READ);
411: }
412:
413: // We don't need to alter the object instance pool; we're just modifying this instance
414: // already in the pool.
415:
416: $stmt = OrganismPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
417: $row = $stmt->fetch(PDO::FETCH_NUM);
418: $stmt->closeCursor();
419: if (!$row) {
420: throw new PropelException('Cannot find matching row in the database to reload object values.');
421: }
422: $this->hydrate($row, 0, true); // rehydrate
423:
424: if ($deep) { // also de-associate any related objects?
425:
426: $this->collBiomaterials = null;
427:
428: $this->collFeatures = null;
429:
430: } // if (deep)
431: }
432:
433: /**
434: * Removes this object from datastore and sets delete attribute.
435: *
436: * @param PropelPDO $con
437: * @return void
438: * @throws PropelException
439: * @throws Exception
440: * @see BaseObject::setDeleted()
441: * @see BaseObject::isDeleted()
442: */
443: public function delete(PropelPDO $con = null)
444: {
445: if ($this->isDeleted()) {
446: throw new PropelException("This object has already been deleted.");
447: }
448:
449: if ($con === null) {
450: $con = Propel::getConnection(OrganismPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
451: }
452:
453: $con->beginTransaction();
454: try {
455: $deleteQuery = OrganismQuery::create()
456: ->filterByPrimaryKey($this->getPrimaryKey());
457: $ret = $this->preDelete($con);
458: if ($ret) {
459: $deleteQuery->delete($con);
460: $this->postDelete($con);
461: $con->commit();
462: $this->setDeleted(true);
463: } else {
464: $con->commit();
465: }
466: } catch (Exception $e) {
467: $con->rollBack();
468: throw $e;
469: }
470: }
471:
472: /**
473: * Persists this object to the database.
474: *
475: * If the object is new, it inserts it; otherwise an update is performed.
476: * All modified related objects will also be persisted in the doSave()
477: * method. This method wraps all precipitate database operations in a
478: * single transaction.
479: *
480: * @param PropelPDO $con
481: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
482: * @throws PropelException
483: * @throws Exception
484: * @see doSave()
485: */
486: public function save(PropelPDO $con = null)
487: {
488: if ($this->isDeleted()) {
489: throw new PropelException("You cannot save an object that has been deleted.");
490: }
491:
492: if ($con === null) {
493: $con = Propel::getConnection(OrganismPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
494: }
495:
496: $con->beginTransaction();
497: $isInsert = $this->isNew();
498: try {
499: $ret = $this->preSave($con);
500: if ($isInsert) {
501: $ret = $ret && $this->preInsert($con);
502: } else {
503: $ret = $ret && $this->preUpdate($con);
504: }
505: if ($ret) {
506: $affectedRows = $this->doSave($con);
507: if ($isInsert) {
508: $this->postInsert($con);
509: } else {
510: $this->postUpdate($con);
511: }
512: $this->postSave($con);
513: OrganismPeer::addInstanceToPool($this);
514: } else {
515: $affectedRows = 0;
516: }
517: $con->commit();
518:
519: return $affectedRows;
520: } catch (Exception $e) {
521: $con->rollBack();
522: throw $e;
523: }
524: }
525:
526: /**
527: * Performs the work of inserting or updating the row in the database.
528: *
529: * If the object is new, it inserts it; otherwise an update is performed.
530: * All related objects are also updated in this method.
531: *
532: * @param PropelPDO $con
533: * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
534: * @throws PropelException
535: * @see save()
536: */
537: protected function doSave(PropelPDO $con)
538: {
539: $affectedRows = 0; // initialize var to track total num of affected rows
540: if (!$this->alreadyInSave) {
541: $this->alreadyInSave = true;
542:
543: if ($this->isNew() || $this->isModified()) {
544: // persist changes
545: if ($this->isNew()) {
546: $this->doInsert($con);
547: } else {
548: $this->doUpdate($con);
549: }
550: $affectedRows += 1;
551: $this->resetModified();
552: }
553:
554: if ($this->biomaterialsScheduledForDeletion !== null) {
555: if (!$this->biomaterialsScheduledForDeletion->isEmpty()) {
556: foreach ($this->biomaterialsScheduledForDeletion as $biomaterial) {
557: // need to save related object because we set the relation to null
558: $biomaterial->save($con);
559: }
560: $this->biomaterialsScheduledForDeletion = null;
561: }
562: }
563:
564: if ($this->collBiomaterials !== null) {
565: foreach ($this->collBiomaterials as $referrerFK) {
566: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
567: $affectedRows += $referrerFK->save($con);
568: }
569: }
570: }
571:
572: if ($this->featuresScheduledForDeletion !== null) {
573: if (!$this->featuresScheduledForDeletion->isEmpty()) {
574: FeatureQuery::create()
575: ->filterByPrimaryKeys($this->featuresScheduledForDeletion->getPrimaryKeys(false))
576: ->delete($con);
577: $this->featuresScheduledForDeletion = null;
578: }
579: }
580:
581: if ($this->collFeatures !== null) {
582: foreach ($this->collFeatures as $referrerFK) {
583: if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
584: $affectedRows += $referrerFK->save($con);
585: }
586: }
587: }
588:
589: $this->alreadyInSave = false;
590:
591: }
592:
593: return $affectedRows;
594: } // doSave()
595:
596: /**
597: * Insert the row in the database.
598: *
599: * @param PropelPDO $con
600: *
601: * @throws PropelException
602: * @see doSave()
603: */
604: protected function doInsert(PropelPDO $con)
605: {
606: $modifiedColumns = array();
607: $index = 0;
608:
609: $this->modifiedColumns[] = OrganismPeer::ORGANISM_ID;
610: if (null !== $this->organism_id) {
611: throw new PropelException('Cannot insert a value for auto-increment primary key (' . OrganismPeer::ORGANISM_ID . ')');
612: }
613: if (null === $this->organism_id) {
614: try {
615: $stmt = $con->query("SELECT nextval('organism_organism_id_seq')");
616: $row = $stmt->fetch(PDO::FETCH_NUM);
617: $this->organism_id = $row[0];
618: } catch (Exception $e) {
619: throw new PropelException('Unable to get sequence id.', $e);
620: }
621: }
622:
623:
624: // check the columns in natural order for more readable SQL queries
625: if ($this->isColumnModified(OrganismPeer::ORGANISM_ID)) {
626: $modifiedColumns[':p' . $index++] = '"organism_id"';
627: }
628: if ($this->isColumnModified(OrganismPeer::ABBREVIATION)) {
629: $modifiedColumns[':p' . $index++] = '"abbreviation"';
630: }
631: if ($this->isColumnModified(OrganismPeer::GENUS)) {
632: $modifiedColumns[':p' . $index++] = '"genus"';
633: }
634: if ($this->isColumnModified(OrganismPeer::SPECIES)) {
635: $modifiedColumns[':p' . $index++] = '"species"';
636: }
637: if ($this->isColumnModified(OrganismPeer::COMMON_NAME)) {
638: $modifiedColumns[':p' . $index++] = '"common_name"';
639: }
640: if ($this->isColumnModified(OrganismPeer::COMMENT)) {
641: $modifiedColumns[':p' . $index++] = '"comment"';
642: }
643:
644: $sql = sprintf(
645: 'INSERT INTO "organism" (%s) VALUES (%s)',
646: implode(', ', $modifiedColumns),
647: implode(', ', array_keys($modifiedColumns))
648: );
649:
650: try {
651: $stmt = $con->prepare($sql);
652: foreach ($modifiedColumns as $identifier => $columnName) {
653: switch ($columnName) {
654: case '"organism_id"':
655: $stmt->bindValue($identifier, $this->organism_id, PDO::PARAM_INT);
656: break;
657: case '"abbreviation"':
658: $stmt->bindValue($identifier, $this->abbreviation, PDO::PARAM_STR);
659: break;
660: case '"genus"':
661: $stmt->bindValue($identifier, $this->genus, PDO::PARAM_STR);
662: break;
663: case '"species"':
664: $stmt->bindValue($identifier, $this->species, PDO::PARAM_STR);
665: break;
666: case '"common_name"':
667: $stmt->bindValue($identifier, $this->common_name, PDO::PARAM_STR);
668: break;
669: case '"comment"':
670: $stmt->bindValue($identifier, $this->comment, PDO::PARAM_STR);
671: break;
672: }
673: }
674: $stmt->execute();
675: } catch (Exception $e) {
676: Propel::log($e->getMessage(), Propel::LOG_ERR);
677: throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
678: }
679:
680: $this->setNew(false);
681: }
682:
683: /**
684: * Update the row in the database.
685: *
686: * @param PropelPDO $con
687: *
688: * @see doSave()
689: */
690: protected function doUpdate(PropelPDO $con)
691: {
692: $selectCriteria = $this->buildPkeyCriteria();
693: $valuesCriteria = $this->buildCriteria();
694: BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
695: }
696:
697: /**
698: * Array of ValidationFailed objects.
699: * @var array ValidationFailed[]
700: */
701: protected $validationFailures = array();
702:
703: /**
704: * Gets any ValidationFailed objects that resulted from last call to validate().
705: *
706: *
707: * @return array ValidationFailed[]
708: * @see validate()
709: */
710: public function getValidationFailures()
711: {
712: return $this->validationFailures;
713: }
714:
715: /**
716: * Validates the objects modified field values and all objects related to this table.
717: *
718: * If $columns is either a column name or an array of column names
719: * only those columns are validated.
720: *
721: * @param mixed $columns Column name or an array of column names.
722: * @return boolean Whether all columns pass validation.
723: * @see doValidate()
724: * @see getValidationFailures()
725: */
726: public function validate($columns = null)
727: {
728: $res = $this->doValidate($columns);
729: if ($res === true) {
730: $this->validationFailures = array();
731:
732: return true;
733: }
734:
735: $this->validationFailures = $res;
736:
737: return false;
738: }
739:
740: /**
741: * This function performs the validation work for complex object models.
742: *
743: * In addition to checking the current object, all related objects will
744: * also be validated. If all pass then <code>true</code> is returned; otherwise
745: * an aggreagated array of ValidationFailed objects will be returned.
746: *
747: * @param array $columns Array of column names to validate.
748: * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
749: */
750: protected function doValidate($columns = null)
751: {
752: if (!$this->alreadyInValidation) {
753: $this->alreadyInValidation = true;
754: $retval = null;
755:
756: $failureMap = array();
757:
758:
759: if (($retval = OrganismPeer::doValidate($this, $columns)) !== true) {
760: $failureMap = array_merge($failureMap, $retval);
761: }
762:
763:
764: if ($this->collBiomaterials !== null) {
765: foreach ($this->collBiomaterials as $referrerFK) {
766: if (!$referrerFK->validate($columns)) {
767: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
768: }
769: }
770: }
771:
772: if ($this->collFeatures !== null) {
773: foreach ($this->collFeatures as $referrerFK) {
774: if (!$referrerFK->validate($columns)) {
775: $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
776: }
777: }
778: }
779:
780:
781: $this->alreadyInValidation = false;
782: }
783:
784: return (!empty($failureMap) ? $failureMap : true);
785: }
786:
787: /**
788: * Retrieves a field from the object by name passed in as a string.
789: *
790: * @param string $name name
791: * @param string $type The type of fieldname the $name is of:
792: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
793: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
794: * Defaults to BasePeer::TYPE_PHPNAME
795: * @return mixed Value of field.
796: */
797: public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
798: {
799: $pos = OrganismPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
800: $field = $this->getByPosition($pos);
801:
802: return $field;
803: }
804:
805: /**
806: * Retrieves a field from the object by Position as specified in the xml schema.
807: * Zero-based.
808: *
809: * @param int $pos position in xml schema
810: * @return mixed Value of field at $pos
811: */
812: public function getByPosition($pos)
813: {
814: switch ($pos) {
815: case 0:
816: return $this->getOrganismId();
817: break;
818: case 1:
819: return $this->getAbbreviation();
820: break;
821: case 2:
822: return $this->getGenus();
823: break;
824: case 3:
825: return $this->getSpecies();
826: break;
827: case 4:
828: return $this->getCommonName();
829: break;
830: case 5:
831: return $this->getComment();
832: break;
833: default:
834: return null;
835: break;
836: } // switch()
837: }
838:
839: /**
840: * Exports the object as an array.
841: *
842: * You can specify the key type of the array by passing one of the class
843: * type constants.
844: *
845: * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
846: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
847: * Defaults to BasePeer::TYPE_PHPNAME.
848: * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
849: * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
850: * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
851: *
852: * @return array an associative array containing the field names (as keys) and field values
853: */
854: public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
855: {
856: if (isset($alreadyDumpedObjects['Organism'][$this->getPrimaryKey()])) {
857: return '*RECURSION*';
858: }
859: $alreadyDumpedObjects['Organism'][$this->getPrimaryKey()] = true;
860: $keys = OrganismPeer::getFieldNames($keyType);
861: $result = array(
862: $keys[0] => $this->getOrganismId(),
863: $keys[1] => $this->getAbbreviation(),
864: $keys[2] => $this->getGenus(),
865: $keys[3] => $this->getSpecies(),
866: $keys[4] => $this->getCommonName(),
867: $keys[5] => $this->getComment(),
868: );
869: if ($includeForeignObjects) {
870: if (null !== $this->collBiomaterials) {
871: $result['Biomaterials'] = $this->collBiomaterials->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
872: }
873: if (null !== $this->collFeatures) {
874: $result['Features'] = $this->collFeatures->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
875: }
876: }
877:
878: return $result;
879: }
880:
881: /**
882: * Sets a field from the object by name passed in as a string.
883: *
884: * @param string $name peer name
885: * @param mixed $value field value
886: * @param string $type The type of fieldname the $name is of:
887: * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
888: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
889: * Defaults to BasePeer::TYPE_PHPNAME
890: * @return void
891: */
892: public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
893: {
894: $pos = OrganismPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
895:
896: $this->setByPosition($pos, $value);
897: }
898:
899: /**
900: * Sets a field from the object by Position as specified in the xml schema.
901: * Zero-based.
902: *
903: * @param int $pos position in xml schema
904: * @param mixed $value field value
905: * @return void
906: */
907: public function setByPosition($pos, $value)
908: {
909: switch ($pos) {
910: case 0:
911: $this->setOrganismId($value);
912: break;
913: case 1:
914: $this->setAbbreviation($value);
915: break;
916: case 2:
917: $this->setGenus($value);
918: break;
919: case 3:
920: $this->setSpecies($value);
921: break;
922: case 4:
923: $this->setCommonName($value);
924: break;
925: case 5:
926: $this->setComment($value);
927: break;
928: } // switch()
929: }
930:
931: /**
932: * Populates the object using an array.
933: *
934: * This is particularly useful when populating an object from one of the
935: * request arrays (e.g. $_POST). This method goes through the column
936: * names, checking to see whether a matching key exists in populated
937: * array. If so the setByName() method is called for that column.
938: *
939: * You can specify the key type of the array by additionally passing one
940: * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
941: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
942: * The default key type is the column's BasePeer::TYPE_PHPNAME
943: *
944: * @param array $arr An array to populate the object from.
945: * @param string $keyType The type of keys the array uses.
946: * @return void
947: */
948: public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
949: {
950: $keys = OrganismPeer::getFieldNames($keyType);
951:
952: if (array_key_exists($keys[0], $arr)) $this->setOrganismId($arr[$keys[0]]);
953: if (array_key_exists($keys[1], $arr)) $this->setAbbreviation($arr[$keys[1]]);
954: if (array_key_exists($keys[2], $arr)) $this->setGenus($arr[$keys[2]]);
955: if (array_key_exists($keys[3], $arr)) $this->setSpecies($arr[$keys[3]]);
956: if (array_key_exists($keys[4], $arr)) $this->setCommonName($arr[$keys[4]]);
957: if (array_key_exists($keys[5], $arr)) $this->setComment($arr[$keys[5]]);
958: }
959:
960: /**
961: * Build a Criteria object containing the values of all modified columns in this object.
962: *
963: * @return Criteria The Criteria object containing all modified values.
964: */
965: public function buildCriteria()
966: {
967: $criteria = new Criteria(OrganismPeer::DATABASE_NAME);
968:
969: if ($this->isColumnModified(OrganismPeer::ORGANISM_ID)) $criteria->add(OrganismPeer::ORGANISM_ID, $this->organism_id);
970: if ($this->isColumnModified(OrganismPeer::ABBREVIATION)) $criteria->add(OrganismPeer::ABBREVIATION, $this->abbreviation);
971: if ($this->isColumnModified(OrganismPeer::GENUS)) $criteria->add(OrganismPeer::GENUS, $this->genus);
972: if ($this->isColumnModified(OrganismPeer::SPECIES)) $criteria->add(OrganismPeer::SPECIES, $this->species);
973: if ($this->isColumnModified(OrganismPeer::COMMON_NAME)) $criteria->add(OrganismPeer::COMMON_NAME, $this->common_name);
974: if ($this->isColumnModified(OrganismPeer::COMMENT)) $criteria->add(OrganismPeer::COMMENT, $this->comment);
975:
976: return $criteria;
977: }
978:
979: /**
980: * Builds a Criteria object containing the primary key for this object.
981: *
982: * Unlike buildCriteria() this method includes the primary key values regardless
983: * of whether or not they have been modified.
984: *
985: * @return Criteria The Criteria object containing value(s) for primary key(s).
986: */
987: public function buildPkeyCriteria()
988: {
989: $criteria = new Criteria(OrganismPeer::DATABASE_NAME);
990: $criteria->add(OrganismPeer::ORGANISM_ID, $this->organism_id);
991:
992: return $criteria;
993: }
994:
995: /**
996: * Returns the primary key for this object (row).
997: * @return int
998: */
999: public function getPrimaryKey()
1000: {
1001: return $this->getOrganismId();
1002: }
1003:
1004: /**
1005: * Generic method to set the primary key (organism_id column).
1006: *
1007: * @param int $key Primary key.
1008: * @return void
1009: */
1010: public function setPrimaryKey($key)
1011: {
1012: $this->setOrganismId($key);
1013: }
1014:
1015: /**
1016: * Returns true if the primary key for this object is null.
1017: * @return boolean
1018: */
1019: public function isPrimaryKeyNull()
1020: {
1021:
1022: return null === $this->getOrganismId();
1023: }
1024:
1025: /**
1026: * Sets contents of passed object to values from current object.
1027: *
1028: * If desired, this method can also make copies of all associated (fkey referrers)
1029: * objects.
1030: *
1031: * @param object $copyObj An object of Organism (or compatible) type.
1032: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1033: * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
1034: * @throws PropelException
1035: */
1036: public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
1037: {
1038: $copyObj->setAbbreviation($this->getAbbreviation());
1039: $copyObj->setGenus($this->getGenus());
1040: $copyObj->setSpecies($this->getSpecies());
1041: $copyObj->setCommonName($this->getCommonName());
1042: $copyObj->setComment($this->getComment());
1043:
1044: if ($deepCopy && !$this->startCopy) {
1045: // important: temporarily setNew(false) because this affects the behavior of
1046: // the getter/setter methods for fkey referrer objects.
1047: $copyObj->setNew(false);
1048: // store object hash to prevent cycle
1049: $this->startCopy = true;
1050:
1051: foreach ($this->getBiomaterials() as $relObj) {
1052: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1053: $copyObj->addBiomaterial($relObj->copy($deepCopy));
1054: }
1055: }
1056:
1057: foreach ($this->getFeatures() as $relObj) {
1058: if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
1059: $copyObj->addFeature($relObj->copy($deepCopy));
1060: }
1061: }
1062:
1063: //unflag object copy
1064: $this->startCopy = false;
1065: } // if ($deepCopy)
1066:
1067: if ($makeNew) {
1068: $copyObj->setNew(true);
1069: $copyObj->setOrganismId(NULL); // this is a auto-increment column, so set to default value
1070: }
1071: }
1072:
1073: /**
1074: * Makes a copy of this object that will be inserted as a new row in table when saved.
1075: * It creates a new object filling in the simple attributes, but skipping any primary
1076: * keys that are defined for the table.
1077: *
1078: * If desired, this method can also make copies of all associated (fkey referrers)
1079: * objects.
1080: *
1081: * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
1082: * @return Organism Clone of current object.
1083: * @throws PropelException
1084: */
1085: public function copy($deepCopy = false)
1086: {
1087: // we use get_class(), because this might be a subclass
1088: $clazz = get_class($this);
1089: $copyObj = new $clazz();
1090: $this->copyInto($copyObj, $deepCopy);
1091:
1092: return $copyObj;
1093: }
1094:
1095: /**
1096: * Returns a peer instance associated with this om.
1097: *
1098: * Since Peer classes are not to have any instance attributes, this method returns the
1099: * same instance for all member of this class. The method could therefore
1100: * be static, but this would prevent one from overriding the behavior.
1101: *
1102: * @return OrganismPeer
1103: */
1104: public function getPeer()
1105: {
1106: if (self::$peer === null) {
1107: self::$peer = new OrganismPeer();
1108: }
1109:
1110: return self::$peer;
1111: }
1112:
1113:
1114: /**
1115: * Initializes a collection based on the name of a relation.
1116: * Avoids crafting an 'init[$relationName]s' method name
1117: * that wouldn't work when StandardEnglishPluralizer is used.
1118: *
1119: * @param string $relationName The name of the relation to initialize
1120: * @return void
1121: */
1122: public function initRelation($relationName)
1123: {
1124: if ('Biomaterial' == $relationName) {
1125: $this->initBiomaterials();
1126: }
1127: if ('Feature' == $relationName) {
1128: $this->initFeatures();
1129: }
1130: }
1131:
1132: /**
1133: * Clears out the collBiomaterials collection
1134: *
1135: * This does not modify the database; however, it will remove any associated objects, causing
1136: * them to be refetched by subsequent calls to accessor method.
1137: *
1138: * @return Organism The current object (for fluent API support)
1139: * @see addBiomaterials()
1140: */
1141: public function clearBiomaterials()
1142: {
1143: $this->collBiomaterials = null; // important to set this to null since that means it is uninitialized
1144: $this->collBiomaterialsPartial = null;
1145:
1146: return $this;
1147: }
1148:
1149: /**
1150: * reset is the collBiomaterials collection loaded partially
1151: *
1152: * @return void
1153: */
1154: public function resetPartialBiomaterials($v = true)
1155: {
1156: $this->collBiomaterialsPartial = $v;
1157: }
1158:
1159: /**
1160: * Initializes the collBiomaterials collection.
1161: *
1162: * By default this just sets the collBiomaterials collection to an empty array (like clearcollBiomaterials());
1163: * however, you may wish to override this method in your stub class to provide setting appropriate
1164: * to your application -- for example, setting the initial array to the values stored in database.
1165: *
1166: * @param boolean $overrideExisting If set to true, the method call initializes
1167: * the collection even if it is not empty
1168: *
1169: * @return void
1170: */
1171: public function initBiomaterials($overrideExisting = true)
1172: {
1173: if (null !== $this->collBiomaterials && !$overrideExisting) {
1174: return;
1175: }
1176: $this->collBiomaterials = new PropelObjectCollection();
1177: $this->collBiomaterials->setModel('Biomaterial');
1178: }
1179:
1180: /**
1181: * Gets an array of Biomaterial objects which contain a foreign key that references this object.
1182: *
1183: * If the $criteria is not null, it is used to always fetch the results from the database.
1184: * Otherwise the results are fetched from the database the first time, then cached.
1185: * Next time the same method is called without $criteria, the cached collection is returned.
1186: * If this Organism is new, it will return
1187: * an empty collection or the current collection; the criteria is ignored on a new object.
1188: *
1189: * @param Criteria $criteria optional Criteria object to narrow the query
1190: * @param PropelPDO $con optional connection object
1191: * @return PropelObjectCollection|Biomaterial[] List of Biomaterial objects
1192: * @throws PropelException
1193: */
1194: public function getBiomaterials($criteria = null, PropelPDO $con = null)
1195: {
1196: $partial = $this->collBiomaterialsPartial && !$this->isNew();
1197: if (null === $this->collBiomaterials || null !== $criteria || $partial) {
1198: if ($this->isNew() && null === $this->collBiomaterials) {
1199: // return empty collection
1200: $this->initBiomaterials();
1201: } else {
1202: $collBiomaterials = BiomaterialQuery::create(null, $criteria)
1203: ->filterByOrganism($this)
1204: ->find($con);
1205: if (null !== $criteria) {
1206: if (false !== $this->collBiomaterialsPartial && count($collBiomaterials)) {
1207: $this->initBiomaterials(false);
1208:
1209: foreach($collBiomaterials as $obj) {
1210: if (false == $this->collBiomaterials->contains($obj)) {
1211: $this->collBiomaterials->append($obj);
1212: }
1213: }
1214:
1215: $this->collBiomaterialsPartial = true;
1216: }
1217:
1218: $collBiomaterials->getInternalIterator()->rewind();
1219: return $collBiomaterials;
1220: }
1221:
1222: if($partial && $this->collBiomaterials) {
1223: foreach($this->collBiomaterials as $obj) {
1224: if($obj->isNew()) {
1225: $collBiomaterials[] = $obj;
1226: }
1227: }
1228: }
1229:
1230: $this->collBiomaterials = $collBiomaterials;
1231: $this->collBiomaterialsPartial = false;
1232: }
1233: }
1234:
1235: return $this->collBiomaterials;
1236: }
1237:
1238: /**
1239: * Sets a collection of Biomaterial objects related by a one-to-many relationship
1240: * to the current object.
1241: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1242: * and new objects from the given Propel collection.
1243: *
1244: * @param PropelCollection $biomaterials A Propel collection.
1245: * @param PropelPDO $con Optional connection object
1246: * @return Organism The current object (for fluent API support)
1247: */
1248: public function setBiomaterials(PropelCollection $biomaterials, PropelPDO $con = null)
1249: {
1250: $biomaterialsToDelete = $this->getBiomaterials(new Criteria(), $con)->diff($biomaterials);
1251:
1252: $this->biomaterialsScheduledForDeletion = unserialize(serialize($biomaterialsToDelete));
1253:
1254: foreach ($biomaterialsToDelete as $biomaterialRemoved) {
1255: $biomaterialRemoved->setOrganism(null);
1256: }
1257:
1258: $this->collBiomaterials = null;
1259: foreach ($biomaterials as $biomaterial) {
1260: $this->addBiomaterial($biomaterial);
1261: }
1262:
1263: $this->collBiomaterials = $biomaterials;
1264: $this->collBiomaterialsPartial = false;
1265:
1266: return $this;
1267: }
1268:
1269: /**
1270: * Returns the number of related Biomaterial objects.
1271: *
1272: * @param Criteria $criteria
1273: * @param boolean $distinct
1274: * @param PropelPDO $con
1275: * @return int Count of related Biomaterial objects.
1276: * @throws PropelException
1277: */
1278: public function countBiomaterials(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1279: {
1280: $partial = $this->collBiomaterialsPartial && !$this->isNew();
1281: if (null === $this->collBiomaterials || null !== $criteria || $partial) {
1282: if ($this->isNew() && null === $this->collBiomaterials) {
1283: return 0;
1284: }
1285:
1286: if($partial && !$criteria) {
1287: return count($this->getBiomaterials());
1288: }
1289: $query = BiomaterialQuery::create(null, $criteria);
1290: if ($distinct) {
1291: $query->distinct();
1292: }
1293:
1294: return $query
1295: ->filterByOrganism($this)
1296: ->count($con);
1297: }
1298:
1299: return count($this->collBiomaterials);
1300: }
1301:
1302: /**
1303: * Method called to associate a Biomaterial object to this object
1304: * through the Biomaterial foreign key attribute.
1305: *
1306: * @param Biomaterial $l Biomaterial
1307: * @return Organism The current object (for fluent API support)
1308: */
1309: public function addBiomaterial(Biomaterial $l)
1310: {
1311: if ($this->collBiomaterials === null) {
1312: $this->initBiomaterials();
1313: $this->collBiomaterialsPartial = true;
1314: }
1315: if (!in_array($l, $this->collBiomaterials->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
1316: $this->doAddBiomaterial($l);
1317: }
1318:
1319: return $this;
1320: }
1321:
1322: /**
1323: * @param Biomaterial $biomaterial The biomaterial object to add.
1324: */
1325: protected function doAddBiomaterial($biomaterial)
1326: {
1327: $this->collBiomaterials[]= $biomaterial;
1328: $biomaterial->setOrganism($this);
1329: }
1330:
1331: /**
1332: * @param Biomaterial $biomaterial The biomaterial object to remove.
1333: * @return Organism The current object (for fluent API support)
1334: */
1335: public function removeBiomaterial($biomaterial)
1336: {
1337: if ($this->getBiomaterials()->contains($biomaterial)) {
1338: $this->collBiomaterials->remove($this->collBiomaterials->search($biomaterial));
1339: if (null === $this->biomaterialsScheduledForDeletion) {
1340: $this->biomaterialsScheduledForDeletion = clone $this->collBiomaterials;
1341: $this->biomaterialsScheduledForDeletion->clear();
1342: }
1343: $this->biomaterialsScheduledForDeletion[]= $biomaterial;
1344: $biomaterial->setOrganism(null);
1345: }
1346:
1347: return $this;
1348: }
1349:
1350:
1351: /**
1352: * If this collection has already been initialized with
1353: * an identical criteria, it returns the collection.
1354: * Otherwise if this Organism is new, it will return
1355: * an empty collection; or if this Organism has previously
1356: * been saved, it will retrieve related Biomaterials from storage.
1357: *
1358: * This method is protected by default in order to keep the public
1359: * api reasonable. You can provide public methods for those you
1360: * actually need in Organism.
1361: *
1362: * @param Criteria $criteria optional Criteria object to narrow the query
1363: * @param PropelPDO $con optional connection object
1364: * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1365: * @return PropelObjectCollection|Biomaterial[] List of Biomaterial objects
1366: */
1367: public function getBiomaterialsJoinContact($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
1368: {
1369: $query = BiomaterialQuery::create(null, $criteria);
1370: $query->joinWith('Contact', $join_behavior);
1371:
1372: return $this->getBiomaterials($query, $con);
1373: }
1374:
1375: /**
1376: * Clears out the collFeatures collection
1377: *
1378: * This does not modify the database; however, it will remove any associated objects, causing
1379: * them to be refetched by subsequent calls to accessor method.
1380: *
1381: * @return Organism The current object (for fluent API support)
1382: * @see addFeatures()
1383: */
1384: public function clearFeatures()
1385: {
1386: $this->collFeatures = null; // important to set this to null since that means it is uninitialized
1387: $this->collFeaturesPartial = null;
1388:
1389: return $this;
1390: }
1391:
1392: /**
1393: * reset is the collFeatures collection loaded partially
1394: *
1395: * @return void
1396: */
1397: public function resetPartialFeatures($v = true)
1398: {
1399: $this->collFeaturesPartial = $v;
1400: }
1401:
1402: /**
1403: * Initializes the collFeatures collection.
1404: *
1405: * By default this just sets the collFeatures collection to an empty array (like clearcollFeatures());
1406: * however, you may wish to override this method in your stub class to provide setting appropriate
1407: * to your application -- for example, setting the initial array to the values stored in database.
1408: *
1409: * @param boolean $overrideExisting If set to true, the method call initializes
1410: * the collection even if it is not empty
1411: *
1412: * @return void
1413: */
1414: public function initFeatures($overrideExisting = true)
1415: {
1416: if (null !== $this->collFeatures && !$overrideExisting) {
1417: return;
1418: }
1419: $this->collFeatures = new PropelObjectCollection();
1420: $this->collFeatures->setModel('Feature');
1421: }
1422:
1423: /**
1424: * Gets an array of Feature objects which contain a foreign key that references this object.
1425: *
1426: * If the $criteria is not null, it is used to always fetch the results from the database.
1427: * Otherwise the results are fetched from the database the first time, then cached.
1428: * Next time the same method is called without $criteria, the cached collection is returned.
1429: * If this Organism is new, it will return
1430: * an empty collection or the current collection; the criteria is ignored on a new object.
1431: *
1432: * @param Criteria $criteria optional Criteria object to narrow the query
1433: * @param PropelPDO $con optional connection object
1434: * @return PropelObjectCollection|Feature[] List of Feature objects
1435: * @throws PropelException
1436: */
1437: public function getFeatures($criteria = null, PropelPDO $con = null)
1438: {
1439: $partial = $this->collFeaturesPartial && !$this->isNew();
1440: if (null === $this->collFeatures || null !== $criteria || $partial) {
1441: if ($this->isNew() && null === $this->collFeatures) {
1442: // return empty collection
1443: $this->initFeatures();
1444: } else {
1445: $collFeatures = FeatureQuery::create(null, $criteria)
1446: ->filterByOrganism($this)
1447: ->find($con);
1448: if (null !== $criteria) {
1449: if (false !== $this->collFeaturesPartial && count($collFeatures)) {
1450: $this->initFeatures(false);
1451:
1452: foreach($collFeatures as $obj) {
1453: if (false == $this->collFeatures->contains($obj)) {
1454: $this->collFeatures->append($obj);
1455: }
1456: }
1457:
1458: $this->collFeaturesPartial = true;
1459: }
1460:
1461: $collFeatures->getInternalIterator()->rewind();
1462: return $collFeatures;
1463: }
1464:
1465: if($partial && $this->collFeatures) {
1466: foreach($this->collFeatures as $obj) {
1467: if($obj->isNew()) {
1468: $collFeatures[] = $obj;
1469: }
1470: }
1471: }
1472:
1473: $this->collFeatures = $collFeatures;
1474: $this->collFeaturesPartial = false;
1475: }
1476: }
1477:
1478: return $this->collFeatures;
1479: }
1480:
1481: /**
1482: * Sets a collection of Feature objects related by a one-to-many relationship
1483: * to the current object.
1484: * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
1485: * and new objects from the given Propel collection.
1486: *
1487: * @param PropelCollection $features A Propel collection.
1488: * @param PropelPDO $con Optional connection object
1489: * @return Organism The current object (for fluent API support)
1490: */
1491: public function setFeatures(PropelCollection $features, PropelPDO $con = null)
1492: {
1493: $featuresToDelete = $this->getFeatures(new Criteria(), $con)->diff($features);
1494:
1495: $this->featuresScheduledForDeletion = unserialize(serialize($featuresToDelete));
1496:
1497: foreach ($featuresToDelete as $featureRemoved) {
1498: $featureRemoved->setOrganism(null);
1499: }
1500:
1501: $this->collFeatures = null;
1502: foreach ($features as $feature) {
1503: $this->addFeature($feature);
1504: }
1505:
1506: $this->collFeatures = $features;
1507: $this->collFeaturesPartial = false;
1508:
1509: return $this;
1510: }
1511:
1512: /**
1513: * Returns the number of related Feature objects.
1514: *
1515: * @param Criteria $criteria
1516: * @param boolean $distinct
1517: * @param PropelPDO $con
1518: * @return int Count of related Feature objects.
1519: * @throws PropelException
1520: */
1521: public function countFeatures(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
1522: {
1523: $partial = $this->collFeaturesPartial && !$this->isNew();
1524: if (null === $this->collFeatures || null !== $criteria || $partial) {
1525: if ($this->isNew() && null === $this->collFeatures) {
1526: return 0;
1527: }
1528:
1529: if($partial && !$criteria) {
1530: return count($this->getFeatures());
1531: }
1532: $query = FeatureQuery::create(null, $criteria);
1533: if ($distinct) {
1534: $query->distinct();
1535: }
1536:
1537: return $query
1538: ->filterByOrganism($this)
1539: ->count($con);
1540: }
1541:
1542: return count($this->collFeatures);
1543: }
1544:
1545: /**
1546: * Method called to associate a Feature object to this object
1547: * through the Feature foreign key attribute.
1548: *
1549: * @param Feature $l Feature
1550: * @return Organism The current object (for fluent API support)
1551: */
1552: public function addFeature(Feature $l)
1553: {
1554: if ($this->collFeatures === null) {
1555: $this->initFeatures();
1556: $this->collFeaturesPartial = true;
1557: }
1558: if (!in_array($l, $this->collFeatures->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
1559: $this->doAddFeature($l);
1560: }
1561:
1562: return $this;
1563: }
1564:
1565: /**
1566: * @param Feature $feature The feature object to add.
1567: */
1568: protected function doAddFeature($feature)
1569: {
1570: $this->collFeatures[]= $feature;
1571: $feature->setOrganism($this);
1572: }
1573:
1574: /**
1575: * @param Feature $feature The feature object to remove.
1576: * @return Organism The current object (for fluent API support)
1577: */
1578: public function removeFeature($feature)
1579: {
1580: if ($this->getFeatures()->contains($feature)) {
1581: $this->collFeatures->remove($this->collFeatures->search($feature));
1582: if (null === $this->featuresScheduledForDeletion) {
1583: $this->featuresScheduledForDeletion = clone $this->collFeatures;
1584: $this->featuresScheduledForDeletion->clear();
1585: }
1586: $this->featuresScheduledForDeletion[]= clone $feature;
1587: $feature->setOrganism(null);
1588: }
1589:
1590: return $this;
1591: }
1592:
1593:
1594: /**
1595: * If this collection has already been initialized with
1596: * an identical criteria, it returns the collection.
1597: * Otherwise if this Organism is new, it will return
1598: * an empty collection; or if this Organism has previously
1599: * been saved, it will retrieve related Features from storage.
1600: *
1601: * This method is protected by default in order to keep the public
1602: * api reasonable. You can provide public methods for those you
1603: * actually need in Organism.
1604: *
1605: * @param Criteria $criteria optional Criteria object to narrow the query
1606: * @param PropelPDO $con optional connection object
1607: * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1608: * @return PropelObjectCollection|Feature[] List of Feature objects
1609: */
1610: public function getFeaturesJoinDbxref($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
1611: {
1612: $query = FeatureQuery::create(null, $criteria);
1613: $query->joinWith('Dbxref', $join_behavior);
1614:
1615: return $this->getFeatures($query, $con);
1616: }
1617:
1618:
1619: /**
1620: * If this collection has already been initialized with
1621: * an identical criteria, it returns the collection.
1622: * Otherwise if this Organism is new, it will return
1623: * an empty collection; or if this Organism has previously
1624: * been saved, it will retrieve related Features from storage.
1625: *
1626: * This method is protected by default in order to keep the public
1627: * api reasonable. You can provide public methods for those you
1628: * actually need in Organism.
1629: *
1630: * @param Criteria $criteria optional Criteria object to narrow the query
1631: * @param PropelPDO $con optional connection object
1632: * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
1633: * @return PropelObjectCollection|Feature[] List of Feature objects
1634: */
1635: public function getFeaturesJoinCvterm($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
1636: {
1637: $query = FeatureQuery::create(null, $criteria);
1638: $query->joinWith('Cvterm', $join_behavior);
1639:
1640: return $this->getFeatures($query, $con);
1641: }
1642:
1643: /**
1644: * Clears the current object and sets all attributes to their default values
1645: */
1646: public function clear()
1647: {
1648: $this->organism_id = null;
1649: $this->abbreviation = null;
1650: $this->genus = null;
1651: $this->species = null;
1652: $this->common_name = null;
1653: $this->comment = null;
1654: $this->alreadyInSave = false;
1655: $this->alreadyInValidation = false;
1656: $this->alreadyInClearAllReferencesDeep = false;
1657: $this->clearAllReferences();
1658: $this->resetModified();
1659: $this->setNew(true);
1660: $this->setDeleted(false);
1661: }
1662:
1663: /**
1664: * Resets all references to other model objects or collections of model objects.
1665: *
1666: * This method is a user-space workaround for PHP's inability to garbage collect
1667: * objects with circular references (even in PHP 5.3). This is currently necessary
1668: * when using Propel in certain daemon or large-volumne/high-memory operations.
1669: *
1670: * @param boolean $deep Whether to also clear the references on all referrer objects.
1671: */
1672: public function clearAllReferences($deep = false)
1673: {
1674: if ($deep && !$this->alreadyInClearAllReferencesDeep) {
1675: $this->alreadyInClearAllReferencesDeep = true;
1676: if ($this->collBiomaterials) {
1677: foreach ($this->collBiomaterials as $o) {
1678: $o->clearAllReferences($deep);
1679: }
1680: }
1681: if ($this->collFeatures) {
1682: foreach ($this->collFeatures as $o) {
1683: $o->clearAllReferences($deep);
1684: }
1685: }
1686:
1687: $this->alreadyInClearAllReferencesDeep = false;
1688: } // if ($deep)
1689:
1690: if ($this->collBiomaterials instanceof PropelCollection) {
1691: $this->collBiomaterials->clearIterator();
1692: }
1693: $this->collBiomaterials = null;
1694: if ($this->collFeatures instanceof PropelCollection) {
1695: $this->collFeatures->clearIterator();
1696: }
1697: $this->collFeatures = null;
1698: }
1699:
1700: /**
1701: * return the string representation of this object
1702: *
1703: * @return string
1704: */
1705: public function __toString()
1706: {
1707: return (string) $this->exportTo(OrganismPeer::DEFAULT_STRING_FORMAT);
1708: }
1709:
1710: /**
1711: * return true is the object is in saving state
1712: *
1713: * @return boolean
1714: */
1715: public function isAlreadyInSave()
1716: {
1717: return $this->alreadyInSave;
1718: }
1719:
1720: }
1721: