summaryrefslogtreecommitdiffstats
path: root/application/controllers/FilterController.php
blob: 3f7fa737fab4c120fe3555380ea5e80bf78637ea (plain) (blame)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php

class FilterController extends Zend_Controller_Action
{

    private $_filtermapper = null;

    public function init()
    {
        try{		
        			$this->_filtermapper = new Application_Model_FilterMapper();
        		}catch (Zend_Exception $e) {  
        			echo "Error message 1: " . $e->getMessage() . "\n";
		}
    }

    public function indexAction()
    {
        try{			
        			$this->_filtermapper = new Application_Model_FilterMapper();
               		$this->view->filters = $this->_filtermapper->fetchAll();
        			
        			$filterentries = new Application_Model_FilterEntriesMapper();
        			
        			$this->view->filterentries = $filterentries->fetchAll();
                     			
            	}catch (Zend_Exception $e) {  
        			echo "Error message 2: " . $e->getMessage() . "\n";
			}
    }

    public function addfilterAction()
    {
        if (!isset($_POST["add"])){
    		$addfilterform = new Application_Form_FilterAdd();    		
			$this->view->addfilterform = $addfilterform;		
		}else {
			$addfilterform = new Application_Form_FilterAdd($_POST);
			if ($addfilterform->isValid($_POST)) {			
				try{
					$newfilter = new Application_Model_Filter();
					$newfilter->setTitle($_POST['title']);
					$newfilter->setCreated(time());
					$newfilter->setDescription($_POST['description']);
					$newfilter->setPriority($_POST['priority']);

					// TODO: Ändere mit ACL
					$newfilter->setGroupID('1');
					$newfilter->setMembershipID('1');
					$newfilter->setBootmenuID('1');					

					$newfilter2 = new Application_Model_FilterMapper();
					$newfilter2->save($newfilter);

					$this->_redirect('/filter');
			    	return;
				}catch (Zend_Exception $e) {  
        			echo "Error message 2: " . $e->getMessage() . "\n";  
        		}
			}
		}
    }

    public function removefilterAction()
    {
        
		$filterID = $this->_request->getParam('filterID');
		// TODO: ACL implementieren ob er den filter löschen darf
		if(is_numeric($filterID)){
			$deletefilter = new Application_Model_Filter();
			$deletefilter->setID($filterID);
			$filtermapper = new Application_Model_FilterMapper();
			$filtermapper->delete($deletefilter);
		}
		$this->_redirect('/filter');
    }

    public function editfilterAction()
    {
		if (!isset($_POST["add"])){
		    // TODO: ACL implementieren ob er editieren darf
			$filterID = $this->_request->getParam('filterID');
			$filter = new Application_Model_Filter();

			$filtermapper = new Application_Model_FilterMapper();
			$filtermapper->find($filterID,$filter);		
			$filter2 = $filter->toArray();

			$editfilterform = new Application_Form_FilterAdd();  
			$editfilterform->populate($filter2);
			$this->view->editfilterform = $editfilterform;
		
		} else{
			try{
				echo "<pre>";print_r($_POST);echo "</pre>";
				$editfilterform = new Application_Form_FilterAdd();
				//TODO: ACL integrieren				
				$_POST['groupID'] = 1;
				$_POST['membershipID'] = 1;
				$_POST['bootmenuID'] = 1;
				$_POST['created'] = time();

				if ($editfilterform->isValid($_POST)) {	
					$newfilterenty = new Application_Model_Filter($_POST);
					$newfilterenty->setID($this->_request->getParam('filterID'));
					$newfilter2 = new Application_Model_FilterMapper();				
					$newfilter2->save($newfilterenty);	
				}				

			}catch (Zend_Exception $e) {  
    			echo "Error message 2: " . $e->getMessage() . "\n";  
    		}
			$this->_redirect('/filter');
		}		
    }

    public function addfilterentryAction()
    {
        // TODO: ACL implementieren ob er editieren darf   
		if (!isset($_POST["add"])){
			echo "case1";
			try{
				$editfilterform = new Application_Form_FilterEntriesAdd(array('filterID' => $this->_request->getParam('filterID')));
				$this->view->editfilterform = $editfilterform;
				echo "case 1.1";

			}catch (Zend_Exception $e) {  
				echo "Error message 2: " . $e->getMessage() . "\n";  
			}
		} else{
			$editfilterform = new Application_Form_FilterEntriesAdd($_POST);
			echo "case2";	
			
			if ($editfilterform->isValid($_POST)) {			
				
				$newfilterenty = new Application_Model_FilterEntries();
				$newfilterenty->setFilterID($_POST['filterID']);
				$newfilterenty->setFiltertypeID($_POST['filtertypeID']);
				$newfilterenty->setFiltervalue($_POST['filtervalue']);
				$newfilterenty->setFiltervalue2($_POST['filtervalue2']);	
				
				$newfilter2 = new Application_Model_FilterEntriesMapper();
				
				$newfilter2->save($newfilterenty);					
			}
			$this->_redirect('/filter');
		}
    }
	public function editfilterentryAction()
    {
        if (!isset($_POST["add"])){
			echo "case1";
			try{
				$filterID 		= $this->_request->getParam('filterID');
				$filtertypeID = $this->_request->getParam('filtertypeID');
				
				
				$filterentry = new Application_Model_FilterEntries();

				$filterentriesmapper = new Application_Model_FilterEntriesMapper();
				$filterentriesmapper->find($filterID,$filtertypeID,$filterentry);		

				$editfilterform = new Application_Form_FilterEntriesAdd();
				echo "<pre style='border:1px solid black;background-color:#F5B800'>";
				print_r($filterentry->toArray());
				echo "</pre>";
				$editfilterform->populate($filterentry->toArray());
				$editfilterform->setFilterID($filterID);
				$this->view->editfilterform = $editfilterform;
				echo "case 1.1";

			}catch (Zend_Exception $e) {  
				echo "Error message 2: " . $e->getMessage() . "\n";  
			}
		} else{
			$editfilterform = new Application_Form_FilterEntriesAdd($_POST);
			echo "case2";	
			echo "<pre style='border:1px solid black;background-color:#F5B800'>";
			print_r($_POST);
			echo "</pre>";
			if ($editfilterform->isValid($_POST)) {			
				echo "valid\n";	
				$newfilterenty = new Application_Model_FilterEntries($_POST);				
				$newfilter2 = new Application_Model_FilterEntriesMapper();				
				$newfilter2->save($newfilterenty);
								
			}
			else{
				echo 'nö';
			}
			$this->_redirect('/filter');
		}
    }
	public function removefilterentryAction()
    {
		      
		try{    		
			$filterID = $this->_request->getParam('filterID');
			$filtertypeID = $this->_request->getParam('filtertypeID');
			echo "<pre>";
			var_dump(array($filterID,$filtertypeID));
			echo "</pre>";
			// TODO: ACL implementieren ob er den filter löschen darf
			if(is_numeric($filterID)){
				$deletefilterentry = new Application_Model_FilterEntries();
				$deletefilterentry->setFilterID($filterID);
				$deletefilterentry->setFiltertypeID($filtertypeID);

				$filterentriesmapper = new Application_Model_FilterEntriesMapper();
				$filterentriesmapper->delete($deletefilterentry);
			}
			$this->_redirect('/filter');
		}catch (Zend_Exception $e) {  
			echo "Error message 2: " . $e->getMessage() . "\n";  
		}
    }


}