/**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new NewsletterSubscribersManager($config, $args);
     }
     return self::$instance;
 }
 public function service()
 {
     $newsletterSubscribersManager = NewsletterSubscribersManager::getInstance($this->config, $this->args);
     $email = $this->secure($_REQUEST['email']);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $this->error(array('message' => $this->getPhraseSpan(471)));
     }
     $dtos = $newsletterSubscribersManager->selectByField('email', $email);
     if (!empty($dtos)) {
         $this->error(array('message' => $this->getPhraseSpan(359)));
     }
     $newsletterSubscribersManager->addSubscriber($email);
     $this->ok(array('message' => $this->getPhraseSpan(606)));
 }
 public function service()
 {
     $mandrillEmailSenderManager = new MandrillEmailSenderManager($this->getCmsVar("mandrill_api_key_news"));
     $email_body_html = $_REQUEST['email_body_html'];
     if (empty($email_body_html)) {
         $this->error(array('errText' => 'email body is empty!'));
     }
     $fromEmail = $this->getCmsVar('pcstore_news_email');
     $fromName = 'Pcstore.am Newsletter!';
     $includeUsers = $_REQUEST['include_all_active_users'];
     $subject = 'Newsletter from PcStore.am!!!';
     $test = $_REQUEST['test'];
     if ($test == 1) {
         $testEmail = $_REQUEST['test_email'];
         $res = $mandrillEmailSenderManager->sendHtmlEmail($testEmail, $subject, $email_body_html, $fromEmail, $fromName);
         $this->ok(array('count' => 1));
     }
     $uninterestingEmailsManager = UninterestingEmailsManager::getInstance($this->config, $this->args);
     $newsletterSubscribersManager = NewsletterSubscribersManager::getInstance($this->config, $this->args);
     $emailsArray = $newsletterSubscribersManager->getAllSubscribers();
     $filteredEmailsArray = $uninterestingEmailsManager->removeUninterestingEmailsFromList($emailsArray);
     if ($includeUsers == 1) {
         $userManager = UserManager::getInstance($this->config, $this->args);
         $allUsers = $userManager->selectAll();
         foreach ($allUsers as $userDto) {
             if ($userDto->getAvtive() == 0) {
                 continue;
             }
             $userRealEmailAddress = strtolower($userManager->getRealEmailAddressByUserDto($userDto));
             if (filter_var($userRealEmailAddress, FILTER_VALIDATE_EMAIL)) {
                 $filteredEmailsArray[] = $userRealEmailAddress;
             }
         }
     }
     //for FB, Google and TWITTER users emails may be duplicated!!!! so used array_unique
     $recipients = array_unique($filteredEmailsArray);
     if (count($recipients) === 0) {
         $this->error(array('errText' => 'There is no any recipient!'));
     }
     $email_body_html .= '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>';
     $email_body_html .= '<p style="font-size:10px"><a href="*|UNSUB:http://pcstore.am/unsubscriber|*">Click here to unsubscribe.</a></p>';
     $res = $mandrillEmailSenderManager->sendHtmlEmail($recipients, $subject, $email_body_html, $fromEmail, $fromName);
     $this->ok(array('count' => count($recipients)));
 }
 public function service()
 {
     unset($_SESSION['nl_error_message']);
     unset($_SESSION['nl_success_message']);
     $newsletterSubscribersManager = NewsletterSubscribersManager::getInstance($this->config, $this->args);
     $email = $this->secure($_REQUEST['email']);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $_SESSION['nl_error_message'] = 'Invalid email address!';
         $this->redirect('unsubscribe');
         exit;
     }
     $dtos = $newsletterSubscribersManager->selectByField('email', $email);
     if (empty($dtos)) {
         $_SESSION['nl_error_message'] = $email . ' is not registerd in our newsletter recipient list!';
         $this->redirect('unsubscribe');
         exit;
     }
     $newsletterSubscribersManager->removeSubscriberEmail($email);
     $_SESSION['nl_success_message'] = "You have successfully unsubscribed from our list!";
     $this->redirect('unsubscribe');
 }