<?php
namespace Modules\Partners\Suppliers\ContactPersons; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedEntityListing { protected $listOrderingColumns = ['addTime']; protected $useSqlTransaction = true; protected function initialize() { parent::initialize(); $this->actionsCfg['insert'] = ['checkSection' => false, 'checkOption' => false, ]; $this->actionsCfg['update'] = ['checkSection' => false, 'checkOption' => false, ]; $this->actionsCfg['delete'] = ['checkSection' => false, 'checkOption' => false, ]; } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { switch($option->getId()){ case 'insert': if (!$option->determineOperationAvailability(\Entity\ContactPerson::insert())) { $option->setDisabled(); } break; case 'update': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\ContactPerson::update($selectedItem))) { break; } } break; case 'delete': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\ContactPerson::delete($selectedItem))){ break; } } break; default: return false; } return true; } protected function optionGetEntityName($id) { return \Entity\ContactPerson::select($id)->name; } protected function insert_getDefaultFormData($R) { $formData = []; if ($R['supplier']) { $formData['idCompany'] = $R['supplier']; } return $formData; } protected function insert_createEntityObject($formData) { $person = \Entity\ContactPerson::insert(); $person->type = 'supplier'; $person->idCompany = $formData['idCompany']['id']; $person->title = (string)$formData['title']; $person->firstName = $formData['firstName']; $person->lastName = $formData['lastName']; $person->job = $formData['job']; $person->role = $formData['role']; $person->department = $formData['department']; $person->birthday = $formData['birthday'] ? $formData['birthday'] : null; $person->email = $formData['email']; $person->telephone = $formData['telephone']; $person->telephoneMobile= $formData['telephoneMobile']; $person->fax = $formData['fax']; $person->comments = $formData['comments']; $person->remarks = $formData['remarks']; return $person; } protected function update_getDefaultFormData($idEntity) { $person = \Entity\ContactPerson::select($idEntity); $formData = []; $formData['type'] = $person->type; $formData['idCompany'] = $person->idCompany; $formData['title'] = (String)$person->title; $formData['firstName'] = $person->firstName; $formData['lastName'] = $person->lastName; $formData['job'] = $person->job; $formData['role'] = $person->role; $formData['department'] = $person->department; $formData['birthday'] = $person->birthday; $formData['email'] = $person->email; $formData['telephone'] = $person->telephone; $formData['telephoneMobile']= $person->telephoneMobile; $formData['fax'] = $person->fax; $formData['comments'] = $person->comments; $formData['remarks'] = $person->remarks; return $formData; } protected function update_createEntityObject($formData) { $person = \Entity\ContactPerson::update($this->updateIdRecord); $person->title = $formData['title']; $person->firstName = $formData['firstName']; $person->lastName = $formData['lastName']; $person->job = $formData['job']; $person->role = $formData['role']; $person->department = $formData['department']; $person->birthday = $formData['birthday'] ? $formData['birthday'] : null; $person->email = $formData['email']; $person->telephone = $formData['telephone']; $person->telephoneMobile= $formData['telephoneMobile']; $person->fax = $formData['fax']; $person->comments = $formData['comments']; $person->remarks = $formData['remarks']; return $person; } protected function delete_createEntityObject($idRecord) { return \Entity\ContactPerson::delete($idRecord); } } 