| 309 | | |
|---|
| 310 | | protected function guessOrder($direction = 'desc') |
|---|
| 311 | | { |
|---|
| 312 | | $columnNames = array(); |
|---|
| 313 | | foreach ($this->getColumnsForPeerClass($this->getPeerClass()) as $c) |
|---|
| 314 | | { |
|---|
| 315 | | $columnNames []= $c->getPhpName(); |
|---|
| 316 | | } |
|---|
| 317 | | foreach(sfConfig::get('app_sfPropelFinder_sort_column_guesses', array('UpdatedAt', 'UpdatedOn', 'CreatedAt', 'CreatedOn', 'Id')) as $testColumnName) |
|---|
| 318 | | { |
|---|
| 319 | | if(in_array($testColumnName, $columnNames)) |
|---|
| 320 | | { |
|---|
| 321 | | $this->orderBy($testColumnName, $direction); |
|---|
| 322 | | return; |
|---|
| 323 | | } |
|---|
| 324 | | } |
|---|
| 325 | | |
|---|
| 326 | | throw new Exception('Unable to figure out the column to use to order rows'); |
|---|
| 327 | | } |
|---|
| | 342 | } |
|---|
| | 343 | |
|---|
| | 344 | public function delete($con = null, $reinitCriteria = true) |
|---|
| | 345 | { |
|---|
| | 346 | $deleteCriteria = $this->getCriteria(); |
|---|
| | 347 | if($deleteCriteria->equals(new Criteria())) |
|---|
| | 348 | { |
|---|
| | 349 | // delete will delete nothing when passed an empty criteria |
|---|
| | 350 | // while it should, in fact, delete all |
|---|
| | 351 | $fieldNames = call_user_func(array($this->getPeerClass(), 'getFieldNames'), BasePeer::TYPE_COLNAME); |
|---|
| | 352 | $firstFieldName = $fieldNames[0]; |
|---|
| | 353 | $deleteCriteria->add($firstFieldName, true, Criteria::BINARY_OR); |
|---|
| | 354 | } |
|---|
| | 355 | $ret = call_user_func(array($this->getPeerClass(), 'doDelete'), $deleteCriteria, $con); |
|---|
| | 356 | $this->updateLatestQuery(); |
|---|
| | 357 | if($reinitCriteria) |
|---|
| | 358 | { |
|---|
| | 359 | $this->reinitCriteria(); |
|---|
| | 360 | } |
|---|
| | 361 | |
|---|
| | 362 | return $ret; |
|---|
| | 363 | } |
|---|
| | 364 | |
|---|
| | 365 | public function paginate($page = 1, $maxPerPage = 10, $con = null) |
|---|
| | 366 | { |
|---|
| | 367 | $pager = new sfPropelFinderPager($this->class, $maxPerPage); |
|---|
| | 368 | $pager->setFinder($this); |
|---|
| | 369 | $pager->setConnection($con); |
|---|
| | 370 | $pager->setPage($page); |
|---|
| | 371 | $pager->init(); |
|---|
| | 372 | |
|---|
| | 373 | return $pager; |
|---|
| 496 | | public function delete($con = null, $reinitCriteria = true) |
|---|
| 497 | | { |
|---|
| 498 | | $deleteCriteria = $this->getCriteria(); |
|---|
| 499 | | if($deleteCriteria->equals(new Criteria())) |
|---|
| 500 | | { |
|---|
| 501 | | // delete will delete nothing when passed an empty criteria |
|---|
| 502 | | // while it should, in fact, delete all |
|---|
| 503 | | $fieldNames = call_user_func(array($this->getPeerClass(), 'getFieldNames'), BasePeer::TYPE_COLNAME); |
|---|
| 504 | | $firstFieldName = $fieldNames[0]; |
|---|
| 505 | | $deleteCriteria->add($firstFieldName, true, Criteria::BINARY_OR); |
|---|
| 506 | | } |
|---|
| 507 | | $ret = call_user_func(array($this->getPeerClass(), 'doDelete'), $deleteCriteria, $con); |
|---|
| 508 | | $this->updateLatestQuery(); |
|---|
| 509 | | if($reinitCriteria) |
|---|
| 510 | | { |
|---|
| 511 | | $this->reinitCriteria(); |
|---|
| 512 | | } |
|---|
| 513 | | |
|---|
| 514 | | return $ret; |
|---|
| 515 | | } |
|---|
| 516 | | |
|---|
| | 777 | |
|---|
| | 778 | /** |
|---|
| | 779 | * Finder Fluid Interface for Criteria::addGroupByColumn() |
|---|
| | 780 | * Infers $column and $order from $columnName and some optional arguments |
|---|
| | 781 | * Examples: |
|---|
| | 782 | * $articleFinder->groupBy('CreatedAt') |
|---|
| | 783 | * => $c->addGroupByColumn(ArticlePeer::CREATED_AT) |
|---|
| | 784 | */ |
|---|
| | 785 | public function groupBy($columnName) |
|---|
| | 786 | { |
|---|
| | 787 | $column = $this->getColName($columnName); |
|---|
| | 788 | $this->criteria->addGroupByColumn($column); |
|---|
| | 789 | |
|---|
| | 790 | return $this; |
|---|
| | 791 | } |
|---|
| | 792 | |
|---|
| | 793 | /** |
|---|
| | 794 | * Guess sort column based on their names |
|---|
| | 795 | * Will look primarily for columns named: |
|---|
| | 796 | * 'UpdatedAt', 'UpdatedOn', 'CreatedAt', 'CreatedOn', 'Id' |
|---|
| | 797 | * You can change this sequence by modifying the app_sfPropelFinder_sort_column_guesses value |
|---|
| | 798 | * |
|---|
| | 799 | * @param string $direction 'desc' (default) or 'asc' |
|---|
| | 800 | * |
|---|
| | 801 | * @return sfPropelFinder $this the current finder object |
|---|
| | 802 | */ |
|---|
| | 803 | public function guessOrder($direction = 'desc') |
|---|
| | 804 | { |
|---|
| | 805 | $columnNames = array(); |
|---|
| | 806 | foreach ($this->getColumnsForPeerClass($this->getPeerClass()) as $c) |
|---|
| | 807 | { |
|---|
| | 808 | $columnNames []= $c->getPhpName(); |
|---|
| | 809 | } |
|---|
| | 810 | foreach(sfConfig::get('app_sfPropelFinder_sort_column_guesses', array('UpdatedAt', 'UpdatedOn', 'CreatedAt', 'CreatedOn', 'Id')) as $testColumnName) |
|---|
| | 811 | { |
|---|
| | 812 | if(in_array($testColumnName, $columnNames)) |
|---|
| | 813 | { |
|---|
| | 814 | $this->orderBy($testColumnName, $direction); |
|---|
| | 815 | return $this; |
|---|
| | 816 | } |
|---|
| | 817 | } |
|---|
| | 818 | |
|---|
| | 819 | throw new Exception('Unable to figure out the column to use to order rows'); |
|---|
| | 820 | } |
|---|