00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Newsletter_QueueController extends Mage_Adminhtml_Controller_Action
00035 {
00036
00037
00038
00039 public function indexAction()
00040 {
00041 if ($this->getRequest()->getQuery('ajax')) {
00042 $this->_forward('grid');
00043 return;
00044 }
00045
00046 $this->loadLayout();
00047
00048 $this->_setActiveMenu('newsletter/queue');
00049
00050 $this->_addContent(
00051 $this->getLayout()->createBlock('adminhtml/newsletter_queue', 'queue')
00052 );
00053
00054 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Newsletter Queue'), Mage::helper('newsletter')->__('Newsletter Queue'));
00055
00056 $this->renderLayout();
00057 }
00058
00059
00060
00061
00062 public function gridAction()
00063 {
00064 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/newsletter_queue_grid')->toHtml());
00065 }
00066
00067 public function startAction()
00068 {
00069 $queue = Mage::getModel('newsletter/queue')
00070 ->load($this->getRequest()->getParam('id'));
00071 if ($queue->getId()) {
00072 if (!in_array($queue->getQueueStatus(),
00073 array(Mage_Newsletter_Model_Queue::STATUS_NEVER,
00074 Mage_Newsletter_Model_Queue::STATUS_PAUSE))) {
00075 $this->_redirect('*/*');
00076 return;
00077 }
00078
00079 $queue->setQueueStartAt(Mage::getSingleton('core/date')->gmtDate())
00080 ->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_SENDING)
00081 ->save();
00082 }
00083
00084 $this->_redirect('*/*');
00085 }
00086
00087 public function pauseAction()
00088 {
00089 $queue = Mage::getSingleton('newsletter/queue')
00090 ->load($this->getRequest()->getParam('id'));
00091
00092 if (!in_array($queue->getQueueStatus(),
00093 array(Mage_Newsletter_Model_Queue::STATUS_SENDING))) {
00094 $this->_redirect('*/*');
00095 return;
00096 }
00097
00098 $queue->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_PAUSE);
00099 $queue->save();
00100
00101 $this->_redirect('*/*');
00102 }
00103
00104 public function resumeAction()
00105 {
00106 $queue = Mage::getSingleton('newsletter/queue')
00107 ->load($this->getRequest()->getParam('id'));
00108
00109 if (!in_array($queue->getQueueStatus(),
00110 array(Mage_Newsletter_Model_Queue::STATUS_PAUSE))) {
00111 $this->_redirect('*/*');
00112 return;
00113 }
00114
00115 $queue->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_SENDING);
00116 $queue->save();
00117
00118 $this->_redirect('*/*');
00119 }
00120
00121 public function cancelAction()
00122 {
00123 $queue = Mage::getSingleton('newsletter/queue')
00124 ->load($this->getRequest()->getParam('id'));
00125
00126 if (!in_array($queue->getQueueStatus(),
00127 array(Mage_Newsletter_Model_Queue::STATUS_SENDING))) {
00128 $this->_redirect('*/*');
00129 return;
00130 }
00131
00132 $queue->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_CANCEL);
00133 $queue->save();
00134
00135 $this->_redirect('*/*');
00136 }
00137
00138 public function sendingAction()
00139 {
00140
00141 $countOfQueue = 3;
00142 $countOfSubscritions = 20;
00143
00144 $collection = Mage::getResourceModel('newsletter/queue_collection')
00145 ->setPageSize($countOfQueue)
00146 ->setCurPage(1)
00147 ->addOnlyForSendingFilter()
00148 ->load();
00149
00150 $collection->walk('sendPerSubscriber', array($countOfSubscritions));
00151 }
00152
00153
00154 public function editAction()
00155 {
00156 $queue = Mage::getSingleton('newsletter/queue')
00157 ->load($this->getRequest()->getParam('id'));
00158
00159 Mage::register('current_queue', $queue);
00160
00161 $this->loadLayout();
00162
00163 $this->_setActiveMenu('newsletter/queue');
00164
00165 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Newsletter Queue'), Mage::helper('newsletter')->__('Newsletter Queue'), $this->getUrl('*/newsletter_queue'));
00166 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Edit Queue'), Mage::helper('newsletter')->__('Edit Queue'));
00167
00168 $this->_addContent(
00169 $this->getLayout()->createBlock('adminhtml/newsletter_queue_edit', 'queue.edit')
00170 );
00171
00172 $this->renderLayout();
00173 }
00174
00175 public function saveAction()
00176 {
00177 $queue = Mage::getSingleton('newsletter/queue')
00178 ->load($this->getRequest()->getParam('id'));
00179
00180 if (!in_array($queue->getQueueStatus(),
00181 array(Mage_Newsletter_Model_Queue::STATUS_NEVER,
00182 Mage_Newsletter_Model_Queue::STATUS_PAUSE))) {
00183 $this->_redirect('*/*');
00184 return;
00185 }
00186
00187 $format = Mage::app()->getLocale()->getDateTimeFormat(
00188 Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM
00189 );
00190
00191 if ($queue->getQueueStatus()==Mage_Newsletter_Model_Queue::STATUS_NEVER) {
00192 if ($this->getRequest()->getParam('start_at')) {
00193 $date = Mage::app()->getLocale()->date($this->getRequest()->getParam('start_at'), $format);
00194 $time = $date->getTimestamp();
00195 $queue->setQueueStartAt(
00196 Mage::getModel('core/date')->gmtDate(null, $time)
00197 );
00198 } else {
00199 $queue->setQueueStartAt(null);
00200 }
00201 }
00202
00203 $queue->setStores($this->getRequest()->getParam('stores', array()));
00204
00205 $queue->addTemplateData($queue);
00206 $queue->getTemplate()
00207 ->setTemplateSubject($this->getRequest()->getParam('subject'))
00208 ->setTemplateSenderName($this->getRequest()->getParam('sender_name'))
00209 ->setTemplateSenderEmail($this->getRequest()->getParam('sender_email'))
00210 ->setTemplateTextPreprocessed($this->getRequest()->getParam('text'));
00211
00212 if ($queue->getQueueStatus() == Mage_Newsletter_Model_Queue::STATUS_PAUSE
00213 && $this->getRequest()->getParam('_resume', false)) {
00214 $queue->setQueueStatus(Mage_Newsletter_Model_Queue::STATUS_SENDING);
00215 }
00216
00217 $queue->setSaveTemplateFlag(true);
00218
00219 try {
00220 $queue->save();
00221 }
00222 catch (Exception $e) {
00223 echo $e->getMessage();
00224 exit;
00225 }
00226 $this->_redirect('*/*');
00227 }
00228
00229 protected function _isAllowed()
00230 {
00231 return Mage::getSingleton('admin/session')->isAllowed('newsletter/queue');
00232 }
00233 }