public function run($arg) { // $last_working = Yii::app()->setting->getItem('last_working'); // if(!empty($last_working)) // { // $timestampNext = strtotime(ActiveRecord::timeCalMinutes(-10)); // if(strtotime($last_working) > $timestampNext) // { //// Yii::log(strtotime($last_working), 'error', 'NewsletterCommand.run'); //// Yii::log($timestampNext, 'error', 'NewsletterCommand.run'); // echo 'waiting because last working is nearly'; // return; // } // } $member = Users::model()->findAll('role_id = ' . ROLE_MEMBER); if (count($member) > 0) { foreach ($member as $item) { $email = Subscriber::model()->find('email ="' . $item->email . '"'); if (count($email) == 0) { $subcribe = new Subscriber(); $subcribe->email = $item->email; $subcribe->name = $item->username; $subcribe->subscriber_group_id = GROUP_MEMBER; $subcribe->save(); } } } //Yii::app()->setting->setDbItem('last_working', date('Y-m-d h:i:s')); }
/** * @param bool $refresh * * @return Channel[] */ public function getChannels($refresh = false) { if ($this->_channels && !$refresh) { return $this->_channels; } return $this->_channels = $this->getDbDriver()->findByAttributes(array('subscriber_id' => $this->id), Subscriber::model()); }
public function actionSend($id) { $model = $this->loadModel($id); if (isset($_POST['Massmail'])) { $model->attributes = $_POST['Massmail']; if (empty($model->groups)) { $mailList = Subscriber::model()->findAll(array('condition' => 'confirmed=1 AND enabled=1')); } else { $mailList = Subscriber::model()->findAll(array('condition' => 'FIND_IN_SET(' . $model->groups . ', groups)>0 AND confirmed=1 AND enabled=1')); } $bccList = null; $total = array_filter($mailList); if (!empty($total)) { //get email lists foreach ($mailList as $values) { $bccList .= $values['email'] . ','; } //send mail $to = Yii::app()->params['adminEmail']; $subject = $model->subject; $message = $model->message_body; $fromName = Yii::app()->params['Companyname']; $fromMail = Yii::app()->params['adminEmail']; Massmail::sendMail($to, $subject, $message, $fromName, $fromMail, $bccList); Yii::app()->user->setFlash('success', 'Mail has been sent successfully!'); $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('error', 'No subscriber found in this group!'); $this->redirect(array('admin')); } } $this->render('send', array('model' => $model)); }
protected function doJob($arg) { $models = Newsletter::model()->findAll(array('condition' => 't.remain_subscribers IS NOT NULL AND length(t.remain_subscribers) > 0 AND t.send_time <= NOW()', 'order' => 't.id ASC')); foreach ($models as $model) { $mail_models = ProNewsletterMail::model()->findAll(array('condition' => 't.newsletter_id = ' . $model->id, 'order' => 't.id ASC')); if (count($mail_models)) { $receivers = explode(',', $model->remain_subscribers); $subscriber_count = 0; foreach ($mail_models as $key => $k) { $revei = array_shift($receivers); // need update this field $s = Subscriber::model()->getSubscriberByEmail($k->email); if (empty($s)) { continue; } if ($s) { if ($s->status == 0) { continue; } } // add by Nguyen Dung $url = Yii::app()->setting->getItem('server_name') . '/site/track_newsletter?newsletter_id=' . $model->id . '&subscriber_email=' . $s->email; $img_track_read_email = '<img src="' . $url . '" alt="" height="1" width="1"/>'; $r = array('subject' => $model->subject, 'params' => array('content' => $model->content . $img_track_read_email, 'newsletterName' => Yii::app()->params['title'], 'unsubscribe' => Yii::app()->setting->getItem('server_name') . '/site/unsubscribe?id=' . $s->id . '&code=' . md5($s->id . $s->email)), 'view' => 'newsletter', 'to' => $s->email, 'from' => Yii::app()->params['autoEmail']); $this->data[] = $r; //Delete record in newsletter mail ProNewsletterMail::model()->deleteByPk($k->id); $subscriber_count++; //count subscriber is served for current newsletter job $this->index++; //count email is sent for current cron job if ($this->index >= $this->max) { break; } } $model->total_sent = $model->total_sent + $subscriber_count; // track amount mail sent $model->remain_subscribers = implode(',', $receivers); $model->update(array('remain_subscribers', 'total_sent')); } } //when sent all subscriber of a newsletter job but the // if($this->index < $this->max) // $this->doJob($arg); }
public function buildListSubscriberAdd($mNewsletter) { $newsletter_id = $mNewsletter->id; $send_time = $mNewsletter->send_time; $criteria = new CDbCriteria(); $criteria->compare('t.status', 1); $listIdSubsciber = ''; $totalSubscriber = 0; // if not select group => we get all subscriber => don't exist if (!isset($_POST['Newsletter']['newsletter_group_subscriber']) || count($_POST['Newsletter']['newsletter_group_subscriber']) < 1) { $subscribers = Subscriber::model()->findAll($criteria); foreach ($subscribers as $s) { $listIdSubsciber .= $s->id . ','; } $totalSubscriber = count($subscribers); } else { // if select group => we get all subscriber of this group $criteria->addInCondition('t.subscriber_group_id', $_POST['Newsletter']['newsletter_group_subscriber']); $subscribers = Subscriber::model()->findAll($criteria); $aRowInsert = array(); $tableName = ProNewsletterMail::model()->tableName(); foreach ($subscribers as $s) { $listIdSubsciber .= $s->id . ','; $new_model = new ProNewsletterMail(); $new_model->name = $s->name; $new_model->email = $s->email; $new_model->subscriber_group_id = $s->subscriber_group_id; $new_model->newsletter_id = $newsletter_id; $new_model->send_time = $send_time; $aRowInsert[] = "('{$new_model->name}',\n '{$new_model->email}',\n '{$new_model->subscriber_group_id}',\n '{$new_model->newsletter_id}',\n '{$new_model->send_time}'\n )"; } $totalSubscriber = count($subscribers); if (count($aRowInsert)) { $sql = "insert into {$tableName} (name,\n email,\n subscriber_group_id,\n newsletter_id,\n send_time\n ) values " . implode(',', $aRowInsert); ProNewsletterMail::model()->deleteAll("newsletter_id={$mNewsletter->id}"); Yii::app()->db->createCommand($sql)->execute(); } } return array('listIdSubsciber' => $listIdSubsciber, 'totalSubscriber' => $totalSubscriber); }
public function actionSynchronize() { set_time_limit(7200); $idNameGroup = array(); $criteria = new CDbCriteria(); $mSubG = SubscriberGroup::model()->findAll($criteria); if (count($mSubG) > 0) { foreach ($mSubG as $i) { $idNameGroup[$i->id] = $i->name; } } $criteria = new CDbCriteria(); $criteria->addCondition('subscriber_group_id = 1 OR subscriber_group_id = 2'); $mSubscriber = Subscriber::model()->findAll($criteria); //var_dump($mSubscriber); $test = array(); if (count($mSubscriber) > 0) { Yii::import('ext.MailChimp.MailChimp', true); foreach ($mSubscriber as $item) { $mailChimp = new MailChimp(); // $mailChimp->removeSubscriber('*****@*****.**'); // die; $sGroupName = Yii::app()->params['mailchimp_title_groups']; $sGroup = strtolower($idNameGroup[$item->subscriber_group_id]); $merge_vars = array('GROUPINGS' => array(array('name' => $sGroupName, 'groups' => $sGroup))); if ($item->status == 1) { // echo '<pre>'; //echo print_r($merge_vars); //echo '</pre>'; //echo $item->email; //die(); $test[] = $mailChimp->addSubscriber($item->email, $merge_vars); } else { $mailChimp->removeSubscriber($item->email); } } } Yii::app()->user->setFlash('mailchimp', "Synchronize Mailling list successfully!"); $this->redirect(Yii::app()->createAbsoluteUrl("admin/setting/mailchimp")); }
$model->position = $_POST['ContactForm']['position']; $model->company = $_POST['ContactForm']['company']; $model->message = $_POST['ContactForm']['message']; $model->email = trim($model->email); if ($model->validate()) { $model->message = nl2br($model->message); $enquiry_type = $_POST['ContactForm']['enquiry_type']; $model->enquiry_type = ContactForm::$enqueryType[$enquiry_type]; $email_to = Yii::app()->params['adminEmail']; //save data $contactus = new ProContactUs(); $contactus->attributes = $_POST['ContactForm']; $contactus->save(); SendEmail::sendMailContact($model, $email_to);
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Subscriber::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public static function deleteSubscriber($email) { $subscriber = self::getSubscriberByEmail($email); if (!empty($subscriber)) { Subscriber::model()->deleteAll('email =' . $email); } }
public static function Synchronize() { set_time_limit(7200); $idNameGroup = array(); $criteria = new CDbCriteria(); // $criteria->compare('t.status',1); $mSubG = SubscriberGroup::model()->findAll($criteria); if (count($mSubG) > 0) { foreach ($mSubG as $i) { $idNameGroup[$i->id] = $i->name; } } $criteria = new CDbCriteria(); $mSubscriber = Subscriber::model()->findAll($criteria); $test = array(); if (count($mSubscriber) > 0) { Yii::import('ext.MailChimp.MailChimp', true); foreach ($mSubscriber as $item) { $mailChimp = new MailChimp(); // $mailChimp->removeSubscriber('*****@*****.**'); // die; $sGroupName = Yii::app()->params['mailchimp_title_groups']; $sGroup = strtolower($idNameGroup[$item->subscriber_group_id]); $merge_vars = array('GROUPINGS' => array(array('name' => $sGroupName, 'groups' => $sGroup))); if ($item->status == 1) { $test[] = $mailChimp->addSubscriber($item->email, $merge_vars); } else { $mailChimp->removeSubscriber($item->email); } } } }
public static function get_groups($id) { $model = Subscriber::model()->findByAttributes(array('id' => $id)); $exval = explode(',', $model->groups); $groups = ''; $total = count($exval); for ($i = 0; $i < $total; $i++) { if ($i == $total - 1) { $groups .= SubscriberGroup::get_title(trim($exval[$i])) . ' '; } else { $groups .= SubscriberGroup::get_title(trim($exval[$i])) . ', '; } } return $groups; }