'osobní odběr', 'posta' => 'balík Česká Pošta', 'toptrans' => 'balík Toptrans', //'matl-bula' => 'doprava Mátl&Bula', //'specialni' => 'speciální požadavek na dopravu (expresní, dokládka, jiná zásilková služba)', ); protected $payments = array('hotovost' => 'v hotovosti při předání', 'ucet' => 'předem na účet', //'faktura' => 'na fakturu', 'dobirka' => 'dobírkou', //'bude-upresneno' => 'bude upřesněno - budeme Vás kontaktovat' ); protected $packs = array('balik' => 'balík', 'paleta' => 'zásilka na paletě', 'bedna' => 'zásilka v přepravní bedně' ); protected $weight = 0; public function __construct($defaults = array(), $options = array(), $CSRFSecret = null, $weight = 0) { $this->weight = $weight; parent::__construct($defaults, $options, $CSRFSecret); } public function configure() { $this->widgetSchema->setNameFormat('shipping_form[%s]'); $this->widgetSchema['shipping'] = new sfWidgetFormChoice(array('choices' => $this->getShippings())); $this->widgetSchema['shipping']->setLabel('Doprava'); $this->widgetSchema['shipping']->setAttribute('onChange', 'submit();'); $this->validatorSchema['shipping'] = new sfValidatorChoice(array('choices' => array_keys($this->getShippings()))); $this->widgetSchema['payment'] = new sfWidgetFormChoice(array('choices' => $this->getPayments('osobni-odber'))); $this->widgetSchema['payment']->setAttribute('onChange', 'submit();'); $this->widgetSchema['payment']->setLabel('Platba'); $this->validatorSchema['payment'] = new sfValidatorChoice(array('choices' => array_keys($this->getPayments('osobni-odber')))); $this->widgetSchema['pack'] = new sfWidgetFormChoice(array('choices' => $this->getPacks('posta'))); $this->widgetSchema['pack']->setAttribute('onChange', 'submit();'); $this->widgetSchema['pack']->setLabel('Balné'); $this->validatorSchema['pack'] = new sfValidatorChoice(array('choices' => array_keys($this->getPacks('posta')), 'required' => false)); } public function bind(array $taintedValues = null, array $taintedFiles = null) { if(!is_null($taintedValues['shipping'])) { $this->widgetSchema['payment']->setOption('choices',$this->getPayments($taintedValues['shipping'])); $this->widgetSchema['payment']->setAttribute('onChange', 'submit();'); $this->widgetSchema['payment']->setLabel('Platba'); $this->validatorSchema['payment'] = new sfValidatorChoice(array('choices' => array_keys($this->getPayments($taintedValues['shipping'])))); if(!in_array($taintedValues['payment'], array_keys($this->getPayments($taintedValues['shipping'])))) { $p = array_keys($this->getPayments($taintedValues['shipping'])); $taintedValues['payment'] = $p[0]; } if(count($this->getPacks($taintedValues['shipping'])) == 0) { unset($this['pack']); unset($taintedValues['pack']); } else { $this->widgetSchema['pack']->setOption('choices', $this->getPacks($taintedValues['shipping'])); } } parent::bind($taintedValues, $taintedFiles); } public function getShippings() { $shipping = $this->shippings; $cp_max = @array_pop(array_keys(sfConfig::get('app_doprava_cpCenik'))); if($this->weight >= $cp_max) { unset($shipping['posta']); } return $shipping; } public function getPayments($shipping) { $payments = $this->payments; switch($shipping) { case 'osobni-odber': unset($payments['dobirka']); unset($payments['bude-upresneno']); break; case 'posta': case 'toptrans': unset($payments['hotovost']); unset($payments['bude-upresneno']); break; case 'matl-bula': unset($payments['hotovost']); unset($payments['bude-upresneno']); unset($payments['dobirka']); break; case 'specialni': unset($payments['dobirka']); unset($payments['hotovost']); unset($payments['ucet']); unset($payments['faktura']); break; } return $payments; } public function getPacks($shipping) { $packs = $this->packs; switch($shipping) { case 'posta': case 'toptrans': break; default: $packs = array(); break; } if($this->weight >= sfConfig::get('app_balne_balikDo')) { unset($packs['balik']); } if($this->weight < sfConfig::get('app_balne_paletaOd') || $this->weight > sfConfig::get('app_balne_paletaDo')) { unset($packs['paleta']); } if($this->weight < sfConfig::get('app_balne_bednaOd') || $this->weight > sfConfig::get('app_balne_bednaDo')) { unset($packs['bedna']); } return $packs; } public function getShipping($index) { return $this->shippings[$index]; } public function getPayment($index) { return $this->payments[$index]; } public function getPack($index) { return $this->packs[$index]; } }