/**
  *
  * @param MailingList $source
  * @param Campaign $campaign
  * @param string $name
  * @return MailingList|null
  */
 public function copy(MailingList $source, Campaign $campaign = null, $name = null)
 {
     $con = $this->getConnection();
     $con->beginTransaction();
     try {
         $target = new MailingList();
         $target->setStatus(MailingListTable::STATUS_DRAFT);
         if ($name) {
             $target->setName($name);
         } else {
             $target->setName($source->getName() . ' copy ' . gmdate('Y-M-d H:i'));
         }
         if ($campaign) {
             $target->setCampaign($campaign);
         }
         $target->save();
         $meta_ids = array();
         $choice_ids = array();
         foreach ($source->getMailingListMeta() as $meta_source) {
             /* @var $meta_source MailingListMeta */
             $meta = new MailingListMeta();
             $meta->setMailingList($target);
             $meta->setKind($meta_source->getKind());
             $meta->setName($meta_source->getName());
             $meta->setSubst($meta_source->getSubst());
             $meta->save();
             $meta_ids[$meta_source->getId()] = $meta->getId();
             foreach ($meta_source->getMailingListMetaChoice() as $choice_source) {
                 /* @var $choice_source MailingListMetaChoice */
                 $choice = new MailingListMetaChoice();
                 $choice->setMailingListMeta($meta);
                 $choice->setChoice($choice_source->getChoice());
                 $choice->save();
                 $choice_ids[$choice_source->getId()] = $choice->getId();
             }
         }
         foreach ($source->getContact() as $contact_source) {
             /* @var $contact_source Contact */
             $contact = new Contact();
             $contact->setMailingList($target);
             $contact->setStatus($contact_source->getStatus());
             $contact->setEmail($contact_source->getEmail());
             $contact->setGender($contact_source->getGender());
             $contact->setFirstname($contact_source->getFirstname());
             $contact->setLastname($contact_source->getLastname());
             $contact->setCountry($contact_source->getCountry());
             $contact->save();
             foreach ($contact_source->getContactMeta() as $contact_meta_source) {
                 /* @var $contact_meta_source ContactMeta */
                 $contact_meta = new ContactMeta();
                 $contact_meta->setContact($contact);
                 $contact_meta->setValue($contact_meta_source->getValue());
                 $contact_meta->setMailingListMetaId($meta_ids[$contact_meta_source->getMailingListMetaId()]);
                 if ($contact_meta_source->getMailingListMetaChoiceId()) {
                     $contact_meta->setMailingListMetaChoiceId($choice_ids[$contact_meta_source->getMailingListMetaChoiceId()]);
                 }
                 $contact_meta->save();
             }
         }
         $con->commit();
         return $target;
     } catch (Exception $e) {
         $con->rollback();
     }
     return null;
 }
Exemplo n.º 2
0
    exit_permission_denied();
}
$ml = new MailingList($Group, getIntFromGet('group_list_id'));
if (getStringFromPost('submit')) {
    $sure = getStringFromPost('sure');
    $really_sure = getStringFromPost('really_sure');
    if (!$ml->delete($sure, $really_sure)) {
        exit_error('Error', $ml->getErrorMessage());
    } else {
        header("Location: index.php?group_id={$group_id}&feedback=DELETED");
    }
}
mail_header(array('title' => _('Permanently Delete List')));
?>
<h3><?php 
echo $ml->getName();
?>
</h3>
<p>
<form method="post" action="<?php 
echo getStringFromServer('PHP_SELF');
?>
?group_id=<?php 
echo $group_id;
?>
&amp;group_list_id=<?php 
echo $ml->getID();
?>
">
<input type="checkbox" name="sure" value="1"><?php 
echo _('Confirm Delete');