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