Subversion Repositories SmartDukaan

Rev

Rev 14768 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14768 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * ActivationCodes Controller
5
 *
6
 * @property ActivationCode $ActivationCode
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ActivationCodesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * admin_index method
20
 *
21
 * @return void
22
 */
23
	public function admin_index() {
15222 anikendra 24
		$options = array('order'=>array('id'=>'desc'));
14768 anikendra 25
		$this->ActivationCode->recursive = 0;
15222 anikendra 26
		$this->Paginator->settings = $options;
14768 anikendra 27
		$this->set('activationCodes', $this->Paginator->paginate());
28
	}
29
 
30
/**
31
 * admin_view method
32
 *
33
 * @throws NotFoundException
34
 * @param string $id
35
 * @return void
36
 */
37
	public function admin_view($id = null) {
38
		if (!$this->ActivationCode->exists($id)) {
39
			throw new NotFoundException(__('Invalid activation code'));
40
		}
41
		$options = array('conditions' => array('ActivationCode.' . $this->ActivationCode->primaryKey => $id));
42
		$this->set('activationCode', $this->ActivationCode->find('first', $options));
43
	}
44
 
45
/**
46
 * admin_add method
47
 *
48
 * @return void
49
 */
50
	public function admin_add() {
51
		if ($this->request->is('post')) {
52
			$this->ActivationCode->create();
53
			if ($this->ActivationCode->save($this->request->data)) {
54
				$this->Session->setFlash(__('The activation code has been saved.'));
55
				return $this->redirect(array('action' => 'index'));
56
			} else {
57
				$this->Session->setFlash(__('The activation code could not be saved. Please, try again.'));
58
			}
59
		}
60
	}
61
 
62
/**
63
 * admin_edit method
64
 *
65
 * @throws NotFoundException
66
 * @param string $id
67
 * @return void
68
 */
69
	public function admin_edit($id = null) {
70
		if (!$this->ActivationCode->exists($id)) {
71
			throw new NotFoundException(__('Invalid activation code'));
72
		}
73
		if ($this->request->is(array('post', 'put'))) {
74
			if ($this->ActivationCode->save($this->request->data)) {
75
				$this->Session->setFlash(__('The activation code has been saved.'));
76
				return $this->redirect(array('action' => 'index'));
77
			} else {
78
				$this->Session->setFlash(__('The activation code could not be saved. Please, try again.'));
79
			}
80
		} else {
81
			$options = array('conditions' => array('ActivationCode.' . $this->ActivationCode->primaryKey => $id));
82
			$this->request->data = $this->ActivationCode->find('first', $options);
83
		}
84
	}
85
 
86
/**
87
 * admin_delete method
88
 *
89
 * @throws NotFoundException
90
 * @param string $id
91
 * @return void
92
 */
93
	public function admin_delete($id = null) {
94
		$this->ActivationCode->id = $id;
95
		if (!$this->ActivationCode->exists()) {
96
			throw new NotFoundException(__('Invalid activation code'));
97
		}
98
		$this->request->onlyAllow('post', 'delete');
99
		if ($this->ActivationCode->delete()) {
100
			$this->Session->setFlash(__('The activation code has been deleted.'));
101
		} else {
102
			$this->Session->setFlash(__('The activation code could not be deleted. Please, try again.'));
103
		}
104
		return $this->redirect(array('action' => 'index'));
105
	}}