<?php
 namespace Modules\Admin\Stations; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedEntityListing { protected $useSqlTransaction = true; protected $listOrderingColumns = ['code', 'name', 'idAddUser', 'addTime']; protected function insert_createEntityObject($formData) { $location = explode('|', $formData['locationName']['id']); $entityObj = \Entity\Station::insert(); $entityObj->code = $formData['code']; $entityObj->type = $formData['type']; if ($formData['codeLocal']) { $entityObj->codeLocal = $formData['codeLocal']; } $entityObj->name = $formData['name']; if ($formData['nameLocal']) { $entityObj->nameLocal = $formData['nameLocal']; } if ($location[1]) { $entityObj->cityId = $location[1]; } else { $entityObj->cityId = 0; } if ($location[0]) { $entityObj->countryCode = $location[0]; } else { $entityObj->countryCode = ''; } $entityObj->timezone = $formData['timezone']; return $entityObj; } protected function update_getDefaultFormData($idEntity) { $station = \Entity\Station::select($idEntity); if (!$station->recordExists()) { return null; } $formData = []; $formData['code'] = $station->code; $formData['type'] = $station->type; $formData['codeLocal'] = $station->codeLocal; $formData['name'] = $station->name; $formData['nameLocal'] = $station->nameLocal; $formData['locationName'] = ['id' => $station->countryCode.'|'.$station->cityId]; $formData['timezone'] = $station->timezone; return $formData; } protected function update_createEntityObject($formData) { $location = explode('|', $formData['locationName']['id']); $entityObj = \Entity\Station::update($this->updateIdRecord); $entityObj->codeLocal = $formData['codeLocal']; $entityObj->name = $formData['name']; $entityObj->nameLocal = $formData['nameLocal']; if ($location[1]) { $entityObj->cityId = $location[1]; } else { $entityObj->cityId = 0; } if ($location[0]) { $entityObj->countryCode = $location[0]; } else { $entityObj->countryCode = ''; } $entityObj->timezone = $formData['timezone']; return $entityObj; } protected function delete_createEntityObject($idRecord) { return \Entity\Station::delete($idRecord); } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { switch($option->getId()){ case 'insert': if (!$option->determineOperationAvailability(\Entity\Station::insert())) { $option->setDisabled(); } break; case 'update': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\Station::update($selectedItem))) { break; } } break; case 'delete': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\Station::delete($selectedItem))) { break; } } break; default: return false; } return true; } protected function optionGetEntityName($id) { return \Entity\Station::select($id)->name; } } 