getUser()->getCulture(); unset($this['created_at']); unset($this['updated_at']); unset($this['slug']); unset($this['prepayment_active']); $this->widgetSchema['agree'] = new saWidgetFormInputCheckboxAgree(); $this->validatorSchema['agree'] = new sfValidatorBoolean(array('required' => true)); $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden(); $this->validatorSchema['user_id']->setOption('required', false); $this->validatorSchema['web'] = new sfValidatorUrl(array('required' => false)); $this->validatorSchema['mail'] = new sfValidatorEmail(); $this->widgetSchema['prepayment_from'] = new sfWidgetFormI18nDate(array('culture' => $culture, 'can_be_empty' => false)); $this->widgetSchema['prepayment_from']->setDefault(date('Y-m-d')); $this->widgetSchema['prepayment_to'] = new sfWidgetFormI18nDate(array('culture' => $culture, 'can_be_empty' => false)); $this->widgetSchema['prepayment_to']->setDefault(date('Y-m-d')); $this->widgetSchema['region_id']->setOption('order_by', array('name', 'ASC')); $this->widgetSchema['prepayment_type_id'] = new sfWidgetFormInputHidden(); $this->widgetSchema['prepayment_type_id']->setLabel('Typ'); $this->setDefault('prepayment_type_id', PrepaymentType::TYPE_ROW); $this->widgetSchema['name']->setLabel(__('Název')); $this->widgetSchema['web']->setLabel(__('Web (včetně http://)')); $this->widgetSchema['tel']->setLabel(__('Telefon')); $this->validatorSchema['tel']->setOption('required', true); $this->widgetSchema['country_id']->setLabel(__('Země')); $this->widgetSchema['region_id']->setLabel(__('Kraj')); $this->widgetSchema['city']->setLabel(__('Město')); $this->validatorSchema['city']->setOption('required', true); $this->widgetSchema['street']->setLabel(__('Ulice')); $this->validatorSchema['street']->setOption('required', true); $this->widgetSchema['zip']->setLabel(__('PSČ')); $this->validatorSchema['zip']->setOption('required', true); $this->widgetSchema['mail']->setLabel(__('E-mail')); $this->widgetSchema['text']->setLabel(__('Další informace')); $this->widgetSchema['agree']->setLabel(__('Podmínky')); $this->widgetSchema['first_name']->setLabel(__('Jméno')); $this->widgetSchema['last_name']->setLabel(__('Příjmení')); $this->widgetSchema['prefix']->setLabel(__('Titul před jménem')); $this->widgetSchema['sufix']->setLabel(__('Titul za jménem')); $this->widgetSchema['representant_id']->setLabel(__('Representant')); $this->widgetSchema['is_pdf_subscriber']->setLabel(__('Odebírat ZVZ pdf')); $this->widgetSchema->moveField('is_pdf_subscriber', sfWidgetFormSchema::AFTER, 'mail'); $this->widgetSchema['prepayment_from']->setLabel(__('Od')); $this->widgetSchema['prepayment_to']->setLabel(__('Do')); $this->widgetSchema['is_public']->setLabel(__('Zobrazit Vaše osobní informace')); $this->widgetSchema['logo_no_resize'] = new sfWidgetFormInputCheckbox(); $this->widgetSchema['logo_no_resize']->setLabel(__('Neměnit velikosti loga')); $this->widgetSchema['logo_no_resize']->setDefault(false); $this->validatorSchema['logo_no_resize'] = new sfValidatorBoolean(array('required' => false)); $this->widgetSchema['ic']->setLabel(__('IČ')); $this->validatorSchema['ic']->setOption('required', true); $this->widgetSchema['bank_account']->setLabel(__('Bankovní spojení')); $this->validatorSchema['bank_account']->setOption('required', true); foreach(Doctrine::getTable('JobStyle')->findAll() as $style) { $this->widgetSchema['prepayment_count_'.$style->getId()] = new sfWidgetFormInputHidden();//new sfWidgetFormInputText(); $this->widgetSchema['prepayment_count_'.$style->getId()]->setLabel($style->getName()); $this->validatorSchema['prepayment_count_'.$style->getId()] = new sfValidatorInteger(array('required' => false)); $this->setDefault('prepayment_count_'.$style->getId(), $this->getObject()->getPrepaymentCount($style)); $this->widgetSchema->moveField('prepayment_count_'.$style->getId(), sfWidgetFormSchema::BEFORE, 'filename'); } if(!$this->isNew() && $this->getObject()->existsFile()) { $this->widgetSchema['filename'] = new sfWidgetFormInputFileEditable(array('is_image' => true, 'file_src' => $this->getObject()->getSrc())); $this->widgetSchema['filename']->setOption('delete_label', __('Odstranit aktuální logo')); } else { $this->widgetSchema['filename'] = new sfWidgetFormInputFile(); } $this->widgetSchema['filename']->setLabel(__('Logo')); $this->validatorSchema['filename'] = new sfValidatorFile(array( 'required' => false, 'path' => sfConfig::get('sf_upload_dir').'/profiles', 'mime_types' => 'web_images', //'mime_type_guessers' => array('guessFromFileBinary'), 'validated_file_class' => 'saProfileFotoResizeFile', )); $this->validatorSchema['filename']->setOption('mime_type_guessers', array(array($this->validatorSchema['filename'], 'guessFromFileBinary'))); $this->validatorSchema['filename_delete'] = new sfValidatorBoolean(); $this->widgetSchema['is_eventer']->setLabel(__('Může zadávat události do kalendáře')); $this->widgetSchema->moveField('representant_id', sfWidgetFormSchema::FIRST); $this->widgetSchema->moveField('is_eventer', sfWidgetFormSchema::LAST); } public function bind(array $taintedValues = null, array $taintedFiles = null) { if(isset($taintedValues['logo_no_resize']) && $taintedValues['logo_no_resize']) { $this->validatorSchema['filename']->setOption('validated_file_class', 'sfValidatedFile'); } if(isset($taintedValues['prepayment_type_id'])) { switch($taintedValues['prepayment_type_id']) { case PrepaymentType::TYPE_BASIC: if(isset($taintedValues['prepayment_from'])) $taintedValues['prepayment_from'] = null; if(isset($taintedValues['prepayment_to'])) $taintedValues['prepayment_to'] = null; if(isset($taintedValues['prepayment_active'])) $taintedValues['prepayment_active'] = false; break; case PrepaymentType::TYPE_COUNT: if(isset($taintedValues['prepayment_from'])) $taintedValues['prepayment_from'] = null; if(isset($taintedValues['prepayment_to'])) $taintedValues['prepayment_to'] = null; if(isset($taintedValues['prepayment_active']))$taintedValues['prepayment_active'] = true; break; case PrepaymentType::TYPE_DATE: if(isset($taintedValues['prepayment_active'])) $taintedValues['prepayment_active'] = true; break; case PrepaymentType::TYPE_ROW: if(isset($taintedValues['prepayment_active'])) $taintedValues['prepayment_active'] = true; if(isset($taintedValues['prepayment_from'])) $taintedValues['prepayment_from'] = null; if(isset($taintedValues['prepayment_to'])) $taintedValues['prepayment_to'] = null; break; } } parent::bind($taintedValues, $taintedFiles); } public function getJavaScripts() { $js = parent::getJavaScripts(); $js[] = 'forms/ProfileForm.js'; return $js; } public function save($con = null) { $profile = parent::save($con); $values = $this->getValues(); if(isset($values['prepayment_type_id']) && $values['prepayment_type_id'] == PrepaymentType::TYPE_COUNT) { foreach(Doctrine::getTable('JobStyle')->findAll() as $style) { if(isset($values['prepayment_count_'.$style->getId()])) { $profile->setPrepaymentCount($style, $values['prepayment_count_'.$style->getId()]); } if(isset($values['prepayment_discount_'.$style->getId()])) { $profile->setPrepaymentDiscountAsPercent($style, $values['prepayment_discount_'.$style->getId()]); } if(isset($values['prepayment_request_count_'.$style->getId()])) { $profile->setPrepaymentRequestCount($style, $values['prepayment_request_count_'.$style->getId()]); } if(isset($values['prepayment_request_discount_'.$style->getId()])) { $profile->setPrepaymentRequestDiscountAsPercent($style, $values['prepayment_request_discount_'.$style->getId()]); } if(isset($values['prepayment_rows_'.$style->getId()])) { $profile->setPrepaymentRows($style, $values['prepayment_rows_'.$style->getId()]); } } } elseif(isset($values['prepayment_type_id']) && $values['prepayment_type_id'] == PrepaymentType::TYPE_ROW) { foreach(Doctrine::getTable('JobStyle')->findAll() as $style) { if(isset($values['prepayment_rows_'.$style->getId()])) { $profile->setPrepaymentRows($style, $values['prepayment_rows_'.$style->getId()]); } if(isset($values['prepayment_rows_discount'.$style->getId()])) { $profile->setPrepaymentRowsDiscountAsPercent($style, $values['prepayment_rows_discount_'.$style->getId()]); } if(isset($values['prepayment_request_rows_'.$style->getId()])) { $profile->setPrepaymentRequestRows($style, $values['prepayment_request_rows_'.$style->getId()]); } } } return $profile; } }