| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
class sfPropelRoute extends sfObjectRoute |
|---|
| 22 |
{ |
|---|
| 23 |
protected |
|---|
| 24 |
$criteria = null; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
* Constructor. |
|---|
| 28 |
* |
|---|
| 29 |
* @param string $pattern The pattern to match |
|---|
| 30 |
* @param array $defaults An array of default parameter values |
|---|
| 31 |
* @param array $requirements An array of requirements for parameters (regexes) |
|---|
| 32 |
* @param array $options An array of options |
|---|
| 33 |
* |
|---|
| 34 |
* @see sfObjectRoute |
|---|
| 35 |
*/ |
|---|
| 36 |
public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array()) |
|---|
| 37 |
{ |
|---|
| 38 |
parent::__construct($pattern, $defaults, $requirements, $options); |
|---|
| 39 |
|
|---|
| 40 |
$this->options['object_model'] = $this->options['model']; |
|---|
| 41 |
$this->options['model'] = constant($this->options['model'].'::PEER'); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
public function setListCriteria(Criteria $criteria) |
|---|
| 45 |
{ |
|---|
| 46 |
if (!$this->isBound()) |
|---|
| 47 |
{ |
|---|
| 48 |
throw new LogicException('The route is not bound.'); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
$this->criteria = $criteria; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
protected function getObjectForParameters($parameters) |
|---|
| 55 |
{ |
|---|
| 56 |
if (!isset($this->options['method'])) |
|---|
| 57 |
{ |
|---|
| 58 |
$this->options['method'] = isset($this->options['method_for_criteria']) ? $this->options['method_for_criteria'] : 'doSelectOne'; |
|---|
| 59 |
|
|---|
| 60 |
$className = $this->options['model']; |
|---|
| 61 |
$criteria = new Criteria(); |
|---|
| 62 |
$variables = $this->getRealVariables(); |
|---|
| 63 |
if (!count($variables)) |
|---|
| 64 |
{ |
|---|
| 65 |
return false; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
foreach ($variables as $variable) |
|---|
| 69 |
{ |
|---|
| 70 |
try |
|---|
| 71 |
{ |
|---|
| 72 |
$constant = call_user_func(array($className, 'translateFieldName'), $variable, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); |
|---|
| 73 |
$criteria->add($constant, $parameters[$variable]); |
|---|
| 74 |
} |
|---|
| 75 |
catch (Exception $e) |
|---|
| 76 |
{ |
|---|
| 77 |
|
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
$parameters = $criteria; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
return parent::getObjectForParameters($parameters); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
protected function getObjectsForParameters($parameters) |
|---|
| 88 |
{ |
|---|
| 89 |
if (!isset($this->options['method'])) |
|---|
| 90 |
{ |
|---|
| 91 |
$this->options['method'] = isset($this->options['method_for_criteria']) ? $this->options['method_for_criteria'] : 'doSelect'; |
|---|
| 92 |
$parameters = new Criteria(); |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
if (!is_null($this->criteria)) |
|---|
| 96 |
{ |
|---|
| 97 |
$parameters = $this->criteria; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
return parent::getObjectForParameters($parameters); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
protected function doConvertObjectToArray($object) |
|---|
| 104 |
{ |
|---|
| 105 |
if (isset($this->options['convert']) || method_exists($object, 'toParams')) |
|---|
| 106 |
{ |
|---|
| 107 |
return parent::doConvertObjectToArray($object); |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
$className = $this->options['model']; |
|---|
| 111 |
|
|---|
| 112 |
$parameters = array(); |
|---|
| 113 |
foreach ($this->getRealVariables() as $variable) |
|---|
| 114 |
{ |
|---|
| 115 |
try |
|---|
| 116 |
{ |
|---|
| 117 |
$method = 'get'.call_user_func(array($className, 'translateFieldName'), $variable, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); |
|---|
| 118 |
} |
|---|
| 119 |
catch (Exception $e) |
|---|
| 120 |
{ |
|---|
| 121 |
$method = 'get'.sfInflector::camelize($variable); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
$parameters[$variable] = $object->$method(); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
return $parameters; |
|---|
| 128 |
} |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|