* @version SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */ class TopJobForm extends BaseTopJobForm { public function configure() { unset($this['created_at']); unset($this['updated_at']); $this->widgetSchema['job_id'] = new sfWidgetFormInputHidden(); $this->widgetSchema['valid_from'] = new sfWidgetFormJQueryDate(array('culture' => 'cs', 'date_widget' => new sfWidgetFormI18nDate(array('culture' => 'cs','can_be_empty' => false, 'format' => '%day%.%month%.%year%')))); $this->widgetSchema['valid_from']->setLabel('Od:'); $this->widgetSchema['valid_to'] = new sfWidgetFormJQueryDate(array('culture' => 'cs', 'date_widget' => new sfWidgetFormI18nDate(array('culture' => 'cs','can_be_empty' => false, 'format' => '%day%.%month%.%year%')))); $this->widgetSchema['valid_to']->setLabel('Do:'); $this->widgetSchema['is_active']->setLabel(__('Aktivní')); if (!$this->isNew()) { $this->setDefaultDates($this->getObject()->getJob()); } $this->validatorSchema->setPostValidator( new sfValidatorCallback(array('callback' => array($this, 'checkDates'))) ); commonFormFunctions::setJqUiFormater($this); } public function checkDates($validator, $values) { if (strtotime($values['valid_from']) >= strtotime($values['valid_to'])) { throw new sfValidatorError($validator, __('Datum "Od" musí být před datem "Do".')); } if($values['is_active']) { if(!$this->isNew()) { $topJob = Doctrine::getTable('TopJob')->getTopJob($values['valid_from'], $values['valid_to'], $this->getObject()); } else { $topJob = Doctrine::getTable('TopJob')->getTopJob($values['valid_from'], $values['valid_to']); } if ($topJob instanceof TopJob) { throw new sfValidatorError($validator, __('V zadaném čacovém rospětí už je aktivní jiný TOP inzerát.')); } } return $values; } public function setDefaultDates(Job $job) { $next = Doctrine::getTable('TopJob')->getNextAvailableDate(); $this->setDefault('valid_from', $next); $this->setDefault('valid_to', strtotime($next) + sfConfig::get('app_job_valid_time')); } }