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_Newsletter
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: * Newsletter problem model
29: *
30: * @method Mage_Newsletter_Model_Resource_Problem _getResource()
31: * @method Mage_Newsletter_Model_Resource_Problem getResource()
32: * @method int getSubscriberId()
33: * @method Mage_Newsletter_Model_Problem setSubscriberId(int $value)
34: * @method int getQueueId()
35: * @method Mage_Newsletter_Model_Problem setQueueId(int $value)
36: * @method int getProblemErrorCode()
37: * @method Mage_Newsletter_Model_Problem setProblemErrorCode(int $value)
38: * @method string getProblemErrorText()
39: * @method Mage_Newsletter_Model_Problem setProblemErrorText(string $value)
40: *
41: * @category Mage
42: * @package Mage_Newsletter
43: * @author Magento Core Team <core@magentocommerce.com>
44: */
45: class Mage_Newsletter_Model_Problem extends Mage_Core_Model_Abstract
46: {
47: /**
48: * Current Subscriber
49: *
50: * @var Mage_Newsletter_Model_Subscriber
51: */
52: protected $_subscriber = null;
53:
54: /**
55: * Initialize Newsletter Problem Model
56: */
57: protected function _construct()
58: {
59: $this->_init('newsletter/problem');
60: }
61:
62: /**
63: * Add Subscriber Data
64: *
65: * @param Mage_Newsletter_Model_Subscriber $subscriber
66: * @return Mage_Newsletter_Model_Problem
67: */
68: public function addSubscriberData(Mage_Newsletter_Model_Subscriber $subscriber)
69: {
70: $this->setSubscriberId($subscriber->getId());
71: return $this;
72: }
73:
74: /**
75: * Add Queue Data
76: *
77: * @param Mage_Newsletter_Model_Queue $queue
78: * @return Mage_Newsletter_Model_Problem
79: */
80: public function addQueueData(Mage_Newsletter_Model_Queue $queue)
81: {
82: $this->setQueueId($queue->getId());
83: return $this;
84: }
85:
86: /**
87: * Add Error Data
88: *
89: * @param Exception $e
90: * @return Mage_Newsletter_Model_Problem
91: */
92: public function addErrorData(Exception $e)
93: {
94: $this->setProblemErrorCode($e->getCode());
95: $this->setProblemErrorText($e->getMessage());
96: return $this;
97: }
98:
99: /**
100: * Retrieve Subscriber
101: *
102: * @return Mage_Newsletter_Model_Subscriber
103: */
104: public function getSubscriber()
105: {
106: if(!$this->getSubscriberId()) {
107: return null;
108: }
109:
110: if(is_null($this->_subscriber)) {
111: $this->_subscriber = Mage::getModel('newsletter/subscriber')
112: ->load($this->getSubscriberId());
113: }
114:
115: return $this->_subscriber;
116: }
117:
118: /**
119: * Unsubscribe Subscriber
120: *
121: * @return Mage_Newsletter_Model_Problem
122: */
123: public function unsubscribe()
124: {
125: if($this->getSubscriber()) {
126: $this->getSubscriber()->setSubscriberStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED)
127: ->setIsStatusChanged(true)
128: ->save();
129: }
130: return $this;
131: }
132:
133: }
134: