Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Rule.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  protected $_createdatFactory;
19 
23  protected $_updatedatFactory;
24 
36  public function __construct(
37  \Magento\Framework\Model\ResourceModel\Db\Context $context,
38  \Psr\Log\LoggerInterface $logger,
39  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
40  \Magento\Reports\Model\FlagFactory $reportsFlagFactory,
41  \Magento\Framework\Stdlib\DateTime\Timezone\Validator $timezoneValidator,
42  \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
43  \Magento\SalesRule\Model\ResourceModel\Report\Rule\CreatedatFactory $createdatFactory,
44  \Magento\SalesRule\Model\ResourceModel\Report\Rule\UpdatedatFactory $updatedatFactory,
45  $connectionName = null
46  ) {
47  parent::__construct(
48  $context,
49  $logger,
50  $localeDate,
51  $reportsFlagFactory,
52  $timezoneValidator,
53  $dateTime,
55  );
56  $this->_createdatFactory = $createdatFactory;
57  $this->_updatedatFactory = $updatedatFactory;
58  }
59 
65  protected function _construct()
66  {
67  $this->_setResource('salesrule');
68  }
69 
77  public function aggregate($from = null, $to = null)
78  {
79  $this->_createdatFactory->create()->aggregate($from, $to);
80  $this->_updatedatFactory->create()->aggregate($from, $to);
81  $this->_setFlagData(\Magento\Reports\Model\Flag::REPORT_COUPONS_FLAG_CODE);
82 
83  return $this;
84  }
85 
91  public function getUniqRulesNamesList()
92  {
93  $connection = $this->getConnection();
94  $tableName = $this->getTable('salesrule_coupon_aggregated');
95  $select = $connection->select()->from(
96  $tableName,
97  new \Zend_Db_Expr('DISTINCT rule_name')
98  )->where(
99  'rule_name IS NOT NULL'
100  )->where(
101  'rule_name <> ?',
102  ''
103  )->order(
104  'rule_name ASC'
105  );
106 
107  $rulesNames = $connection->fetchAll($select);
108 
109  $result = [];
110 
111  foreach ($rulesNames as $row) {
112  $result[] = $row['rule_name'];
113  }
114 
115  return $result;
116  }
117 }
$tableName
Definition: trigger.php:13
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Reports\Model\FlagFactory $reportsFlagFactory, \Magento\Framework\Stdlib\DateTime\Timezone\Validator $timezoneValidator, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, \Magento\SalesRule\Model\ResourceModel\Report\Rule\CreatedatFactory $createdatFactory, \Magento\SalesRule\Model\ResourceModel\Report\Rule\UpdatedatFactory $updatedatFactory, $connectionName=null)
Definition: Rule.php:36
$logger
$connection
Definition: bulk.php:13