Blame view

src/Controller/DocumentsController.php 3.73 KB
6c4edfa3   Alexandre   First Commit LabI...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * Documents Controller
 *
 * @property \App\Model\Table\DocumentsTable $Documents
 */
class DocumentsController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Network\Response|null
     */
    public function index()
    {
        $this->paginate = [
            'contain' => ['Materiels', 'Suivis']
        ];
        $documents = $this->paginate($this->Documents);

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

    /**
     * View method
     *
     * @param string|null $id Document id.
     * @return \Cake\Network\Response|null
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $document = $this->Documents->get($id, [
            'contain' => ['Materiels', 'Suivis']
        ]);

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

    /**
     * Add method
     *
     * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $document = $this->Documents->newEntity();
        if ($this->request->is('post')) {
            $document = $this->Documents->patchEntity($document, $this->request->data);
            if ($this->Documents->save($document)) {
3601f4f5   Alexandre   Traduction messag...
58
                $this->Flash->success(__('Le fichier a bien été ajouté.'));
6c4edfa3   Alexandre   First Commit LabI...
59
60
                return $this->redirect(['action' => 'index']);
            } else {
3601f4f5   Alexandre   Traduction messag...
61
                $this->Flash->error(__('Le fichier n\'a pas pu être ajouté.'));
6c4edfa3   Alexandre   First Commit LabI...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
            }
        }
        $materiels = $this->Documents->Materiels->find('list', ['limit' => 200]);
        $suivis = $this->Documents->Suivis->find('list', ['limit' => 200]);
        $this->set(compact('document', 'materiels', 'suivis'));
        $this->set('_serialize', ['document']);
    }

    /**
     * Edit method
     *
     * @param string|null $id Document id.
     * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $document = $this->Documents->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $document = $this->Documents->patchEntity($document, $this->request->data);
            if ($this->Documents->save($document)) {
3601f4f5   Alexandre   Traduction messag...
85
                $this->Flash->success(__('Le fichier a bien été édité.'));
6c4edfa3   Alexandre   First Commit LabI...
86
87
                return $this->redirect(['action' => 'index']);
            } else {
3601f4f5   Alexandre   Traduction messag...
88
                $this->Flash->error(__('Le fichier n\'a pas pu être édité.'));
6c4edfa3   Alexandre   First Commit LabI...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
            }
        }
        $materiels = $this->Documents->Materiels->find('list', ['limit' => 200]);
        $suivis = $this->Documents->Suivis->find('list', ['limit' => 200]);
        $this->set(compact('document', 'materiels', 'suivis'));
        $this->set('_serialize', ['document']);
    }

    /**
     * Delete method
     *
     * @param string|null $id Document id.
     * @return \Cake\Network\Response|null Redirects to index.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $document = $this->Documents->get($id);
        if ($this->Documents->delete($document)) {
3601f4f5   Alexandre   Traduction messag...
109
            $this->Flash->success(__('Le fichier a bien été supprimé.'));
6c4edfa3   Alexandre   First Commit LabI...
110
        } else {
3601f4f5   Alexandre   Traduction messag...
111
            $this->Flash->error(__('Le fichier n\'a pas pu être supprimé.'));
6c4edfa3   Alexandre   First Commit LabI...
112
113
114
115
        }
        return $this->redirect(['action' => 'index']);
    }
}