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. 2
0
 protected function targetListMember(Ticket $ticket)
 {
     $tr = TargetListRightsTable::getInstance()->queryByTargetListAndUser($ticket->getTargetList(), $ticket->getFrom())->fetchOne();
     if (!$tr) {
         $tr = new TargetListRights();
         $tr->setMailingList($ticket->getTargetList());
         $tr->setUser($ticket->getFrom());
     }
     /* @var $tr TargetListRights */
     $tr->setActive(1);
     $tr->save();
 }
Esempio n. 3
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();
 }