public function setup()
 {
     parent::setup();
     $this->generateDateTime();
     $user = sfContext::getInstance()->getUser();
     $members = opCalendarPluginExtension::getAllowedFriendMember($user->getMember());
     $this->setWidget('title', new sfWidgetFormInput());
     $cul = $user->getCulture();
     $dateItems = array('culture' => $cul, 'month_format' => 'number', 'years' => $this->dateTime['years']);
     if ('ja_JP' === $cul) {
         $dateItems['format'] = '%year%年%month%月%day%日';
     }
     $dateObj = new sfWidgetFormI18nDate($dateItems);
     $this->setWidget('start_date', $dateObj);
     $this->setWidget('end_date', $dateObj);
     $timeItems = array('with_seconds' => false, 'minutes' => $this->dateTime['minutes']);
     if ('ja_JP' === $cul) {
         $timeItems['format'] = '%hour%時%minute%分';
     }
     $timeObj = new sfWidgetFormTime($timeItems);
     $this->setWidget('start_time', $timeObj);
     $this->setWidget('end_time', $timeObj);
     $this->setWidget('public_flag', new sfWidgetFormChoice(array('choices' => Doctrine::getTable('Schedule')->getPublicFlags(), 'expanded' => true)));
     $this->setWidget('schedule_member', new sfWidgetFormSelectCheckbox(array('choices' => $members)));
     $this->setDefault('schedule_member', $this->getDefaultSheduleMembers());
     $this->validatorSchema['title'] = new opValidatorString(array('trim' => true));
     $this->validatorSchema['public_flag'] = new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Schedule')->getPublicFlags())));
     $this->validatorSchema['schedule_member'] = new sfValidatorChoice(array('choices' => array_keys($members), 'multiple' => true));
     $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateEndDate')), array('invalid' => 'You can not set the end date before start date')));
     $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateResourceLock')), array('invalid' => 'There is not the resource that you can use')));
     $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateClosedSchedule')), array('invalid' => 'A closed schedule cannot set a resource')));
     $this->useFields(array('title', 'start_date', 'start_time', 'end_date', 'end_time', 'body', 'public_flag', 'schedule_member'));
     if (!$this->isNew()) {
         $scheduleResourceLocks = $this->getObject()->ScheduleResourceLocks;
     }
     $count = Doctrine_Core::getTable('ScheduleResource')->createQuery()->count();
     if (!$count) {
         sfConfig::set('app_schedule_resource_list_max', 0);
     }
     $max = (int) sfConfig::get('app_schedule_resource_list_max', 5);
     for ($i = 1; $i <= $max; $i++) {
         $key = 'schedule_resource_lock_' . $i;
         if (isset($scheduleResourceLocks[$i - 1])) {
             $scheduleResourceLock = $scheduleResourceLocks[$i - 1];
         } else {
             $scheduleResourceLock = new ScheduleResourceLock();
             $scheduleResourceLock->setSchedule($this->getObject());
         }
         $scheduleResourceLockForm = new ScheduleResourceLockForm($scheduleResourceLock);
         $scheduleResourceLockForm->getWidgetSchema()->setFormFormatterName('list');
         $this->embedForm($key, $scheduleResourceLockForm, '<ul id="schedule_resource_lock_' . $key . '">%content%</ul>');
     }
 }