|
35 | 35 | <div class="card card-primary card-outline"> |
36 | 36 | <div class="card-header"> |
37 | 37 | <div class="card-title"> |
38 | | - <i class="fa fa-cogs mr-2"></i>'.tr('Servizi').' |
| 38 | + <i class="fa fa-cogs mr-2"></i>'.tr('Servizi OSMCloud').' |
39 | 39 | </div> |
40 | 40 | </div> |
41 | 41 |
|
42 | 42 | <div class="card-body p-0">'; |
43 | 43 |
|
| 44 | + // Recupero di tutti i servizi e risorse attivi |
44 | 45 | $servizi = Services::getServiziAttivi(true); |
45 | 46 |
|
46 | 47 | if (!$servizi->isEmpty()) { |
47 | | - echo ' |
48 | | - <table class="table table-hover table-striped table-sm mb-0"> |
49 | | - <thead> |
50 | | - <tr> |
51 | | - <th width="5%" class="text-center">'.tr('Stato').'</th> |
52 | | - <th width="40%">'.tr('Nome').'</th> |
53 | | - <th width="20%">'.tr('Tipo').'</th> |
54 | | - <th width="25%">'.tr('Scadenza').'</th> |
55 | | - <th width="10%" class="text-center">'.tr('#').'</th> |
56 | | - </tr> |
57 | | - </thead> |
58 | | -
|
59 | | - <tbody>'; |
60 | | - foreach ($servizi as $servizio) { |
61 | | - // Verifica che $servizio sia un array e contenga i campi necessari |
62 | | - if (!is_array($servizio) || !isset($servizio['expiration_at'])) { |
63 | | - continue; |
| 48 | + // Calcolo degli elementi in scadenza e scadut |
| 49 | + $servizi_in_scadenza = $servizi->filter(function ($item) use ($limite_scadenze) { |
| 50 | + if (!is_array($item) || !isset($item['expiration_at'])) { |
| 51 | + return false; |
64 | 52 | } |
65 | | - $scadenza = Carbon::parse($servizio['expiration_at']); |
66 | | - $status_class = $scadenza->lessThan(Carbon::now()) ? 'table-danger' : ($scadenza->lessThan($limite_scadenze) ? 'table-warning' : ''); |
67 | | - $status_icon = $scadenza->lessThan(Carbon::now()) ? '<i class="fa fa-times-circle text-danger" title="'.tr('Scaduto').'"></i>' : ($scadenza->lessThan($limite_scadenze) ? '<i class="fa fa-exclamation-triangle text-warning" title="'.tr('In scadenza').'"></i>' : '<i class="fa fa-check-circle text-success" title="'.tr('Attivo').'"></i>'); |
68 | | - |
69 | | - // Usa i campi corretti dalla risposta API |
70 | | - $codice = $servizio['code'] ?? $servizio['name'] ?? 'N/A'; |
71 | | - $nome = $servizio['name'] ?? 'N/A'; |
72 | | - $tipo = $servizio['type'] ?? $servizio['category'] ?? 'N/A'; |
73 | | - |
74 | | - echo ' |
75 | | - <tr class="'.$status_class.'"> |
76 | | - <td class="text-center">'.$status_icon.'</td> |
77 | | - <td><strong>'.$codice.'</strong><br><small class="text-muted">'.$nome.'</small></td> |
78 | | - <td><span class="badge badge-secondary">'.$tipo.'</span></td> |
79 | | - <td>'.dateFormat($scadenza).' <br><small class="text-muted">'.$scadenza->diffForHumans().'</small></td> |
80 | | - <td class="text-center"> |
81 | | - <input type="checkbox" class="check_rinnova '.($scadenza->lessThan($limite_scadenze) ? '' : 'hide').'" name="rinnova[]" value="'.$codice.'"> |
82 | | - </td> |
83 | | - </tr>'; |
84 | | - } |
85 | | - |
86 | | - $servizi_in_scadenza = Services::getServiziInScadenza($limite_scadenze); |
87 | | - $servizi_scaduti = Services::getServiziScaduti(); |
88 | | - |
89 | | - echo ' </tbody> |
90 | | - <tfoot> |
91 | | - <tr class="table-light"> |
92 | | - <td colspan="3"><strong>'.tr('Totale servizi: _NUM_', ['_NUM_' => $servizi->count()]).'</strong></td> |
93 | | - <td colspan="2" class="text-right">'; |
94 | | - |
95 | | - if (!$servizi_in_scadenza->isEmpty() || !$servizi_scaduti->isEmpty()) { |
96 | | - echo '<a href="https://marketplace.devcode.it/" target="_blank" id="btn_rinnova" class="btn btn-sm btn-primary"><i class="fa fa-shopping-cart mr-1"></i>'.tr('Rinnova').'</a>'; |
97 | | - } |
| 53 | + $scadenza = Carbon::parse($item['expiration_at']); |
| 54 | + $credits_warning = isset($item['credits']) && $item['credits'] < 100 && $item['credits'] !== null; |
| 55 | + $is_expiring = $scadenza->greaterThan(Carbon::now()) && $scadenza->lessThan($limite_scadenze); |
98 | 56 |
|
99 | | - echo ' </td> |
100 | | - </tr> |
101 | | - </tfoot>'; |
102 | | - |
103 | | - echo ' |
104 | | - </table>'; |
105 | | - } else { |
106 | | - echo ' |
107 | | - <div class="alert alert-info m-3"> |
108 | | - <i class="fa fa-info-circle mr-2"></i>'.tr('Nessun servizio abilitato al momento').'. |
109 | | - </div>'; |
110 | | - } |
111 | | - |
112 | | - echo ' |
113 | | - </div> |
114 | | - </div> |
115 | | - </div> |
116 | | -
|
117 | | - <!-- Informazioni sulle Risorse API --> |
118 | | - <div class="col-12 mb-3"> |
119 | | - <div class="card card-success card-outline"> |
120 | | - <div class="card-header"> |
121 | | - <div class="card-title"> |
122 | | - <i class="fa fa-cubes mr-2"></i>'.tr('Risorse').' |
123 | | - </div> |
124 | | - </div> |
| 57 | + return $is_expiring || $credits_warning; |
| 58 | + }); |
125 | 59 |
|
126 | | - <div class="card-body p-0">'; |
| 60 | + $servizi_scaduti = $servizi->filter(function ($item) { |
| 61 | + if (!is_array($item) || !isset($item['expiration_at'])) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + $scadenza = Carbon::parse($item['expiration_at']); |
| 65 | + $credits_expired = isset($item['credits']) && $item['credits'] < 0; |
| 66 | + $is_expired = $scadenza->lessThan(Carbon::now()); |
127 | 67 |
|
128 | | - // Elaborazione delle risorse API in scadenza |
129 | | - $risorse_attive = Services::getRisorseAttive(true); |
130 | | - if (!$risorse_attive->isEmpty()) { |
131 | | - $risorse_in_scadenza = Services::getRisorseInScadenza($limite_scadenze); |
132 | | - $risorse_scadute = Services::getRisorseScadute(); |
| 68 | + return $is_expired || $credits_expired; |
| 69 | + }); |
133 | 70 |
|
134 | | - if (!$risorse_in_scadenza->isEmpty() || !$risorse_scadute->isEmpty()) { |
135 | | - if (!$risorse_scadute->isEmpty()) { |
136 | | - echo ' |
| 71 | + // Messaggi di avviso |
| 72 | + if (!$servizi_scaduti->isEmpty()) { |
| 73 | + echo ' |
137 | 74 | <div class="alert alert-danger m-3 mb-0"> |
138 | | - <i class="fa fa-exclamation-triangle mr-2"></i>'.tr('Attenzione, alcune risorse sono scadute o hanno esaurito i crediti:', [ |
139 | | - '_NUM_' => $risorse_scadute->count(), |
140 | | - ]).' |
| 75 | + <i class="fa fa-exclamation-triangle mr-2"></i>'.tr('Attenzione, alcuni elementi sono scaduti o hanno esaurito i crediti: _NUM_', [ |
| 76 | + '_NUM_' => $servizi_scaduti->count(), |
| 77 | + ]).' |
141 | 78 | </div>'; |
142 | | - } |
| 79 | + } |
143 | 80 |
|
144 | | - if (!$risorse_in_scadenza->isEmpty()) { |
145 | | - echo ' |
| 81 | + if (!$servizi_in_scadenza->isEmpty()) { |
| 82 | + echo ' |
146 | 83 | <div class="alert alert-warning m-3 mb-0"> |
147 | | - <i class="fa fa-clock-o mr-2"></i>'.tr('Attenzione, alcune risorse sono in scadenza o stanno per esaurire i crediti:', [ |
148 | | - '_NUM_' => $risorse_in_scadenza->count(), |
149 | | - ]).' |
| 84 | + <i class="fa fa-clock-o mr-2"></i>'.tr('Attenzione, alcuni elementi sono in scadenza o stanno per esaurire i crediti: _NUM_', [ |
| 85 | + '_NUM_' => $servizi_in_scadenza->count(), |
| 86 | + ]).' |
150 | 87 | </div>'; |
151 | | - } |
152 | 88 | } |
153 | 89 |
|
154 | 90 | echo ' |
155 | 91 | <table class="table table-hover table-striped table-sm mb-0"> |
156 | 92 | <thead> |
157 | 93 | <tr> |
158 | 94 | <th width="5%" class="text-center">'.tr('Stato').'</th> |
159 | | - <th width="40%">'.tr('Nome').'</th> |
160 | | - <th width="20%">'.tr('Crediti').'</th> |
161 | | - <th width="35%">'.tr('Scadenza').'</th> |
| 95 | + <th width="35%">'.tr('Nome').'</th> |
| 96 | + <th width="15%">'.tr('Tipo').'</th> |
| 97 | + <th width="15%">'.tr('Crediti').'</th> |
| 98 | + <th width="20%">'.tr('Scadenza').'</th> |
| 99 | + <th width="10%" class="text-center">'.tr('#').'</th> |
162 | 100 | </tr> |
163 | 101 | </thead> |
164 | 102 |
|
165 | 103 | <tbody>'; |
166 | | - |
167 | | - foreach ($risorse_attive as $servizio) { |
168 | | - // Verifica che $servizio sia un array e contenga i campi necessari |
169 | | - if (!is_array($servizio) || !isset($servizio['expiration_at'])) { |
| 104 | + foreach ($servizi as $elemento) { |
| 105 | + // Verifica che $elemento sia un array e contenga i campi necessari |
| 106 | + if (!is_array($elemento) || !isset($elemento['expiration_at'])) { |
170 | 107 | continue; |
171 | 108 | } |
172 | | - $scadenza = Carbon::parse($servizio['expiration_at']); |
173 | | - $credits_warning = $servizio['credits'] < 100 && $servizio['credits'] !== null; |
| 109 | + |
| 110 | + $scadenza = Carbon::parse($elemento['expiration_at']); |
| 111 | + $has_credits = isset($elemento['credits']); |
| 112 | + $credits_warning = $has_credits && $elemento['credits'] < 100 && $elemento['credits'] !== null; |
| 113 | + $credits_expired = $has_credits && $elemento['credits'] < 0; |
174 | 114 | $is_expired = $scadenza->lessThan(Carbon::now()); |
175 | | - $is_expiring = $scadenza->lessThan($limite_scadenze); |
| 115 | + $is_expiring = $scadenza->greaterThan(Carbon::now()) && $scadenza->lessThan($limite_scadenze); |
| 116 | + |
| 117 | + // Determinazione dello stato |
| 118 | + $status_class = ($is_expired || $credits_expired) ? 'table-danger' : (($is_expiring || $credits_warning) ? 'table-warning' : ''); |
| 119 | + $status_icon = ($is_expired || $credits_expired) ? '<i class="fa fa-times-circle text-danger" title="'.tr('Scaduto/Esaurito').'"></i>' : |
| 120 | + (($is_expiring || $credits_warning) ? '<i class="fa fa-exclamation-triangle text-warning" title="'.tr('Attenzione').'"></i>' : |
| 121 | + '<i class="fa fa-check-circle text-success" title="'.tr('Attivo').'"></i>'); |
| 122 | + |
| 123 | + // Campi dell'elemento |
| 124 | + $codice = $elemento['code'] ?? $elemento['name'] ?? 'N/A'; |
| 125 | + $nome = $elemento['name'] ?? 'N/A'; |
| 126 | + $tipo = $elemento['type'] ?? $elemento['category'] ?? 'N/A'; |
176 | 127 |
|
177 | | - $status_class = $is_expired ? 'table-danger' : ($is_expiring || $credits_warning ? 'table-warning' : ''); |
178 | | - $status_icon = $is_expired ? '<i class="fa fa-times-circle text-danger" title="'.tr('Scaduto').'"></i>' : ($is_expiring || $credits_warning ? '<i class="fa fa-exclamation-triangle text-warning" title="'.tr('Attenzione').'"></i>' : '<i class="fa fa-check-circle text-success" title="'.tr('Attivo').'"></i>'); |
| 128 | + // Gestione crediti: mostra solo se presenti, altrimenti "-" |
| 129 | + $crediti_display = $has_credits ? |
| 130 | + ($credits_warning || $credits_expired ? '<i class="fa fa-exclamation-triangle text-warning mr-1"></i>' : '').($elemento['credits'] ?? '-') : |
| 131 | + '<span class="text-muted">-</span>'; |
179 | 132 |
|
180 | 133 | echo ' |
181 | 134 | <tr class="'.$status_class.'"> |
182 | 135 | <td class="text-center">'.$status_icon.'</td> |
183 | | - <td><strong>'.$servizio['name'].'</strong></td> |
184 | | - <td>'.($credits_warning ? '<i class="fa fa-exclamation-triangle text-warning mr-1"></i>' : '').($servizio['credits'] ?? '-').'</td> |
| 136 | + <td><strong>'.$codice.'</strong><br><small class="text-muted">'.$nome.'</small></td> |
| 137 | + <td><span class="badge badge-secondary">'.$tipo.'</span></td> |
| 138 | + <td>'.$crediti_display.'</td> |
185 | 139 | <td>'.dateFormat($scadenza).' <br><small class="text-muted">'.$scadenza->diffForHumans().'</small></td> |
| 140 | + <td class="text-center"> |
| 141 | + <input type="checkbox" class="check_rinnova '.($is_expiring || $is_expired || $credits_warning || $credits_expired ? '' : 'hide').'" name="rinnova[]" value="'.$codice.'"> |
| 142 | + </td> |
186 | 143 | </tr>'; |
187 | 144 | } |
188 | 145 |
|
| 146 | + // Conteggio servizi e risorse |
| 147 | + $count_servizi = $servizi->filter(fn($item) => !isset($item['credits']))->count(); |
| 148 | + |
189 | 149 | echo ' |
190 | 150 | </tbody> |
191 | 151 | <tfoot> |
192 | 152 | <tr class="table-light"> |
193 | | - <td colspan="4"><strong>'.tr('Totale risorse: _NUM_', ['_NUM_' => $risorse_attive->count()]).'</strong></td> |
| 153 | + <td colspan="4"> |
| 154 | + <strong>'.tr('Totale elementi: _NUM_', ['_NUM_' => $servizi->count()]).'</strong> |
| 155 | + </td> |
| 156 | + <td colspan="2" class="text-right">'; |
| 157 | + |
| 158 | + if (!$servizi_in_scadenza->isEmpty() || !$servizi_scaduti->isEmpty()) { |
| 159 | + echo '<a href="https://marketplace.devcode.it/" target="_blank" id="btn_rinnova" class="btn btn-sm btn-primary"><i class="fa fa-shopping-cart mr-1"></i>'.tr('Rinnova').'</a>'; |
| 160 | + } |
| 161 | + |
| 162 | + echo ' </td> |
194 | 163 | </tr> |
195 | 164 | </tfoot> |
196 | 165 | </table>'; |
197 | 166 |
|
198 | 167 | } else { |
199 | 168 | echo ' |
200 | 169 | <div class="alert alert-info m-3"> |
201 | | - <i class="fa fa-info-circle mr-2"></i>'.tr('Nessuna risorsa Services abilitata').'. |
| 170 | + <i class="fa fa-info-circle mr-2"></i>'.tr('Nessun servizio OSMCloud abilitato al momento').'. |
202 | 171 | </div>'; |
203 | 172 | } |
204 | 173 |
|
205 | 174 | echo ' |
206 | 175 | </div> |
207 | 176 | </div> |
208 | 177 | </div> |
| 178 | +
|
| 179 | +
|
209 | 180 | </div> |
210 | 181 | </div> |
211 | 182 |
|
|
0 commit comments