Ejemplo n.º 1
0
 public function executeEmailBulkQueue(sfWebRequest $request)
 {
     $subject = $request->getParameter('subject');
     $to = $request->getParameter('recipients');
     $sender_email = $request->getParameter('sender_email');
     $sender_name = $request->getParameter('sender_name');
     $message = $request->getParameter('message');
     $send_date = $request->getParameter('send_date');
     $priority = $request->getParameter('priority');
     $errors = array();
     // validate recievers
     if (empty($to)) {
         $errors['email'][0] = 'please specify email address';
     } else {
         $recievers = explode(',', $to);
         $pat = '/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i';
         $full_pat = '/^([- a-z0-9]+)\\<(([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,}))\\>$/i';
         $emails = array();
         foreach ($recievers as $reciever) {
             $reciever = trim($reciever);
             if (empty($reciever)) {
                 continue;
             }
             if (preg_match($full_pat, $reciever, $matches)) {
                 $emails[$matches[2]] = $matches[1];
             } elseif (preg_match($pat, $reciever, $matches)) {
                 $emails[$matches[0]] = '';
             } else {
                 if (!isset($errors['email'])) {
                     $errors['email'] = array();
                 }
                 $errors['email'][] = $reciever . ' is unrecognizable email';
             }
         }
     }
     // validate subject
     if (empty($subject)) {
         $errors['subject'] = 'subject required';
     }
     // validate send_date
     if (empty($send_date)) {
         $errors['send_date'] = 'Send date required';
     }
     // validate sender
     $v_email = new sfValidatorEmail(array(), array('invalid' => 'please specify email address'));
     try {
         $sender_email = $v_email->clean($sender_email);
     } catch (sfValidatorError $e) {
         $errors['sender_email'] = $e->__toString();
     }
     // attachments
     $upload_dir = sfConfig::get('sf_upload_dir') . '/' . 'bulk-email-attachments' . '/';
     $files = array();
     foreach ($request->getFiles() as $file) {
         if ($file[0]['error'] != 0) {
             continue;
         }
         if (move_uploaded_file($file[0]["tmp_name"], $upload_dir . $file[0]["name"])) {
             $files[] = array('path' => $upload_dir, 'name' => $file[0]['name']);
         } else {
             //echo '<h1>Error while uploading '.$file[0]["tmp_name"].'/'.$file[0]["name"].' to '.$upload_dir . $file[0]["name"].'</h1>';
             $error['attachment'] = 'Error while uploading ' . $file[0]["name"];
         }
     }
     // catch errors
     if ($errors) {
         $this->email_templates = EmailTemplatePeer::getByPersonId($this->getUser()->getId());
         $this->errors = $errors;
         $this->recipients = $to;
         $this->subject = $subject;
         $this->sender_email = $sender_email;
         $this->sender_name = $sender_name;
         $this->message = $message;
         $this->priority = $priority;
         $this->send_date = $send_date;
         if (!empty($error['attachment'])) {
             $this->attachement_error = $error['attachment'];
         }
         $this->setTemplate('sendBulkQueue');
         return sfView::SUCCESS;
     }
     $email_letter = new EmailLetter();
     $email_letter->setSubject($subject);
     $email_letter->setSenderEmail($sender_email);
     $email_letter->setSenderName($sender_name);
     $email_letter->setBody($message);
     $email_letter->setAttachFilePath(serialize($files));
     $email_letter->setRecipients(implode(',', array_keys($emails)));
     $email_letter->save();
     $email_queue = new EmailQueue();
     $email_queue->setPersonId($this->getUser()->getId());
     $email_queue->setLetterId($email_letter->getId());
     $email_queue->setRequestDate(date('Y-m-d H:i:s', time()));
     $email_queue->setSendDate($send_date);
     $email_queue->setPriority($priority);
     $email_queue->setSendStatus('pending');
     $email_queue->save();
     /*
         $this->getComponent('mail', 'sendBulkQueue', array(
           'subject' => $subject,
           'recievers' => $emails,
           'sender' => array($sender_email => $sender_name),
           'body' => $message,
           'files' => $files,
         ));
     */
     $this->getUser()->setFlash('success', 'Bulk email have successfully queued!');
     $this->redirect($request->getReferer());
 }
Ejemplo n.º 2
0
 /**
  * Declares an association between this object and a EmailLetter object.
  *
  * @param      EmailLetter $v
  * @return     EmailTracking The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setEmailLetter(EmailLetter $v = null)
 {
     if ($v === null) {
         $this->setLetterId(NULL);
     } else {
         $this->setLetterId($v->getId());
     }
     $this->aEmailLetter = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the EmailLetter object, it will not be re-added.
     if ($v !== null) {
         $v->addEmailTracking($this);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      EmailLetter $value A EmailLetter object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(EmailLetter $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }