-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkListsController.php
More file actions
117 lines (111 loc) · 3.39 KB
/
LinkListsController.php
File metadata and controls
117 lines (111 loc) · 3.39 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
App::uses('LinkListsAppController', 'LinkLists.Controller');
/**
* LinkLists Controller
*
* @property LinkList $LinkList
* @property PaginatorComponent $Paginator
*
* @author Jun Nishikawa <topaz2@m0n0m0n0.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
class LinkListsController extends LinkListsAppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index() {
$this->LinkList->recursive = 0;
$this->set('linkLists', $this->Paginator->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->LinkList->exists($id)) {
throw new NotFoundException(__('Invalid link list'));
}
$options = array('conditions' => array('LinkList.' . $this->LinkList->primaryKey => $id));
$this->set('linkList', $this->LinkList->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->LinkList->create();
if ($this->LinkList->save($this->request->data)) {
$this->Session->setFlash(__('The link list has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The link list could not be saved. Please, try again.'));
}
}
$linklistsBlocks = $this->LinkList->LinklistsBlock->find('list');
$languages = $this->LinkList->Language->find('list');
$linklistsCategories = $this->LinkList->LinklistsCategory->find('list');
$blocks = $this->LinkList->Block->find('list');
$this->set(compact('linklistsBlocks', 'languages', 'linklistsCategories', 'blocks'));
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->LinkList->exists($id)) {
throw new NotFoundException(__('Invalid link list'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->LinkList->save($this->request->data)) {
$this->Session->setFlash(__('The link list has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The link list could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('LinkList.' . $this->LinkList->primaryKey => $id));
$this->request->data = $this->LinkList->find('first', $options);
}
$linklistsBlocks = $this->LinkList->LinklistsBlock->find('list');
$languages = $this->LinkList->Language->find('list');
$linklistsCategories = $this->LinkList->LinklistsCategory->find('list');
$blocks = $this->LinkList->Block->find('list');
$this->set(compact('linklistsBlocks', 'languages', 'linklistsCategories', 'blocks'));
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->LinkList->id = $id;
if (!$this->LinkList->exists()) {
throw new NotFoundException(__('Invalid link list'));
}
$this->request->onlyAllow('post', 'delete');
if ($this->LinkList->delete()) {
$this->Session->setFlash(__('The link list has been deleted.'));
} else {
$this->Session->setFlash(__('The link list could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}}