Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Problem.php
Go to the documentation of this file.
1 <?php
7 
26 {
32  protected $_subscriber = null;
33 
40 
51  public function __construct(
52  \Magento\Framework\Model\Context $context,
53  \Magento\Framework\Registry $registry,
54  \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
55  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
56  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
57  array $data = []
58  ) {
59  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
60  $this->_subscriberFactory = $subscriberFactory;
61  }
62 
68  protected function _construct()
69  {
70  $this->_init(\Magento\Newsletter\Model\ResourceModel\Problem::class);
71  }
72 
79  public function addSubscriberData(\Magento\Newsletter\Model\Subscriber $subscriber)
80  {
81  $this->setSubscriberId($subscriber->getId());
82  return $this;
83  }
84 
91  public function addQueueData(\Magento\Newsletter\Model\Queue $queue)
92  {
93  $this->setQueueId($queue->getId());
94  return $this;
95  }
96 
103  public function addErrorData(\Exception $e)
104  {
105  $this->setProblemErrorCode($e->getCode());
106  $this->setProblemErrorText($e->getMessage());
107  return $this;
108  }
109 
115  public function getSubscriber()
116  {
117  if (!$this->getSubscriberId()) {
118  return null;
119  }
120 
121  if ($this->_subscriber === null) {
122  $this->_subscriber = $this->_subscriberFactory->create()->load($this->getSubscriberId());
123  }
124 
125  return $this->_subscriber;
126  }
127 
133  public function unsubscribe()
134  {
135  if ($this->getSubscriber()) {
136  $this->getSubscriber()->setSubscriberStatus(
137  \Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED
138  )->setIsStatusChanged(
139  true
140  )->save();
141  }
142  return $this;
143  }
144 }
$queue
Definition: queue.php:21
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Problem.php:51
$resource
Definition: bulk.php:12
$subscriber
Definition: subscribers.php:20
addSubscriberData(\Magento\Newsletter\Model\Subscriber $subscriber)
Definition: Problem.php:79
addQueueData(\Magento\Newsletter\Model\Queue $queue)
Definition: Problem.php:91