| 145 | | |
|---|
| | 170 | |
|---|
| | 171 | /** |
|---|
| | 172 | * Magic version of where() |
|---|
| | 173 | * Infers $column, $value, $comparison from $columnName and some optional arguments |
|---|
| | 174 | * Examples: |
|---|
| | 175 | * $articleFinder->_where('CommentId', 3) |
|---|
| | 176 | * => $c->add(ArticlePeer::COMMENT_ID, 3) |
|---|
| | 177 | * $articleFinder->_where('Title', 'like', '%foo') |
|---|
| | 178 | * => $c->add(ArticlePeer::TITLE, '%foo', Criteria::LIKE) |
|---|
| | 179 | */ |
|---|
| | 180 | public function _where($columnName, $arguments = array()) |
|---|
| | 181 | { |
|---|
| | 182 | $column = $this->getColName($columnName); |
|---|
| | 183 | $comparison = Criteria::EQUAL; |
|---|
| | 184 | switch (count($arguments)) |
|---|
| | 185 | { |
|---|
| | 186 | case 0: |
|---|
| | 187 | $value = true; |
|---|
| | 188 | break; |
|---|
| | 189 | case 1: |
|---|
| | 190 | $value = array_shift($arguments); |
|---|
| | 191 | break; |
|---|
| | 192 | case 2: |
|---|
| | 193 | $comparison = array_shift($arguments); |
|---|
| | 194 | $comparisonUp = trim(strtoupper($comparison)); |
|---|
| | 195 | if(in_array($comparisonUp, array('LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE', 'IN', 'NOT IN', 'IS NULL', 'IS NOT NULL'))) |
|---|
| | 196 | { |
|---|
| | 197 | $comparison = ' '.$comparisonUp.' '; |
|---|
| | 198 | } |
|---|
| | 199 | $value = array_shift($arguments); |
|---|
| | 200 | break; |
|---|
| | 201 | default: |
|---|
| | 202 | throw new Exception('{sfPropelFinder} whereXXX can only be called with one or two arguments'); |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | return $this->where($column, $value, $comparison); |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | /** |
|---|
| | 209 | * Finder Fluid Interface for Criteria::addAscendingOrderByColumn() |
|---|
| | 210 | * and Criteria::addDescendingOrderByColumn() |
|---|
| | 211 | */ |
|---|
| | 229 | /** |
|---|
| | 230 | * Magic version of orderBy() |
|---|
| | 231 | * Infers $column and $order from $columnName and some optional arguments |
|---|
| | 232 | * Examples: |
|---|
| | 233 | * $articleFinder->_orderBy('CreatedAt') |
|---|
| | 234 | * => $c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT) |
|---|
| | 235 | * $articlefinder->_orderBy('CategoryId', 'desc') |
|---|
| | 236 | * => $c->addDescendingOrderByColumn(ArticlePeer::CATEGORY_ID) |
|---|
| | 237 | */ |
|---|
| | 238 | public function _orderBy($columnName, $arguments = array()) |
|---|
| | 239 | { |
|---|
| | 240 | $column = $this->getColName($columnName); |
|---|
| | 241 | $order = strtoupper(array_shift($arguments)); |
|---|
| | 242 | if(!$order) |
|---|
| | 243 | { |
|---|
| | 244 | $order = Criteria::ASC; |
|---|
| | 245 | } |
|---|
| | 246 | |
|---|
| | 247 | return $this->orderBy($column, $order); |
|---|
| | 248 | } |
|---|
| | 249 | |
|---|
| | 250 | /** |
|---|
| | 251 | * Finder Fluid Interface for Criteria::addJoin() |
|---|
| | 252 | */ |
|---|
| 170 | | public function __call($name, $arguments) |
|---|
| 171 | | { |
|---|
| 172 | | // simple where equal |
|---|
| 173 | | if(strpos($name, 'where') === 0) |
|---|
| 174 | | { |
|---|
| 175 | | $columnName = substr($name, 5); |
|---|
| 176 | | if(strpos($columnName, '_') !== false) |
|---|
| 177 | | { |
|---|
| 178 | | list($class, $columnName) = split('_', $columnName); |
|---|
| 179 | | $column = $this->getColName($columnName, $class.'Peer'); |
|---|
| 180 | | } |
|---|
| 181 | | else |
|---|
| 182 | | { |
|---|
| 183 | | $column = $this->getColName($columnName); |
|---|
| 184 | | } |
|---|
| 185 | | $comparison = Criteria::EQUAL; |
|---|
| 186 | | switch (count($arguments)) |
|---|
| 187 | | { |
|---|
| 188 | | case 0: |
|---|
| 189 | | $value = true; |
|---|
| 190 | | break; |
|---|
| 191 | | case 1: |
|---|
| 192 | | $value = array_shift($arguments); |
|---|
| 193 | | break; |
|---|
| 194 | | case 2: |
|---|
| 195 | | $comparison = array_shift($arguments); |
|---|
| 196 | | $comparisonUp = trim(strtoupper($comparison)); |
|---|
| 197 | | if(in_array($comparisonUp, array('LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE', 'IN', 'NOT IN', 'IS NULL', 'IS NOT NULL'))) |
|---|
| 198 | | { |
|---|
| 199 | | $comparison = ' '.$comparisonUp.' '; |
|---|
| 200 | | } |
|---|
| 201 | | $value = array_shift($arguments); |
|---|
| 202 | | break; |
|---|
| 203 | | default: |
|---|
| 204 | | throw new Exception('{sfPropelFinder} whereXXX can only be called with one or two arguments'); |
|---|
| 205 | | } |
|---|
| 206 | | return $this->where($column, $value, $comparison); |
|---|
| 207 | | } |
|---|
| 208 | | |
|---|
| 209 | | // order by column |
|---|
| 210 | | if(strpos($name, 'orderBy') === 0) |
|---|
| 211 | | { |
|---|
| 212 | | $column = $this->getColName(substr($name, 7)); |
|---|
| 213 | | $order = strtoupper(array_shift($arguments)); |
|---|
| 214 | | if(!$order) |
|---|
| 215 | | { |
|---|
| 216 | | $order = Criteria::ASC; |
|---|
| 217 | | } |
|---|
| 218 | | return $this->orderBy($column, $order); |
|---|
| 219 | | } |
|---|
| 220 | | |
|---|
| 221 | | // join |
|---|
| 222 | | if(strpos($name, 'join') === 0) |
|---|
| 223 | | { |
|---|
| 224 | | $relatedClass = substr($name, 4); |
|---|
| 225 | | list($column1, $column2) = $this->getRelation($relatedClass); |
|---|
| 226 | | $this->relations[]= $relatedClass.'Peer'; |
|---|
| 227 | | $operator = array_shift($arguments); |
|---|
| 228 | | if(!$operator) |
|---|
| 229 | | { |
|---|
| 230 | | $operator = null; |
|---|
| 231 | | } |
|---|
| 232 | | return $this->join($column1, $column2, $operator); |
|---|
| 233 | | } |
|---|
| 234 | | |
|---|
| 235 | | return $this; |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| | 260 | /** |
|---|
| | 261 | * Magic version of join() |
|---|
| | 262 | * Infers $column1, $column2 and $operator from $relatedClass and some optional arguments |
|---|
| | 263 | * Uses the Propel column maps, based on the schema, to guess the related columns |
|---|
| | 264 | * Examples: |
|---|
| | 265 | * $articleFinder->_join('Comment') |
|---|
| | 266 | * => $c->addJoin(ArticlePeer::ID, CommentPeer::ARTICLE_ID) |
|---|
| | 267 | * $articleFinder->_join('Category', 'RIGHT JOIN') |
|---|
| | 268 | * => $c->addJoin(ArticlePeer::CATEGORY_ID, CategoryPeer::ID, Criteria::RIGHT_JOIN) |
|---|
| | 269 | */ |
|---|
| | 270 | public function _join($relatedClass, $arguments = array()) |
|---|
| | 271 | { |
|---|
| | 272 | list($column1, $column2) = $this->getRelation($relatedClass); |
|---|
| | 273 | $this->relations[]= $relatedClass.'Peer'; |
|---|
| | 274 | $operator = array_shift($arguments); |
|---|
| | 275 | if(!$operator) |
|---|
| | 276 | { |
|---|
| | 277 | $operator = null; |
|---|
| | 278 | } |
|---|
| | 279 | |
|---|
| | 280 | return $this->join($column1, $column2, $operator); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 351 | |
|---|
| | 352 | public function __call($name, $arguments) |
|---|
| | 353 | { |
|---|
| | 354 | if(strpos($name, 'where') === 0) |
|---|
| | 355 | { |
|---|
| | 356 | return $this->_where(substr($name, 5), $arguments); |
|---|
| | 357 | } |
|---|
| | 358 | if(strpos($name, 'orderBy') === 0) |
|---|
| | 359 | { |
|---|
| | 360 | return $this->_orderBy(substr($name, 7), $arguments); |
|---|
| | 361 | } |
|---|
| | 362 | if(strpos($name, 'join') === 0) |
|---|
| | 363 | { |
|---|
| | 364 | return $this->_join(substr($name, 4), $arguments); |
|---|
| | 365 | } |
|---|
| | 366 | throw new Exception(sprintf('{sfPropelFinder} Undefined method %s', $name)); |
|---|
| | 367 | } |
|---|