| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
require_once 'propel/util/BasePeer.php'; |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
include_once 'model/SnippetSnippet.php'; |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
abstract class BaseSnippetSnippetPeer { |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
const DATABASE_NAME = 'propel'; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
const TABLE_NAME = 'sn_snippet'; |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
const CLASS_DEFAULT = 'model.SnippetSnippet'; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
const NUM_COLUMNS = 9; |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
const NUM_LAZY_LOAD_COLUMNS = 0; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
const ID = 'sn_snippet.ID'; |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
const USER_ID = 'sn_snippet.USER_ID'; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
const TITLE = 'sn_snippet.TITLE'; |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
const BODY = 'sn_snippet.BODY'; |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
const HTML_BODY = 'sn_snippet.HTML_BODY'; |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
const CREATED_AT = 'sn_snippet.CREATED_AT'; |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
const AVERAGE_VOTE = 'sn_snippet.AVERAGE_VOTE'; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
const NB_COMMENTS = 'sn_snippet.NB_COMMENTS'; |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
const ALL_TAGS = 'sn_snippet.ALL_TAGS'; |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
private static $phpNameMap = null; |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
* holds an array of fieldnames |
|---|
| 66 |
* |
|---|
| 67 |
* first dimension keys are the type constants |
|---|
| 68 |
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' |
|---|
| 69 |
*/ |
|---|
| 70 |
private static $fieldNames = array ( |
|---|
| 71 |
BasePeer::TYPE_PHPNAME => array ('Id', 'UserId', 'Title', 'Body', 'HtmlBody', 'CreatedAt', 'AverageVote', 'NbComments', 'AllTags', ), |
|---|
| 72 |
BasePeer::TYPE_COLNAME => array (SnippetSnippetPeer::ID, SnippetSnippetPeer::USER_ID, SnippetSnippetPeer::TITLE, SnippetSnippetPeer::BODY, SnippetSnippetPeer::HTML_BODY, SnippetSnippetPeer::CREATED_AT, SnippetSnippetPeer::AVERAGE_VOTE, SnippetSnippetPeer::NB_COMMENTS, SnippetSnippetPeer::ALL_TAGS, ), |
|---|
| 73 |
BasePeer::TYPE_FIELDNAME => array ('id', 'user_id', 'title', 'body', 'html_body', 'created_at', 'average_vote', 'nb_comments', 'all_tags', ), |
|---|
| 74 |
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) |
|---|
| 75 |
); |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
* holds an array of keys for quick access to the fieldnames array |
|---|
| 79 |
* |
|---|
| 80 |
* first dimension keys are the type constants |
|---|
| 81 |
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 |
|---|
| 82 |
*/ |
|---|
| 83 |
private static $fieldKeys = array ( |
|---|
| 84 |
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'UserId' => 1, 'Title' => 2, 'Body' => 3, 'HtmlBody' => 4, 'CreatedAt' => 5, 'AverageVote' => 6, 'NbComments' => 7, 'AllTags' => 8, ), |
|---|
| 85 |
BasePeer::TYPE_COLNAME => array (SnippetSnippetPeer::ID => 0, SnippetSnippetPeer::USER_ID => 1, SnippetSnippetPeer::TITLE => 2, SnippetSnippetPeer::BODY => 3, SnippetSnippetPeer::HTML_BODY => 4, SnippetSnippetPeer::CREATED_AT => 5, SnippetSnippetPeer::AVERAGE_VOTE => 6, SnippetSnippetPeer::NB_COMMENTS => 7, SnippetSnippetPeer::ALL_TAGS => 8, ), |
|---|
| 86 |
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'user_id' => 1, 'title' => 2, 'body' => 3, 'html_body' => 4, 'created_at' => 5, 'average_vote' => 6, 'nb_comments' => 7, 'all_tags' => 8, ), |
|---|
| 87 |
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) |
|---|
| 88 |
); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
* @return MapBuilder the map builder for this peer |
|---|
| 92 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 93 |
* rethrown wrapped into a PropelException. |
|---|
| 94 |
*/ |
|---|
| 95 |
public static function getMapBuilder() |
|---|
| 96 |
{ |
|---|
| 97 |
include_once 'model/map/SnippetSnippetMapBuilder.php'; |
|---|
| 98 |
return BasePeer::getMapBuilder('model.map.SnippetSnippetMapBuilder'); |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
* Gets a map (hash) of PHP names to DB column names. |
|---|
| 102 |
* |
|---|
| 103 |
* @return array The PHP to DB name map for this peer |
|---|
| 104 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 105 |
* rethrown wrapped into a PropelException. |
|---|
| 106 |
* @deprecated Use the getFieldNames() and translateFieldName() methods instead of this. |
|---|
| 107 |
*/ |
|---|
| 108 |
public static function getPhpNameMap() |
|---|
| 109 |
{ |
|---|
| 110 |
if (self::$phpNameMap === null) { |
|---|
| 111 |
$map = SnippetSnippetPeer::getTableMap(); |
|---|
| 112 |
$columns = $map->getColumns(); |
|---|
| 113 |
$nameMap = array(); |
|---|
| 114 |
foreach ($columns as $column) { |
|---|
| 115 |
$nameMap[$column->getPhpName()] = $column->getColumnName(); |
|---|
| 116 |
} |
|---|
| 117 |
self::$phpNameMap = $nameMap; |
|---|
| 118 |
} |
|---|
| 119 |
return self::$phpNameMap; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
* Translates a fieldname to another type |
|---|
| 123 |
* |
|---|
| 124 |
* @param string $name field name |
|---|
| 125 |
* @param string $fromType One of the class type constants TYPE_PHPNAME, |
|---|
| 126 |
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM |
|---|
| 127 |
* @param string $toType One of the class type constants |
|---|
| 128 |
* @return string translated name of the field. |
|---|
| 129 |
*/ |
|---|
| 130 |
static public function translateFieldName($name, $fromType, $toType) |
|---|
| 131 |
{ |
|---|
| 132 |
$toNames = self::getFieldNames($toType); |
|---|
| 133 |
$key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null; |
|---|
| 134 |
if ($key === null) { |
|---|
| 135 |
throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true)); |
|---|
| 136 |
} |
|---|
| 137 |
return $toNames[$key]; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
* Returns an array of of field names. |
|---|
| 142 |
* |
|---|
| 143 |
* @param string $type The type of fieldnames to return: |
|---|
| 144 |
* One of the class type constants TYPE_PHPNAME, |
|---|
| 145 |
* TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM |
|---|
| 146 |
* @return array A list of field names |
|---|
| 147 |
*/ |
|---|
| 148 |
|
|---|
| 149 |
static public function getFieldNames($type = BasePeer::TYPE_PHPNAME) |
|---|
| 150 |
{ |
|---|
| 151 |
if (!array_key_exists($type, self::$fieldNames)) { |
|---|
| 152 |
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.'); |
|---|
| 153 |
} |
|---|
| 154 |
return self::$fieldNames[$type]; |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
* Convenience method which changes table.column to alias.column. |
|---|
| 159 |
* |
|---|
| 160 |
* Using this method you can maintain SQL abstraction while using column aliases. |
|---|
| 161 |
* <code> |
|---|
| 162 |
* $c->addAlias("alias1", TablePeer::TABLE_NAME); |
|---|
| 163 |
* $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN); |
|---|
| 164 |
* </code> |
|---|
| 165 |
* @param string $alias The alias for the current table. |
|---|
| 166 |
* @param string $column The column name for current table. (i.e. SnippetSnippetPeer::COLUMN_NAME). |
|---|
| 167 |
* @return string |
|---|
| 168 |
*/ |
|---|
| 169 |
public static function alias($alias, $column) |
|---|
| 170 |
{ |
|---|
| 171 |
return str_replace(SnippetSnippetPeer::TABLE_NAME.'.', $alias.'.', $column); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
* Add all the columns needed to create a new object. |
|---|
| 176 |
* |
|---|
| 177 |
* Note: any columns that were marked with lazyLoad="true" in the |
|---|
| 178 |
* XML schema will not be added to the select list and only loaded |
|---|
| 179 |
* on demand. |
|---|
| 180 |
* |
|---|
| 181 |
* @param criteria object containing the columns to add. |
|---|
| 182 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 183 |
* rethrown wrapped into a PropelException. |
|---|
| 184 |
*/ |
|---|
| 185 |
public static function addSelectColumns(Criteria $criteria) |
|---|
| 186 |
{ |
|---|
| 187 |
|
|---|
| 188 |
$criteria->addSelectColumn(SnippetSnippetPeer::ID); |
|---|
| 189 |
|
|---|
| 190 |
$criteria->addSelectColumn(SnippetSnippetPeer::USER_ID); |
|---|
| 191 |
|
|---|
| 192 |
$criteria->addSelectColumn(SnippetSnippetPeer::TITLE); |
|---|
| 193 |
|
|---|
| 194 |
$criteria->addSelectColumn(SnippetSnippetPeer::BODY); |
|---|
| 195 |
|
|---|
| 196 |
$criteria->addSelectColumn(SnippetSnippetPeer::HTML_BODY); |
|---|
| 197 |
|
|---|
| 198 |
$criteria->addSelectColumn(SnippetSnippetPeer::CREATED_AT); |
|---|
| 199 |
|
|---|
| 200 |
$criteria->addSelectColumn(SnippetSnippetPeer::AVERAGE_VOTE); |
|---|
| 201 |
|
|---|
| 202 |
$criteria->addSelectColumn(SnippetSnippetPeer::NB_COMMENTS); |
|---|
| 203 |
|
|---|
| 204 |
$criteria->addSelectColumn(SnippetSnippetPeer::ALL_TAGS); |
|---|
| 205 |
|
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
const COUNT = 'COUNT(sn_snippet.ID)'; |
|---|
| 209 |
const COUNT_DISTINCT = 'COUNT(DISTINCT sn_snippet.ID)'; |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
* Returns the number of rows matching criteria. |
|---|
| 213 |
* |
|---|
| 214 |
* @param Criteria $criteria |
|---|
| 215 |
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria). |
|---|
| 216 |
* @param Connection $con |
|---|
| 217 |
* @return int Number of matching rows. |
|---|
| 218 |
*/ |
|---|
| 219 |
public static function doCount(Criteria $criteria, $distinct = false, $con = null) |
|---|
| 220 |
{ |
|---|
| 221 |
|
|---|
| 222 |
$criteria = clone $criteria; |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
$criteria->clearSelectColumns()->clearOrderByColumns(); |
|---|
| 226 |
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { |
|---|
| 227 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT_DISTINCT); |
|---|
| 228 |
} else { |
|---|
| 229 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT); |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
foreach($criteria->getGroupByColumns() as $column) |
|---|
| 234 |
{ |
|---|
| 235 |
$criteria->addSelectColumn($column); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
$rs = SnippetSnippetPeer::doSelectRS($criteria, $con); |
|---|
| 239 |
if ($rs->next()) { |
|---|
| 240 |
return $rs->getInt(1); |
|---|
| 241 |
} else { |
|---|
| 242 |
|
|---|
| 243 |
return 0; |
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
* Method to select one object from the DB. |
|---|
| 248 |
* |
|---|
| 249 |
* @param Criteria $criteria object used to create the SELECT statement. |
|---|
| 250 |
* @param Connection $con |
|---|
| 251 |
* @return SnippetSnippet |
|---|
| 252 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 253 |
* rethrown wrapped into a PropelException. |
|---|
| 254 |
*/ |
|---|
| 255 |
public static function doSelectOne(Criteria $criteria, $con = null) |
|---|
| 256 |
{ |
|---|
| 257 |
$critcopy = clone $criteria; |
|---|
| 258 |
$critcopy->setLimit(1); |
|---|
| 259 |
$objects = SnippetSnippetPeer::doSelect($critcopy, $con); |
|---|
| 260 |
if ($objects) { |
|---|
| 261 |
return $objects[0]; |
|---|
| 262 |
} |
|---|
| 263 |
return null; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
* Method to do selects. |
|---|
| 267 |
* |
|---|
| 268 |
* @param Criteria $criteria The Criteria object used to build the SELECT statement. |
|---|
| 269 |
* @param Connection $con |
|---|
| 270 |
* @return array Array of selected Objects |
|---|
| 271 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 272 |
* rethrown wrapped into a PropelException. |
|---|
| 273 |
*/ |
|---|
| 274 |
public static function doSelect(Criteria $criteria, $con = null) |
|---|
| 275 |
{ |
|---|
| 276 |
return SnippetSnippetPeer::populateObjects(SnippetSnippetPeer::doSelectRS($criteria, $con)); |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
* Prepares the Criteria object and uses the parent doSelect() |
|---|
| 280 |
* method to get a ResultSet. |
|---|
| 281 |
* |
|---|
| 282 |
* Use this method directly if you want to just get the resultset |
|---|
| 283 |
* (instead of an array of objects). |
|---|
| 284 |
* |
|---|
| 285 |
* @param Criteria $criteria The Criteria object used to build the SELECT statement. |
|---|
| 286 |
* @param Connection $con the connection to use |
|---|
| 287 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 288 |
* rethrown wrapped into a PropelException. |
|---|
| 289 |
* @return ResultSet The resultset object with numerically-indexed fields. |
|---|
| 290 |
* @see BasePeer::doSelect() |
|---|
| 291 |
*/ |
|---|
| 292 |
public static function doSelectRS(Criteria $criteria, $con = null) |
|---|
| 293 |
{ |
|---|
| 294 |
if ($con === null) { |
|---|
| 295 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
if (!$criteria->getSelectColumns()) { |
|---|
| 299 |
$criteria = clone $criteria; |
|---|
| 300 |
SnippetSnippetPeer::addSelectColumns($criteria); |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
$criteria->setDbName(self::DATABASE_NAME); |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
// rows indexed numerically. |
|---|
| 308 |
return BasePeer::doSelect($criteria, $con); |
|---|
| 309 |
} |
|---|
| 310 |
|
|---|
| 311 |
* The returned array will contain objects of the default type or |
|---|
| 312 |
* objects that inherit from the default. |
|---|
| 313 |
* |
|---|
| 314 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 315 |
* rethrown wrapped into a PropelException. |
|---|
| 316 |
*/ |
|---|
| 317 |
public static function populateObjects(ResultSet $rs) |
|---|
| 318 |
{ |
|---|
| 319 |
$results = array(); |
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
$cls = SnippetSnippetPeer::getOMClass(); |
|---|
| 323 |
$cls = Propel::import($cls); |
|---|
| 324 |
|
|---|
| 325 |
while($rs->next()) { |
|---|
| 326 |
|
|---|
| 327 |
$obj = new $cls(); |
|---|
| 328 |
$obj->hydrate($rs); |
|---|
| 329 |
$results[] = $obj; |
|---|
| 330 |
|
|---|
| 331 |
} |
|---|
| 332 |
return $results; |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
* Returns the number of rows matching criteria, joining the related SnippetUser table |
|---|
| 337 |
* |
|---|
| 338 |
* @param Criteria $c |
|---|
| 339 |
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria). |
|---|
| 340 |
* @param Connection $con |
|---|
| 341 |
* @return int Number of matching rows. |
|---|
| 342 |
*/ |
|---|
| 343 |
public static function doCountJoinSnippetUser(Criteria $criteria, $distinct = false, $con = null) |
|---|
| 344 |
{ |
|---|
| 345 |
|
|---|
| 346 |
$criteria = clone $criteria; |
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
$criteria->clearSelectColumns()->clearOrderByColumns(); |
|---|
| 350 |
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { |
|---|
| 351 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT_DISTINCT); |
|---|
| 352 |
} else { |
|---|
| 353 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT); |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
foreach($criteria->getGroupByColumns() as $column) |
|---|
| 358 |
{ |
|---|
| 359 |
$criteria->addSelectColumn($column); |
|---|
| 360 |
} |
|---|
| 361 |
|
|---|
| 362 |
$criteria->addJoin(SnippetSnippetPeer::USER_ID, SnippetUserPeer::ID); |
|---|
| 363 |
|
|---|
| 364 |
$rs = SnippetSnippetPeer::doSelectRS($criteria, $con); |
|---|
| 365 |
if ($rs->next()) { |
|---|
| 366 |
return $rs->getInt(1); |
|---|
| 367 |
} else { |
|---|
| 368 |
|
|---|
| 369 |
return 0; |
|---|
| 370 |
} |
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
* Selects a collection of SnippetSnippet objects pre-filled with their SnippetUser objects. |
|---|
| 376 |
* |
|---|
| 377 |
* @return array Array of SnippetSnippet objects. |
|---|
| 378 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 379 |
* rethrown wrapped into a PropelException. |
|---|
| 380 |
*/ |
|---|
| 381 |
public static function doSelectJoinSnippetUser(Criteria $c, $con = null) |
|---|
| 382 |
{ |
|---|
| 383 |
$c = clone $c; |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
if ($c->getDbName() == Propel::getDefaultDB()) { |
|---|
| 387 |
$c->setDbName(self::DATABASE_NAME); |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
SnippetSnippetPeer::addSelectColumns($c); |
|---|
| 391 |
$startcol = (SnippetSnippetPeer::NUM_COLUMNS - SnippetSnippetPeer::NUM_LAZY_LOAD_COLUMNS) + 1; |
|---|
| 392 |
SnippetUserPeer::addSelectColumns($c); |
|---|
| 393 |
|
|---|
| 394 |
$c->addJoin(SnippetSnippetPeer::USER_ID, SnippetUserPeer::ID); |
|---|
| 395 |
$rs = BasePeer::doSelect($c, $con); |
|---|
| 396 |
$results = array(); |
|---|
| 397 |
|
|---|
| 398 |
while($rs->next()) { |
|---|
| 399 |
|
|---|
| 400 |
$omClass = SnippetSnippetPeer::getOMClass(); |
|---|
| 401 |
|
|---|
| 402 |
$cls = Propel::import($omClass); |
|---|
| 403 |
$obj1 = new $cls(); |
|---|
| 404 |
$obj1->hydrate($rs); |
|---|
| 405 |
|
|---|
| 406 |
$omClass = SnippetUserPeer::getOMClass(); |
|---|
| 407 |
|
|---|
| 408 |
$cls = Propel::import($omClass); |
|---|
| 409 |
$obj2 = new $cls(); |
|---|
| 410 |
$obj2->hydrate($rs, $startcol); |
|---|
| 411 |
|
|---|
| 412 |
$newObject = true; |
|---|
| 413 |
foreach($results as $temp_obj1) { |
|---|
| 414 |
$temp_obj2 = $temp_obj1->getSnippetUser(); |
|---|
| 415 |
if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { |
|---|
| 416 |
$newObject = false; |
|---|
| 417 |
|
|---|
| 418 |
$temp_obj2->addSnippetSnippet($obj1); |
|---|
| 419 |
break; |
|---|
| 420 |
} |
|---|
| 421 |
} |
|---|
| 422 |
if ($newObject) { |
|---|
| 423 |
$obj2->initSnippetSnippets(); |
|---|
| 424 |
$obj2->addSnippetSnippet($obj1); |
|---|
| 425 |
} |
|---|
| 426 |
$results[] = $obj1; |
|---|
| 427 |
} |
|---|
| 428 |
return $results; |
|---|
| 429 |
} |
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
* Returns the number of rows matching criteria, joining all related tables |
|---|
| 434 |
* |
|---|
| 435 |
* @param Criteria $c |
|---|
| 436 |
* @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria). |
|---|
| 437 |
* @param Connection $con |
|---|
| 438 |
* @return int Number of matching rows. |
|---|
| 439 |
*/ |
|---|
| 440 |
public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null) |
|---|
| 441 |
{ |
|---|
| 442 |
$criteria = clone $criteria; |
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
$criteria->clearSelectColumns()->clearOrderByColumns(); |
|---|
| 446 |
if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { |
|---|
| 447 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT_DISTINCT); |
|---|
| 448 |
} else { |
|---|
| 449 |
$criteria->addSelectColumn(SnippetSnippetPeer::COUNT); |
|---|
| 450 |
} |
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
foreach($criteria->getGroupByColumns() as $column) |
|---|
| 454 |
{ |
|---|
| 455 |
$criteria->addSelectColumn($column); |
|---|
| 456 |
} |
|---|
| 457 |
|
|---|
| 458 |
$criteria->addJoin(SnippetSnippetPeer::USER_ID, SnippetUserPeer::ID); |
|---|
| 459 |
|
|---|
| 460 |
$rs = SnippetSnippetPeer::doSelectRS($criteria, $con); |
|---|
| 461 |
if ($rs->next()) { |
|---|
| 462 |
return $rs->getInt(1); |
|---|
| 463 |
} else { |
|---|
| 464 |
|
|---|
| 465 |
return 0; |
|---|
| 466 |
} |
|---|
| 467 |
} |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
* Selects a collection of SnippetSnippet objects pre-filled with all related objects. |
|---|
| 472 |
* |
|---|
| 473 |
* @return array Array of SnippetSnippet objects. |
|---|
| 474 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 475 |
* rethrown wrapped into a PropelException. |
|---|
| 476 |
*/ |
|---|
| 477 |
public static function doSelectJoinAll(Criteria $c, $con = null) |
|---|
| 478 |
{ |
|---|
| 479 |
$c = clone $c; |
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
if ($c->getDbName() == Propel::getDefaultDB()) { |
|---|
| 483 |
$c->setDbName(self::DATABASE_NAME); |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
SnippetSnippetPeer::addSelectColumns($c); |
|---|
| 487 |
$startcol2 = (SnippetSnippetPeer::NUM_COLUMNS - SnippetSnippetPeer::NUM_LAZY_LOAD_COLUMNS) + 1; |
|---|
| 488 |
|
|---|
| 489 |
SnippetUserPeer::addSelectColumns($c); |
|---|
| 490 |
$startcol3 = $startcol2 + SnippetUserPeer::NUM_COLUMNS; |
|---|
| 491 |
|
|---|
| 492 |
$c->addJoin(SnippetSnippetPeer::USER_ID, SnippetUserPeer::ID); |
|---|
| 493 |
|
|---|
| 494 |
$rs = BasePeer::doSelect($c, $con); |
|---|
| 495 |
$results = array(); |
|---|
| 496 |
|
|---|
| 497 |
while($rs->next()) { |
|---|
| 498 |
|
|---|
| 499 |
$omClass = SnippetSnippetPeer::getOMClass(); |
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
$cls = Propel::import($omClass); |
|---|
| 503 |
$obj1 = new $cls(); |
|---|
| 504 |
$obj1->hydrate($rs); |
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
$omClass = SnippetUserPeer::getOMClass(); |
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
$cls = Propel::import($omClass); |
|---|
| 513 |
$obj2 = new $cls(); |
|---|
| 514 |
$obj2->hydrate($rs, $startcol2); |
|---|
| 515 |
|
|---|
| 516 |
$newObject = true; |
|---|
| 517 |
for ($j=0, $resCount=count($results); $j < $resCount; $j++) { |
|---|
| 518 |
$temp_obj1 = $results[$j]; |
|---|
| 519 |
$temp_obj2 = $temp_obj1->getSnippetUser(); |
|---|
| 520 |
if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) { |
|---|
| 521 |
$newObject = false; |
|---|
| 522 |
$temp_obj2->addSnippetSnippet($obj1); |
|---|
| 523 |
break; |
|---|
| 524 |
} |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
if ($newObject) { |
|---|
| 528 |
$obj2->initSnippetSnippets(); |
|---|
| 529 |
$obj2->addSnippetSnippet($obj1); |
|---|
| 530 |
} |
|---|
| 531 |
|
|---|
| 532 |
$results[] = $obj1; |
|---|
| 533 |
} |
|---|
| 534 |
return $results; |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
* Returns the TableMap related to this peer. |
|---|
| 539 |
* This method is not needed for general use but a specific application could have a need. |
|---|
| 540 |
* @return TableMap |
|---|
| 541 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 542 |
* rethrown wrapped into a PropelException. |
|---|
| 543 |
*/ |
|---|
| 544 |
public static function getTableMap() |
|---|
| 545 |
{ |
|---|
| 546 |
return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME); |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
* The class that the Peer will make instances of. |
|---|
| 551 |
* |
|---|
| 552 |
* This uses a dot-path notation which is tranalted into a path |
|---|
| 553 |
* relative to a location on the PHP include_path. |
|---|
| 554 |
* (e.g. path.to.MyClass -> 'path/to/MyClass.php') |
|---|
| 555 |
* |
|---|
| 556 |
* @return string path.to.ClassName |
|---|
| 557 |
*/ |
|---|
| 558 |
public static function getOMClass() |
|---|
| 559 |
{ |
|---|
| 560 |
return SnippetSnippetPeer::CLASS_DEFAULT; |
|---|
| 561 |
} |
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
* Method perform an INSERT on the database, given a SnippetSnippet or Criteria object. |
|---|
| 565 |
* |
|---|
| 566 |
* @param mixed $values Criteria or SnippetSnippet object containing data that is used to create the INSERT statement. |
|---|
| 567 |
* @param Connection $con the connection to use |
|---|
| 568 |
* @return mixed The new primary key. |
|---|
| 569 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 570 |
* rethrown wrapped into a PropelException. |
|---|
| 571 |
*/ |
|---|
| 572 |
public static function doInsert($values, $con = null) |
|---|
| 573 |
{ |
|---|
| 574 |
if ($con === null) { |
|---|
| 575 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 576 |
} |
|---|
| 577 |
|
|---|
| 578 |
if ($values instanceof Criteria) { |
|---|
| 579 |
$criteria = clone $values; |
|---|
| 580 |
} else { |
|---|
| 581 |
$criteria = $values->buildCriteria(); |
|---|
| 582 |
} |
|---|
| 583 |
|
|---|
| 584 |
$criteria->remove(SnippetSnippetPeer::ID); |
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
// Set the correct dbName |
|---|
| 588 |
$criteria->setDbName(self::DATABASE_NAME); |
|---|
| 589 |
|
|---|
| 590 |
try { |
|---|
| 591 |
|
|---|
| 592 |
// for more than one table (I guess, conceivably) |
|---|
| 593 |
$con->begin(); |
|---|
| 594 |
$pk = BasePeer::doInsert($criteria, $con); |
|---|
| 595 |
$con->commit(); |
|---|
| 596 |
} catch(PropelException $e) { |
|---|
| 597 |
$con->rollback(); |
|---|
| 598 |
throw $e; |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
return $pk; |
|---|
| 602 |
} |
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
* Method perform an UPDATE on the database, given a SnippetSnippet or Criteria object. |
|---|
| 606 |
* |
|---|
| 607 |
* @param mixed $values Criteria or SnippetSnippet object containing data that is used to create the UPDATE statement. |
|---|
| 608 |
* @param Connection $con The connection to use (specify Connection object to exert more control over transactions). |
|---|
| 609 |
* @return int The number of affected rows (if supported by underlying database driver). |
|---|
| 610 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 611 |
* rethrown wrapped into a PropelException. |
|---|
| 612 |
*/ |
|---|
| 613 |
public static function doUpdate($values, $con = null) |
|---|
| 614 |
{ |
|---|
| 615 |
if ($con === null) { |
|---|
| 616 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
$selectCriteria = new Criteria(self::DATABASE_NAME); |
|---|
| 620 |
|
|---|
| 621 |
if ($values instanceof Criteria) { |
|---|
| 622 |
$criteria = clone $values; |
|---|
| 623 |
|
|---|
| 624 |
$comparison = $criteria->getComparison(SnippetSnippetPeer::ID); |
|---|
| 625 |
$selectCriteria->add(SnippetSnippetPeer::ID, $criteria->remove(SnippetSnippetPeer::ID), $comparison); |
|---|
| 626 |
|
|---|
| 627 |
} else { |
|---|
| 628 |
$criteria = $values->buildCriteria(); |
|---|
| 629 |
$selectCriteria = $values->buildPkeyCriteria(); |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
$criteria->setDbName(self::DATABASE_NAME); |
|---|
| 634 |
|
|---|
| 635 |
return BasePeer::doUpdate($selectCriteria, $criteria, $con); |
|---|
| 636 |
} |
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
* Method to DELETE all rows from the sn_snippet table. |
|---|
| 640 |
* |
|---|
| 641 |
* @return int The number of affected rows (if supported by underlying database driver). |
|---|
| 642 |
*/ |
|---|
| 643 |
public static function doDeleteAll($con = null) |
|---|
| 644 |
{ |
|---|
| 645 |
if ($con === null) { |
|---|
| 646 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 647 |
} |
|---|
| 648 |
$affectedRows = 0; |
|---|
| 649 |
try { |
|---|
| 650 |
|
|---|
| 651 |
// for more than one table or we could emulating ON DELETE CASCADE, etc. |
|---|
| 652 |
$con->begin(); |
|---|
| 653 |
$affectedRows += BasePeer::doDeleteAll(SnippetSnippetPeer::TABLE_NAME, $con); |
|---|
| 654 |
$con->commit(); |
|---|
| 655 |
return $affectedRows; |
|---|
| 656 |
} catch (PropelException $e) { |
|---|
| 657 |
$con->rollback(); |
|---|
| 658 |
throw $e; |
|---|
| 659 |
} |
|---|
| 660 |
} |
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
* Method perform a DELETE on the database, given a SnippetSnippet or Criteria object OR a primary key value. |
|---|
| 664 |
* |
|---|
| 665 |
* @param mixed $values Criteria or SnippetSnippet object or primary key or array of primary keys |
|---|
| 666 |
* which is used to create the DELETE statement |
|---|
| 667 |
* @param Connection $con the connection to use |
|---|
| 668 |
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
|---|
| 669 |
* if supported by native driver or if emulated using Propel. |
|---|
| 670 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 671 |
* rethrown wrapped into a PropelException. |
|---|
| 672 |
*/ |
|---|
| 673 |
public static function doDelete($values, $con = null) |
|---|
| 674 |
{ |
|---|
| 675 |
if ($con === null) { |
|---|
| 676 |
$con = Propel::getConnection(SnippetSnippetPeer::DATABASE_NAME); |
|---|
| 677 |
} |
|---|
| 678 |
|
|---|
| 679 |
if ($values instanceof Criteria) { |
|---|
| 680 |
$criteria = clone $values; |
|---|
| 681 |
} elseif ($values instanceof SnippetSnippet) { |
|---|
| 682 |
|
|---|
| 683 |
$criteria = $values->buildPkeyCriteria(); |
|---|
| 684 |
} else { |
|---|
| 685 |
|
|---|
| 686 |
$criteria = new Criteria(self::DATABASE_NAME); |
|---|
| 687 |
$criteria->add(SnippetSnippetPeer::ID, (array) $values, Criteria::IN); |
|---|
| 688 |
} |
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
$criteria->setDbName(self::DATABASE_NAME); |
|---|
| 692 |
|
|---|
| 693 |
$affectedRows = 0; |
|---|
| 694 |
|
|---|
| 695 |
try { |
|---|
| 696 |
|
|---|
| 697 |
// for more than one table or we could emulating ON DELETE CASCADE, etc. |
|---|
| 698 |
$con->begin(); |
|---|
| 699 |
|
|---|
| 700 |
$affectedRows += BasePeer::doDelete($criteria, $con); |
|---|
| 701 |
$con->commit(); |
|---|
| 702 |
return $affectedRows; |
|---|
| 703 |
} catch (PropelException $e) { |
|---|
| 704 |
$con->rollback(); |
|---|
| 705 |
throw $e; |
|---|
| 706 |
} |
|---|
| 707 |
} |
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
* Validates all modified columns of given SnippetSnippet object. |
|---|
| 711 |
* If parameter $columns is either a single column name or an array of column names |
|---|
| 712 |
* than only those columns are validated. |
|---|
| 713 |
* |
|---|
| 714 |
* NOTICE: This does not apply to primary or foreign keys for now. |
|---|
| 715 |
* |
|---|
| 716 |
* @param SnippetSnippet $obj The object to validate. |
|---|
| 717 |
* @param mixed $cols Column name or array of column names. |
|---|
| 718 |
* |
|---|
| 719 |
* @return mixed TRUE if all columns are valid or the error message of the first invalid column. |
|---|
| 720 |
*/ |
|---|
| 721 |
public static function doValidate(SnippetSnippet $obj, $cols = null) |
|---|
| 722 |
{ |
|---|
| 723 |
$columns = array(); |
|---|
| 724 |
|
|---|
| 725 |
if ($cols) { |
|---|
| 726 |
$dbMap = Propel::getDatabaseMap(SnippetSnippetPeer::DATABASE_NAME); |
|---|
| 727 |
$tableMap = $dbMap->getTable(SnippetSnippetPeer::TABLE_NAME); |
|---|
| 728 |
|
|---|
| 729 |
if (! is_array($cols)) { |
|---|
| 730 |
$cols = array($cols); |
|---|
| 731 |
} |
|---|
| 732 |
|
|---|
| 733 |
foreach($cols as $colName) { |
|---|
| 734 |
if ($tableMap->containsColumn($colName)) { |
|---|
| 735 |
$get = 'get' . $tableMap->getColumn($colName)->getPhpName(); |
|---|
| 736 |
$columns[$colName] = $obj->$get(); |
|---|
| 737 |
} |
|---|
| 738 |
} |
|---|
| 739 |
} else { |
|---|
| 740 |
|
|---|
| 741 |
} |
|---|
| 742 |
|
|---|
| 743 |
$res = BasePeer::doValidate(SnippetSnippetPeer::DATABASE_NAME, SnippetSnippetPeer::TABLE_NAME, $columns); |
|---|
| 744 |
if ($res !== true) { |
|---|
| 745 |
$request = sfContext::getInstance()->getRequest(); |
|---|
| 746 |
foreach ($res as $failed) { |
|---|
| 747 |
$col = SnippetSnippetPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME); |
|---|
| 748 |
$request->setError($col, $failed->getMessage()); |
|---|
| 749 |
} |
|---|
| 750 |
} |
|---|
| 751 |
|
|---|
| 752 |
return $res; |
|---|
| 753 |
} |
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
* Retrieve a single object by pkey. |
|---|
| 757 |
* |
|---|
| 758 |
* @param mixed $pk the primary key. |
|---|
| 759 |
* @param Connection $con the connection to use |
|---|
| 760 |
* @return SnippetSnippet |
|---|
| 761 |
*/ |
|---|
| 762 |
public static function retrieveByPK($pk, $con = null) |
|---|
| 763 |
{ |
|---|
| 764 |
if ($con === null) { |
|---|
| 765 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 766 |
} |
|---|
| 767 |
|
|---|
| 768 |
$criteria = new Criteria(SnippetSnippetPeer::DATABASE_NAME); |
|---|
| 769 |
|
|---|
| 770 |
$criteria->add(SnippetSnippetPeer::ID, $pk); |
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
$v = SnippetSnippetPeer::doSelect($criteria, $con); |
|---|
| 774 |
|
|---|
| 775 |
return !empty($v) > 0 ? $v[0] : null; |
|---|
| 776 |
} |
|---|
| 777 |
|
|---|
| 778 |
|
|---|
| 779 |
* Retrieve multiple objects by pkey. |
|---|
| 780 |
* |
|---|
| 781 |
* @param array $pks List of primary keys |
|---|
| 782 |
* @param Connection $con the connection to use |
|---|
| 783 |
* @throws PropelException Any exceptions caught during processing will be |
|---|
| 784 |
* rethrown wrapped into a PropelException. |
|---|
| 785 |
*/ |
|---|
| 786 |
public static function retrieveByPKs($pks, $con = null) |
|---|
| 787 |
{ |
|---|
| 788 |
if ($con === null) { |
|---|
| 789 |
$con = Propel::getConnection(self::DATABASE_NAME); |
|---|
| 790 |
} |
|---|
| 791 |
|
|---|
| 792 |
$objs = null; |
|---|
| 793 |
if (empty($pks)) { |
|---|
| 794 |
$objs = array(); |
|---|
| 795 |
} else { |
|---|
| 796 |
$criteria = new Criteria(); |
|---|
| 797 |
$criteria->add(SnippetSnippetPeer::ID, $pks, Criteria::IN); |
|---|
| 798 |
$objs = SnippetSnippetPeer::doSelect($criteria, $con); |
|---|
| 799 |
} |
|---|
| 800 |
return $objs; |
|---|
| 801 |
} |
|---|
| 802 |
|
|---|
| 803 |
} |
|---|
| 804 |
|
|---|
| 805 |
// static code to register the map builder for this Peer with the main Propel class |
|---|
| 806 |
if (Propel::isInit()) { |
|---|
| 807 |
|
|---|
| 808 |
// so we need to load them here. |
|---|
| 809 |
try { |
|---|
| 810 |
BaseSnippetSnippetPeer::getMapBuilder(); |
|---|
| 811 |
} catch (Exception $e) { |
|---|
| 812 |
Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR); |
|---|
| 813 |
} |
|---|
| 814 |
} else { |
|---|
| 815 |
|
|---|
| 816 |
// now and then it will be loaded when Propel initializes. |
|---|
| 817 |
require_once 'model/map/SnippetSnippetMapBuilder.php'; |
|---|
| 818 |
Propel::registerMapBuilder('model.map.SnippetSnippetMapBuilder'); |
|---|
| 819 |
} |
|---|
| 820 |
|
|---|