<?php
namespace Modules\Partners\Customers\Profile; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function getDefaultFormData($R) { $entityCustomerProfile = \App\EntityPreference\Customer::getInstance($R['id']); $formData = []; $formData['id'] = $entityCustomerProfile->getId(); $formData['farePreference'] = $entityCustomerProfile->farePreference; $formData['seatPreference'] = $entityCustomerProfile->seatPreference; $formData['mealPreference'] = $entityCustomerProfile->mealPreference; $formData['carRental'] = $entityCustomerProfile->carRental; $formData['accommodationPreference'] = explodeClean('|', $entityCustomerProfile->accommodationPreference); $formData['supplierServicesText'] = $entityCustomerProfile->supplierServicesText; return $formData; } protected function processFormData(Array $R, \App\MessagesCollector $msgs) { try { $closePopup = false; \DB::startTransaction(); foreach (['farePreference','seatPreference','mealPreference','carRental','accommodationPreference'] as $profileKey) { if ($profileKey == "accommodationPreference") { if (is_array($R['profile'][$profileKey])) { $thisProfileValue = '|' . implode('|', $R['profile'][$profileKey]) . '|'; } else { $thisProfileValue = NULL; } } else { $thisProfileValue = $R['profile'][$profileKey]; } \App\EntityPreference\Customer::getInstance($R['id'])->{$profileKey} = $thisProfileValue ?: null; } \App\EntityPreference\Customer::getInstance($R['id'])->supplierServicesText = $R['supplierServicesText'] ?: null; $filesWithPath = []; $unlinkFiles = []; foreach ($_FILES as $fileCode => $fileDetails) { if (! $R[$fileCode . '_keepFile']) { if ($R['files'][$fileCode]) { $unlinkFiles[] = $R['files'][$fileCode]; } $uploadedFile = new \App\Form\UploadedFiles\File($fileCode); if ($uploadedFile->hasValidFile()) { $filesWithPath[$uploadedFile->getName()] = $uploadedFile->getTempName(); } } } $customer = \Entity\Customer::update($R['id']); $customer->unlinkFiles = $unlinkFiles; $customer->filesWithPath = $filesWithPath; $customer->save(); \DB::commitTransaction(); $msgs->addSuccess($this->lang['messages']['profileServices_saveSuccess']); $closePopup = true; } catch (\App\Entity\Exception $e) { \DB::rollbackTransaction(); $msgs->appendMessages($e->getMessagesCollector()); } return $closePopup; } }