SoftwaresTagsController.php 4.1 KB
Newer Older
1
<?php
2

3 4 5
namespace App\Controller\Api\V1;

use App\Controller\AppController;
6 7 8 9
use App\Model\Table\SoftwaresTagsTable;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Network\Exception\NotFoundException;
use Cake\Network\Response;
10 11 12 13

/**
 * SoftwaresTags Controller
 *
14
 * @property SoftwaresTagsTable $SoftwaresTags
15 16 17 18 19 20 21
 */
class SoftwaresTagsController extends AppController
{

    /**
     * Index method
     *
22
     * @return Response|null
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
     */
    public function index()
    {
        $this->paginate = [
            'contain' => ['Softwares', 'Tags']
        ];
        $softwaresTags = $this->paginate($this->SoftwaresTags);

        $this->set(compact('softwaresTags'));
        $this->set('_serialize', ['softwaresTags']);
    }

    /**
     * View method
     *
38
     * @param string|null $id Softwares Tag id.
39 40
     * @return Response|null
     * @throws RecordNotFoundException When record not found.
41 42 43
     */
    public function view($id = null)
    {
44
        $softwaresTag = $this->SoftwaresTags->get(
45 46
            $id,
            [
47
                'contain' => ['Softwares', 'Tags']
48 49
            ]
        );
50 51 52 53 54 55 56 57

        $this->set('softwaresTag', $softwaresTag);
        $this->set('_serialize', ['softwaresTag']);
    }

    /**
     * Add method
     *
58
     * @return Response|void Redirects on successful add, renders view otherwise.
59 60 61 62 63
     */
    public function add()
    {
        $softwaresTag = $this->SoftwaresTags->newEntity();
        if ($this->request->is('post')) {
64
            $softwaresTag = $this->SoftwaresTags->patchEntity($softwaresTag, $this->request->getData());
65
            if ($this->SoftwaresTags->save($softwaresTag)) {
66
                $this->Flash->success(__d('Tags', 'The software tag has been saved.'));
67 68 69

                return $this->redirect(['action' => 'index']);
            } else {
70
                $this->Flash->error(__d('Tags', 'The software tag could not be saved. Please, try again.'));
71 72 73 74 75 76 77 78 79 80 81
            }
        }
        $softwares = $this->SoftwaresTags->Softwares->find('list', ['limit' => 200]);
        $tags = $this->SoftwaresTags->Tags->find('list', ['limit' => 200]);
        $this->set(compact('softwaresTag', 'softwares', 'tags'));
        $this->set('_serialize', ['softwaresTag']);
    }

    /**
     * Edit method
     *
82
     * @param string|null $id Softwares Tag id.
83 84
     * @return Response|void Redirects on successful edit, renders view otherwise.
     * @throws NotFoundException When record not found.
85 86 87
     */
    public function edit($id = null)
    {
88
        $softwaresTag = $this->SoftwaresTags->get(
89 90
            $id,
            [
91
                'contain' => []
92 93
            ]
        );
94
        if ($this->request->is(['patch', 'post', 'put'])) {
95
            $softwaresTag = $this->SoftwaresTags->patchEntity($softwaresTag, $this->request->getData());
96
            if ($this->SoftwaresTags->save($softwaresTag)) {
97
                $this->Flash->success(__d('Tags', 'The softwares tag has been saved.'));
98 99 100

                return $this->redirect(['action' => 'index']);
            } else {
101
                $this->Flash->error(__d('Tags', 'The softwares tag could not be saved. Please, try again.'));
102 103 104 105 106 107 108 109 110 111 112
            }
        }
        $softwares = $this->SoftwaresTags->Softwares->find('list', ['limit' => 200]);
        $tags = $this->SoftwaresTags->Tags->find('list', ['limit' => 200]);
        $this->set(compact('softwaresTag', 'softwares', 'tags'));
        $this->set('_serialize', ['softwaresTag']);
    }

    /**
     * Delete method
     *
113
     * @param string|null $id Softwares Tag id.
114 115
     * @return Response|null Redirects to index.
     * @throws RecordNotFoundException When record not found.
116 117 118 119 120 121
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $softwaresTag = $this->SoftwaresTags->get($id);
        if ($this->SoftwaresTags->delete($softwaresTag)) {
122
            $this->Flash->success(__d('Tags', 'The softwares tag has been deleted.'));
123
        } else {
124
            $this->Flash->error(__d('Tags', 'The softwares tag could not be deleted. Please, try again.'));
125 126 127 128 129
        }

        return $this->redirect(['action' => 'index']);
    }
}