/
mikopbx
/
ModuleCTIClientV5
Обзор
Документация
Войти
/
mikopbx
/
ModuleCTIClientV5
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
App/Controllers/ModuleCTIClientV5Controller.php
150 строк
5 KB
Nikolay Beketov
initial commit
12 май 2025, 17:33
12 май 2025, 17:33
dc398f0
Код
Авторство
О чём код?
<?php /* * MikoPBX - free phone system for small business * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. * If not, see <https://www.gnu.org/licenses/>. */ namespace Modules\ModuleCTIClientV5\App\Controllers; use MikoPBX\AdminCabinet\Controllers\BaseController; use MikoPBX\AdminCabinet\Providers\AssetProvider; use MikoPBX\Common\Models\Providers; use MikoPBX\Modules\PbxExtensionUtils; use Modules\ModuleCTIClientV5\App\Forms\ModuleCTIClientV5Form; use Modules\ModuleCTIClientV5\Models\ModuleCTIClientV5; class ModuleCTIClientV5Controller extends BaseController { private string $moduleUniqueID = 'ModuleCTIClientV5'; private string $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.svg'; $this->view->submitMode = null; parent::initialize(); } /** * Renders the index page for the module. * * @return void */ public function indexAction(): void { $headerCollectionCSS = $this->assets->collection(AssetProvider::HEADER_CSS); $headerCollectionCSS->addCss('css/cache/'.$this->moduleUniqueID.'/modulecticlient-v5-index.css', true); // Add JavaScript files to the footer collection $footerCollectionJS = $this->assets->collection(AssetProvider::FOOTER_JS); $footerCollectionJS->addJs('js/cache/'.$this->moduleUniqueID.'/modulecticlient-v5-index.js', true); $this->view->pick('Modules/'.$this->moduleUniqueID.'/ModuleCTIClientV5/index'); } /** * Renders the modify page for the module. * * @return void */ public function modifyAction(): void { // Add JavaScript files to the footer collection $footerCollectionJS = $this->assets->collection(AssetProvider::FOOTER_JS); $footerCollectionJS ->addJs('js/pbx/main/form.js', true) ->addJs('js/cache/'.$this->moduleUniqueID.'/modulecticlient-v5-modify.js', true); // Retrieve or create new module settings $settings = ModuleCTIClientV5::findFirst(); if ($settings === null) { $settings = new ModuleCTIClientV5(); } // Create options array for form $options = []; // Retrieve providers list for form $providers = Providers::find(); $providersList = []; foreach ($providers as $provider){ $providersList[ $provider->uniqid ] = $provider->getRepresent(); } $options['providers']=$providersList; $this->view->form = new ModuleCTIClientV5Form($settings, $options); $this->view->pick('Modules/'.$this->moduleUniqueID.'/ModuleCTIClientV5/modify'); } /** * Saves the form data to the database. * * @return void */ public function saveAction() :void { if (!$this->request->isPost()) { return; } $data = $this->request->getPost(); $record = ModuleCTIClientV5::findFirstById($data['id']); if ($record === null) { $record = new ModuleCTIClientV5(); } 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 = ''; } } } $this->saveEntity($record); } /** * Deletes a record from db. * * @param string $recordId * @return void */ public function deleteAction(string $recordId): void { $record = ModuleCTIClientV5::findFirstById($recordId); if ($record !== null) { $this->deleteEntity($record,'modulecticlient-v5/modulecticlient-v5/index'); } } }