| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
class patForms_Creator_Definition |
|---|
| 43 |
{ |
|---|
| 44 |
|
|---|
| 45 |
* Factory method to create a new patForms instance |
|---|
| 46 |
* |
|---|
| 47 |
* This method will check for the existence of a patForms_Definition xml |
|---|
| 48 |
* file and populate itself from the file if it exists. If it does not |
|---|
| 49 |
* exist the class will lookup necessary data in the Propel peer class |
|---|
| 50 |
* and write it to the xml file. |
|---|
| 51 |
* |
|---|
| 52 |
* When a Propel object is provided as a parameter, the form values will |
|---|
| 53 |
* be populated with the objects member values. |
|---|
| 54 |
* |
|---|
| 55 |
* @static |
|---|
| 56 |
* @access public |
|---|
| 57 |
* @param object $definition A patForms_Definition instance |
|---|
| 58 |
* @param object $object A Propel object instance |
|---|
| 59 |
* @return object The patForms instance |
|---|
| 60 |
*/ |
|---|
| 61 |
static function create($definition, $object = null) |
|---|
| 62 |
{ |
|---|
| 63 |
$form = patForms::createForm(null, array( |
|---|
| 64 |
'name' => $definition->getName() |
|---|
| 65 |
)); |
|---|
| 66 |
|
|---|
| 67 |
foreach ($definition->getElements() as $el) { |
|---|
| 68 |
|
|---|
| 69 |
if (!empty($el['attributes']['datasource'])) { |
|---|
| 70 |
$datasource = $el['attributes']['datasource']; |
|---|
| 71 |
unset($el['attributes']['datasource']); |
|---|
| 72 |
} else { |
|---|
| 73 |
$datasource = null; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
$element = $form->createElement($el['name'], $el['type'], $el['attributes']); |
|---|
| 77 |
|
|---|
| 78 |
if (!is_null($datasource)) { |
|---|
| 79 |
|
|---|
| 80 |
$type = $datasource['type']; |
|---|
| 81 |
$ds = patForms::createDatasource($type); |
|---|
| 82 |
$ds->init($datasource); |
|---|
| 83 |
$element->attributes['datasource'] = $ds; |
|---|
| 84 |
|
|---|
| 85 |
} |
|---|
| 86 |
if (isset($el['rules'])) { |
|---|
| 87 |
foreach($el['rules'] as $rule) { |
|---|
| 88 |
$type = $rule['type']; |
|---|
| 89 |
$value = $rule['value']; |
|---|
| 90 |
$ruleObj = &patForms::createRule($type); |
|---|
| 91 |
$ruleObj->setValue($value); |
|---|
| 92 |
$element->addRule($ruleObj); |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
$form->elements[sizeof($form->elements)] = $element; |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
} |
|---|
| 100 |
if (!is_null($object)) { |
|---|
| 101 |
$form->setValues($object->toArray()); |
|---|
| 102 |
} |
|---|
| 103 |
$form->setAutoValidate($definition->getAutoValidate()); |
|---|
| 104 |
|
|---|
| 105 |
return $form; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
} |
|---|
| 109 |
?> |
|---|