Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
64.15% covered (warning)
64.15%
34 / 53
40.00% covered (danger)
40.00%
2 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
AipromptsController
64.15% covered (warning)
64.15%
34 / 53
40.00% covered (danger)
40.00%
2 / 5
18.63
0.00% covered (danger)
0.00%
0 / 1
 index
62.96% covered (warning)
62.96%
17 / 27
0.00% covered (danger)
0.00%
0 / 1
3.46
 view
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 add
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 edit
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
3.33
 delete
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare(strict_types=1);
3
4namespace App\Controller\Admin;
5
6use App\Controller\AppController;
7use Cake\Http\Response;
8
9/**
10 * Aiprompts Controller
11 *
12 * @property \App\Model\Table\AipromptsTable $Aiprompts
13 */
14class AipromptsController 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        $query = $this->Aiprompts->find()
24            ->select([
25                'Aiprompts.id',
26                'Aiprompts.task_type',
27                'Aiprompts.system_prompt',
28                'Aiprompts.model',
29                'Aiprompts.max_tokens',
30                'Aiprompts.temperature',
31                'Aiprompts.created',
32                'Aiprompts.modified',
33            ]);
34
35        $search = $this->request->getQuery('search');
36        if (!empty($search)) {
37            $query->where([
38                'OR' => [
39                    'Aiprompts.task_type LIKE' => '%' . $search . '%',
40                    'Aiprompts.system_prompt LIKE' => '%' . $search . '%',
41                    'Aiprompts.model LIKE' => '%' . $search . '%',
42                ],
43            ]);
44        }
45        $aiprompts = $this->paginate($query);
46        if ($this->request->is('ajax')) {
47            $this->set(compact('aiprompts', 'search'));
48            $this->viewBuilder()->setLayout('ajax');
49
50            return $this->render('search_results');
51        }
52        $this->set(compact('aiprompts'));
53
54        return null;
55    }
56
57    /**
58     * View method
59     *
60     * @param string|null $id Aiprompt id.
61     * @return \Cake\Http\Response|null|void Renders view
62     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
63     */
64    public function view(?string $id = null): void
65    {
66        $aiprompt = $this->Aiprompts->get($id, contain: []);
67        $this->set(compact('aiprompt'));
68    }
69
70    /**
71     * Add method
72     *
73     * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
74     */
75    public function add(): ?Response
76    {
77        $aiprompt = $this->Aiprompts->newEmptyEntity();
78        if ($this->request->is('post')) {
79            $aiprompt = $this->Aiprompts->patchEntity($aiprompt, $this->request->getData());
80            if ($this->Aiprompts->save($aiprompt)) {
81                $this->Flash->success(__('The aiprompt has been saved.'));
82
83                return $this->redirect(['action' => 'index']);
84            }
85            $this->Flash->error(__('The aiprompt could not be saved. Please, try again.'));
86        }
87        $this->set(compact('aiprompt'));
88
89        return null;
90    }
91
92    /**
93     * Edit method
94     *
95     * @param string|null $id Aiprompt id.
96     * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
97     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
98     */
99    public function edit(?string $id = null): ?Response
100    {
101        $aiprompt = $this->Aiprompts->get($id, contain: []);
102        if ($this->request->is(['patch', 'post', 'put'])) {
103            $aiprompt = $this->Aiprompts->patchEntity($aiprompt, $this->request->getData());
104            if ($this->Aiprompts->save($aiprompt)) {
105                $this->Flash->success(__('The aiprompt has been saved.'));
106
107                return $this->redirect(['action' => 'index']);
108            }
109            $this->Flash->error(__('The aiprompt could not be saved. Please, try again.'));
110        }
111        $this->set(compact('aiprompt'));
112
113        return null;
114    }
115
116    /**
117     * Delete method
118     *
119     * @param string|null $id Aiprompt id.
120     * @return \Cake\Http\Response|null Redirects to index.
121     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
122     */
123    public function delete(?string $id = null): ?Response
124    {
125        $this->request->allowMethod(['post', 'delete']);
126        $aiprompt = $this->Aiprompts->get($id);
127        if ($this->Aiprompts->delete($aiprompt)) {
128            $this->Flash->success(__('The aiprompt has been deleted.'));
129        } else {
130            $this->Flash->error(__('The aiprompt could not be deleted. Please, try again.'));
131        }
132
133        return $this->redirect($this->referer());
134    }
135}