Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Event.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Reports\Model;
7 
29 {
30  const EVENT_PRODUCT_VIEW = 1;
31 
32  const EVENT_PRODUCT_SEND = 2;
33 
35 
37 
39 
41 
45  protected $_dateFactory;
46 
50  protected $_eventTypeFactory;
51 
61  public function __construct(
62  \Magento\Framework\Model\Context $context,
63  \Magento\Framework\Registry $registry,
64  \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory,
65  \Magento\Reports\Model\Event\TypeFactory $eventTypeFactory,
66  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
67  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
68  array $data = []
69  ) {
70  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
71  $this->_dateFactory = $dateFactory;
72  $this->_eventTypeFactory = $eventTypeFactory;
73  }
74 
80  protected function _construct()
81  {
82  $this->_init(\Magento\Reports\Model\ResourceModel\Event::class);
83  }
84 
90  public function beforeSave()
91  {
92  $date = $this->_dateFactory->create();
93  $this->setLoggedAt($date->gmtDate());
94  return parent::beforeSave();
95  }
96 
105  public function updateCustomerType($visitorId, $customerId, $types = null)
106  {
107  if ($types === null) {
108  $types = [];
109  $typesCollection = $this->_eventTypeFactory->create()->getCollection();
110  foreach ($typesCollection as $eventType) {
111  if ($eventType->getCustomerLogin()) {
112  $types[$eventType->getId()] = $eventType->getId();
113  }
114  }
115  }
116  $this->getResource()->updateCustomerType($this, $visitorId, $customerId, $types);
117  return $this;
118  }
119 
125  public function clean()
126  {
127  $this->getResource()->clean($this);
128  return $this;
129  }
130 }
$resource
Definition: bulk.php:12
updateCustomerType($visitorId, $customerId, $types=null)
Definition: Event.php:105
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory, \Magento\Reports\Model\Event\TypeFactory $eventTypeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Event.php:61