hajtest | ||||
![]() |
||||
|
||||
![]() |
Coverage | ||||||||||||
Classes | Functions / Methods | Lines | ||||||||||
Total |
|
0.00% | 0 / 1 |
|
0.00% | 0 / 3 |
|
0.00% | 0 / 17 | |||
Application_Form_Base |
|
0.00% | 0 / 1 |
|
0.00% | 0 / 3 |
|
0.00% | 0 / 17 | |||
public function fillForm(Doctrine_Record $model) |
|
0.00% | 0 / 1 |
|
0.00% | 0 / 6 | ||||||
public function fillModel(Doctrine_Record $model) |
|
0.00% | 0 / 1 |
|
0.00% | 0 / 8 | ||||||
public function bind($elementName, $modelProperty, $callback = null) |
|
0.00% | 0 / 1 |
|
0.00% | 0 / 2 |
1 : <?php 2 : 3 : class Application_Form_Base extends Zend_Form 4 0 : { 5 : 6 : /** 7 : * Fills form's fields with values from model. 8 : * 9 : * @param Doctrine_Record $model 10 : * @return bool 11 : */ 12 : public function fillForm(Doctrine_Record $model) 13 : { 14 0 : foreach ($model as $prop => $value) { 15 0 : if ($element = $this->getElement($prop)) { 16 0 : $element->setValue($value); 17 0 : } 18 0 : } 19 0 : return true; 20 : } 21 : 22 : /** 23 : * Fills $model's fields with filtered values from form. 24 : * 25 : * @param Doctrine_Record $model 26 : * @return Doctrine_Record 27 : */ 28 : public function fillModel(Doctrine_Record $model) 29 : { 30 0 : foreach ($this->getElements() as $name => $element) { 31 0 : if (!array_key_exists($name, $this->_bindings)) { 32 0 : continue; 33 : } 34 : 35 0 : list($prop, $callback) = $this->_bindings[$name]; 36 0 : if ($model->contains($prop)) 37 0 : $model->$prop = (null !== $callback) ? call_user_func($callback, $element->getValue()) : $element->getValue(); 38 0 : } 39 : 40 0 : return $model; 41 : } 42 : 43 : /** 44 : * Binding's registry. 45 : * 46 : * Multi-dimensional array. Each element of this array is identified by 47 : * string name of element of this form and value is an array where first 48 : * element is model's property name and second is optional callback 49 : * function or method. 50 : * 51 : * Example: 52 : * 53 : * $this->_bindings['film_name'] = array('name', null); 54 : * $this->_bindings['actors'] = array('actors', 'prepareActorsList'); 55 : * 56 : * 57 : * @see My_Form::bind() 58 : * @var array 59 : */ 60 : protected $_bindings = array(); 61 : 62 : /** 63 : * Add binding to the registry 64 : * 65 : * If you want to mangle value which would be passed to model's property 66 : * you can specify $callback function which will be called with value of 67 : * element passed as first argument and it's return value will be then 68 : * used instead of form element's value. 69 : * 70 : * Example: 71 : * 72 : * function prepareActorsList($value) 73 : * { 74 : * return serialize(explode(';', $value)); 75 : * } 76 : 77 : * 78 : * @param string $elementName 79 : * @param string $modelProperty 80 : * @param mixed $callback (optional) 81 : * @return My_Form Self-reference 82 : */ 83 : public function bind($elementName, $modelProperty, $callback = null) 84 : { 85 0 : $this->_bindings[$elementName] = array($modelProperty, $callback); 86 0 : return $this; 87 : } 88 : 89 : // ... |
![]() |
Generated by PHPUnit 3.4.15 and Xdebug 2.1.0rc1 using PHP 5.3.1 at Mon Jan 17 15:42:18 PST 2011. |