141 lines
4.3 KiB
PHP

<?php
Class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
{
public function Field($name, $field)
{
if($field != null) {
foreach($field['fields'] as $type => $valeur)
{
if($type == $field['type']) {
switch($type){
case 'select':
return ($this->structureHTML($field['label'], $this->selectHTML($name, $field), $this->createValidate($type, $name)));
case 'selectMultiple':
return ($this->structureHTML($field['label'], $this->selectMultipleHTML($name, $field), $this->createValidate($type, $name)));
case 'interval':
return ($this->structureHTML($field['label'], $this->intervalHTML($name, $field), $this->createValidate($type, $name)));
case 'date':
return ($this->structureHTML($field['label'], $this->dateHTML($name, $field), $this->createValidate($type, $name)));
case 'text':
return ($this->structureHTML($field['label'], $this->textHTML($name, $field), $this->createValidate($type, $name)));
case 'textarea':
return ($this->structureHTML($field['label'], $this->textareaHTML($name, $field), $this->createValidate($type, $name)));
case 'radio':
return ($this->structureHTML($field['label'], $this->radioHTML($name, $field), $this->createValidate($type, $name)));
}
}
}
}
}
private function createValidate($type, $name)
{
switch($type) {
case 'textarea':
case 'date':
$return = ('<a href="">Valider</a>');
}
$return .= ' <a href="">Switch de champ</a>';
return ($return);
}
private function structureHTML($label, $html, $lien = null)
{
$return ='<div class="fieldgrp">
<label>'.$label.'</label>
<div class="field">
'.$html.'
</div>
<span>'.$lien.'</span>
</div>';
return ($return);
}
/* Select */
private function selectMultipleHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<select class="criteres" name="'.$name.'">';
$return .= '<option value="tous">Tous</option>';
foreach($field['fields'][$field['type']]['value'] as $value => $label) {
$selected = "";
if(($session->getCritere($name) != null) and $session->getCritere($name) == $value)
$selected = " selected";
$return .= '<option'.((!empty($selected))?$selected:null).' value="'.$value.'">'.$label.'</option>';
}
$return .= '</select>';
return ($return);
}
/* Select Multiple */
private function selectHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<select class="criteres" name="'.$name.'">';
$return .= '<option value="tous">Tous</option>';
foreach($field['fields'][$field['type']]['value'] as $value => $label) {
$selected = "";
if(($session->getCritere($name) != null) and $session->getCritere($name) == $value)
$selected = " selected";
$return .= '<option'.((!empty($selected))?$selected:null).' value="'.$value.'">'.$label.'</option>';
}
$return .= '</select>';
return ($return);
}
/* Interval */
private function intervalHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<div class="mySlider" style="text-align:right;height:17px;">';
$return .= '<input style="display:none;" value="'.$session->getCritere($name).'" name="'.$name.'" class="range slider_Text" type="text" id="'.$name.'" min="0" max="1000" />';
$return .= '<div input="'.$name.'" class="slider-range"></div>';
return ($return);
}
/* Dates */
private function dateHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<input value="'.$session->getCritere($name).'" type="text" class="datepicker" name="'.$name.'1" /> a ';
$return .= '<input type="text" class="datepicker" name="'.$name.'2" />';
return ($return);
}
/* Textes */
private function textHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<input style="border:1px inset silver;width:60%" class="criteres" type="text" name="'.$name.'" value="'.$session->getCritere($name).'" />';
return ($return);
}
/* Textarea */
private function textareaHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<textarea name="'.$name.'">'.$session->getCritere($name).'</textarea>';
return ($return);
}
/* Radios */
private function radioHTML($name, $field, $item)
{
$session = new SessionCiblage();
$return = '<input type="radio" name="'.$name.'" />';
return ($return);
}
}