1: <?php
2:
3: namespace cli_db\propel\om;
4:
5: use \BasePeer;
6: use \Criteria;
7: use \PDO;
8: use \PDOStatement;
9: use \Propel;
10: use \PropelException;
11: use \PropelPDO;
12: use cli_db\propel\AssayPeer;
13: use cli_db\propel\BiomaterialPeer;
14: use cli_db\propel\Contact;
15: use cli_db\propel\ContactPeer;
16: use cli_db\propel\CvtermPeer;
17: use cli_db\propel\QuantificationPeer;
18: use cli_db\propel\map\ContactTableMap;
19:
20: /**
21: * Base static class for performing query and update operations on the 'contact' table.
22: *
23: *
24: *
25: * @package propel.generator.cli_db.om
26: */
27: abstract class BaseContactPeer
28: {
29:
30: /** the default database name for this class */
31: const DATABASE_NAME = 'cli_db';
32:
33: /** the table name for this class */
34: const TABLE_NAME = 'contact';
35:
36: /** the related Propel class for this table */
37: const OM_CLASS = 'cli_db\\propel\\Contact';
38:
39: /** the related TableMap class for this table */
40: const TM_CLASS = 'ContactTableMap';
41:
42: /** The total number of columns. */
43: const NUM_COLUMNS = 4;
44:
45: /** The number of lazy-loaded columns. */
46: const NUM_LAZY_LOAD_COLUMNS = 0;
47:
48: /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
49: const NUM_HYDRATE_COLUMNS = 4;
50:
51: /** the column name for the contact_id field */
52: const CONTACT_ID = 'contact.contact_id';
53:
54: /** the column name for the type_id field */
55: const TYPE_ID = 'contact.type_id';
56:
57: /** the column name for the name field */
58: const NAME = 'contact.name';
59:
60: /** the column name for the description field */
61: const DESCRIPTION = 'contact.description';
62:
63: /** The default string format for model objects of the related table **/
64: const DEFAULT_STRING_FORMAT = 'YAML';
65:
66: /**
67: * An identiy map to hold any loaded instances of Contact objects.
68: * This must be public so that other peer classes can access this when hydrating from JOIN
69: * queries.
70: * @var array Contact[]
71: */
72: public static $instances = array();
73:
74:
75: /**
76: * holds an array of fieldnames
77: *
78: * first dimension keys are the type constants
79: * e.g. ContactPeer::$fieldNames[ContactPeer::TYPE_PHPNAME][0] = 'Id'
80: */
81: protected static $fieldNames = array (
82: BasePeer::TYPE_PHPNAME => array ('ContactId', 'TypeId', 'Name', 'Description', ),
83: BasePeer::TYPE_STUDLYPHPNAME => array ('contactId', 'typeId', 'name', 'description', ),
84: BasePeer::TYPE_COLNAME => array (ContactPeer::CONTACT_ID, ContactPeer::TYPE_ID, ContactPeer::NAME, ContactPeer::DESCRIPTION, ),
85: BasePeer::TYPE_RAW_COLNAME => array ('CONTACT_ID', 'TYPE_ID', 'NAME', 'DESCRIPTION', ),
86: BasePeer::TYPE_FIELDNAME => array ('contact_id', 'type_id', 'name', 'description', ),
87: BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
88: );
89:
90: /**
91: * holds an array of keys for quick access to the fieldnames array
92: *
93: * first dimension keys are the type constants
94: * e.g. ContactPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
95: */
96: protected static $fieldKeys = array (
97: BasePeer::TYPE_PHPNAME => array ('ContactId' => 0, 'TypeId' => 1, 'Name' => 2, 'Description' => 3, ),
98: BasePeer::TYPE_STUDLYPHPNAME => array ('contactId' => 0, 'typeId' => 1, 'name' => 2, 'description' => 3, ),
99: BasePeer::TYPE_COLNAME => array (ContactPeer::CONTACT_ID => 0, ContactPeer::TYPE_ID => 1, ContactPeer::NAME => 2, ContactPeer::DESCRIPTION => 3, ),
100: BasePeer::TYPE_RAW_COLNAME => array ('CONTACT_ID' => 0, 'TYPE_ID' => 1, 'NAME' => 2, 'DESCRIPTION' => 3, ),
101: BasePeer::TYPE_FIELDNAME => array ('contact_id' => 0, 'type_id' => 1, 'name' => 2, 'description' => 3, ),
102: BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
103: );
104:
105: /**
106: * Translates a fieldname to another type
107: *
108: * @param string $name field name
109: * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
110: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
111: * @param string $toType One of the class type constants
112: * @return string translated name of the field.
113: * @throws PropelException - if the specified name could not be found in the fieldname mappings.
114: */
115: public static function translateFieldName($name, $fromType, $toType)
116: {
117: $toNames = ContactPeer::getFieldNames($toType);
118: $key = isset(ContactPeer::$fieldKeys[$fromType][$name]) ? ContactPeer::$fieldKeys[$fromType][$name] : null;
119: if ($key === null) {
120: throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(ContactPeer::$fieldKeys[$fromType], true));
121: }
122:
123: return $toNames[$key];
124: }
125:
126: /**
127: * Returns an array of field names.
128: *
129: * @param string $type The type of fieldnames to return:
130: * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
131: * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
132: * @return array A list of field names
133: * @throws PropelException - if the type is not valid.
134: */
135: public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
136: {
137: if (!array_key_exists($type, ContactPeer::$fieldNames)) {
138: throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
139: }
140:
141: return ContactPeer::$fieldNames[$type];
142: }
143:
144: /**
145: * Convenience method which changes table.column to alias.column.
146: *
147: * Using this method you can maintain SQL abstraction while using column aliases.
148: * <code>
149: * $c->addAlias("alias1", TablePeer::TABLE_NAME);
150: * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
151: * </code>
152: * @param string $alias The alias for the current table.
153: * @param string $column The column name for current table. (i.e. ContactPeer::COLUMN_NAME).
154: * @return string
155: */
156: public static function alias($alias, $column)
157: {
158: return str_replace(ContactPeer::TABLE_NAME.'.', $alias.'.', $column);
159: }
160:
161: /**
162: * Add all the columns needed to create a new object.
163: *
164: * Note: any columns that were marked with lazyLoad="true" in the
165: * XML schema will not be added to the select list and only loaded
166: * on demand.
167: *
168: * @param Criteria $criteria object containing the columns to add.
169: * @param string $alias optional table alias
170: * @throws PropelException Any exceptions caught during processing will be
171: * rethrown wrapped into a PropelException.
172: */
173: public static function addSelectColumns(Criteria $criteria, $alias = null)
174: {
175: if (null === $alias) {
176: $criteria->addSelectColumn(ContactPeer::CONTACT_ID);
177: $criteria->addSelectColumn(ContactPeer::TYPE_ID);
178: $criteria->addSelectColumn(ContactPeer::NAME);
179: $criteria->addSelectColumn(ContactPeer::DESCRIPTION);
180: } else {
181: $criteria->addSelectColumn($alias . '.contact_id');
182: $criteria->addSelectColumn($alias . '.type_id');
183: $criteria->addSelectColumn($alias . '.name');
184: $criteria->addSelectColumn($alias . '.description');
185: }
186: }
187:
188: /**
189: * Returns the number of rows matching criteria.
190: *
191: * @param Criteria $criteria
192: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
193: * @param PropelPDO $con
194: * @return int Number of matching rows.
195: */
196: public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
197: {
198: // we may modify criteria, so copy it first
199: $criteria = clone $criteria;
200:
201: // We need to set the primary table name, since in the case that there are no WHERE columns
202: // it will be impossible for the BasePeer::createSelectSql() method to determine which
203: // tables go into the FROM clause.
204: $criteria->setPrimaryTableName(ContactPeer::TABLE_NAME);
205:
206: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
207: $criteria->setDistinct();
208: }
209:
210: if (!$criteria->hasSelectClause()) {
211: ContactPeer::addSelectColumns($criteria);
212: }
213:
214: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
215: $criteria->setDbName(ContactPeer::DATABASE_NAME); // Set the correct dbName
216:
217: if ($con === null) {
218: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
219: }
220: // BasePeer returns a PDOStatement
221: $stmt = BasePeer::doCount($criteria, $con);
222:
223: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
224: $count = (int) $row[0];
225: } else {
226: $count = 0; // no rows returned; we infer that means 0 matches.
227: }
228: $stmt->closeCursor();
229:
230: return $count;
231: }
232: /**
233: * Selects one object from the DB.
234: *
235: * @param Criteria $criteria object used to create the SELECT statement.
236: * @param PropelPDO $con
237: * @return Contact
238: * @throws PropelException Any exceptions caught during processing will be
239: * rethrown wrapped into a PropelException.
240: */
241: public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
242: {
243: $critcopy = clone $criteria;
244: $critcopy->setLimit(1);
245: $objects = ContactPeer::doSelect($critcopy, $con);
246: if ($objects) {
247: return $objects[0];
248: }
249:
250: return null;
251: }
252: /**
253: * Selects several row from the DB.
254: *
255: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
256: * @param PropelPDO $con
257: * @return array Array of selected Objects
258: * @throws PropelException Any exceptions caught during processing will be
259: * rethrown wrapped into a PropelException.
260: */
261: public static function doSelect(Criteria $criteria, PropelPDO $con = null)
262: {
263: return ContactPeer::populateObjects(ContactPeer::doSelectStmt($criteria, $con));
264: }
265: /**
266: * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
267: *
268: * Use this method directly if you want to work with an executed statement directly (for example
269: * to perform your own object hydration).
270: *
271: * @param Criteria $criteria The Criteria object used to build the SELECT statement.
272: * @param PropelPDO $con The connection to use
273: * @throws PropelException Any exceptions caught during processing will be
274: * rethrown wrapped into a PropelException.
275: * @return PDOStatement The executed PDOStatement object.
276: * @see BasePeer::doSelect()
277: */
278: public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
279: {
280: if ($con === null) {
281: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
282: }
283:
284: if (!$criteria->hasSelectClause()) {
285: $criteria = clone $criteria;
286: ContactPeer::addSelectColumns($criteria);
287: }
288:
289: // Set the correct dbName
290: $criteria->setDbName(ContactPeer::DATABASE_NAME);
291:
292: // BasePeer returns a PDOStatement
293: return BasePeer::doSelect($criteria, $con);
294: }
295: /**
296: * Adds an object to the instance pool.
297: *
298: * Propel keeps cached copies of objects in an instance pool when they are retrieved
299: * from the database. In some cases -- especially when you override doSelect*()
300: * methods in your stub classes -- you may need to explicitly add objects
301: * to the cache in order to ensure that the same objects are always returned by doSelect*()
302: * and retrieveByPK*() calls.
303: *
304: * @param Contact $obj A Contact object.
305: * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
306: */
307: public static function addInstanceToPool($obj, $key = null)
308: {
309: if (Propel::isInstancePoolingEnabled()) {
310: if ($key === null) {
311: $key = (string) $obj->getContactId();
312: } // if key === null
313: ContactPeer::$instances[$key] = $obj;
314: }
315: }
316:
317: /**
318: * Removes an object from the instance pool.
319: *
320: * Propel keeps cached copies of objects in an instance pool when they are retrieved
321: * from the database. In some cases -- especially when you override doDelete
322: * methods in your stub classes -- you may need to explicitly remove objects
323: * from the cache in order to prevent returning objects that no longer exist.
324: *
325: * @param mixed $value A Contact object or a primary key value.
326: *
327: * @return void
328: * @throws PropelException - if the value is invalid.
329: */
330: public static function removeInstanceFromPool($value)
331: {
332: if (Propel::isInstancePoolingEnabled() && $value !== null) {
333: if (is_object($value) && $value instanceof Contact) {
334: $key = (string) $value->getContactId();
335: } elseif (is_scalar($value)) {
336: // assume we've been passed a primary key
337: $key = (string) $value;
338: } else {
339: $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Contact object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
340: throw $e;
341: }
342:
343: unset(ContactPeer::$instances[$key]);
344: }
345: } // removeInstanceFromPool()
346:
347: /**
348: * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
349: *
350: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
351: * a multi-column primary key, a serialize()d version of the primary key will be returned.
352: *
353: * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
354: * @return Contact Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
355: * @see getPrimaryKeyHash()
356: */
357: public static function getInstanceFromPool($key)
358: {
359: if (Propel::isInstancePoolingEnabled()) {
360: if (isset(ContactPeer::$instances[$key])) {
361: return ContactPeer::$instances[$key];
362: }
363: }
364:
365: return null; // just to be explicit
366: }
367:
368: /**
369: * Clear the instance pool.
370: *
371: * @return void
372: */
373: public static function clearInstancePool($and_clear_all_references = false)
374: {
375: if ($and_clear_all_references)
376: {
377: foreach (ContactPeer::$instances as $instance)
378: {
379: $instance->clearAllReferences(true);
380: }
381: }
382: ContactPeer::$instances = array();
383: }
384:
385: /**
386: * Method to invalidate the instance pool of all tables related to contact
387: * by a foreign key with ON DELETE CASCADE
388: */
389: public static function clearRelatedInstancePool()
390: {
391: // Invalidate objects in AssayPeer instance pool,
392: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
393: AssayPeer::clearInstancePool();
394: // Invalidate objects in BiomaterialPeer instance pool,
395: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
396: BiomaterialPeer::clearInstancePool();
397: // Invalidate objects in QuantificationPeer instance pool,
398: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
399: QuantificationPeer::clearInstancePool();
400: }
401:
402: /**
403: * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
404: *
405: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
406: * a multi-column primary key, a serialize()d version of the primary key will be returned.
407: *
408: * @param array $row PropelPDO resultset row.
409: * @param int $startcol The 0-based offset for reading from the resultset row.
410: * @return string A string version of PK or null if the components of primary key in result array are all null.
411: */
412: public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
413: {
414: // If the PK cannot be derived from the row, return null.
415: if ($row[$startcol] === null) {
416: return null;
417: }
418:
419: return (string) $row[$startcol];
420: }
421:
422: /**
423: * Retrieves the primary key from the DB resultset row
424: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
425: * a multi-column primary key, an array of the primary key columns will be returned.
426: *
427: * @param array $row PropelPDO resultset row.
428: * @param int $startcol The 0-based offset for reading from the resultset row.
429: * @return mixed The primary key of the row
430: */
431: public static function getPrimaryKeyFromRow($row, $startcol = 0)
432: {
433:
434: return (int) $row[$startcol];
435: }
436:
437: /**
438: * The returned array will contain objects of the default type or
439: * objects that inherit from the default.
440: *
441: * @throws PropelException Any exceptions caught during processing will be
442: * rethrown wrapped into a PropelException.
443: */
444: public static function populateObjects(PDOStatement $stmt)
445: {
446: $results = array();
447:
448: // set the class once to avoid overhead in the loop
449: $cls = ContactPeer::getOMClass();
450: // populate the object(s)
451: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
452: $key = ContactPeer::getPrimaryKeyHashFromRow($row, 0);
453: if (null !== ($obj = ContactPeer::getInstanceFromPool($key))) {
454: // We no longer rehydrate the object, since this can cause data loss.
455: // See http://www.propelorm.org/ticket/509
456: // $obj->hydrate($row, 0, true); // rehydrate
457: $results[] = $obj;
458: } else {
459: $obj = new $cls();
460: $obj->hydrate($row);
461: $results[] = $obj;
462: ContactPeer::addInstanceToPool($obj, $key);
463: } // if key exists
464: }
465: $stmt->closeCursor();
466:
467: return $results;
468: }
469: /**
470: * Populates an object of the default type or an object that inherit from the default.
471: *
472: * @param array $row PropelPDO resultset row.
473: * @param int $startcol The 0-based offset for reading from the resultset row.
474: * @throws PropelException Any exceptions caught during processing will be
475: * rethrown wrapped into a PropelException.
476: * @return array (Contact object, last column rank)
477: */
478: public static function populateObject($row, $startcol = 0)
479: {
480: $key = ContactPeer::getPrimaryKeyHashFromRow($row, $startcol);
481: if (null !== ($obj = ContactPeer::getInstanceFromPool($key))) {
482: // We no longer rehydrate the object, since this can cause data loss.
483: // See http://www.propelorm.org/ticket/509
484: // $obj->hydrate($row, $startcol, true); // rehydrate
485: $col = $startcol + ContactPeer::NUM_HYDRATE_COLUMNS;
486: } else {
487: $cls = ContactPeer::OM_CLASS;
488: $obj = new $cls();
489: $col = $obj->hydrate($row, $startcol);
490: ContactPeer::addInstanceToPool($obj, $key);
491: }
492:
493: return array($obj, $col);
494: }
495:
496:
497: /**
498: * Returns the number of rows matching criteria, joining the related Cvterm table
499: *
500: * @param Criteria $criteria
501: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
502: * @param PropelPDO $con
503: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
504: * @return int Number of matching rows.
505: */
506: public static function doCountJoinCvterm(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
507: {
508: // we're going to modify criteria, so copy it first
509: $criteria = clone $criteria;
510:
511: // We need to set the primary table name, since in the case that there are no WHERE columns
512: // it will be impossible for the BasePeer::createSelectSql() method to determine which
513: // tables go into the FROM clause.
514: $criteria->setPrimaryTableName(ContactPeer::TABLE_NAME);
515:
516: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
517: $criteria->setDistinct();
518: }
519:
520: if (!$criteria->hasSelectClause()) {
521: ContactPeer::addSelectColumns($criteria);
522: }
523:
524: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
525:
526: // Set the correct dbName
527: $criteria->setDbName(ContactPeer::DATABASE_NAME);
528:
529: if ($con === null) {
530: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
531: }
532:
533: $criteria->addJoin(ContactPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
534:
535: $stmt = BasePeer::doCount($criteria, $con);
536:
537: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
538: $count = (int) $row[0];
539: } else {
540: $count = 0; // no rows returned; we infer that means 0 matches.
541: }
542: $stmt->closeCursor();
543:
544: return $count;
545: }
546:
547:
548: /**
549: * Selects a collection of Contact objects pre-filled with their Cvterm objects.
550: * @param Criteria $criteria
551: * @param PropelPDO $con
552: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
553: * @return array Array of Contact objects.
554: * @throws PropelException Any exceptions caught during processing will be
555: * rethrown wrapped into a PropelException.
556: */
557: public static function doSelectJoinCvterm(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
558: {
559: $criteria = clone $criteria;
560:
561: // Set the correct dbName if it has not been overridden
562: if ($criteria->getDbName() == Propel::getDefaultDB()) {
563: $criteria->setDbName(ContactPeer::DATABASE_NAME);
564: }
565:
566: ContactPeer::addSelectColumns($criteria);
567: $startcol = ContactPeer::NUM_HYDRATE_COLUMNS;
568: CvtermPeer::addSelectColumns($criteria);
569:
570: $criteria->addJoin(ContactPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
571:
572: $stmt = BasePeer::doSelect($criteria, $con);
573: $results = array();
574:
575: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
576: $key1 = ContactPeer::getPrimaryKeyHashFromRow($row, 0);
577: if (null !== ($obj1 = ContactPeer::getInstanceFromPool($key1))) {
578: // We no longer rehydrate the object, since this can cause data loss.
579: // See http://www.propelorm.org/ticket/509
580: // $obj1->hydrate($row, 0, true); // rehydrate
581: } else {
582:
583: $cls = ContactPeer::getOMClass();
584:
585: $obj1 = new $cls();
586: $obj1->hydrate($row);
587: ContactPeer::addInstanceToPool($obj1, $key1);
588: } // if $obj1 already loaded
589:
590: $key2 = CvtermPeer::getPrimaryKeyHashFromRow($row, $startcol);
591: if ($key2 !== null) {
592: $obj2 = CvtermPeer::getInstanceFromPool($key2);
593: if (!$obj2) {
594:
595: $cls = CvtermPeer::getOMClass();
596:
597: $obj2 = new $cls();
598: $obj2->hydrate($row, $startcol);
599: CvtermPeer::addInstanceToPool($obj2, $key2);
600: } // if obj2 already loaded
601:
602: // Add the $obj1 (Contact) to $obj2 (Cvterm)
603: $obj2->addContact($obj1);
604:
605: } // if joined row was not null
606:
607: $results[] = $obj1;
608: }
609: $stmt->closeCursor();
610:
611: return $results;
612: }
613:
614:
615: /**
616: * Returns the number of rows matching criteria, joining all related tables
617: *
618: * @param Criteria $criteria
619: * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
620: * @param PropelPDO $con
621: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
622: * @return int Number of matching rows.
623: */
624: public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
625: {
626: // we're going to modify criteria, so copy it first
627: $criteria = clone $criteria;
628:
629: // We need to set the primary table name, since in the case that there are no WHERE columns
630: // it will be impossible for the BasePeer::createSelectSql() method to determine which
631: // tables go into the FROM clause.
632: $criteria->setPrimaryTableName(ContactPeer::TABLE_NAME);
633:
634: if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
635: $criteria->setDistinct();
636: }
637:
638: if (!$criteria->hasSelectClause()) {
639: ContactPeer::addSelectColumns($criteria);
640: }
641:
642: $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
643:
644: // Set the correct dbName
645: $criteria->setDbName(ContactPeer::DATABASE_NAME);
646:
647: if ($con === null) {
648: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
649: }
650:
651: $criteria->addJoin(ContactPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
652:
653: $stmt = BasePeer::doCount($criteria, $con);
654:
655: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
656: $count = (int) $row[0];
657: } else {
658: $count = 0; // no rows returned; we infer that means 0 matches.
659: }
660: $stmt->closeCursor();
661:
662: return $count;
663: }
664:
665: /**
666: * Selects a collection of Contact objects pre-filled with all related objects.
667: *
668: * @param Criteria $criteria
669: * @param PropelPDO $con
670: * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
671: * @return array Array of Contact objects.
672: * @throws PropelException Any exceptions caught during processing will be
673: * rethrown wrapped into a PropelException.
674: */
675: public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
676: {
677: $criteria = clone $criteria;
678:
679: // Set the correct dbName if it has not been overridden
680: if ($criteria->getDbName() == Propel::getDefaultDB()) {
681: $criteria->setDbName(ContactPeer::DATABASE_NAME);
682: }
683:
684: ContactPeer::addSelectColumns($criteria);
685: $startcol2 = ContactPeer::NUM_HYDRATE_COLUMNS;
686:
687: CvtermPeer::addSelectColumns($criteria);
688: $startcol3 = $startcol2 + CvtermPeer::NUM_HYDRATE_COLUMNS;
689:
690: $criteria->addJoin(ContactPeer::TYPE_ID, CvtermPeer::CVTERM_ID, $join_behavior);
691:
692: $stmt = BasePeer::doSelect($criteria, $con);
693: $results = array();
694:
695: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
696: $key1 = ContactPeer::getPrimaryKeyHashFromRow($row, 0);
697: if (null !== ($obj1 = ContactPeer::getInstanceFromPool($key1))) {
698: // We no longer rehydrate the object, since this can cause data loss.
699: // See http://www.propelorm.org/ticket/509
700: // $obj1->hydrate($row, 0, true); // rehydrate
701: } else {
702: $cls = ContactPeer::getOMClass();
703:
704: $obj1 = new $cls();
705: $obj1->hydrate($row);
706: ContactPeer::addInstanceToPool($obj1, $key1);
707: } // if obj1 already loaded
708:
709: // Add objects for joined Cvterm rows
710:
711: $key2 = CvtermPeer::getPrimaryKeyHashFromRow($row, $startcol2);
712: if ($key2 !== null) {
713: $obj2 = CvtermPeer::getInstanceFromPool($key2);
714: if (!$obj2) {
715:
716: $cls = CvtermPeer::getOMClass();
717:
718: $obj2 = new $cls();
719: $obj2->hydrate($row, $startcol2);
720: CvtermPeer::addInstanceToPool($obj2, $key2);
721: } // if obj2 loaded
722:
723: // Add the $obj1 (Contact) to the collection in $obj2 (Cvterm)
724: $obj2->addContact($obj1);
725: } // if joined row not null
726:
727: $results[] = $obj1;
728: }
729: $stmt->closeCursor();
730:
731: return $results;
732: }
733:
734: /**
735: * Returns the TableMap related to this peer.
736: * This method is not needed for general use but a specific application could have a need.
737: * @return TableMap
738: * @throws PropelException Any exceptions caught during processing will be
739: * rethrown wrapped into a PropelException.
740: */
741: public static function getTableMap()
742: {
743: return Propel::getDatabaseMap(ContactPeer::DATABASE_NAME)->getTable(ContactPeer::TABLE_NAME);
744: }
745:
746: /**
747: * Add a TableMap instance to the database for this peer class.
748: */
749: public static function buildTableMap()
750: {
751: $dbMap = Propel::getDatabaseMap(BaseContactPeer::DATABASE_NAME);
752: if (!$dbMap->hasTable(BaseContactPeer::TABLE_NAME)) {
753: $dbMap->addTableObject(new ContactTableMap());
754: }
755: }
756:
757: /**
758: * The class that the Peer will make instances of.
759: *
760: *
761: * @return string ClassName
762: */
763: public static function getOMClass($row = 0, $colnum = 0)
764: {
765: return ContactPeer::OM_CLASS;
766: }
767:
768: /**
769: * Performs an INSERT on the database, given a Contact or Criteria object.
770: *
771: * @param mixed $values Criteria or Contact object containing data that is used to create the INSERT statement.
772: * @param PropelPDO $con the PropelPDO connection to use
773: * @return mixed The new primary key.
774: * @throws PropelException Any exceptions caught during processing will be
775: * rethrown wrapped into a PropelException.
776: */
777: public static function doInsert($values, PropelPDO $con = null)
778: {
779: if ($con === null) {
780: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
781: }
782:
783: if ($values instanceof Criteria) {
784: $criteria = clone $values; // rename for clarity
785: } else {
786: $criteria = $values->buildCriteria(); // build Criteria from Contact object
787: }
788:
789: if ($criteria->containsKey(ContactPeer::CONTACT_ID) && $criteria->keyContainsValue(ContactPeer::CONTACT_ID) ) {
790: throw new PropelException('Cannot insert a value for auto-increment primary key ('.ContactPeer::CONTACT_ID.')');
791: }
792:
793:
794: // Set the correct dbName
795: $criteria->setDbName(ContactPeer::DATABASE_NAME);
796:
797: try {
798: // use transaction because $criteria could contain info
799: // for more than one table (I guess, conceivably)
800: $con->beginTransaction();
801: $pk = BasePeer::doInsert($criteria, $con);
802: $con->commit();
803: } catch (PropelException $e) {
804: $con->rollBack();
805: throw $e;
806: }
807:
808: return $pk;
809: }
810:
811: /**
812: * Performs an UPDATE on the database, given a Contact or Criteria object.
813: *
814: * @param mixed $values Criteria or Contact object containing data that is used to create the UPDATE statement.
815: * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
816: * @return int The number of affected rows (if supported by underlying database driver).
817: * @throws PropelException Any exceptions caught during processing will be
818: * rethrown wrapped into a PropelException.
819: */
820: public static function doUpdate($values, PropelPDO $con = null)
821: {
822: if ($con === null) {
823: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
824: }
825:
826: $selectCriteria = new Criteria(ContactPeer::DATABASE_NAME);
827:
828: if ($values instanceof Criteria) {
829: $criteria = clone $values; // rename for clarity
830:
831: $comparison = $criteria->getComparison(ContactPeer::CONTACT_ID);
832: $value = $criteria->remove(ContactPeer::CONTACT_ID);
833: if ($value) {
834: $selectCriteria->add(ContactPeer::CONTACT_ID, $value, $comparison);
835: } else {
836: $selectCriteria->setPrimaryTableName(ContactPeer::TABLE_NAME);
837: }
838:
839: } else { // $values is Contact object
840: $criteria = $values->buildCriteria(); // gets full criteria
841: $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
842: }
843:
844: // set the correct dbName
845: $criteria->setDbName(ContactPeer::DATABASE_NAME);
846:
847: return BasePeer::doUpdate($selectCriteria, $criteria, $con);
848: }
849:
850: /**
851: * Deletes all rows from the contact table.
852: *
853: * @param PropelPDO $con the connection to use
854: * @return int The number of affected rows (if supported by underlying database driver).
855: * @throws PropelException
856: */
857: public static function doDeleteAll(PropelPDO $con = null)
858: {
859: if ($con === null) {
860: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
861: }
862: $affectedRows = 0; // initialize var to track total num of affected rows
863: try {
864: // use transaction because $criteria could contain info
865: // for more than one table or we could emulating ON DELETE CASCADE, etc.
866: $con->beginTransaction();
867: $affectedRows += BasePeer::doDeleteAll(ContactPeer::TABLE_NAME, $con, ContactPeer::DATABASE_NAME);
868: // Because this db requires some delete cascade/set null emulation, we have to
869: // clear the cached instance *after* the emulation has happened (since
870: // instances get re-added by the select statement contained therein).
871: ContactPeer::clearInstancePool();
872: ContactPeer::clearRelatedInstancePool();
873: $con->commit();
874:
875: return $affectedRows;
876: } catch (PropelException $e) {
877: $con->rollBack();
878: throw $e;
879: }
880: }
881:
882: /**
883: * Performs a DELETE on the database, given a Contact or Criteria object OR a primary key value.
884: *
885: * @param mixed $values Criteria or Contact object or primary key or array of primary keys
886: * which is used to create the DELETE statement
887: * @param PropelPDO $con the connection to use
888: * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
889: * if supported by native driver or if emulated using Propel.
890: * @throws PropelException Any exceptions caught during processing will be
891: * rethrown wrapped into a PropelException.
892: */
893: public static function doDelete($values, PropelPDO $con = null)
894: {
895: if ($con === null) {
896: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
897: }
898:
899: if ($values instanceof Criteria) {
900: // invalidate the cache for all objects of this type, since we have no
901: // way of knowing (without running a query) what objects should be invalidated
902: // from the cache based on this Criteria.
903: ContactPeer::clearInstancePool();
904: // rename for clarity
905: $criteria = clone $values;
906: } elseif ($values instanceof Contact) { // it's a model object
907: // invalidate the cache for this single object
908: ContactPeer::removeInstanceFromPool($values);
909: // create criteria based on pk values
910: $criteria = $values->buildPkeyCriteria();
911: } else { // it's a primary key, or an array of pks
912: $criteria = new Criteria(ContactPeer::DATABASE_NAME);
913: $criteria->add(ContactPeer::CONTACT_ID, (array) $values, Criteria::IN);
914: // invalidate the cache for this object(s)
915: foreach ((array) $values as $singleval) {
916: ContactPeer::removeInstanceFromPool($singleval);
917: }
918: }
919:
920: // Set the correct dbName
921: $criteria->setDbName(ContactPeer::DATABASE_NAME);
922:
923: $affectedRows = 0; // initialize var to track total num of affected rows
924:
925: try {
926: // use transaction because $criteria could contain info
927: // for more than one table or we could emulating ON DELETE CASCADE, etc.
928: $con->beginTransaction();
929:
930: $affectedRows += BasePeer::doDelete($criteria, $con);
931: ContactPeer::clearRelatedInstancePool();
932: $con->commit();
933:
934: return $affectedRows;
935: } catch (PropelException $e) {
936: $con->rollBack();
937: throw $e;
938: }
939: }
940:
941: /**
942: * Validates all modified columns of given Contact object.
943: * If parameter $columns is either a single column name or an array of column names
944: * than only those columns are validated.
945: *
946: * NOTICE: This does not apply to primary or foreign keys for now.
947: *
948: * @param Contact $obj The object to validate.
949: * @param mixed $cols Column name or array of column names.
950: *
951: * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
952: */
953: public static function doValidate($obj, $cols = null)
954: {
955: $columns = array();
956:
957: if ($cols) {
958: $dbMap = Propel::getDatabaseMap(ContactPeer::DATABASE_NAME);
959: $tableMap = $dbMap->getTable(ContactPeer::TABLE_NAME);
960:
961: if (! is_array($cols)) {
962: $cols = array($cols);
963: }
964:
965: foreach ($cols as $colName) {
966: if ($tableMap->hasColumn($colName)) {
967: $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
968: $columns[$colName] = $obj->$get();
969: }
970: }
971: } else {
972:
973: }
974:
975: return BasePeer::doValidate(ContactPeer::DATABASE_NAME, ContactPeer::TABLE_NAME, $columns);
976: }
977:
978: /**
979: * Retrieve a single object by pkey.
980: *
981: * @param int $pk the primary key.
982: * @param PropelPDO $con the connection to use
983: * @return Contact
984: */
985: public static function retrieveByPK($pk, PropelPDO $con = null)
986: {
987:
988: if (null !== ($obj = ContactPeer::getInstanceFromPool((string) $pk))) {
989: return $obj;
990: }
991:
992: if ($con === null) {
993: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
994: }
995:
996: $criteria = new Criteria(ContactPeer::DATABASE_NAME);
997: $criteria->add(ContactPeer::CONTACT_ID, $pk);
998:
999: $v = ContactPeer::doSelect($criteria, $con);
1000:
1001: return !empty($v) > 0 ? $v[0] : null;
1002: }
1003:
1004: /**
1005: * Retrieve multiple objects by pkey.
1006: *
1007: * @param array $pks List of primary keys
1008: * @param PropelPDO $con the connection to use
1009: * @return Contact[]
1010: * @throws PropelException Any exceptions caught during processing will be
1011: * rethrown wrapped into a PropelException.
1012: */
1013: public static function retrieveByPKs($pks, PropelPDO $con = null)
1014: {
1015: if ($con === null) {
1016: $con = Propel::getConnection(ContactPeer::DATABASE_NAME, Propel::CONNECTION_READ);
1017: }
1018:
1019: $objs = null;
1020: if (empty($pks)) {
1021: $objs = array();
1022: } else {
1023: $criteria = new Criteria(ContactPeer::DATABASE_NAME);
1024: $criteria->add(ContactPeer::CONTACT_ID, $pks, Criteria::IN);
1025: $objs = ContactPeer::doSelect($criteria, $con);
1026: }
1027:
1028: return $objs;
1029: }
1030:
1031: } // BaseContactPeer
1032:
1033: // This is the static code needed to register the TableMap for this table with the main Propel class.
1034: //
1035: BaseContactPeer::buildTableMap();
1036:
1037: