getUser()->getCulture(); unset($this['created_at']); unset($this['updated_at']); unset($this['is_active']); unset($this['slug']); unset($this['price']); unset($this['discount']); unset($this['prepayment_rows']); $this->widgetSchema['name']->setLabel(__('Nadpis inzerátu')); $this->widgetSchema['city']->setLabel(__('Město')); $this->widgetSchema['street']->setLabel(__('Ulice')); $this->widgetSchema['zip']->setLabel(__('PSČ')); $this->widgetSchema['text']->setLabel(__('Upřesňující popis')); $this->widgetSchema['profile_id']->setLabel(__('Uživatel')); $this->widgetSchema['category_id'] = new sfWidgetFormChoice(array('choices' => JobFormCommonFunctions::getCategoryGroupedChoices())); $this->widgetSchema['category_id']->setLabel('Kategorie'); $this->widgetSchema['specializations_list'] = new sfWidgetFormChoice(array('choices' => JobFormCommonFunctions::getSpecializationsListGroupedChoices($this->getName()))); $this->widgetSchema['specializations_list']->setOption('expanded', true); $this->widgetSchema['specializations_list']->setOption('multiple', true); $this->widgetSchema['specializations_list']->setOption('renderer_options', array('template' => '
%options%
')); $this->widgetSchema['specializations_list']->setLabel(__('Specializace')); $this->widgetSchema['regions_list']->setOption('expanded', true); $this->widgetSchema['regions_list']->setOption('order_by', array('name', 'ASC')); $this->widgetSchema['regions_list']->setLabel(__('Kraje')); if ($this->isNew()) { $years = range(date('Y') - 1, date('Y') + 1); } else { $years = range(date('Y', strtotime($this->getObject()->getValidFrom())) - 1, date('Y') + 1); } $this->widgetSchema['valid_from'] = new sfWidgetFormI18nDate(array('culture' => $culture, 'can_be_empty' => false)); $this->widgetSchema['valid_from']->setLabel(__('Platnost od')); $this->widgetSchema['valid_from']->setOption('years', array_combine($years, $years)); $this->widgetSchema['valid_months'] = new sfWidgetFormChoice(array('choices' => $this->getValidTimeChoices())); $this->widgetSchema['valid_months']->setDefault(1); $this->validatorSchema['valid_months'] = new sfValidatorInteger(); $this->widgetSchema['valid_months']->setLabel(__('Platnost měsíců')); $this->widgetSchema['valid_to'] = new sfWidgetFormI18nDate(array('culture' => $culture, 'can_be_empty' => false)); $this->widgetSchema['valid_to']->setLabel(__('Platnost do')); $this->widgetSchema['valid_to']->setOption('years', array_combine($years, $years)); $this->widgetSchema['country_id']->setLabel(__('Země')); $this->widgetSchema['style_id']->setLabel(__('Druh')); $this->widgetSchema->moveField('specializations_list', sfWidgetFormSchema::AFTER, 'category_id'); $this->widgetSchema->moveField('regions_list', sfWidgetFormSchema::BEFORE, 'city'); $this->widgetSchema->moveField('name', sfWidgetFormSchema::BEFORE, 'text'); $this->widgetSchema->moveField('style_id', sfWidgetFormSchema::LAST); $this->validatorSchema['city']->setOption('required', true); $this->validatorSchema['street']->setOption('required', true); $this->validatorSchema['zip']->setOption('required', true); if ($this->isNew()) { // $this->validatorSchema['valid_from']->setOption('min', date('Y-m-d')); // $this->validatorSchema['valid_from']->setMessage('min', 'Nezle zadat inzerát v minulosti.'); $this->setDefault('valid_from', date('Y-m-d')); } if (!$this->isValidToEditable()) { $this->widgetSchema['valid_to']->setAttribute('disabled', 'disabled'); $this->validatorSchema['valid_to']->setOption('required', false); } $this->validatorSchema->setPostValidator( new sfValidatorCallback(array('callback' => array($this, 'checkValidity'))) ); commonFormFunctions::addClasses($this); commonFormFunctions::setJqUiFormater($this); } public function getValidTimeChoices() { $result = array(); for($i = 1; $i <= 12; $i++) { $result[$i] = $i; } return $result; } public function checkValidity($validator, $values) { $valid_from = strtotime($values['valid_from']); $valid_to = strtotime($values['valid_to']); // if ($valid_from < strtotime(date('Y-m-d'))) // { // throw new sfValidatorError($validator, 'Platnost od nemůže být v minulosti.'); // } if ($valid_from > $valid_to) { throw new sfValidatorError($validator, __('Platnost od nemůže být po platnosti do.')); } if($this->getUser()->isAuthenticated() && !$this->getUser()->isSuperadmin() && $this->getUser()->getProfile()->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE) { if($valid_to > strtotime($this->getUser()->getProfile()->getPrepaymentTo())) { throw new sfValidatorError($validator, __('Platnost do může být nastavena maximálně na konec platnosti vašeho předplatného.')); } } return $values; } private function getUser() { if (!$this->user instanceof myUser) { $this->user = sfContext::getInstance()->getUser(); } return $this->user; } /** * Vrací true pokud může uživatel editovat platnost DO * * @return boolean */ private function isValidToEditable() { return $this->getUser()->isAuthenticated() && ($this->getUser()->isSuperadmin() || ($this->getUser()->getProfile()->getPrepaymentTypeId() == PrepaymentType::TYPE_DATE && $this->getUser()->getProfile()->isPrepaymentValid())); } public function getJavaScripts() { $result = parent::getJavaScripts(); $result[] = 'forms/JobForm.js'; return $result; } public function bind(array $taintedValues = null, array $taintedFiles = null) { JobFormCommonFunctions::checkSpecializations($taintedValues); if (!$this->isValidToEditable()) { $valid_from = $taintedValues['valid_from']['year'] . '-' . $taintedValues['valid_from']['month'] . '-' . $taintedValues['valid_from']['day']; $taintedValues['valid_to']['day'] = date('d', strtotime('+'.$taintedValues['valid_months'].' months', strtotime($valid_from))); $taintedValues['valid_to']['month'] = date('m', strtotime('+'.$taintedValues['valid_months'].' months', strtotime($valid_from))); $taintedValues['valid_to']['year'] = date('Y',strtotime('+'.$taintedValues['valid_months'].' months', strtotime($valid_from))); } parent::bind($taintedValues, $taintedFiles); } }