forked from bartcc/app.todos
/
albums_photos_controller.php
79 lines (69 loc) · 2.51 KB
/
albums_photos_controller.php
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
<?php
class AlbumsPhotosController extends AppController {
var $name = 'AlbumsPhotos';
function beforeFilter() {
//$this->Auth->allowedActions = array('index', 'view', 'add', 'edit', 'delete');
parent::beforeFilter();
}
function index() {
$this->AlbumsPhoto->recursive = 0;
$this->set('albumsPhotos', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid albums photo', true));
$this->redirect(array('action' => 'index'));
}
$this->set('albumsPhoto', $this->AlbumsPhoto->read(null, $id));
}
function add() {
$this->log('AlbumsPhotosController::add', LOG_DEBUG);
if (!empty($this->data)) {
$this->log($this->data, LOG_DEBUG);
$this->AlbumsPhoto->create();
if ($this->AlbumsPhoto->saveAll($this->data)) {
$this->Session->setFlash(__('The albums photo has been saved', true));
// $this->redirect(array('action' => 'index'));
$this->render(BLANK_RESPONSE);
} else {
$this->Session->setFlash(__('The albums photo could not be saved. Please, try again.', true));
}
}
$albums = $this->AlbumsPhoto->Album->find('list');
$photos = $this->AlbumsPhoto->Photo->find('list');
$this->set(compact('albums', 'photos'));
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid albums photo', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->AlbumsPhoto->save($this->data)) {
$this->Session->setFlash(__('The albums photo has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The albums photo could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->AlbumsPhoto->read(null, $id);
}
$albums = $this->AlbumsPhoto->Album->find('list');
$photos = $this->AlbumsPhoto->Photo->find('list');
$this->set(compact('albums', 'photos'));
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for albums photo', true));
$this->redirect(array('action' => 'index'));
}
if ($this->AlbumsPhoto->delete($id)) {
$this->Session->setFlash(__('Albums photo deleted', true));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Albums photo was not deleted', true));
$this->redirect(array('action' => 'index'));
}
}
?>