1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Email Template Mailer Model
29: *
30: * @category Mage
31: * @package Mage_Core
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Core_Model_Email_Template_Mailer extends Varien_Object
35: {
36: /**
37: * List of email infos
38: * @see Mage_Core_Model_Email_Info
39: *
40: * @var array
41: */
42: protected $_emailInfos = array();
43:
44: /**
45: * Add new email info to corresponding list
46: *
47: * @param Mage_Core_Model_Email_Info $emailInfo
48: * @return Mage_Core_Model_Email_Template_Mailer
49: */
50: public function addEmailInfo(Mage_Core_Model_Email_Info $emailInfo)
51: {
52: array_push($this->_emailInfos, $emailInfo);
53: return $this;
54: }
55:
56: /**
57: * Send all emails from email list
58: * @see self::$_emailInfos
59: *
60: * @return Mage_Core_Model_Email_Template_Mailer
61: */
62: public function send()
63: {
64: $emailTemplate = Mage::getModel('core/email_template');
65: // Send all emails from corresponding list
66: while (!empty($this->_emailInfos)) {
67: $emailInfo = array_pop($this->_emailInfos);
68: // Handle "Bcc" recepients of the current email
69: $emailTemplate->addBcc($emailInfo->getBccEmails());
70: // Set required design parameters and delegate email sending to Mage_Core_Model_Email_Template
71: $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))
72: ->sendTransactional(
73: $this->getTemplateId(),
74: $this->getSender(),
75: $emailInfo->getToEmails(),
76: $emailInfo->getToNames(),
77: $this->getTemplateParams(),
78: $this->getStoreId()
79: );
80: }
81: return $this;
82: }
83:
84: /**
85: * Set email sender
86: *
87: * @param string|array $sender
88: * @return Mage_Core_Model_Email_Template_Mailer
89: */
90: public function setSender($sender)
91: {
92: return $this->setData('sender', $sender);
93: }
94:
95: /**
96: * Get email sender
97: *
98: * @return string|array|null
99: */
100: public function getSender()
101: {
102: return $this->_getData('sender');
103: }
104:
105: /**
106: * Set store id
107: *
108: * @param int $storeId
109: * @return Mage_Core_Model_Email_Template_Mailer
110: */
111: public function setStoreId($storeId)
112: {
113: return $this->setData('store_id', $storeId);
114: }
115:
116: /**
117: * Get store id
118: *
119: * @return int|null
120: */
121: public function getStoreId()
122: {
123: return $this->_getData('store_id');
124: }
125:
126: /**
127: * Set template id
128: *
129: * @param int $templateId
130: * @return Mage_Core_Model_Email_Template_Mailer
131: */
132: public function setTemplateId($templateId)
133: {
134: return $this->setData('template_id', $templateId);
135: }
136:
137: /**
138: * Get template id
139: *
140: * @return int|null
141: */
142: public function getTemplateId()
143: {
144: return $this->_getData('template_id');
145: }
146:
147: /**
148: * Set tempate parameters
149: *
150: * @param array $templateParams
151: * @return Mage_Core_Model_Email_Template_Mailer
152: */
153: public function setTemplateParams(array $templateParams)
154: {
155: return $this->setData('template_params', $templateParams);
156: }
157:
158: /**
159: * Get template parameters
160: *
161: * @return array|null
162: */
163: public function getTemplateParams()
164: {
165: return $this->_getData('template_params');
166: }
167: }
168: