public function executeList()
 {
     if (isset($this->campaign)) {
         $this->target_lists = MailingListTable::getInstance()->queryByCampaign($this->campaign, false, $this->userIsAdmin())->execute();
     } else {
         $this->target_lists = MailingListTable::getInstance()->queryGlobal()->execute();
     }
     $this->csrf_token_join = UtilCSRF::gen('target_join');
 }
 public function setup()
 {
     $this->widgetSchema->setFormFormatterName('bootstrap');
     $this->widgetSchema->setNameFormat('target_global[%s]');
     $query = MailingListTable::getInstance()->queryGlobalActive();
     $this->setWidget('global', new sfWidgetFormDoctrineChoice(array('model' => 'MailingList', 'query' => $query, 'add_empty' => '-- select Target-list --', 'label' => 'Source'), array('class' => 'span4', 'onchange' => "\$('#target_global_new_name').val(\$('option:selected', this).text());")));
     $this->setValidator('global', new sfValidatorDoctrineChoice(array('required' => true, 'model' => 'MailingList', 'query' => $query)));
     $this->setWidget('new_name', new sfWidgetFormInputText(array(), array('class' => 'span4')));
     $this->setValidator('new_name', new sfValidatorString(array('max_length' => 100, 'required' => true)));
 }
 public function getByMetaIdCached($id, $target_list_id = null)
 {
     if ($target_list_id) {
         $query = MailingListTable::getInstance()->createQuery('ml');
         if ($target_list_id) {
             $query->where('ml.id = ?', $target_list_id);
         }
         // help the db
         $result = $query->leftJoin('ml.MailingListMeta mlm')->leftJoin('mlm.MailingListMetaChoice mlmc')->leftJoin('mlmc.ContactMeta cm')->andWhere('cm.mailing_list_meta_id = ?', $id)->orderBy('mlmc.choice ASC')->useResultCache()->fetchOne();
         /* @var $result MailingList */
         if (!$result) {
             return array();
         }
         $a = $result->getMailingListMeta()->getFirst();
         if ($a) {
             return $a->getMailingListMetaChoice();
         }
         return array();
     }
 }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 public function executeTarget(sfWebRequest $request)
 {
     $petition = PetitionTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $petition Petition */
     if (!$petition) {
         return $this->notFound();
     }
     if (!$petition->isEditableBy($this->getGuardUser())) {
         return $this->noAccess();
     }
     $value = $request->getPostParameter('value');
     if (!is_numeric($value)) {
         $value = null;
     }
     if ($value) {
         $ml = MailingListTable::getInstance()->queryByCampaignForUser($petition->getCampaign(), $this->getGuardUser(), $petition->getMailingListId() ? $petition->getMailingList() : null, false, $value)->fetchOne();
         if (!$ml) {
             return $this->notFound();
         }
         $target_choices = $ml->getTargetChoices();
     } else {
         $target_choices = array();
     }
     $html = '';
     foreach ($target_choices as $key => $name) {
         $html .= sprintf('<option value="%s">%s</option>', $key, htmlentities($name, ENT_COMPAT, 'UTF-8'));
     }
     return $this->ajax()->html('#edit_petition_target_target_selector_1', $html)->trigger('#edit_petition_target_target_selector_1', 'liszt:updated')->html('#edit_petition_target_target_selector_2', $html)->trigger('#edit_petition_target_target_selector_2', 'liszt:updated')->remove('#edit, #edit-btn')->show('#edit-btn-save')->render();
 }
 public function processValues($values)
 {
     $values = parent::processValues($values);
     if (isset($values['mailing_list_id'])) {
         $ml_id = $values['mailing_list_id'];
         if ($ml_id) {
             if (strpos($ml_id, 'c') === 0) {
                 $ml_id = substr($ml_id, 1);
                 $source_target_list = MailingListTable::getInstance()->findById($ml_id, true);
                 $copy_target_list = MailingListTable::getInstance()->copy($source_target_list, $this->getObject()->getCampaign(), $source_target_list->getName() . ' copy ' . gmdate('Y-m-d H:i'));
                 if ($copy_target_list) {
                     $user = $this->getOption(self::USER, null);
                     /* @var $user sfGuardUser */
                     $tr = new TargetListRights();
                     $tr->setMailingListId($copy_target_list->getId());
                     $tr->setUserId($user->getId());
                     $tr->setActive(1);
                     $tr->save();
                     $this->getObject()->setMailingList($copy_target_list);
                     $values['mailing_list_id'] = $copy_target_list->getId();
                 } else {
                     throw new Exception('target list copy error');
                 }
             } else {
                 $this->getObject()->setMailingList(MailingListTable::getInstance()->findById($ml_id, true));
             }
         } else {
             $ml = new MailingList();
             $ml->setCampaignId($this->getObject()->getCampaignId());
             $ml->setStatus(MailingListTable::STATUS_DRAFT);
             $ml->setName($this->getObject()->getName() . ' Target-List ' . gmdate('Y-m-d H:i'));
             $this->getObject()->setMailingList($ml);
         }
     }
     if ($this->getObject()->isGeoKind()) {
         $target_choices = $target_choices = $this->getObject()->getMailingList()->getTargetChoices();
         $set = array();
         foreach (array($this->getValue('target_selector_1'), $this->getValue('target_selector_2')) as $ts) {
             if ($ts && array_key_exists($ts, $target_choices)) {
                 $set[] = $ts;
             }
         }
         $values['email_targets'] = json_encode($set);
     }
     return $values;
 }
Esempio n. 7
0
 protected function getGeoSubstFields()
 {
     if ($this->isGeoKind()) {
         if ($this->getMailingListId()) {
             $ml = MailingListTable::getInstance()->findAndFetchCached($this->getMailingListId());
             if ($ml) {
                 return $ml->getSubstFields();
             }
         }
     }
     return array();
 }