sql = array(); } /** * Retourne le SQL généré * */ function getSQL() { return $this->sql; } /** * Form => SQL (pas d'action) * */ function visitFormosite(Formosite $comp, $level) { return true; } /** * Page => SQL (pas d'action) * */ function visitPage(Page $comp, $level) { return true; } /** * Champ => SQL * */ function visitField(Field $comp, $level) { if ($comp->toBeSaved == true) { $sqlfield = $this->toSQL(&$comp); if ($sqlfield != '') { $this->sql[] = $sqlfield; } } } /** * génération du sql en fonction du type de champ * */ function toSQL($field) { $sql = ''; switch($field->type) { case 'Text': $maxlength = ($this->maxLength($field->validIf) !== false) ? $this->maxLength($field->validIf) : 255; $sql = "`".strtolower($field->name)."` VARCHAR(".$maxlength.") collate utf8_unicode_ci NOT NULL"; break; case 'Select': $maxlength = ($this->maxLength($field->validIf) !== false) ? $this->maxLength($field->validIf) : 255; $sql = "`".strtolower($field->name)."` VARCHAR(".$maxlength.") collate utf8_unicode_ci NOT NULL"; break; case 'Checkbox': $sql = "`".strtolower($field->name)."` BOOLEAN NOT NULL"; break; case 'Radio': $maxlength = ($this->maxLength($field->validIf) !== false) ? $this->maxLength($field->validIf) : 255; $sql = "`".strtolower($field->name)."` VARCHAR(".$maxlength.") collate utf8_unicode_ci NOT NULL"; break; case 'Textarea': $sql = "`".strtolower($field->name)."` TEXT collate utf8_unicode_ci NOT NULL"; break; case 'Hidden': break; case 'File': break; case 'Password': $maxlength = ($this->maxLength($field->validIf) !== false) ? $this->maxLength($field->validIf) : 255; $sql = "`".strtolower($field->name)."` VARCHAR(".$maxlength.") collate utf8_unicode_ci NOT NULL"; break; case 'Linked_1-n': $sql = "`".strtolower($field->name)."` INT NOT NULL"; break; case 'Submit': break; case 'Fieldset': break; case 'Fieldset_end': break; case 'Comment': break; default : break; } return $sql; } // Retourne la longueur max du champ si existante function maxLength($validIf) { $max = false; $tests = explode("|", $validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'max' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$max = substr($test, 3);} } return $max; } // Retourne la longueur min du champ si existante function minLength($validIf) { $min = false; $tests = explode("|",$validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'min' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$min = substr($test, 3);} } return $min; } //Pas d'action sur ces composites function visitBlock(Block $comp, $level) { return true; } } ?>