public function configure()
 {
     $user = $this->getOption(self::USER);
     if ($this->getOption(self::WITH_CAMPAIGN)) {
         $query = $user ? CampaignTable::getInstance()->queryByMember($user, $this->getOption('is_member', true) ? true : false) : CampaignTable::getInstance()->queryAll();
         $this->setWidget(PetitionTable::FILTER_CAMPAIGN, new sfWidgetFormDoctrineChoice(array('model' => 'Campaign', 'query' => $query, 'add_empty' => 'select campaign', 'label' => 'campaign'), array('class' => 'span2')));
         $this->setValidator(PetitionTable::FILTER_CAMPAIGN, new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'Campaign', 'query' => $query)));
     }
     $status_with_empty = array(0 => 'select status') + Petition::$STATUS_SHOW;
     if (!$this->getOption(self::DELETED_TOO)) {
         unset($status_with_empty[Petition::STATUS_DELETED]);
     }
     $this->setWidget(PetitionTable::FILTER_STATUS, new sfWidgetFormChoice(array('choices' => $status_with_empty, 'label' => 'status'), array('class' => 'span2')));
     $this->setValidator(PetitionTable::FILTER_STATUS, new sfValidatorChoice(array('choices' => array_keys($status_with_empty), 'required' => false)));
     $kinds_with_empty = array(0 => 'select type') + Petition::$KIND_SHOW;
     $this->setWidget(PetitionTable::FILTER_KIND, new sfWidgetFormChoice(array('choices' => $kinds_with_empty, 'label' => 'type'), array('class' => 'span2')));
     $this->setValidator(PetitionTable::FILTER_KIND, new sfValidatorChoice(array('choices' => array_keys($kinds_with_empty), 'required' => false)));
     $this->setWidget(PetitionTable::FILTER_START, new sfWidgetFormInput(array('type' => 'date', 'label' => 'started after'), array()));
     $this->setValidator(PetitionTable::FILTER_START, new sfValidatorDate(array('required' => false)));
     $this->setWidget(PetitionTable::FILTER_END, new sfWidgetFormInput(array('type' => 'date', 'label' => 'ended before'), array()));
     $this->setValidator(PetitionTable::FILTER_END, new sfValidatorDate(array('required' => false)));
     $this->setWidget(PetitionTable::FILTER_ORDER, new sfWidgetFormInputHidden());
     $this->setValidator(PetitionTable::FILTER_ORDER, new sfValidatorPass(array('required' => false)));
     $this->setWidget(PetitionTable::FILTER_MIN_SIGNINGS, new sfWidgetFormInput(array('type' => 'number', 'label' => 'min signings', 'default' => 1), array('min' => 0)));
     $this->setValidator(PetitionTable::FILTER_MIN_SIGNINGS, new sfValidatorInteger(array('required' => false)));
 }
 public function setup()
 {
     $this->widgetSchema->setFormFormatterName('bootstrap');
     $this->widgetSchema->setNameFormat('target_copy[%s]');
     $user = $this->getOption('user');
     $query = $user ? CampaignTable::getInstance()->queryByMember($user) : CampaignTable::getInstance()->queryAll();
     $this->setWidget('target', new sfWidgetFormDoctrineChoice(array('model' => 'Campaign', 'query' => $query, 'add_empty' => $user ? 'select target campaign' : '-- copy to global pool --', 'label' => 'Target'), array('class' => 'span4')));
     $this->setValidator('target', new sfValidatorDoctrineChoice(array('required' => $user ? true : false, 'model' => 'Campaign', 'query' => $query)));
     $this->setWidget('new_name', new sfWidgetFormInputText(array(), array('class' => 'span4')));
     $this->setValidator('new_name', new sfValidatorString(array('max_length' => 100, 'required' => true)));
 }
 /**
  * @param $id
  * @return Campaign
  */
 private function getCampaign($id)
 {
     $campaign = CampaignTable::getInstance()->findById($id, $this->userIsAdmin());
     /* @var $campaign Campaign */
     $right = $this->rightCampaign($campaign);
     if ($right) {
         return $campaign;
     } else {
         return $right === false ? $this->notFound() : $this->noAccess();
     }
 }
 public function setup()
 {
     $this->widgetSchema->setFormFormatterName('bootstrapInline');
     $this->widgetSchema->setNameFormat($this->getOption(self::NAME, 'select_campaign') . '[%s]');
     $user = $this->getOption('user');
     $query = $user ? CampaignTable::getInstance()->queryByMember($user, $this->getOption('is_member', true) ? true : false) : CampaignTable::getInstance()->queryAll();
     /* @var $query Doctrine_Query */
     $query->orderBy($query->getRootAlias() . '.name ASC');
     $empty = $this->getOption('empty');
     if (!$empty) {
         $empty = 'select campaign';
     }
     $this->setWidget('id', new sfWidgetFormDoctrineChoice(array('model' => 'Campaign', 'query' => $query, 'add_empty' => $empty, 'label' => false), array('class' => 'input-medium')));
     $this->setValidator('id', new sfValidatorDoctrineChoice(array('required' => true, 'model' => 'Campaign', 'query' => $query)));
     $help = $this->getOption(self::HELP, '');
     if ($help) {
         $this->getWidget('id')->setAttribute('class', 'input-medium add_popover popover_left');
         $this->getWidget('id')->setAttribute('data-content', $help);
     }
 }
 public function configure()
 {
     $user = $this->getOption(self::USER);
     if ($this->getOption(self::WITH_CAMPAIGN)) {
         $query = $user ? CampaignTable::getInstance()->queryByMember($user, $this->getOption('is_member', true) ? true : false) : CampaignTable::getInstance()->queryAll();
         $this->setWidget(WidgetTable::FILTER_CAMPAIGN, new sfWidgetFormDoctrineChoice(array('model' => 'Campaign', 'query' => $query, 'add_empty' => 'select campaign', 'label' => 'campaign'), array('class' => 'span2 select-update', 'data-update-target' => '#' . WidgetTable::FILTER_PETITION, 'data-update-url' => sfContext::getInstance()->getRouting()->generate('action_by_campaign'))));
         $this->setValidator(WidgetTable::FILTER_CAMPAIGN, new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'Campaign', 'query' => $query)));
         $this->setWidget(WidgetTable::FILTER_PETITION, new WidgetChoiceRefresh(array('choices' => array('' => 'select action'), 'label' => 'action'), array('class' => 'span2')));
         $this->setValidator(WidgetTable::FILTER_PETITION, new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'Petition')));
     }
     $this->setWidget(WidgetTable::FILTER_LANGUAGE, new sfWidgetFormDoctrineChoice(array('model' => 'Language', 'add_empty' => 'select language', 'label' => 'language'), array('class' => 'span2')));
     $this->setValidator(WidgetTable::FILTER_LANGUAGE, new sfValidatorDoctrineChoice(array('required' => false, 'model' => 'Language')));
     $status_with_empty = array(0 => 'select status') + Widget::$STATUS_SHOW;
     $this->setWidget(WidgetTable::FILTER_STATUS, new sfWidgetFormChoice(array('choices' => $status_with_empty, 'label' => 'status'), array('class' => 'span2')));
     $this->setValidator(WidgetTable::FILTER_STATUS, new sfValidatorChoice(array('choices' => array_keys($status_with_empty), 'required' => false)));
     $this->setWidget(WidgetTable::FILTER_START, new sfWidgetFormInput(array('type' => 'date', 'label' => 'started after'), array()));
     $this->setValidator(WidgetTable::FILTER_START, new sfValidatorDate(array('required' => false)));
     $this->setWidget(WidgetTable::FILTER_END, new sfWidgetFormInput(array('type' => 'date', 'label' => 'ended before'), array()));
     $this->setValidator(WidgetTable::FILTER_END, new sfValidatorDate(array('required' => false)));
     $this->setWidget(WidgetTable::FILTER_ORDER, new sfWidgetFormInputHidden());
     $this->setValidator(WidgetTable::FILTER_ORDER, new sfValidatorPass(array('required' => false)));
     $this->setWidget(WidgetTable::FILTER_MIN_SIGNINGS, new sfWidgetFormInput(array('type' => 'number', 'label' => 'min signings', 'default' => 1), array('min' => 0)));
     $this->setValidator(WidgetTable::FILTER_MIN_SIGNINGS, new sfValidatorInteger(array('required' => false)));
 }
 public function executeUndelete(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     if (is_numeric($id)) {
         $campaign = CampaignTable::getInstance()->findById($id, true);
         /* @var $campaign Campaign */
         if (!$campaign) {
             return $this->notFound('xx');
         }
     }
     $csrf_token = UtilCSRF::gen('undelete_campaign', $campaign->getId());
     if ($request->isMethod('post')) {
         if ($request->getPostParameter('csrf_token') != $csrf_token) {
             return $this->ajax()->alert('CSRF Attack detected, please relogin.', 'Error', '#campaign_undelete_modal .modal-body')->render();
         }
         $campaign->setStatus(CampaignTable::STATUS_ACTIVE);
         $campaign->save();
         return $this->ajax()->redirectRotue('campaign_edit_', array('id' => $campaign->getId()))->render();
     }
     return $this->ajax()->appendPartial('body', 'undelete', array('id' => $id, 'name' => $campaign->getName(), 'csrf_token' => $csrf_token))->modal('#campaign_undelete_modal')->render();
 }
 public function executeCopyGlobal(sfWebRequest $request)
 {
     $campaign = CampaignTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $campaign Campaign */
     if (!$campaign) {
         return $this->notFound();
     }
     if (!$this->getGuardUser()->isCampaignMember($campaign)) {
         return $this->noAccess();
     }
     $form = new TargetListCopyGlobalForm();
     if ($request->isMethod('post')) {
         $form->bind($request->getPostParameter($form->getName()));
         if ($form->isValid()) {
             $data = $form->getValues();
             $target_list = $this->findTargetList($data['global']);
             $new = MailingListTable::getInstance()->copy($target_list, $campaign, $data['new_name']);
             if ($new) {
                 $tr = new TargetListRights();
                 $tr->setMailingListId($new->getId());
                 $tr->setUserId($this->getGuardUser()->getId());
                 $tr->setActive(1);
                 $tr->save();
                 return $this->ajax()->modal('#target_copy_global_modal', 'hide')->remove('#target_copy_gloabl_modal')->alert('Target-list copied', '', '#target_list', 'before', false, 'success')->render();
             } else {
                 return $this->ajax()->alert('Error on copy', '', '#target_list', 'before', false, 'success')->render();
             }
         } else {
             return $this->ajax()->form($form)->render();
         }
     }
     return $this->ajax()->appendPartial('body', 'copy_global', array('id' => $campaign->getId(), 'form' => $form))->modal('#target_copy_global_modal')->render();
 }
 public function executeTranslationDefaultText(sfWebRequest $request)
 {
     $campaign = CampaignTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     if (!$campaign) {
         return $this->notFound();
     }
     if (!$this->getGuardUser()->isCampaignMember($campaign)) {
         return $this->noAccess();
     }
     $form = new TranslationForm();
     $form_name = $form->getName();
     $value = $request->getGetParameter('value');
     if (!is_string($value)) {
         return $this->notFound();
     }
     $language = LanguageTable::getInstance()->find($value);
     if (!$language) {
         return $this->notFound();
     }
     $validation_email = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::SIGNING_VALIDATION_EMAIL, $value);
     if ($validation_email) {
         $this->ajax()->val('#' . $form_name . '_email_validation_subject', $validation_email->getField('subject', ''));
         $this->ajax()->val('#' . $form_name . '_email_validation_body', $validation_email->getField('body', ''));
     }
     $tellyourfriend_email = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::ACTION_TELL_YOUR_FRIEND_EMAIL, $value);
     if ($tellyourfriend_email) {
         $this->ajax()->val('#' . $form_name . '_email_tellyour_subject', $tellyourfriend_email->getField('subject', ''));
         $this->ajax()->val('#' . $form_name . '_email_tellyour_body', $tellyourfriend_email->getField('body', ''));
     }
     $default_campaign_privacy = CampaignStoreTable::getInstance()->findByCampaignLanguageKey($campaign, $language, CampaignStoreTable::KEY_PRIVACY_POLICY);
     if ($default_campaign_privacy) {
         $this->ajax()->val('#' . $form_name . '_privacy_policy_body', $default_campaign_privacy->getValue());
     } else {
         $privacy = StoreTable::getInstance()->findByKeyAndLanguageCached(StoreTable::ACTION_PRIVACY_POLICY, $value);
         if ($privacy) {
             $this->ajax()->val('#' . $form_name . '_privacy_policy_body', $privacy->getField('body', ''));
         }
     }
     return $this->ajax()->render();
 }
 public function hasCampaigns()
 {
     return CampaignTable::getInstance()->queryByMember($this)->limit(1)->count();
 }