Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14098 anikendra 1
<?php
2
/**
3
 * SubdocumentsController class
4
 *
5
 * @uses          AppController
6
 * @package       mongodb
7
 * @subpackage    mongodb.samples.controllers
8
 */
9
class SubdocumentsController extends AppController {
10
 
11
/**
12
 * name property
13
 *
14
 * @var string 'Subdocuments'
15
 * @access public
16
 */
17
	public $name = 'Subdocuments';
18
 
19
/**
20
 * index method
21
 *
22
 * @return void
23
 * @access public
24
 */
25
	public function index() {
26
		$params = array(
27
			'order' => array('_id' => -1),
28
			'limit' => 35,
29
			'page' => 1,
30
		);
31
		$results = $this->Subdocument->find('all', $params);
32
		$this->set(compact('results'));
33
	}
34
 
35
/**
36
 * add method
37
 *
38
 * @return void
39
 * @access public
40
 */
41
	public function add() {
42
		if (!empty($this->data)) {
43
			$this->Subdocument->create();
44
			if ($this->Subdocument->save($this->data)) {
45
				$this->flash(__('Subdocument saved.', true), array('action' => 'index'));
46
			} else {
47
			}
48
		}
49
	}
50
 
51
/**
52
 * edit method
53
 *
54
 * @param mixed $id null
55
 * @return void
56
 * @access public
57
 */
58
	public function edit($id = null) {
59
		if (!$id && empty($this->data)) {
60
			$this->flash(__('Invalid Subdocument', true), array('action' => 'index'));
61
		}
62
		if (!empty($this->data)) {
63
			if ($this->Subdocument->save($this->data)) {
64
				$this->flash(__('The Subdocument has been saved.', true), array('action' => 'index'));
65
			} else {
66
			}
67
		}
68
		if (empty($this->data)) {
69
			$this->data = $this->Subdocument->read(null, $id);
70
		}
71
	}
72
 
73
/**
74
 * delete method
75
 *
76
 * @param mixed $id null
77
 * @return void
78
 * @access public
79
 */
80
	public function delete($id = null) {
81
		if (!$id) {
82
			$this->flash(__('Invalid Subdocument', true), array('action' => 'index'));
83
		}
84
		if ($this->Subdocument->delete($id)) {
85
			$this->flash(__('Subdocument deleted', true), array('action' => 'index'));
86
		} else {
87
			$this->flash(__('Subdocument deleted Fail', true), array('action' => 'index'));
88
		}
89
	}
90
}