<?php
namespace Modules\Admin\Config\ImportedDocuments\EntitiesMatch; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedListing { protected $useSqlTransaction=false; protected $listOrderingColumns= ['idEntityExtSys', 'id', 'lastUpdateTime',]; private function extractDataFromId($idEntity) { list($entityType, $idEntityExtSys, $idSystem, $idEntityTina) = explode('##', $idEntity); switch($entityType) { case 'user': case 'office': case 'customer': case 'corporate': case 'supplier': case 'city': case 'docType': case 'agencyBankAccount': $idEntityTina = [ 'id' => $idEntityTina, ]; break; } return [ 'entityType' => $entityType, 'idEntityExtSys' => $idEntityExtSys, 'idSystem' => $idSystem, 'idEntityTina' => $idEntityTina ]; } protected function insert_getDefaultFormData($R) { if ($R['entityType'] || $R['idSystem'] || $R['idEntityExtSys'] || $R['idEntityTina']) { return $R; } return []; } protected function update_getDefaultFormData($idEntity) { return $this->extractDataFromId($idEntity); } protected function insert_doInsert($formData, \App\MessagesCollector $msgs) { $this->insertIdRecord = true; $model = new Model(); return $model->insert($formData, $msgs); } protected function update_doUpdate($formData, \App\MessagesCollector $msgs) { $this->getListingSelection()->clear(); $model = new Model(); $msgs1 = \App\MessagesCollector::create(); $msgs2 = \App\MessagesCollector::create(); $model->delete($this->extractDataFromId($this->updateIdRecord), $msgs1); $return = $model->insert($formData, $msgs2); if ($return) { $msgs->appendMessages($msgs1); } else { if ($msgs1->hasErrorOrWarning()) $msgs->appendMessages($msgs1); if ($msgs2->hasErrorOrWarning()) $msgs->appendMessages($msgs2); } return $return; } protected function delete_doDelete(array $recordsIds, \App\MessagesCollector $msgs, array $R) { $model = new Model(); foreach ($recordsIds as $idEntity) { if ($model->delete($this->extractDataFromId($idEntity), $msgs)) { $this->getListingSelection()->delete([$idEntity]); } } } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); switch($option->getId()){ case 'insert': if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/Config/ImportedDocuments/EntitiesMatch-insert')) { $option->setDisabled()->addMessage('warning', $_LANG['noAccessToOption']); } break; case 'update': if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/Config/ImportedDocuments/EntitiesMatch-update')) { $option->setDisabled()->addMessage('warning', $_LANG['noAccessToOption']); } break; case 'delete': if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/Config/ImportedDocuments/EntitiesMatch-delete')) { $option->setDisabled()->addMessage('warning', $_LANG['noAccessToOption']); } break; default: return false; } return true; } protected function optionGetEntityName($id) { return ''; } } 