235 lines
6.7 KiB
PHP
Raw Normal View History

2012-02-02 17:29:14 +00:00
<?php
Class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
{
public function Field($name, $field, $type = null)
2012-02-02 17:29:14 +00:00
{
$html = '';
if($field != null) {
$html.= '<div class="fieldgrp">';
if($type == null)
$type = $field['type'];
2012-02-02 17:29:14 +00:00
switch($type)
{
case 'select':
$html.= $this->structureHTML(
$field['label'],
$this->selectHTML($name, $field));
break;
case 'selectMultiple':
$html.= $this->structureHTML(
$field['label'],
$this->selectMultipleHTML($name, $field));
break;
case 'intervalSelect':
$html.= $this->structureHTML(
$field['label'],
$this->intervalSelectHTML($name, $field));
break;
case 'interval':
$html.= $this->structureHTML(
$field['label'],
$this->intervalHTML($name, $field));
break;
case 'date':
$html.= $this->structureHTML(
$field['label'],
$this->dateHTML($name, $field));
break;
case 'text':
switch($name) {
case 'reg':
$label = 'Localisation Régions';
break;
case 'vil':
$label = 'Localisation Villes';
break;
case 'dep':
$label = 'Localisation Départements';
break;
default:
$label = $field['label'];
}
2012-02-02 17:29:14 +00:00
$html.= $this->structureHTML(
$label,
$this->textHTML($name, $field, $name));
2012-02-02 17:29:14 +00:00
break;
case 'textarea':
$html.= $this->structureHTML(
$field['label'],
$this->textareaHTML($name, $field));
break;
case 'radio':
$html.= $this->structureHTML(
$field['label'],
$this->radioHTML($name, $field));
break;
}
$html.= '</div>';
}
return $html;
}
private function structureHTML($label, $html, $liens = array())
{
$out = '';
$out.= $this->structureLabel($label);
$out.= '<div class="field">'.$html.$this->structureLink($liens).'</div>';
return $out;
}
/**
* Définition du label
* @param unknown_type $label
*/
private function structureLabel($label)
{
return '<label>'.$label.'</label>';
}
/**
* Définition des liens
*/
private function structureLink($liens = array())
{
$html = '';
if (count($liens)>0) {
foreach($liens as $lien){
$html.= '<a href="'.$lien['url'].'">'.$lien['lib'].'</a>';
}
}
if (!empty($html)) {
return '<span>'.$html.'</span>';
}
return '';
}
private function intervalSelectHTML($name, $field)
{
$session = new SessionCiblage();
$sessionValeur = explode(',', $session->getCritere($name));
2012-02-02 17:29:14 +00:00
$return = '<select class="intervalSelect" name="'.$name.'1" id="'.$name.'" number="1">';
foreach($field['fields'][$field['type']]['value'] as $elements) {
$return .= '<option '.(($sessionValeur[0] == $elements[0])?'selected':'').' value="'. $elements[0].'">'.number_format($elements[0], 0,'', ' ').'</option>';
2012-02-02 17:29:14 +00:00
}
$return .= '</select> à ';
$return .= '<select class="intervalSelect" name="'.$name.'2" id="'.$name.'" number="2">';
foreach($field['fields'][$field['type']]['value'] as $elements) {
$return .= '<option '.(($sessionValeur[1] == $elements[1])?'selected':'').' value="'. $elements[1].'">'.number_format($elements[1], 0,'', ' ').'</option>';
2012-02-02 17:29:14 +00:00
}
$return .= '</select>';
$return .= ' <span id="'.$name.'"><a href="" class="intervalSelect" id="'.$name.'">Valider</a></span>';
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();
$sessionValeur = $session->getCritere($name);
if(is_array($sessionValeur))
$sessionValeur = implode(',', $sessionValeur);
$return = '<select class="criteres '.$field['type']['class'].'" name="'.$name.'">';
$return .= '<option '.(($sessionValeur == 'tous')?'selected':'').' value="tous">Tous</option>';
2012-02-02 17:29:14 +00:00
foreach($field['fields'][$field['type']]['value'] as $value => $label) {
$selected = "";
if(($sessionValeur != null) and $sessionValeur == $value and $sessionValeur != "tous")
2012-02-02 17:29:14 +00:00
$selected = " selected";
$return .= '<option'.$selected.' value="'.$value.'">'.$label.'</option>';
2012-02-02 17:29:14 +00:00
}
$return .= '</select>';
return ($return);
}
/* Interval */
private function intervalHTML($name, $field)
{
$session = new SessionCiblage();
$valeur = $session->getCritere($name);
2012-02-16 09:17:20 +00:00
$valeur = explode(',', $valeur);
2012-02-02 17:29:14 +00:00
$return = '<div class="interval" >';
$return .= '<input class="'.$field['class'].'" type="text" name="'.$name.'1" value="'.$valeur[0].'" /> à ';
$return .= '<input class="'.$field['class'].'" type="text" name="'.$name.'2" value="'.$valeur[1].'" />';
$return .= ' <a href="" class="interval" id="'.$name.'">Valider</a>';
$return .= '</div>';
return ($return);
}
/* Dates */
private function dateHTML($name, $field)
{
$session = new SessionCiblage();
$return = '<div class="date" >';
$return .= '<input value="'.$session->getCritere($name).'" type="text" class="datepicker" name="'.$name.'1" /> a ';
$return .= '<input type="text" class="datepicker" name="'.$name.'2" />';
$return .= '</div>';
return ($return);
}
/* Textes */
private function textHTML($name, $field, $name)
2012-02-02 17:29:14 +00:00
{
$session = new SessionCiblage();
switch($name) {
case 'ape_entrep':
case 'ape_etab':
$type = 'Naf';
break;
case 'dep':
$type = 'Dep';
break;
case 'reg':
$type = 'Reg';
break;
case 'vil':
$type= 'Vil';
break;
case 'cj':
$type = 'Cj';
break;
}
$return = '<textarea rows="5" style="border:1px inset silver;width:60%" class="criteres complited'.$type.'" id="textarea_'.$name.'" name="'.$name.'">'.$session->getCritere($name).'</textarea>';
$return .= '<a href="" class="autocomplet" textarea="'.$name.'">Valider</a>';
2012-02-02 17:29:14 +00:00
return ($return);
}
/* Textarea */
private function textareaHTML($name, $field)
{
$return = '<a class="arborescence" title="'.$field['title'].'" href="'.$this->view->url(array('controller' => 'arborescence', 'action' => $field['action'], 'key' => $name)).'">
Selection dans une arborescence
</a>';
return ($return);
}
/* Radios */
private function radioHTML($name, $field, $item)
{
$return = '<input type="radio" name="'.$name.'" />';
return ($return);
}
}