<?php
namespace ModulesAbstract\PluginReports\Report\Model\Gatherer; class OrderServices extends GathererAbstract { protected $orderServicesIterator = NULL; protected $lastReportedKey = NULL; public function getRequiredFilters() { return [ 'ticketDate', 'corporatesAndSegmentsAndGroups', ]; } protected function objectInitialize() { $listObj = new \App\EntityList\OrderServices(); $listObj->setColumns([ 'serv.id' => 'idOrderService', 'serv.passengersTicketsDate' => 'ticketDate', ]); $listObj->setFilter('serv.passengersTicketsDate', 'BETWEEN', [ $this->filters['ticketDate']['start'], $this->filters['ticketDate']['end'], ]); $listObj->setFilter('serv.cancelReason', '=', ''); $listObj->setFilter('serv.statusOp', '=', 'OK'); $listObj->setFilter('serv.statusFin', '=', 'TI'); if ($this->filters['userAndOffice']['type'] == 'user') { if ($this->filters['userAndOffice']['entityId']) { $listObj->setFilter('serv.idUser', '=', $this->filters['userAndOffice']['entityId']); } } elseif ($this->filters['userAndOffice']['type'] == 'office') { if ($this->filters['userAndOffice']['entityId']) { $listObj->setFilter('serv.idOffice', '=', $this->filters['userAndOffice']['entityId']); } } if (in_array($this->filters['corporatesAndSegmentsAndGroups']['type'], ['segment', 'groups']) && !$this->filters['corporatesAndSegmentsAndGroups']['corporateIds']) { $this->orderServicesIterator = new \ADORecordSet_empty(); return; } if (in_array($this->filters['corporatesAndSegmentsAndGroups']['type'], ['all', 'corporate', 'segment', 'groups'])) { if ($this->filters['corporatesAndSegmentsAndGroups']['corporateIds']) { $listObj->setFilter('res.idCorporateOwner', 'IN', $this->filters['corporatesAndSegmentsAndGroups']['corporateIds']); } else { $listObj->setFilter('res.idCorporateOwner', '!=', 0); } } else { throw new \Exception(sprintf("%s type is invalid", __METHOD__)); } $listObj->setOrderBy('ticketDate', 'ASC'); $listObj->setOrderBy('idOrderService', 'ASC'); $listObj->applyUserRestriction(false); $this->orderServicesIterator = $listObj->getExecution(); } protected function objectDestroy() { if ($this->orderServicesIterator) { $this->orderServicesIterator->Close(); $this->orderServicesIterator = NULL; } } protected function generateKey(Array $result) { return sprintf("%s/%s", $result['idOrderService'], $result['special']); } protected function objectNext() { if ($this->orderServicesIterator && !$this->orderServicesIterator->EOF) { $result = $this->orderServicesIterator->FetchRow(); $key = $this->generateKey($result); if ($key !== $this->lastReportedKey) { $this->lastReportedKey = $key; return $result; } else { return "intern:skip"; } } return NULL; } }