Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 65 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| InternationalisationsController | |
0.00% |
0 / 65 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
20 | |||
| view | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| add | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| edit | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| delete | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace App\Controller\Admin; |
| 5 | |
| 6 | use App\Controller\AppController; |
| 7 | use Cake\Http\Response; |
| 8 | |
| 9 | /** |
| 10 | * Internationalisations Controller |
| 11 | * |
| 12 | * @property \App\Model\Table\InternationalisationsTable $Internationalisations |
| 13 | */ |
| 14 | class InternationalisationsController extends AppController |
| 15 | { |
| 16 | /** |
| 17 | * Index method |
| 18 | * |
| 19 | * @return \Cake\Http\Response|null|void Renders view |
| 20 | */ |
| 21 | public function index(): ?Response |
| 22 | { |
| 23 | $statusFilter = $this->request->getQuery('locale'); |
| 24 | |
| 25 | $query = $this->Internationalisations->find() |
| 26 | ->select([ |
| 27 | 'Internationalisations.id', |
| 28 | 'Internationalisations.locale', |
| 29 | 'Internationalisations.message_id', |
| 30 | 'Internationalisations.message_str', |
| 31 | 'Internationalisations.created', |
| 32 | 'Internationalisations.modified', |
| 33 | ]); |
| 34 | |
| 35 | if ($statusFilter !== null) { |
| 36 | $query->where(['Internationalisations.locale' => $statusFilter]); |
| 37 | } |
| 38 | |
| 39 | $search = $this->request->getQuery('search'); |
| 40 | if (!empty($search)) { |
| 41 | $query->where([ |
| 42 | 'OR' => [ |
| 43 | 'Internationalisations.locale LIKE' => '%' . $search . '%', |
| 44 | 'Internationalisations.message_id LIKE' => '%' . $search . '%', |
| 45 | 'Internationalisations.message_str LIKE' => '%' . $search . '%', |
| 46 | ], |
| 47 | ]); |
| 48 | } |
| 49 | $internationalisations = $this->paginate($query); |
| 50 | if ($this->request->is('ajax')) { |
| 51 | $this->set(compact('internationalisations', 'search')); |
| 52 | $this->viewBuilder()->setLayout('ajax'); |
| 53 | |
| 54 | return $this->render('search_results'); |
| 55 | } |
| 56 | |
| 57 | // Get unique locales for the locale filter |
| 58 | $localesQuery = $this->Internationalisations->find() |
| 59 | ->select(['Internationalisations.locale']) |
| 60 | ->distinct(['Internationalisations.locale']) |
| 61 | ->orderBy(['Internationalisations.locale' => 'ASC']); |
| 62 | |
| 63 | $locales = $localesQuery->all()->extract('locale')->toList(); |
| 64 | $this->set(compact('internationalisations', 'locales')); |
| 65 | |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * View method |
| 71 | * |
| 72 | * @param string|null $id Internationalisation id. |
| 73 | * @return \Cake\Http\Response|null|void Renders view |
| 74 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
| 75 | */ |
| 76 | public function view(?string $id = null): void |
| 77 | { |
| 78 | $internationalisation = $this->Internationalisations->get($id, contain: []); |
| 79 | $this->set(compact('internationalisation')); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Add method |
| 84 | * |
| 85 | * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. |
| 86 | */ |
| 87 | public function add(): ?Response |
| 88 | { |
| 89 | $internationalisation = $this->Internationalisations->newEmptyEntity(); |
| 90 | if ($this->request->is('post')) { |
| 91 | $internationalisation = $this->Internationalisations->patchEntity( |
| 92 | $internationalisation, |
| 93 | $this->request->getData(), |
| 94 | ); |
| 95 | if ($this->Internationalisations->save($internationalisation)) { |
| 96 | $this->Flash->success(__('The internationalisation has been saved.')); |
| 97 | |
| 98 | return $this->redirect(['action' => 'index']); |
| 99 | } |
| 100 | $this->Flash->error(__('The internationalisation could not be saved. Please, try again.')); |
| 101 | } |
| 102 | $this->set(compact('internationalisation')); |
| 103 | |
| 104 | return null; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Edit method |
| 109 | * |
| 110 | * @param string|null $id Internationalisation id. |
| 111 | * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. |
| 112 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
| 113 | */ |
| 114 | public function edit(?string $id = null): ?Response |
| 115 | { |
| 116 | $internationalisation = $this->Internationalisations->get($id, contain: []); |
| 117 | if ($this->request->is(['patch', 'post', 'put'])) { |
| 118 | $internationalisation = $this->Internationalisations->patchEntity( |
| 119 | $internationalisation, |
| 120 | $this->request->getData(), |
| 121 | ); |
| 122 | if ($this->Internationalisations->save($internationalisation)) { |
| 123 | $this->Flash->success(__('The internationalisation has been saved.')); |
| 124 | |
| 125 | return $this->redirect(['action' => 'index']); |
| 126 | } |
| 127 | $this->Flash->error(__('The internationalisation could not be saved. Please, try again.')); |
| 128 | } |
| 129 | $this->set(compact('internationalisation')); |
| 130 | |
| 131 | return null; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Delete method |
| 136 | * |
| 137 | * @param string|null $id Internationalisation id. |
| 138 | * @return \Cake\Http\Response|null Redirects to index. |
| 139 | * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. |
| 140 | */ |
| 141 | public function delete(?string $id = null): Response |
| 142 | { |
| 143 | $this->request->allowMethod(['post', 'delete']); |
| 144 | $internationalisation = $this->Internationalisations->get($id); |
| 145 | if ($this->Internationalisations->delete($internationalisation)) { |
| 146 | $this->Flash->success(__('The internationalisation has been deleted.')); |
| 147 | } else { |
| 148 | $this->Flash->error(__('The internationalisation could not be deleted. Please, try again.')); |
| 149 | } |
| 150 | |
| 151 | return $this->redirect($this->referer()); |
| 152 | } |
| 153 | } |