<?php
namespace Modules\Admin\Config\Services\Basic; class Model extends \App\Mvc\Model_ListingAbstract { private function getServicesList() { $servicesCfg = \App\Config\Services_Basic::getAdmin(); $generalServicesList = []; $groupPosition = 1; foreach ($servicesCfg->getAll() as $categoryCode => $details) { $moveUpGroup = true; if ($groupPosition == 1) { $moveUpGroup = false; } if ($groupPosition == count($servicesCfg->getAll())) { $moveDownGroup = false; } else { $moveDownGroup = true; } $servicePosition = 1; if ($details['type'] == 'group') { $generalServicesList[] = [ 'id' => $categoryCode, 'groupCode' => $categoryCode, 'groupName' => $details['name'], 'serviceType' => '', 'serviceName' => '', 'groupPosition' => $groupPosition, 'canMoveUp' => $moveUpGroup, 'canMoveDown' => $moveDownGroup, 'type' => 'group', ]; if ($details['list']) { foreach ($details['list'] as $serviceType => $serviceDetails) { $moveUpService = true; if ($servicePosition == 1) { $moveUpService = false; } if ($servicePosition == count($details['list'])) { $moveDownService = false; } else { $moveDownService = true; } $generalServicesList[] = [ 'id' => $serviceType, 'groupCode' => $categoryCode, 'groupName' => $details['name'], 'serviceType' => $serviceType, 'serviceName' => $serviceDetails['name'], 'groupPosition' => $groupPosition, 'servicePosition' =>$servicePosition, 'canMoveUp' => $moveUpService, 'canMoveDown' => $moveDownService, 'type' => 'service', ]; $servicePosition++; } } } else{ $generalServicesList[] = [ 'id' => $categoryCode, 'groupCode' => '', 'groupName' => '', 'serviceType' => $categoryCode, 'serviceName' => $details['name'], 'groupPosition' => $groupPosition, 'servicePosition' =>$servicePosition, 'canMoveUp' => $moveUpService, 'canMoveDown' => $moveDownService, 'type' => 'service', ]; } $groupPosition++; } return $generalServicesList; } public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams) { $filters = $listingParams->getFilters(); $servicesList = []; $generalServicesList = $this->getServicesList(); if ($filters['service']) { foreach ($generalServicesList as $service) { if ($service['type'] == 'service' and stripos($service['serviceName'], $filters['service'])!==false) { $servicesList[] = $service; } } } else { $servicesList = $generalServicesList; } $this->totalRecordsCount = count($servicesList); $this->recordsList = $servicesList; } public function canMoveUp($code, \App\Config\Services_Basic $serviceCfg) { $generalServicesList = $this->getServicesList(); foreach ($generalServicesList as $details) { if ( $details['groupCode'] == $code || $details['serviceType'] == $code) { return $details['canMoveUp']; } } return false; } public function canMoveDown($code, \App\Config\Services_Basic $serviceCfg) { $generalServicesList = $this->getServicesList(); foreach ($generalServicesList as $details) { if ( $details['groupCode'] == $code || $details['serviceType'] == $code) { return $details['canMoveDown']; } } return false; } public function isGroup($code, \App\Config\Services_Basic $serviceCfg) { $generalServicesList = $this->getServicesList(); foreach ($generalServicesList as $details) { if ( $details['groupCode'] == $code){ return false; } if ( $details['serviceType'] == $code) { return true; } } return false; } }