Changeset 504
- Timestamp:
- 07/20/07 18:13:35 (1 year ago)
- Files:
-
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/lib/jelix-modules/junittests/classes/jhtmlrespreporter.class.php (modified) (1 diff)
- trunk/lib/jelix-modules/junittests/classes/jhtmlrespreporter.class.php (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.ISO-8859-1.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.UTF-8.properties (modified) (1 diff)
- trunk/lib/jelix/dao/jDaoBase.class.php (modified) (4 diffs)
- trunk/lib/jelix/dao/jDaoBase.class.php (modified) (4 diffs)
- trunk/lib/jelix/docs/ns/jforms-controls.rng (modified) (8 diffs)
- trunk/lib/jelix/docs/ns/jforms-controls.rng (modified) (8 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (6 diffs)
- trunk/lib/jelix/forms/jFormsBase.class.php (modified) (6 diffs)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (6 diffs)
- trunk/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (6 diffs)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (5 diffs)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (5 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (8 diffs)
- trunk/lib/jelix/forms/jFormsControl.class.php (modified) (8 diffs)
- trunk/testapp/install/install.mysql.sql (modified) (1 diff)
- trunk/testapp/install/install.mysql.sql (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/daos/product_tags.dao.xml (added)
- trunk/testapp/modules/jelix_tests/daos/product_tags.dao.xml (added)
- trunk/testapp/modules/jelix_tests/forms/product.form.xml (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/forms/product.form.xml (modified) (1 diff)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (7 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.compiler.html.php (modified) (7 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (7 diffs)
- trunk/testapp/modules/jelix_tests/tests/jforms.with_dao.html.php (modified) (7 diffs)
- trunk/testapp/modules/testapp/controllers/forms.classic.php (modified) (2 diffs)
- trunk/testapp/modules/testapp/controllers/forms.classic.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/testapp.mn
r483 r504 90 90 cd testapp/modules/jelix_tests/daos 91 91 products.dao.xml 92 product_tags.dao.xml 92 93 description.dao.xml 93 94 cd testapp/modules/jelix_tests/forms trunk/build/manifests/testapp.mn
r483 r504 90 90 cd testapp/modules/jelix_tests/daos 91 91 products.dao.xml 92 product_tags.dao.xml 92 93 description.dao.xml 93 94 cd testapp/modules/jelix_tests/forms trunk/lib/jelix-modules/junittests/classes/jhtmlrespreporter.class.php
r462 r504 89 89 90 90 function paintDiff($stringA, $stringB){ 91 $this->_response->body->append('MAIN','<!--A:'.$stringA.'-->'); 92 $this->_response->body->append('MAIN','<!--B:'.$stringB.'-->'); 91 93 $diff = new Diff(explode("\n",$stringA),explode("\n",$stringB)); 92 94 if($diff->isEmpty()) { trunk/lib/jelix-modules/junittests/classes/jhtmlrespreporter.class.php
r462 r504 89 89 90 90 function paintDiff($stringA, $stringB){ 91 $this->_response->body->append('MAIN','<!--A:'.$stringA.'-->'); 92 $this->_response->body->append('MAIN','<!--B:'.$stringB.'-->'); 91 93 $diff = new Diff(explode("\n",$stringA),explode("\n",$stringB)); 92 94 if($diff->isEmpty()) { trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid 9 12 js.err.required= "%s" field is required 13 trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid 9 12 js.err.required= "%s" field is required 13 trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/en_EN/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/en_US/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) unknow datatype %1$s on %2$s (file %3$s) 6 6 invalid.xml.file=(805) invalid xml syntax in jforms file (file %s) 7 selected.attribute.not.allowed=(806)"selected" attribute on <item> is not allowed when using defaultvalue attribute or <defaultvalues> (file %s) 8 defaultvalues.not.allowed=(807) <defaultvalues> is not allowed in a <listbox multiple="false"> element (file %s) 9 multiple.selected.not.allowed=(808)Only one selected item is allowed in <listbox multiple="false">, <radiobuttons> and <menulist> elements (file %s) 7 10 8 11 js.err.invalid= "%s" field is invalid trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) datatype inconnu %1$s sur %2$s (fichier %3$s) 6 6 invalid.xml.file=(805) erreur de syntaxe xml dans un fichier jforms (fichier %s) 7 selected.attribute.not.allowed=(806)L'utilisation de l'attribut selected sur <item> n'est pas autoris�uand il y a aussi l'attribut defaultvalue ou l'element <defaultvalues> (fichier %s) 8 defaultvalues.not.allowed=(807)La balise <defaultvalues> n'est pas autoris�ans un element <listbox multiple="false"> (fichier %s) 9 multiple.selected.not.allowed=(808)Dans les element <listbox multiple="false"> <radiobuttons> et <menulist>, un seul item s�ctionn�st autoris�fichier %s) 7 10 8 11 js.err.invalid=La saisie de "%s" est invalide trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.ISO-8859-1.properties
r473 r504 5 5 datatype.unknow=(804) datatype inconnu %1$s sur %2$s (fichier %3$s) 6 6 invalid.xml.file=(805) erreur de syntaxe xml dans un fichier jforms (fichier %s) 7 selected.attribute.not.allowed=(806)L'utilisation de l'attribut selected sur <item> n'est pas autoris�uand il y a aussi l'attribut defaultvalue ou l'element <defaultvalues> (fichier %s) 8 defaultvalues.not.allowed=(807)La balise <defaultvalues> n'est pas autoris�ans un element <listbox multiple="false"> (fichier %s) 9 multiple.selected.not.allowed=(808)Dans les element <listbox multiple="false"> <radiobuttons> et <menulist>, un seul item s�ctionn�st autoris�fichier %s) 7 10 8 11 js.err.invalid=La saisie de "%s" est invalide trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) datatype inconnu %1$s sur %2$s (fichier %3$s) 6 6 invalid.xml.file=(805) erreur de syntaxe xml dans un fichier jforms (fichier %s) 7 selected.attribute.not.allowed=(806)L'utilisation de l'attribut selected sur <item> n'est pas autorisé quand il y a aussi l'attribut defaultvalue ou l'element <defaultvalues> (fichier %s) 8 defaultvalues.not.allowed=(807)La balise <defaultvalues> n'est autorisé que dans les elements <listbox multiple="true"> et <checkboxes> (fichier %s) 9 multiple.selected.not.allowed=(808)Dans les element <listbox multiple="false"> <radiobuttons> et <menulist>, un seul item sélectionné est autorisé (fichier %s) 7 10 8 11 js.err.invalid=La saisie de "%s" est invalide trunk/lib/jelix/core-modules/jelix/locales/fr_FR/formserr.UTF-8.properties
r473 r504 5 5 datatype.unknow=(804) datatype inconnu %1$s sur %2$s (fichier %3$s) 6 6 invalid.xml.file=(805) erreur de syntaxe xml dans un fichier jforms (fichier %s) 7 selected.attribute.not.allowed=(806)L'utilisation de l'attribut selected sur <item> n'est pas autorisé quand il y a aussi l'attribut defaultvalue ou l'element <defaultvalues> (fichier %s) 8 defaultvalues.not.allowed=(807)La balise <defaultvalues> n'est autorisé que dans les elements <listbox multiple="true"> et <checkboxes> (fichier %s) 9 multiple.selected.not.allowed=(808)Dans les element <listbox multiple="false"> <radiobuttons> et <menulist>, un seul item sélectionné est autorisé (fichier %s) 7 10 8 11 js.err.invalid=La saisie de "%s" est invalide trunk/lib/jelix/dao/jDaoBase.class.php
r483 r504 63 63 64 64 /** 65 * @return array list of properties name which contains primary keys 66 */ 67 public function getPrimaryKeyNames(){ return $this->_pkFields; } 68 69 /** 65 70 * check values in the properties of the record, according on the dao definition 66 71 * @return array list of errors … … 341 346 } 342 347 348 349 /** 350 * delete all record corresponding to the conditions stored into the 351 * jDaoConditions object. 352 * @param jDaoConditions $searchcond 353 * @return 354 */ 355 public function deleteBy ($searchcond){ 356 if ($searchcond->isEmpty ()){ 357 return; 358 } 359 $query = 'DELETE FROM '.$this->_tables[$this->_primaryTable]['realname'].' WHERE '; 360 $query .= $this->_createConditionsClause($searchcond, false); 361 362 return $this->_conn->exec($query); 363 } 364 365 343 366 /** 344 367 * create a WHERE clause with conditions on primary keys with given value. This method … … 361 384 * @internal 362 385 */ 363 protected function _createConditionsClause($daocond ){386 protected function _createConditionsClause($daocond, $withOrder=true){ 364 387 365 388 $c = $this->_DaoRecordClassName; … … 369 392 $sql = $this->_generateCondition ($daocond->condition, $fields, true); 370 393 371 $order = array (); 372 foreach ($daocond->order as $name => $way){ 373 if (isset($fields[$name])){ 374 $order[] = $name.' '.$way; 375 } 376 } 377 if(count ($order) > 0){ 378 if(trim($sql) =='') { 379 $sql.= ' 1=1 '; 380 } 381 $sql.=' ORDER BY '.implode (', ', $order); 394 if($withOrder){ 395 $order = array (); 396 foreach ($daocond->order as $name => $way){ 397 if (isset($fields[$name])){ 398 $order[] = $name.' '.$way; 399 } 400 } 401 if(count ($order) > 0){ 402 if(trim($sql) =='') { 403 $sql.= ' 1=1 '; 404 } 405 $sql.=' ORDER BY '.implode (', ', $order); 406 } 382 407 } 383 408 return $sql; trunk/lib/jelix/dao/jDaoBase.class.php
r483 r504 63 63 64 64 /** 65 * @return array list of properties name which contains primary keys 66 */ 67 public function getPrimaryKeyNames(){ return $this->_pkFields; } 68 69 /** 65 70 * check values in the properties of the record, according on the dao definition 66 71 * @return array list of errors … … 341 346 } 342 347 348 349 /** 350 * delete all record corresponding to the conditions stored into the 351 * jDaoConditions object. 352 * @param jDaoConditions $searchcond 353 * @return 354 */ 355 public function deleteBy ($searchcond){ 356 if ($searchcond->isEmpty ()){ 357 return; 358 } 359 $query = 'DELETE FROM '.$this->_tables[$this->_primaryTable]['realname'].' WHERE '; 360 $query .= $this->_createConditionsClause($searchcond, false); 361 362 return $this->_conn->exec($query); 363 } 364 365 343 366 /** 344 367 * create a WHERE clause with conditions on primary keys with given value. This method … … 361 384 * @internal 362 385 */ 363 protected function _createConditionsClause($daocond ){386 protected function _createConditionsClause($daocond, $withOrder=true){ 364 387 365 388 $c = $this->_DaoRecordClassName; … … 369 392 $sql = $this->_generateCondition ($daocond->condition, $fields, true); 370 393 371 $order = array (); 372 foreach ($daocond->order as $name => $way){ 373 if (isset($fields[$name])){ 374 $order[] = $name.' '.$way; 375 } 376 } 377 if(count ($order) > 0){ 378 if(trim($sql) =='') { 379 $sql.= ' 1=1 '; 380 } 381 $sql.=' ORDER BY '.implode (', ', $order); 394 if($withOrder){ 395 $order = array (); 396 foreach ($daocond->order as $name => $way){ 397 if (isset($fields[$name])){ 398 $order[] = $name.' '.$way; 399 } 400 } 401 if(count ($order) > 0){ 402 if(trim($sql) =='') { 403 $sql.= ' 1=1 '; 404 } 405 $sql.=' ORDER BY '.implode (', ', $order); 406 } 382 407 } 383 408 return $sql; trunk/lib/jelix/docs/ns/jforms-controls.rng
r493 r504 33 33 <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 34 34 </define> 35 <define name="UI.attr.defaultvalue"> 36 <optional><attribute name="defaultvalue" /></optional> 37 </define> 38 35 39 36 40 <define name="List.UI.Common"> … … 43 47 <ref name="daodatasource" /> 44 48 </choice> 49 <optional> 50 <choice> 51 <attribute name="selectedvalue" /> 52 <element name="selectedvalues"> 53 <oneOrMore> 54 <element name="value"><text/></element> 55 </oneOrMore> 56 </element> 57 </choice> 58 </optional> 45 59 </define> 46 60 … … 53 67 </choice> 54 68 </optional> 69 <optional><attribute name="selected"><choice><value>true</value><value>false</value></choice></attribute></optional> 55 70 <attribute name="value" /> 56 71 </element> … … 100 115 </attribute> 101 116 </define> 102 103 104 105 117 106 118 <!-- Controls --> … … 133 145 <ref name="UI.Common" /> 134 146 <ref name="UI.Common.data" /> 147 <ref name="UI.attr.defaultvalue" /> 135 148 </element> 136 149 </define> … … 141 154 <ref name="UI.attr.readonly" /> 142 155 <ref name="UI.attr.required" /> 156 <ref name="UI.attr.defaultvalue" /> 143 157 </element> 144 158 </define> … … 172 186 <ref name="UI.Common" /> 173 187 <ref name="UI.attr.readonly" /> 188 <ref name="UI.attr.defaultvalue" /> 174 189 </element> 175 190 </define> … … 244 259 <element name="output"> 245 260 <ref name="UI.Common" /> 261 <ref name="UI.attr.defaultvalue" /> 246 262 <!--<optional><attribute name="value"/></optional>--> 247 263 </element> trunk/lib/jelix/docs/ns/jforms-controls.rng
r493 r504 33 33 <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 34 34 </define> 35 <define name="UI.attr.defaultvalue"> 36 <optional><attribute name="defaultvalue" /></optional> 37 </define> 38 35 39 36 40 <define name="List.UI.Common"> … … 43 47 <ref name="daodatasource" /> 44 48 </choice> 49 <optional> 50 <choice> 51 <attribute name="selectedvalue" /> 52 <element name="selectedvalues"> 53 <oneOrMore> 54 <element name="value"><text/></element> 55 </oneOrMore> 56 </element> 57 </choice> 58 </optional> 45 59 </define> 46 60 … … 53 67 </choice> 54 68 </optional> 69 <optional><attribute name="selected"><choice><value>true</value><value>false</value></choice></attribute></optional> 55 70 <attribute name="value" /> 56 71 </element> … … 100 115 </attribute> 101 116 </define> 102 103 104 105 117 106 118 <!-- Controls --> … … 133 145 <ref name="UI.Common" /> 134 146 <ref name="UI.Common.data" /> 147 <ref name="UI.attr.defaultvalue" /> 135 148 </element> 136 149 </define> … … 141 154 <ref name="UI.attr.readonly" /> 142 155 <ref name="UI.attr.required" /> 156 <ref name="UI.attr.defaultvalue" /> 143 157 </element> 144 158 </define> … … 172 186 <ref name="UI.Common" /> 173 187 <ref name="UI.attr.readonly" /> 188 <ref name="UI.attr.defaultvalue" /> 174 189 </element> 175 190 </define> … … 244 259 <element name="output"> 245 260 <ref name="UI.Common" /> 261 <ref name="UI.attr.defaultvalue" /> 246 262 <!--<optional><attribute name="value"/></optional>--> 247 263 </element> trunk/lib/jelix/forms/jFormsBase.class.php
r483 r504 69 69 foreach($this->_controls as $name=>$ctrl){ 70 70 $value = $req->getParam($name); 71 //if($value !== null) on commente pour le moment,72 71 //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 73 72 if($value === null) $value=''; … … 75 74 } 76 75 } 77 78 76 79 77 /** … … 98 96 if($value === null && $ctrl->required){ 99 97 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 100 }elseif(!$ctrl->datatype->check($value)){ 101 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 98 }else{ 99 if(is_array($value)){ 100 foreach($value as $v){ 101 if(!$ctrl->datatype->check($v)){ 102 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 103 break; 104 } 105 } 106 }elseif(!$ctrl->datatype->check($value)){ 107 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 108 } 102 109 } 103 110 } … … 116 123 return new Exception('formId is invalid, couldn\'t get the corresponding dao object'); 117 124 foreach($this->_controls as $name=>$ctrl){ 118 $this->_container->datas[$name] = $daorec->$name; 125 if(isset($daorec->$name)) 126 $this->_container->datas[$name] = $daorec->$name; 119 127 } 120 128 } … … 131 139 $daorec = jDao::createRecord($daoSelector); 132 140 foreach($this->_controls as $name=>$ctrl){ 133 $daorec->$name = $this->_container->datas[$name]; 141 if(is_array($this->_container->datas[$name])){ 142 if( count ($this->_container->datas[$name]) ==1){ 143 $daorec->$name = $this->_container->datas[$name][0]; 144 }else{ 145 // do nothing for arrays ? 146 } 147 }else 148 $daorec->$name = $this->_container->datas[$name]; 134 149 } 135 150 if($this->_container->formId){ … … 137 152 $dao->update($daorec); 138 153 }else{ 154 // todo : what about updating the formId with the Pk. 139 155 $dao->insert($daorec); 140 156 } 141 157 return $daorec->getPk(); 158 } 159 160 /** 161 * set datas from a DAO, in a control 162 * 163 * The control must be a container like checkboxes or listbox with multiple attribute. 164 * The form should contain a formId 165 * 166 * The Dao should map to an "association table" : its primary key should be 167 * the primary key stored in the formId + the field which will contain one of 168 * the values of the control. If this order is not the same as defined into the dao, 169 * you should provide the list of property names which corresponds to the primary key 170 * in this order : properties for the formId, followed by the property which contains 171 * the value. 172 * @param string $controlName the name of the control 173 * @param string $daoSelector the selector of a dao file 174 * @param mixed $primaryKeyNames list of field corresponding to primary keys (optional) 175 * @see jDao 176 */ 177 public function initControlFromDao($controlName, $daoSelector, $primaryKeyNames=null){ 178 179 if(!$this->_controls[$controlName]->isContainer()){ 180 throw new Exception("jFormsBase::initControlFromDao: the control $controlName is not a container"); 181 } 182 183 if(!$this->_container->formId) 184 throw new Exception("jFormsBase::initControlFromDao: no primary key"); 185 186 $primaryKey = $this->_container->formId; 187 188 if(!is_array($primaryKey)) 189 $primaryKey =array($primaryKey); 190 191 $dao = jDao::create($daoSelector); 192 $daorec = jDao::createRecord($daoSelector); 193 194 $conditions = jDao::createConditions(); 195 if($primaryKeyNames) 196 $pkNamelist = $primaryKeyNames; 197 else 198 $pkNamelist = $daorec->getPrimaryKeyNames(); 199 200 foreach($primaryKey as $k=>$pk){ 201 $conditions->addCondition ($pkNamelist[$k], '=', $pk); 202 } 203 204 $results = $dao->findBy($conditions); 205 $valuefield = $pkNamelist[$k+1]; 206 $val = array(); 207 foreach($results as $res){ 208 $val[]=$res->$valuefield; 209 } 210 $this->_container->datas[$controlName]=$val; 211 } 212 213 214 /** 215 * save datas of a control using a dao. 216 * 217 * The control must be a container like checkboxes or listbox with multiple attribute. 218 * If the form contain a new record (no formId), you should call saveToDao before 219 * in order to get a new id (the primary key of the new record), or you should get a new id 220 * by an other way. then you must pass this primary key in the third argument. 221 * If the form have already a formId, then it will be used as a primary key, unless 222 * you give one in the third argument. 223 * 224 * The Dao should map to an "association table" : its primary key should be 225 * the primary key stored in the formId + the field which will contain one of 226 * the values of the control. If this order is not the same as defined into the dao, 227 * you should provide the list of property names which corresponds to the primary key 228 * in this order : properties for the formId, followed by the property which contains 229 * the value. 230 * All existing records which have the formid in their keys are deleted 231 * before to insert new values. 232 * 233 * @param string $controlName the name of the control 234 * @param string $daoSelector the selector of a dao file 235 * @param mixed $primaryKey the primary key if the form have no id. (optional) 236 * @param mixed $primaryKeyNames list of field corresponding to primary keys (optional) 237 * @see jDao 238 */ 239 public function saveControlToDao($controlName, $daoSelector, $primaryKey = null, $primaryKeyNames=null){ 240 241 if(!$this->_controls[$controlName]->isContainer()){ 242 throw new Exception("jFormsBase::saveControlToDao: the control $controlName is not a container"); 243 } 244 245 $values = $this->_container->datas[$controlName]; 246 if(!is_array($values)) 247 throw new Exception("jFormsBase::saveControlToDao: value of the control $controlName is not an array !"); 248 249 if(!$this->_container->formId && !$primaryKey) 250 throw new Exception("jFormsBase::saveControlToDao: no primary key"); 251 252 if(!$primaryKey) 253 $primaryKey = $this->_container->formId; 254 255 if(!is_array($primaryKey)) 256 $primaryKey =array($primaryKey); 257 258 $dao = jDao::create($daoSelector); 259 $daorec = jDao::createRecord($daoSelector); 260 261 $conditions = jDao::createConditions(); 262 if($primaryKeyNames) 263 $pkNamelist = $primaryKeyNames; 264 else 265 $pkNamelist = $daorec->getPrimaryKeyNames(); 266 267 foreach($primaryKey as $k=>$pk){ 268 $conditions->addCondition ($pkNamelist[$k], '=', $pk); 269 $daorec->{$pkNamelist[$k]} = $pk; 270 } 271 272 $dao->deleteBy($conditions); 273 274 $valuefield = $pkNamelist[$k+1]; 275 foreach($values as $value){ 276 $daorec->$valuefield = $value; 277 $dao->insert($daorec); 278 } 142 279 } 143 280 trunk/lib/jelix/forms/jFormsBase.class.php
r483 r504 69 69 foreach($this->_controls as $name=>$ctrl){ 70 70 $value = $req->getParam($name); 71 //if($value !== null) on commente pour le moment,72 71 //@todo à prevoir un meilleur test, pour les formulaires sur plusieurs pages 73 72 if($value === null) $value=''; … … 75 74 } 76 75 } 77 78 76 79 77 /** … … 98 96 if($value === null && $ctrl->required){ 99 97 $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 100 }elseif(!$ctrl->datatype->check($value)){ 101 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 98 }else{ 99 if(is_array($value)){ 100 foreach($value as $v){ 101 if(!$ctrl->datatype->check($v)){ 102 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 103 break; 104 } 105 } 106 }elseif(!$ctrl->datatype->check($value)){ 107 $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 108 } 102 109 } 103 110 } … … 116 123 return new Exception('formId is invalid, couldn\'t get the corresponding dao object'); 117 124 foreach($this->_controls as $name=>$ctrl){ 118 $this->_container->datas[$name] = $daorec->$name; 125 if(isset($daorec->$name)) 126 $this->_container->datas[$name] = $daorec->$name; 119 127 } 120 128 } … … 131 139 $daorec = jDao::createRecord($daoSelector); 132 140 foreach($this->_controls as $name=>$ctrl){ 133 $daorec->$name = $this->_container->datas[$name]; 141 if(is_array($this->_container->datas[$name])){ 142 if( count ($this->_container->datas[$name]) ==1){ 143 $daorec->$name = $this->_container->datas[$name][0]; 144 }else{ 145 // do nothing for arrays ? 146 } 147 }else 148 $daorec->$name = $this->_container->datas[$name]; 134 149 } 135 150 if($this->_container->formId){ … … 137 152 $dao->update($daorec); 138 153 }else{ 154 // todo : what about updating the formId with the Pk. 139 155 $dao->insert($daorec); 140 156 } 141 157 return $daorec->getPk(); 158 } 159 160 /** 161 * set datas from a DAO, in a control 162 * 163 * The control must be a container like checkboxes or listbox with multiple attribute. 164 * The form should contain a formId 165 * 166 * The Dao should map to an "association table" : its primary key should be 167 * the primary key stored in the formId + the field which will contain one of 168 * the values of the control. If this order is not the same as defined into the dao, 169 * you should provide the list of property names which corresponds to the primary key 170 * in this order : properties for the formId, followed by the property which contains 171 * the value. 172 * @param string $controlName the name of the control 173 * @param string $daoSelector the selector of a dao file 174 * @param mixed $primaryKeyNames list of field corresponding to primary keys (optional) 175 * @see jDao 176 */ 177 public function initControlFromDao($controlName, $daoSelector, $primaryKeyNames=null){ 178 179 if(!$this->_controls[$controlName]->isContainer()){ 180 throw new Exception("jFormsBase::initControlFromDao: the control $controlName is not a container"); 181 } 182 183 if(!$this->_container->formId) 184 throw new Exception("jFormsBase::initControlFromDao: no primary key"); 185 186 $primaryKey = $this->_container->formId; 187 188 if(!is_array($primaryKey)) 189 $primaryKey =array($primaryKey); 190 191 $dao = jDao::create($daoSelector); 192 $daorec = jDao::createRecord($daoSelector); 193 194 $conditions = jDao::createConditions(); 195 if($primaryKeyNames) 196 $pkNamelist = $primaryKeyNames; 197 else 198 $pkNamelist = $daorec->getPrimaryKeyNames(); 199 200 foreach($primaryKey as $k=>$pk){ 201 $conditions->addCondition ($pkNamelist[$k], '=', $pk); 202 } 203 204 $results = $dao->findBy($conditions); 205 $valuefield = $pkNamelist[$k+1]; 206
