Loading module/Autoform/src/Autoform/View/Helper/ChampAsInputHelper.php +60 −94 Original line number Diff line number Diff line Loading @@ -2,9 +2,11 @@ namespace Autoform\View\Helper; use Application\View\Renderer\PhpRenderer; use Autoform\Entity\Db\Champ; use Autoform\Entity\Db\FormulaireReponse; use Zend\Form\View\Helper\AbstractHelper; use Zend\View\Resolver\TemplatePathStack; class ChampAsInputHelper extends AbstractHelper { Loading @@ -18,121 +20,85 @@ class ChampAsInputHelper extends AbstractHelper public function render($champ, $data = null) { $texte = ""; /** @var PhpRenderer $view */ $view = $this->getView(); $view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]])); $reponse = (isset($data[$champ->getId()]))?$data[$champ->getId()]->getReponse():null; switch($champ->getElement()) { case Champ::TYPE_LABEL : $texte .= '<strong>'.$champ->getLibelle().'</strong>'; $texte .= '<div class="row"><div class="form-group"><strong>'.$champ->getLibelle().'</strong></div></div>'; break; case Champ::TYPE_SPACER : $texte .= ' <br/>'; $texte .= '<div class="row"><div class="form-group"> </div></div>'; break; case Champ::TYPE_CHECKBOX : $texte .= '<div class="form-group">'; $texte .= '<div class="col-sm-offset-1 col-sm-11">'; $texte .= '<label>'; $texte .= '<input type="checkbox" name="'.$champ->getId().'"'; if ($reponse && $reponse === 'on') $texte .= ' checked '; $texte .= '/> '.$champ->getLibelle(); $texte .= '</label>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-checkbox', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_TEXT : $texte .= '<div class="form-group">'; $texte .= '<label for="text_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle().' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<input class="form-control" type="text" id="text_'.$champ->getId().'" name="'.$champ->getId().'" value="'; if (trim($reponse) !== '') $texte .= $reponse; $texte .='" />'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-text', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_TEXTAREA : $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<textarea class="form-control" id="textarea_'.$champ->getId().'" name="'.$champ->getId().'" >'; if (trim($reponse) !== '') $texte .= $reponse; $texte .= '</textarea>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-textarea', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_SELECT : $options = explode(';', $champ->getOptions()); $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<select class="form-control" name="'.$champ->getId().'">'; $texte .= '<option value="null"></option>'; foreach ($options as $option) { $texte .= '<option value="'.$option.'"'; if ($reponse === $option) $texte .= ' selected '; $texte .= '>'.$option.'</option>'; } $texte .= '</select>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-select', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_PERIODE : $isBalisee = false; $date1 = null; $date2 = null; $periode = ["Année entière", "Premier semestre", "Second semestre", "Balisée"]; $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<select name="select_'.$champ->getId().'">'; $texte .= '<option value="null"></option>'; foreach ($periode as $item) { $texte .= '<option value="'.$item.'"'; if ($item === $reponse) $texte .= ' selected '; if ($item === 'Balisée' && substr($reponse, 0,3) === 'Du ' && substr($reponse, 13,4) === ' au ') { $isBalisee = true; $texte .= ' selected '; } $texte .= '>'.$item.'</option>'; } $texte .= '</select>'; if ($isBalisee) { $splits = explode(' ', $reponse); $splits1 = explode('/', $splits[1]); $date1 = $splits1[2]. "-" . $splits1[1] . "-" .$splits1[0]; $splits2 = explode('/', $splits[3]); $date2 = $splits2[2]. "-" . $splits2[1] . "-" .$splits2[0]; } $texte .= '<span id="datation_'.$champ->getId().'">'; $texte .= ' du '; $texte .= '<input type="date" name="debut_'.$champ->getId().'"'; if ($isBalisee) $texte .=' value="'.$date1.'" '; $texte .= '/>'; $texte .= ' au '; $texte .= '<input type="date" name="fin_'.$champ->getId().'"'; if ($isBalisee) $texte .=' value="'.$date2.'" '; $texte .='/>'; $texte .= '</span>'; $texte .= '</div>'; $texte .= '</div>'; break; // case Champ::TYPE_PERIODE : // $isBalisee = false; // $date1 = null; // $date2 = null; // // $periode = ["Année entière", "Premier semestre", "Second semestre", "Balisée"]; // $texte .= '<div class="form-group">'; // $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; // $texte .= $champ->getLibelle(). ' : '; // $texte .= '</label>'; // $texte .= '<div class="col-sm-10">'; // $texte .= '<select name="select_'.$champ->getId().'">'; // $texte .= '<option value="null"></option>'; // foreach ($periode as $item) { // $texte .= '<option value="'.$item.'"'; // if ($item === $reponse) $texte .= ' selected '; // if ($item === 'Balisée' && substr($reponse, 0,3) === 'Du ' && substr($reponse, 13,4) === ' au ') { // $isBalisee = true; // $texte .= ' selected '; // } // $texte .= '>'.$item.'</option>'; // } // $texte .= '</select>'; // // if ($isBalisee) { // $splits = explode(' ', $reponse); // $splits1 = explode('/', $splits[1]); // $date1 = $splits1[2]. "-" . $splits1[1] . "-" .$splits1[0]; // $splits2 = explode('/', $splits[3]); // $date2 = $splits2[2]. "-" . $splits2[1] . "-" .$splits2[0]; // // } // $texte .= '<span id="datation_'.$champ->getId().'">'; // $texte .= ' du '; // $texte .= '<input type="date" name="debut_'.$champ->getId().'"'; // if ($isBalisee) $texte .=' value="'.$date1.'" '; // $texte .= '/>'; // $texte .= ' au '; // $texte .= '<input type="date" name="fin_'.$champ->getId().'"'; // if ($isBalisee) $texte .=' value="'.$date2.'" '; // $texte .='/>'; // $texte .= '</span>'; // // $texte .= '</div>'; // $texte .= '</div>'; // break; default : $texte .= 'Type ['. $champ->getElement() .'] inconnu !'; break; Loading module/Autoform/src/Autoform/View/Helper/ChampAsResultHelper.php +0 −37 Original line number Diff line number Diff line Loading @@ -26,61 +26,24 @@ class ChampAsResultHelper extends AbstractHelper break; case Champ::TYPE_TEXT : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $length = rand(8, 20); for ($i = 0; $i < $length; $i++) { $value = rand(0, 25) + 97; $texte .= chr($value); $space = rand(0, 8); if ($space === 0) $texte .= ' '; } } if ($data !== '') { $texte .= $data; } break; case Champ::TYPE_TEXTAREA : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $length = rand(50, 200); for ($i = 0; $i < $length; $i++) { $value = rand(0, 25) + 97; $texte .= chr($value); $space = rand(0, 8); if ($space === 0) $texte .= ' '; } } if ($data !== '') { $texte .= $data; } break; case Champ::TYPE_SELECT : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $options = explode(';', $champ->getOptions()); $position = rand(0, count($options) - 1); $texte .= $options[$position]; } if ($data !== 'null') { $texte .= $data; } break; case Champ::TYPE_PERIODE : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $periodes = ['Année entière', 'Premier semestre', 'Second semestre', 'Baslisée']; $periode = rand(0, 3); if ($periode !== 3) { $texte .= $periodes[$periode]; } else { $texte .= 'du ' . '01/01/2111' . ' au ' . '02/02/2222'; } } if ($data !== 'null') { $texte .= $data; } Loading module/Autoform/src/Autoform/View/Helper/partial/input-checkbox.phtml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group"> <div class="col-sm-offset-1 col-sm-11"> <label> <input type="checkbox" name="<?php echo $champ->getId()?>" <?php if ($reponse && $reponse === 'on') :?> checked <?php endif; ?> /> <?php echo $champ->getLibelle(); ?> </label> </div> </div> </div> module/Autoform/src/Autoform/View/Helper/partial/input-select.phtml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group" style="display: block;"> <label for="textarea_<?php echo $champ->getId()?>" class="col-sm-2 control-label"> <?php echo $champ->getLibelle(); ?> : </label> <div class="col-sm-10"> <select class="form-control" name="<?php echo $champ->getId(); ?>"> <option value="null"></option> <?php foreach ($options as $option) : ?> <option value="<?php echo $option; ?>" <?php if ($reponse === $option) : ?> selected <?php endif; ?> > <?php echo $option; ?> </option> <?php endforeach; ?> </select> </div> </div> </div> module/Autoform/src/Autoform/View/Helper/partial/input-text.phtml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group"> <label for="text_<?php echo $champ->getId()?>" class="col-sm-2 control-label"> <?php echo $champ->getLibelle()?> : </label> <div class="col-sm-10"> <input class="form-control" type="text" id="text_<?php echo $champ->getId()?>" name="<?php echo $champ->getId()?>" value=" <?php if (trim($reponse) !== ''): ?> <?php echo $reponse; ?> <?php endif; ?> "/> </div> </div> </div> No newline at end of file Loading
module/Autoform/src/Autoform/View/Helper/ChampAsInputHelper.php +60 −94 Original line number Diff line number Diff line Loading @@ -2,9 +2,11 @@ namespace Autoform\View\Helper; use Application\View\Renderer\PhpRenderer; use Autoform\Entity\Db\Champ; use Autoform\Entity\Db\FormulaireReponse; use Zend\Form\View\Helper\AbstractHelper; use Zend\View\Resolver\TemplatePathStack; class ChampAsInputHelper extends AbstractHelper { Loading @@ -18,121 +20,85 @@ class ChampAsInputHelper extends AbstractHelper public function render($champ, $data = null) { $texte = ""; /** @var PhpRenderer $view */ $view = $this->getView(); $view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]])); $reponse = (isset($data[$champ->getId()]))?$data[$champ->getId()]->getReponse():null; switch($champ->getElement()) { case Champ::TYPE_LABEL : $texte .= '<strong>'.$champ->getLibelle().'</strong>'; $texte .= '<div class="row"><div class="form-group"><strong>'.$champ->getLibelle().'</strong></div></div>'; break; case Champ::TYPE_SPACER : $texte .= ' <br/>'; $texte .= '<div class="row"><div class="form-group"> </div></div>'; break; case Champ::TYPE_CHECKBOX : $texte .= '<div class="form-group">'; $texte .= '<div class="col-sm-offset-1 col-sm-11">'; $texte .= '<label>'; $texte .= '<input type="checkbox" name="'.$champ->getId().'"'; if ($reponse && $reponse === 'on') $texte .= ' checked '; $texte .= '/> '.$champ->getLibelle(); $texte .= '</label>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-checkbox', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_TEXT : $texte .= '<div class="form-group">'; $texte .= '<label for="text_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle().' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<input class="form-control" type="text" id="text_'.$champ->getId().'" name="'.$champ->getId().'" value="'; if (trim($reponse) !== '') $texte .= $reponse; $texte .='" />'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-text', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_TEXTAREA : $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<textarea class="form-control" id="textarea_'.$champ->getId().'" name="'.$champ->getId().'" >'; if (trim($reponse) !== '') $texte .= $reponse; $texte .= '</textarea>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-textarea', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_SELECT : $options = explode(';', $champ->getOptions()); $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<select class="form-control" name="'.$champ->getId().'">'; $texte .= '<option value="null"></option>'; foreach ($options as $option) { $texte .= '<option value="'.$option.'"'; if ($reponse === $option) $texte .= ' selected '; $texte .= '>'.$option.'</option>'; } $texte .= '</select>'; $texte .= '</div>'; $texte .= '</div>'; $texte .= $view->partial('input-select', ['champ' => $champ, 'reponse' => $reponse]); break; case Champ::TYPE_PERIODE : $isBalisee = false; $date1 = null; $date2 = null; $periode = ["Année entière", "Premier semestre", "Second semestre", "Balisée"]; $texte .= '<div class="form-group">'; $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; $texte .= $champ->getLibelle(). ' : '; $texte .= '</label>'; $texte .= '<div class="col-sm-10">'; $texte .= '<select name="select_'.$champ->getId().'">'; $texte .= '<option value="null"></option>'; foreach ($periode as $item) { $texte .= '<option value="'.$item.'"'; if ($item === $reponse) $texte .= ' selected '; if ($item === 'Balisée' && substr($reponse, 0,3) === 'Du ' && substr($reponse, 13,4) === ' au ') { $isBalisee = true; $texte .= ' selected '; } $texte .= '>'.$item.'</option>'; } $texte .= '</select>'; if ($isBalisee) { $splits = explode(' ', $reponse); $splits1 = explode('/', $splits[1]); $date1 = $splits1[2]. "-" . $splits1[1] . "-" .$splits1[0]; $splits2 = explode('/', $splits[3]); $date2 = $splits2[2]. "-" . $splits2[1] . "-" .$splits2[0]; } $texte .= '<span id="datation_'.$champ->getId().'">'; $texte .= ' du '; $texte .= '<input type="date" name="debut_'.$champ->getId().'"'; if ($isBalisee) $texte .=' value="'.$date1.'" '; $texte .= '/>'; $texte .= ' au '; $texte .= '<input type="date" name="fin_'.$champ->getId().'"'; if ($isBalisee) $texte .=' value="'.$date2.'" '; $texte .='/>'; $texte .= '</span>'; $texte .= '</div>'; $texte .= '</div>'; break; // case Champ::TYPE_PERIODE : // $isBalisee = false; // $date1 = null; // $date2 = null; // // $periode = ["Année entière", "Premier semestre", "Second semestre", "Balisée"]; // $texte .= '<div class="form-group">'; // $texte .= '<label for="textarea_'.$champ->getId().'" class="col-sm-2 control-label">'; // $texte .= $champ->getLibelle(). ' : '; // $texte .= '</label>'; // $texte .= '<div class="col-sm-10">'; // $texte .= '<select name="select_'.$champ->getId().'">'; // $texte .= '<option value="null"></option>'; // foreach ($periode as $item) { // $texte .= '<option value="'.$item.'"'; // if ($item === $reponse) $texte .= ' selected '; // if ($item === 'Balisée' && substr($reponse, 0,3) === 'Du ' && substr($reponse, 13,4) === ' au ') { // $isBalisee = true; // $texte .= ' selected '; // } // $texte .= '>'.$item.'</option>'; // } // $texte .= '</select>'; // // if ($isBalisee) { // $splits = explode(' ', $reponse); // $splits1 = explode('/', $splits[1]); // $date1 = $splits1[2]. "-" . $splits1[1] . "-" .$splits1[0]; // $splits2 = explode('/', $splits[3]); // $date2 = $splits2[2]. "-" . $splits2[1] . "-" .$splits2[0]; // // } // $texte .= '<span id="datation_'.$champ->getId().'">'; // $texte .= ' du '; // $texte .= '<input type="date" name="debut_'.$champ->getId().'"'; // if ($isBalisee) $texte .=' value="'.$date1.'" '; // $texte .= '/>'; // $texte .= ' au '; // $texte .= '<input type="date" name="fin_'.$champ->getId().'"'; // if ($isBalisee) $texte .=' value="'.$date2.'" '; // $texte .='/>'; // $texte .= '</span>'; // // $texte .= '</div>'; // $texte .= '</div>'; // break; default : $texte .= 'Type ['. $champ->getElement() .'] inconnu !'; break; Loading
module/Autoform/src/Autoform/View/Helper/ChampAsResultHelper.php +0 −37 Original line number Diff line number Diff line Loading @@ -26,61 +26,24 @@ class ChampAsResultHelper extends AbstractHelper break; case Champ::TYPE_TEXT : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $length = rand(8, 20); for ($i = 0; $i < $length; $i++) { $value = rand(0, 25) + 97; $texte .= chr($value); $space = rand(0, 8); if ($space === 0) $texte .= ' '; } } if ($data !== '') { $texte .= $data; } break; case Champ::TYPE_TEXTAREA : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $length = rand(50, 200); for ($i = 0; $i < $length; $i++) { $value = rand(0, 25) + 97; $texte .= chr($value); $space = rand(0, 8); if ($space === 0) $texte .= ' '; } } if ($data !== '') { $texte .= $data; } break; case Champ::TYPE_SELECT : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $options = explode(';', $champ->getOptions()); $position = rand(0, count($options) - 1); $texte .= $options[$position]; } if ($data !== 'null') { $texte .= $data; } break; case Champ::TYPE_PERIODE : $texte .= $champ->getLibelle(). ' : '; if ($data === null) { $periodes = ['Année entière', 'Premier semestre', 'Second semestre', 'Baslisée']; $periode = rand(0, 3); if ($periode !== 3) { $texte .= $periodes[$periode]; } else { $texte .= 'du ' . '01/01/2111' . ' au ' . '02/02/2222'; } } if ($data !== 'null') { $texte .= $data; } Loading
module/Autoform/src/Autoform/View/Helper/partial/input-checkbox.phtml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group"> <div class="col-sm-offset-1 col-sm-11"> <label> <input type="checkbox" name="<?php echo $champ->getId()?>" <?php if ($reponse && $reponse === 'on') :?> checked <?php endif; ?> /> <?php echo $champ->getLibelle(); ?> </label> </div> </div> </div>
module/Autoform/src/Autoform/View/Helper/partial/input-select.phtml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group" style="display: block;"> <label for="textarea_<?php echo $champ->getId()?>" class="col-sm-2 control-label"> <?php echo $champ->getLibelle(); ?> : </label> <div class="col-sm-10"> <select class="form-control" name="<?php echo $champ->getId(); ?>"> <option value="null"></option> <?php foreach ($options as $option) : ?> <option value="<?php echo $option; ?>" <?php if ($reponse === $option) : ?> selected <?php endif; ?> > <?php echo $option; ?> </option> <?php endforeach; ?> </select> </div> </div> </div>
module/Autoform/src/Autoform/View/Helper/partial/input-text.phtml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?php /** * @var Champ $champ * @var string $reponse */ use Autoform\Entity\Db\Champ; $options = explode(';', $champ->getOptions()); ?> <div class="row"> <div class="form-group"> <label for="text_<?php echo $champ->getId()?>" class="col-sm-2 control-label"> <?php echo $champ->getLibelle()?> : </label> <div class="col-sm-10"> <input class="form-control" type="text" id="text_<?php echo $champ->getId()?>" name="<?php echo $champ->getId()?>" value=" <?php if (trim($reponse) !== ''): ?> <?php echo $reponse; ?> <?php endif; ?> "/> </div> </div> </div> No newline at end of file