|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione |
| 4 | + * Copyright (C) DevCode s.r.l. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +namespace HTMLBuilder\Manager; |
| 21 | + |
| 22 | +use Models\Module; |
| 23 | +use Modules\SMS\Sms; |
| 24 | + |
| 25 | +/** |
| 26 | + * Gestione SMS. |
| 27 | + * |
| 28 | + * @since 2.4.2 |
| 29 | + */ |
| 30 | +class SMSManager implements ManagerInterface |
| 31 | +{ |
| 32 | + /** |
| 33 | + * Gestione "log_sms". |
| 34 | + * Esempio: {( "name": "log_sms", "id_module": "2", "id_record": "1" )}. |
| 35 | + * |
| 36 | + * @param array $options |
| 37 | + * |
| 38 | + * @return string |
| 39 | + */ |
| 40 | + public function manage($options) |
| 41 | + { |
| 42 | + // Verifico se il modulo SMS è installato |
| 43 | + $sms_module = Module::where('name', 'Template SMS')->first(); |
| 44 | + if (!$sms_module || !$sms_module->id) { |
| 45 | + return ' '; |
| 46 | + } |
| 47 | + |
| 48 | + // Visualizzo il log delle operazioni di invio SMS |
| 49 | + $messages = Sms::whereRaw('id_template IN (SELECT id FROM sms_templates WHERE id_module = '.prepare($options['id_module']).')') |
| 50 | + ->where('id_record', $options['id_record']) |
| 51 | + ->orderBy('created_at', 'DESC') |
| 52 | + ->get(); |
| 53 | + |
| 54 | + if ($messages->isEmpty()) { |
| 55 | + return ' '; |
| 56 | + } |
| 57 | + |
| 58 | + // Codice HTML |
| 59 | + $result = ' |
| 60 | +<div class="card card-info collapsable collapsed-card"> |
| 61 | + <div class="card-header with-border"> |
| 62 | + <h3 class="card-title"><i class="fa fa-comment"></i> '.tr('SMS inviati: _NUM_', [ |
| 63 | + '_NUM_' => $messages->count(), |
| 64 | + ]).'</h3> |
| 65 | + <div class="card-tools pull-right"> |
| 66 | + <button type="button" class="btn btn-card-tool" data-card-widget="collapse"><i class="fa fa-plus"></i></button> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + <div class="card-body"> |
| 70 | + <ul>'; |
| 71 | + |
| 72 | + foreach ($messages as $message) { |
| 73 | + $sent = !empty($message['sent_at']) ? tr('inviato il _DATE_ alle _HOUR_', [ |
| 74 | + '_DATE_' => dateFormat($message['sent_at']), |
| 75 | + '_HOUR_' => timeFormat($message['sent_at']), |
| 76 | + ]) : tr('in coda di invio'); |
| 77 | + |
| 78 | + $descrizione = \Modules::link('Coda SMS', $message->id, tr('SMS "_TEMPLATE_" da _USER_', [ |
| 79 | + '_TEMPLATE_' => $message->template ? $message->template->name : tr('Template eliminato'), |
| 80 | + '_USER_' => $message->user ? $message->user->username : tr('Utente eliminato'), |
| 81 | + ])); |
| 82 | + |
| 83 | + $result .= ' |
| 84 | + <li>'.$descrizione.' ('.$sent.')</li>'; |
| 85 | + } |
| 86 | + |
| 87 | + $result .= ' |
| 88 | + </ul> |
| 89 | + </div> |
| 90 | +</div>'; |
| 91 | + |
| 92 | + return $result; |
| 93 | + } |
| 94 | +} |
0 commit comments