<?php
namespace Modules\Admin\QcRules; class Model extends \App\Mvc\Model_ListingAbstract { public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams) { $filters = $listingParams->getFilters(); $listObj = new \App\EntityList\QcRules(); $listObj->setColumns(['active', 'entity', 'name', 'object', 'idAddUser', 'lastUpdateTime', 'idUpdateUser', 'updatesCount', 'addTime']); if ($filters['entity']) { $listObj->setFilter('entity', '=', $filters['entity']); } if ($filters['status'] == 'active') { $listObj->setFilter('active', '=', '1'); } elseif ($filters['status'] == 'inactive') { $listObj->setFilter('active', '=', '0'); } if ($filters['nameOfRule']) { $listObj->setFilter('name', 'LIKE', "%".$filters['nameOfRule']."%"); } if ($filters['id']) { $listObj->setFilter('id', '=', $filters['id']); } $cacheFiltersList = $cacheFiltersVals = []; if ($filters['corporate']['id']) { $cacheFiltersList[] = "(qcRulesCache.field IN (?, ?) AND qcRulesCache.value=?)"; $cacheFiltersVals[] = 'Corporate'; $cacheFiltersVals[] = 'OrderOwnerCorporate'; $cacheFiltersVals[] = $filters['corporate']['id']; } if ($filters['trust']['id']) { $cacheFiltersList[] = "(qcRulesCache.field=? AND qcRulesCache.value=?)"; $cacheFiltersVals[] = 'CorporateTrust'; $cacheFiltersVals[] = $filters['trust']['id']; } if ($filters['segment']) { $cacheFiltersList[] = "(qcRulesCache.field IN (?, ?) AND qcRulesCache.value=?)"; $cacheFiltersVals[] = 'CorporateSegment'; $cacheFiltersVals[] = 'OrderOwnerCorporateSegment'; $cacheFiltersVals[] = $filters['segment']; } if ($cacheFiltersList) { $listObj->setCustomFilter(implode(' OR ', $cacheFiltersList), $cacheFiltersVals); $listObj->setColumn('qcRulesCache.idRule'); $listObj->setCustomHaving('COUNT(*) = ?', [count($cacheFiltersList)]); $listObj->setGroupBy('qcRules.id'); } $listObj = $this->entityList_inheritListingParams($listingParams, $listObj); $results = $listObj->exportRecords(); $recordCount = $listObj->getRecordsCount(); $resultArr = []; foreach($results as $result){ $restriction = []; $filter = []; $object = \Entity\QcRule::Select($result['id'])->object; foreach ($object->getFilters() as $value) { $filter[] = $value->createDescription(); } foreach ($object->getRestrictions() as $value) { $restriction[] = $value->createDescription(); } $resultArr[] = [ 'id' => $result['id'], 'entity' => $result['entity'], 'name' => $result['name'], 'filters' => $filter, 'restrictions' => $restriction, 'active' => $result['active'], 'addTime' => $result['addTime'], 'idAddUser' => $result['idAddUser'], ]; } $this->recordsList = $resultArr; $this->totalRecordsCount = $recordCount; } }