/
mikopbx
/
ModuleRHVoice
Обзор
Документация
Войти
/
mikopbx
/
ModuleRHVoice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
App/Controllers/ModuleRHVoiceController.php
102 строки
3 KB
Nikolay Beketov
Update for PHP 8.3 and Phalcon 5.8
01 окт 2024, 11:52
01 окт 2024, 11:52
020231f
Код
Авторство
О чём код?
<?php /** * Copyright © MIKO LLC - All Rights Reserved * Unauthorized copying of this file, via any medium is strictly prohibited * Proprietary and confidential * Written by Alexey Portnov, 11 2018 */ namespace Modules\ModuleRHVoice\App\Controllers; use MikoPBX\AdminCabinet\Controllers\BaseController; use MikoPBX\Modules\PbxExtensionUtils; use Modules\ModuleRHVoice\App\Forms\ModuleRHVoiceForm; use Modules\ModuleRHVoice\Models\ModuleRHVoice; class ModuleRHVoiceController extends BaseController { private $moduleUniqueID = 'ModuleRHVoice'; private $moduleDir; /** * Basic initial class */ public function initialize(): void { $this->moduleDir = PbxExtensionUtils::getModuleDir($this->moduleUniqueID); $this->view->logoImagePath = "{$this->url->get()}assets/img/cache/{$this->moduleUniqueID}/logo.png"; $this->view->submitMode = null; parent::initialize(); } /** * Index page controller */ public function indexAction(): void { $footerCollection = $this->assets->collection('footerJS'); $footerCollection->addJs('js/pbx/main/form.js', true); $footerCollection->addJs("js/cache/{$this->moduleUniqueID}/modulerh-voice-index.js", true); $headerCollectionCSS = $this->assets->collection('headerCSS'); $headerCollectionCSS->addCss("css/cache/{$this->moduleUniqueID}/modulerh-voice.css", true); $settings = ModuleRHVoice::findFirst(); if ($settings === null) { $settings = new ModuleRHVoice(); } $this->view->form = new ModuleRHVoiceForm($settings); $this->view->pick("{$this->moduleDir}/App/Views/index"); } /** * Save settings AJAX action */ public function saveAction() :void { if ( ! $this->request->isPost()) { return; } $data = $this->request->getPost(); $record = ModuleRHVoice::findFirst(); if ($record === null) { $record = new ModuleRHVoice(); } $this->db->begin(); foreach ($record as $key => $value) { switch ($key) { case 'id': break; case 'checkbox_field': case 'toggle_field': if (array_key_exists($key, $data)) { $record->$key = ($data[$key] === 'on') ? '1' : '0'; } else { $record->$key = '0'; } break; default: if (array_key_exists($key, $data)) { $record->$key = $data[$key]; } else { $record->$key = ''; } } } if ($record->save() === FALSE) { $errors = $record->getMessages(); $this->flash->error(implode('<br>', $errors)); $this->view->success = false; $this->db->rollback(); return; } $this->flash->success($this->translation->_('ms_SuccessfulSaved')); $this->view->success = true; $this->db->commit(); } }