Completed
Push — master ( e5db64...945d9a )
by Schlaefer
05:09 queued 28s
created
app/Model/Shout.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -1,123 +1,123 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppModel', 'Model');
3
+    App::uses('AppModel', 'Model');
4 4
 
5 5
 /**
6 6
  * Shout Model
7 7
  *
8 8
  * @property User $User
9 9
  */
10
-	class Shout extends AppModel {
10
+    class Shout extends AppModel {
11 11
 
12 12
 /**
13 13
  * Display field
14 14
  *
15 15
  * @var string
16 16
  */
17
-		public $displayField = 'text';
17
+        public $displayField = 'text';
18 18
 
19
-		public $actsAs = [
20
-			'Markup',
21
-			'Containable'
22
-		];
19
+        public $actsAs = [
20
+            'Markup',
21
+            'Containable'
22
+        ];
23 23
 
24
-		public $virtualFields = [
25
-			'username' => 'User.username'
26
-		];
24
+        public $virtualFields = [
25
+            'username' => 'User.username'
26
+        ];
27 27
 
28 28
 /**
29 29
  * Validation rules
30 30
  *
31 31
  * @var array
32 32
  */
33
-		public $validate = array(
34
-			'text' => array(
35
-				'maxlength' => array(
36
-					'rule' => array('maxlength', 255),
37
-				),
38
-			),
39
-		);
33
+        public $validate = array(
34
+            'text' => array(
35
+                'maxlength' => array(
36
+                    'rule' => array('maxlength', 255),
37
+                ),
38
+            ),
39
+        );
40 40
 
41 41
 /**
42 42
  * belongsTo associations
43 43
  *
44 44
  * @var array
45 45
  */
46
-		public $belongsTo = array(
47
-			'User' => array(
48
-				'className' => 'User',
49
-				'foreignKey' => 'user_id',
50
-				'conditions' => '',
51
-				'fields' => '',
52
-				'order' => ''
53
-			)
54
-		);
46
+        public $belongsTo = array(
47
+            'User' => array(
48
+                'className' => 'User',
49
+                'foreignKey' => 'user_id',
50
+                'conditions' => '',
51
+                'fields' => '',
52
+                'order' => ''
53
+            )
54
+        );
55 55
 
56
-		public $maxNumberOfShouts = 10;
56
+        public $maxNumberOfShouts = 10;
57 57
 
58
-		public function findLastId() {
59
-			$out = 0;
60
-			$lastShout = $this->find(
61
-				'list',
62
-				array(
63
-					'contain' => false,
64
-					'fields' => 'id',
65
-					'order' => 'id desc',
66
-					'limit' => 1
67
-				)
68
-			);
69
-			if ($lastShout) {
70
-				$out = (int)current($lastShout);
71
-			}
72
-			return $out;
73
-		}
58
+        public function findLastId() {
59
+            $out = 0;
60
+            $lastShout = $this->find(
61
+                'list',
62
+                array(
63
+                    'contain' => false,
64
+                    'fields' => 'id',
65
+                    'order' => 'id desc',
66
+                    'limit' => 1
67
+                )
68
+            );
69
+            if ($lastShout) {
70
+                $out = (int)current($lastShout);
71
+            }
72
+            return $out;
73
+        }
74 74
 
75 75
 /**
76 76
  * Get all shouts
77 77
  *
78 78
  * @return array
79 79
  */
80
-		public function get() {
81
-			$shouts = $this->find(
82
-				'all',
83
-				[
84
-					'contain' => 'User.username',
85
-					'order' => 'Shout.id DESC'
86
-				]
87
-			);
88
-			return $shouts;
89
-		}
80
+        public function get() {
81
+            $shouts = $this->find(
82
+                'all',
83
+                [
84
+                    'contain' => 'User.username',
85
+                    'order' => 'Shout.id DESC'
86
+                ]
87
+            );
88
+            return $shouts;
89
+        }
90 90
 
91
-		public function push($data) {
92
-			$data[$this->alias]['time'] = gmdate("Y-m-d H:i:s", time());
93
-			$this->create($data);
94
-			$success = $this->save();
91
+        public function push($data) {
92
+            $data[$this->alias]['time'] = gmdate("Y-m-d H:i:s", time());
93
+            $this->create($data);
94
+            $success = $this->save();
95 95
 
96
-			$count = $this->find('count');
97
-			while ($success && $count > $this->maxNumberOfShouts) {
98
-				$success = $this->shift();
99
-				$count -= 1;
100
-			}
101
-			return $success;
102
-		}
96
+            $count = $this->find('count');
97
+            while ($success && $count > $this->maxNumberOfShouts) {
98
+                $success = $this->shift();
99
+                $count -= 1;
100
+            }
101
+            return $success;
102
+        }
103 103
 
104
-		public function shift() {
105
-			$currentIds = $this->find(
106
-				'list',
107
-				[
108
-					'fields' => 'Shout.id',
109
-					'order' => 'Shout.id ASC'
110
-				]
111
-			);
112
-			$oldestId = current($currentIds);
113
-			return $this->delete($oldestId);
114
-		}
104
+        public function shift() {
105
+            $currentIds = $this->find(
106
+                'list',
107
+                [
108
+                    'fields' => 'Shout.id',
109
+                    'order' => 'Shout.id ASC'
110
+                ]
111
+            );
112
+            $oldestId = current($currentIds);
113
+            return $this->delete($oldestId);
114
+        }
115 115
 
116
-		public function beforeSave($options = []) {
117
-			if (empty($this->data[$this->alias]['text']) === false) {
118
-				$this->data[$this->alias]['text'] = $this->prepareMarkup($this->data[$this->alias]['text']);
119
-			}
120
-			return true;
121
-		}
116
+        public function beforeSave($options = []) {
117
+            if (empty($this->data[$this->alias]['text']) === false) {
118
+                $this->data[$this->alias]['text'] = $this->prepareMarkup($this->data[$this->alias]['text']);
119
+            }
120
+            return true;
121
+        }
122 122
 
123
-	}
123
+    }
Please login to merge, or discard this patch.
app/Model/Esevent.php 1 patch
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -1,58 +1,58 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppModel', 'Model');
3
+    App::uses('AppModel', 'Model');
4 4
 
5
-	/**
6
-	 * Esevent Model
7
-	 *
8
-	 * @property Essubject $Essubject
9
-	 * @property Esnotification $Esnotification
10
-	 */
11
-	class Esevent extends AppModel {
5
+    /**
6
+     * Esevent Model
7
+     *
8
+     * @property Essubject $Essubject
9
+     * @property Esnotification $Esnotification
10
+     */
11
+    class Esevent extends AppModel {
12 12
 
13
-		public $actsAs = array('Containable');
13
+        public $actsAs = array('Containable');
14 14
 
15
-		//The Associations below have been created with all possible keys, those that are not needed can be removed
15
+        //The Associations below have been created with all possible keys, those that are not needed can be removed
16 16
 
17 17
 /**
18 18
  * hasMany associations
19 19
  *
20 20
  * @var array
21 21
  */
22
-		public $hasMany = array(
23
-			'Esnotification' => array(
24
-				'className' => 'Esnotification',
25
-				'foreignKey' => 'esevent_id',
26
-				'dependent' => true,
27
-				'conditions' => '',
28
-				'fields' => '',
29
-				'order' => '',
30
-				'limit' => '',
31
-				'offset' => '',
32
-				'exclusive' => '',
33
-				'finderQuery' => '',
34
-				'counterQuery' => ''
35
-			)
36
-		);
22
+        public $hasMany = array(
23
+            'Esnotification' => array(
24
+                'className' => 'Esnotification',
25
+                'foreignKey' => 'esevent_id',
26
+                'dependent' => true,
27
+                'conditions' => '',
28
+                'fields' => '',
29
+                'order' => '',
30
+                'limit' => '',
31
+                'offset' => '',
32
+                'exclusive' => '',
33
+                'finderQuery' => '',
34
+                'counterQuery' => ''
35
+            )
36
+        );
37 37
 
38
-		protected $_eventTypes = array(
39
-			'Model.Entry.replyToEntry' => 1,
40
-			'Model.Entry.replyToThread' => 2
41
-		);
38
+        protected $_eventTypes = array(
39
+            'Model.Entry.replyToEntry' => 1,
40
+            'Model.Entry.replyToThread' => 2
41
+        );
42 42
 
43 43
 /**
44 44
  * Subject types for $eventsTypes
45 45
  *
46 46
  * @var array
47 47
  */
48
-		protected $_subjectTypes = array(
49
-			'entry' => array(1),
50
-			'thread' => array(2),
51
-		);
48
+        protected $_subjectTypes = array(
49
+            'entry' => array(1),
50
+            'thread' => array(2),
51
+        );
52 52
 
53
-		protected $_receivers = array(
54
-				'EmailNotification' => 1,
55
-		);
53
+        protected $_receivers = array(
54
+                'EmailNotification' => 1,
55
+        );
56 56
 
57 57
 /**
58 58
  *
@@ -60,57 +60,57 @@  discard block
 block discarded – undo
60 60
  * @param int $newSubject
61 61
  * @param string $subjectType one of the strings in $_subjectTypes
62 62
  */
63
-		public function transferSubjectForEventType($oldSubject, $newSubject, $subjectType) {
64
-			$old = $this->find(
65
-				'all',
66
-				array(
67
-					'contain' => array('Esnotification'),
68
-					'conditions' => array(
69
-						'subject' => $oldSubject,
70
-						'event' => $this->_subjectTypes[$subjectType],
71
-					)
72
-				)
73
-			);
63
+        public function transferSubjectForEventType($oldSubject, $newSubject, $subjectType) {
64
+            $old = $this->find(
65
+                'all',
66
+                array(
67
+                    'contain' => array('Esnotification'),
68
+                    'conditions' => array(
69
+                        'subject' => $oldSubject,
70
+                        'event' => $this->_subjectTypes[$subjectType],
71
+                    )
72
+                )
73
+            );
74 74
 
75
-			// there are no affected subjects
76
-			if (!$old) {
77
-				return;
78
-			}
75
+            // there are no affected subjects
76
+            if (!$old) {
77
+                return;
78
+            }
79 79
 
80
-			$current = $this->find(
81
-				'all',
82
-				array(
83
-					'contain' => array('Esnotification'),
84
-					'conditions' => array(
85
-						'subject' => $newSubject,
86
-						'event' => $this->_subjectTypes[$subjectType],
87
-					)
88
-				)
89
-			);
80
+            $current = $this->find(
81
+                'all',
82
+                array(
83
+                    'contain' => array('Esnotification'),
84
+                    'conditions' => array(
85
+                        'subject' => $newSubject,
86
+                        'event' => $this->_subjectTypes[$subjectType],
87
+                    )
88
+                )
89
+            );
90 90
 
91
-			$oldEvents = Hash::combine($old, '{n}.Esevent.event', '{n}');
92
-			$currentEvents = Hash::combine($current, '{n}.Esevent.event', '{n}');
91
+            $oldEvents = Hash::combine($old, '{n}.Esevent.event', '{n}');
92
+            $currentEvents = Hash::combine($current, '{n}.Esevent.event', '{n}');
93 93
 
94
-			foreach ($oldEvents as $eventType => $oldEvent) {
95
-				$newData = array();
96
-				$newData['Esnotification'] = $oldEvent['Esnotification'];
97
-				if (isset($currentEvents[$eventType])) {
98
-					$newData['Esevent']['id'] = $currentEvents[$eventType]['Esevent']['id'];
99
-				} else {
100
-					$newData['Esevent']['subject'] = $newSubject;
101
-					$newData['Esevent']['event'] = $eventType;
102
-					$this->create();
103
-				}
104
-				$this->saveAssociated($newData);
105
-			}
106
-			$this->deleteAll(
107
-				array(
108
-					'subject' => $oldSubject,
109
-					'event' => $this->_subjectTypes[$subjectType],
110
-				),
111
-				false
112
-			);
113
-		}
94
+            foreach ($oldEvents as $eventType => $oldEvent) {
95
+                $newData = array();
96
+                $newData['Esnotification'] = $oldEvent['Esnotification'];
97
+                if (isset($currentEvents[$eventType])) {
98
+                    $newData['Esevent']['id'] = $currentEvents[$eventType]['Esevent']['id'];
99
+                } else {
100
+                    $newData['Esevent']['subject'] = $newSubject;
101
+                    $newData['Esevent']['event'] = $eventType;
102
+                    $this->create();
103
+                }
104
+                $this->saveAssociated($newData);
105
+            }
106
+            $this->deleteAll(
107
+                array(
108
+                    'subject' => $oldSubject,
109
+                    'event' => $this->_subjectTypes[$subjectType],
110
+                ),
111
+                false
112
+            );
113
+        }
114 114
 
115 115
 /**
116 116
  *
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
  * 	)
130 130
  * </pre>
131 131
  */
132
-		public function notifyUserOnEvents($user, $events) {
133
-			foreach ($events as $event) {
134
-				$params = array(
135
-					'user_id' => $user,
136
-					'event' => $this->_eventTypes[$event['event']],
137
-					'subject' => $event['subject'],
138
-					'receiver' => $this->_receivers[$event['receiver']],
139
-				);
140
-				if ($event['set']) {
141
-					$this->setNotification($params);
142
-				} else {
143
-					$this->deleteNotification($params);
144
-				}
145
-			}
146
-		}
132
+        public function notifyUserOnEvents($user, $events) {
133
+            foreach ($events as $event) {
134
+                $params = array(
135
+                    'user_id' => $user,
136
+                    'event' => $this->_eventTypes[$event['event']],
137
+                    'subject' => $event['subject'],
138
+                    'receiver' => $this->_receivers[$event['receiver']],
139
+                );
140
+                if ($event['set']) {
141
+                    $this->setNotification($params);
142
+                } else {
143
+                    $this->deleteNotification($params);
144
+                }
145
+            }
146
+        }
147 147
 
148 148
 /**
149 149
  *
@@ -159,54 +159,54 @@  discard block
 block discarded – undo
159 159
  *
160 160
  * @return type
161 161
  */
162
-		public function setNotification($params) {
163
-			$isSet = $this->_getEventSet($params);
164
-			$success = true;
165
-			$eventData = [];
166
-			if ($isSet['Esevent']) {
167
-				$eventData = array(
168
-					'id' => $isSet['Esevent']['id'],
169
-				);
170
-			} else {
171
-				$eventData = array(
172
-					'subject' => $params['subject'],
173
-					'event' => $params['event'],
174
-				);
175
-			}
176
-			if (!$isSet['Esnotification']) {
177
-				$data = array(
178
-					'Esevent' => $eventData,
179
-					'Esnotification' => array(
180
-						array(
181
-							'user_id' => $params['user_id'],
182
-							'esreceiver_id' => $params['receiver'],
183
-						),
184
-					),
185
-				);
186
-				$success = $success && $this->saveAssociated($data);
187
-			}
188
-			return $success;
189
-		}
162
+        public function setNotification($params) {
163
+            $isSet = $this->_getEventSet($params);
164
+            $success = true;
165
+            $eventData = [];
166
+            if ($isSet['Esevent']) {
167
+                $eventData = array(
168
+                    'id' => $isSet['Esevent']['id'],
169
+                );
170
+            } else {
171
+                $eventData = array(
172
+                    'subject' => $params['subject'],
173
+                    'event' => $params['event'],
174
+                );
175
+            }
176
+            if (!$isSet['Esnotification']) {
177
+                $data = array(
178
+                    'Esevent' => $eventData,
179
+                    'Esnotification' => array(
180
+                        array(
181
+                            'user_id' => $params['user_id'],
182
+                            'esreceiver_id' => $params['receiver'],
183
+                        ),
184
+                    ),
185
+                );
186
+                $success = $success && $this->saveAssociated($data);
187
+            }
188
+            return $success;
189
+        }
190 190
 
191 191
 /**
192 192
  * Deletes Subject and all its Notifications
193 193
  */
194
-		public function deleteSubject($subjectId, $subjectType) {
195
-			// remove all events
196
-			$this->deleteAll(array(
197
-					'subject' => $subjectId,
198
-					'event' => $this->_subjectTypes[$subjectType],
199
-			), true);
200
-		}
194
+        public function deleteSubject($subjectId, $subjectType) {
195
+            // remove all events
196
+            $this->deleteAll(array(
197
+                    'subject' => $subjectId,
198
+                    'event' => $this->_subjectTypes[$subjectType],
199
+            ), true);
200
+        }
201 201
 
202
-		public function deleteNotification($params) {
203
-			extract($params);
202
+        public function deleteNotification($params) {
203
+            extract($params);
204 204
 
205
-			$isSet = $this->_getEventSet($params);
206
-			if ($isSet['Esnotification']) {
207
-				return $this->Esnotification->deleteNotificationWithId($isSet['Esnotification'][0]['id']);
208
-			}
209
-		}
205
+            $isSet = $this->_getEventSet($params);
206
+            if ($isSet['Esnotification']) {
207
+                return $this->Esnotification->deleteNotificationWithId($isSet['Esnotification'][0]['id']);
208
+            }
209
+        }
210 210
 
211 211
 /**
212 212
  * Checks if specific notification is set
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
  *
225 225
  * @return mixed array with found set or false otherwise
226 226
  */
227
-		protected function _getEventSet($params) {
228
-			$results = $this->find(
229
-				'first',
230
-				array(
231
-					'contain' => array(
232
-						'Esnotification' => array(
233
-							'conditions' => array(
234
-								'user_id' => $params['user_id'],
235
-								'esreceiver_id' => $params['receiver'],
236
-							),
237
-						),
238
-					),
239
-					'conditions' => array(
240
-						'Esevent.subject' => $params['subject'],
241
-						'Esevent.event' => $params['event'],
242
-					)
243
-				)
244
-			);
245
-			return empty($results) ? false : $results;
246
-		}
227
+        protected function _getEventSet($params) {
228
+            $results = $this->find(
229
+                'first',
230
+                array(
231
+                    'contain' => array(
232
+                        'Esnotification' => array(
233
+                            'conditions' => array(
234
+                                'user_id' => $params['user_id'],
235
+                                'esreceiver_id' => $params['receiver'],
236
+                            ),
237
+                        ),
238
+                    ),
239
+                    'conditions' => array(
240
+                        'Esevent.subject' => $params['subject'],
241
+                        'Esevent.event' => $params['event'],
242
+                    )
243
+                )
244
+            );
245
+            return empty($results) ? false : $results;
246
+        }
247 247
 
248 248
 /**
249 249
  *
@@ -269,41 +269,41 @@  discard block
 block discarded – undo
269 269
  *	)
270 270
  * </pre>
271 271
  */
272
-		public function getUsersForEventOnSubjectWithReceiver($eventName, $subject, $receiver) {
273
-			$recipients = array();
274
-			$results = $this->find(
275
-				'all',
276
-				array(
277
-					'conditions' => array(
278
-						'Esevent.event' => $this->_eventTypes[$eventName],
279
-						'Esevent.subject' => $subject,
280
-					),
281
-					'contain' => array(
282
-						'Esnotification' => array(
283
-							'fields' => array(
284
-								'Esnotification.id',
285
-								'Esnotification.deactivate'
286
-							),
287
-							'conditions' => array(
288
-								'esreceiver_id' => $this->_receivers[$receiver],
289
-							),
290
-							'User' => array(
291
-								'fields' => array('id', 'username', 'user_email'),
292
-							)
293
-						),
294
-					),
295
-				)
296
-			);
297
-			if ($results) {
298
-				$recipients = Hash::map($results, '{n}.Esnotification.{n}', function ($values) {
299
-					$out = $values['User'];
300
-					unset($values['User']);
301
-					$out['Esnotification'] = $values;
302
-					return $out;
303
-				});
304
-			}
305
-			return $recipients;
306
-		}
272
+        public function getUsersForEventOnSubjectWithReceiver($eventName, $subject, $receiver) {
273
+            $recipients = array();
274
+            $results = $this->find(
275
+                'all',
276
+                array(
277
+                    'conditions' => array(
278
+                        'Esevent.event' => $this->_eventTypes[$eventName],
279
+                        'Esevent.subject' => $subject,
280
+                    ),
281
+                    'contain' => array(
282
+                        'Esnotification' => array(
283
+                            'fields' => array(
284
+                                'Esnotification.id',
285
+                                'Esnotification.deactivate'
286
+                            ),
287
+                            'conditions' => array(
288
+                                'esreceiver_id' => $this->_receivers[$receiver],
289
+                            ),
290
+                            'User' => array(
291
+                                'fields' => array('id', 'username', 'user_email'),
292
+                            )
293
+                        ),
294
+                    ),
295
+                )
296
+            );
297
+            if ($results) {
298
+                $recipients = Hash::map($results, '{n}.Esnotification.{n}', function ($values) {
299
+                    $out = $values['User'];
300
+                    unset($values['User']);
301
+                    $out['Esnotification'] = $values;
302
+                    return $out;
303
+                });
304
+            }
305
+            return $recipients;
306
+        }
307 307
 
308 308
 /**
309 309
  *
@@ -326,32 +326,32 @@  discard block
 block discarded – undo
326 326
  * 		1 => [true|false],
327 327
  * )
328 328
  */
329
-		public function checkEventsForUser($user, $events) {
330
-			// Stopwatch::enable(); Stopwatch::start('Event->checkEventsForUser()');
329
+        public function checkEventsForUser($user, $events) {
330
+            // Stopwatch::enable(); Stopwatch::start('Event->checkEventsForUser()');
331 331
 
332
-			$subjects = array();
333
-			foreach ($events as $event) {
334
-				$subjects[] = $event['subject'];
335
-			}
332
+            $subjects = array();
333
+            foreach ($events as $event) {
334
+                $subjects[] = $event['subject'];
335
+            }
336 336
 
337
-			$notis = $this->_getEventsForUserOnSubjects($user, $subjects);
338
-			$out = array();
337
+            $notis = $this->_getEventsForUserOnSubjects($user, $subjects);
338
+            $out = array();
339 339
 
340
-			foreach ($events as $k => $event) {
341
-				foreach ($notis as $noti) {
342
-					if ($noti['subject'] == $event['subject']
343
-							&& $noti['event'] == $this->_eventTypes[$event['event']]
344
-							&& $noti['receiver'] == $this->_receivers[$event['receiver']]) {
345
-						$out[$k] = true;
346
-						break;
347
-					} else {
348
-						$out[$k] = false;
349
-					}
350
-				}
351
-			}
352
-			// Stopwatch::end('Event->checkEventsForUser()'); debug(Stopwatch::getString());
353
-			return $out;
354
-		}
340
+            foreach ($events as $k => $event) {
341
+                foreach ($notis as $noti) {
342
+                    if ($noti['subject'] == $event['subject']
343
+                            && $noti['event'] == $this->_eventTypes[$event['event']]
344
+                            && $noti['receiver'] == $this->_receivers[$event['receiver']]) {
345
+                        $out[$k] = true;
346
+                        break;
347
+                    } else {
348
+                        $out[$k] = false;
349
+                    }
350
+                }
351
+            }
352
+            // Stopwatch::end('Event->checkEventsForUser()'); debug(Stopwatch::getString());
353
+            return $out;
354
+        }
355 355
 
356 356
 /**
357 357
  *
@@ -369,49 +369,49 @@  discard block
 block discarded – undo
369 369
  *
370 370
  * )
371 371
  */
372
-		protected function _getEventsForUserOnSubjects($user, $subjects) {
373
-			$notis = $this->Esnotification->find(
374
-				'all',
375
-				array(
376
-					'joins' => array(
377
-						array(
378
-							'table' => 'esevents',
379
-							'alias' => 'Eseventa',
380
-							'type' => 'LEFT',
381
-							'conditions' => array(
382
-								'Eseventa.id = Esnotification.esevent_id'
383
-							)
384
-						)
385
-					),
386
-					'conditions' => array(
387
-						'Esnotification.user_id' => $user,
388
-						'Esevent.subject' => $subjects
389
-					),
390
-					'fields' => array(
391
-						'Esnotification.id',
392
-						'Esnotification.user_id',
393
-						'Esnotification.esevent_id',
394
-						'Esnotification.esreceiver_id',
395
-						'Esevent.event',
396
-						'Esevent.subject'
397
-					)
398
-				)
399
-			);
400
-			$out = $notis;
401
-			if ($notis) {
402
-				$out = array();
403
-				foreach ($notis as $noti) {
404
-					$out[] = array(
405
-						'user_id' => $noti['Esnotification']['user_id'],
406
-						'esevent_id' => $noti['Esnotification']['esevent_id'],
407
-						'esnotification_id' => $noti['Esnotification']['id'],
408
-						'event' => $noti['Esevent']['event'],
409
-						'subject' => $noti['Esevent']['subject'],
410
-						'receiver' => $noti['Esnotification']['esreceiver_id'],
411
-					);
412
-				}
413
-			}
414
-			return $out;
415
-		}
372
+        protected function _getEventsForUserOnSubjects($user, $subjects) {
373
+            $notis = $this->Esnotification->find(
374
+                'all',
375
+                array(
376
+                    'joins' => array(
377
+                        array(
378
+                            'table' => 'esevents',
379
+                            'alias' => 'Eseventa',
380
+                            'type' => 'LEFT',
381
+                            'conditions' => array(
382
+                                'Eseventa.id = Esnotification.esevent_id'
383
+                            )
384
+                        )
385
+                    ),
386
+                    'conditions' => array(
387
+                        'Esnotification.user_id' => $user,
388
+                        'Esevent.subject' => $subjects
389
+                    ),
390
+                    'fields' => array(
391
+                        'Esnotification.id',
392
+                        'Esnotification.user_id',
393
+                        'Esnotification.esevent_id',
394
+                        'Esnotification.esreceiver_id',
395
+                        'Esevent.event',
396
+                        'Esevent.subject'
397
+                    )
398
+                )
399
+            );
400
+            $out = $notis;
401
+            if ($notis) {
402
+                $out = array();
403
+                foreach ($notis as $noti) {
404
+                    $out[] = array(
405
+                        'user_id' => $noti['Esnotification']['user_id'],
406
+                        'esevent_id' => $noti['Esnotification']['esevent_id'],
407
+                        'esnotification_id' => $noti['Esnotification']['id'],
408
+                        'event' => $noti['Esevent']['event'],
409
+                        'subject' => $noti['Esevent']['subject'],
410
+                        'receiver' => $noti['Esnotification']['esreceiver_id'],
411
+                    );
412
+                }
413
+            }
414
+            return $out;
415
+        }
416 416
 
417
-	}
417
+    }
Please login to merge, or discard this patch.
app/Model/Bookmark.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppModel', 'Model');
3
+    App::uses('AppModel', 'Model');
4 4
 
5 5
 /**
6 6
  * Bookmark Model
@@ -8,73 +8,73 @@  discard block
 block discarded – undo
8 8
  * @property User  $User
9 9
  * @property Entry $Entry
10 10
  */
11
-	class Bookmark extends AppModel {
11
+    class Bookmark extends AppModel {
12 12
 
13
-		public $actsAs = array(
14
-			'Containable',
15
-		);
13
+        public $actsAs = array(
14
+            'Containable',
15
+        );
16 16
 
17 17
 /**
18 18
  * Validation rules
19 19
  *
20 20
  * @var array
21 21
  */
22
-		public $validate = array(
23
-			'user_id' => array(
24
-				'numeric' => array(
25
-					'rule' => array('validateUniqueBookmark'),
26
-					//'message' => 'Your custom message here',
27
-					//'allowEmpty' => false,
28
-					'required' => false,
29
-					//'last' => false, // Stop validation after this rule
30
-					'on' => 'create',
31
-					// Limit validation to 'create' or 'update' operations
32
-				),
33
-			),
34
-			'entry_id' => array(
35
-				'numeric' => array(
36
-					'rule' => array('validateUniqueBookmark'),
37
-					//'message' => 'Your custom message here',
38
-					//'allowEmpty' => false,
39
-					'required' => false,
40
-					//'last' => false, // Stop validation after this rule
41
-					'on' => 'create',
42
-					// Limit validation to 'create' or 'update' operations
43
-				),
44
-			),
45
-		);
22
+        public $validate = array(
23
+            'user_id' => array(
24
+                'numeric' => array(
25
+                    'rule' => array('validateUniqueBookmark'),
26
+                    //'message' => 'Your custom message here',
27
+                    //'allowEmpty' => false,
28
+                    'required' => false,
29
+                    //'last' => false, // Stop validation after this rule
30
+                    'on' => 'create',
31
+                    // Limit validation to 'create' or 'update' operations
32
+                ),
33
+            ),
34
+            'entry_id' => array(
35
+                'numeric' => array(
36
+                    'rule' => array('validateUniqueBookmark'),
37
+                    //'message' => 'Your custom message here',
38
+                    //'allowEmpty' => false,
39
+                    'required' => false,
40
+                    //'last' => false, // Stop validation after this rule
41
+                    'on' => 'create',
42
+                    // Limit validation to 'create' or 'update' operations
43
+                ),
44
+            ),
45
+        );
46 46
 
47
-		//The Associations below have been created with all possible keys, those that are not needed can be removed
47
+        //The Associations below have been created with all possible keys, those that are not needed can be removed
48 48
 
49 49
 /**
50 50
  * belongsTo associations
51 51
  *
52 52
  * @var array
53 53
  */
54
-		public $belongsTo = array(
55
-			'User' => array(
56
-				'className' => 'User',
57
-				'foreignKey' => 'user_id',
58
-				'conditions' => '',
59
-				'fields' => '',
60
-				'order' => ''
61
-			),
62
-			'Entry' => array(
63
-				'className' => 'Entry',
64
-				'foreignKey' => 'entry_id',
65
-				'conditions' => '',
66
-				'fields' => '',
67
-				'order' => ''
68
-			)
69
-		);
54
+        public $belongsTo = array(
55
+            'User' => array(
56
+                'className' => 'User',
57
+                'foreignKey' => 'user_id',
58
+                'conditions' => '',
59
+                'fields' => '',
60
+                'order' => ''
61
+            ),
62
+            'Entry' => array(
63
+                'className' => 'Entry',
64
+                'foreignKey' => 'entry_id',
65
+                'conditions' => '',
66
+                'fields' => '',
67
+                'order' => ''
68
+            )
69
+        );
70 70
 
71
-		public function validateUniqueBookmark() {
72
-			$fields = array(
73
-				$this->alias . '.user_id' => $this->data['Bookmark']['user_id'],
74
-				$this->alias . '.entry_id' => $this->data['Bookmark']['entry_id'],
75
-			);
76
-			return $this->isUnique($fields, false);
77
-		}
71
+        public function validateUniqueBookmark() {
72
+            $fields = array(
73
+                $this->alias . '.user_id' => $this->data['Bookmark']['user_id'],
74
+                $this->alias . '.entry_id' => $this->data['Bookmark']['entry_id'],
75
+            );
76
+            return $this->isUnique($fields, false);
77
+        }
78 78
 
79 79
 /**
80 80
  *
@@ -82,18 +82,18 @@  discard block
 block discarded – undo
82 82
  * @param int $user_id
83 83
  * @return bool
84 84
  */
85
-		public function isBookmarked($entryId, $userId) {
86
-			$result = $this->find(
87
-				'first',
88
-				array(
89
-					'contain' => false,
90
-					'conditions' => array(
91
-						$this->alias . '.entry_id' => $entryId,
92
-						$this->alias . '.user_id' => $userId,
93
-					)
94
-				)
95
-			);
96
-			return $result == true;
97
-		}
85
+        public function isBookmarked($entryId, $userId) {
86
+            $result = $this->find(
87
+                'first',
88
+                array(
89
+                    'contain' => false,
90
+                    'conditions' => array(
91
+                        $this->alias . '.entry_id' => $entryId,
92
+                        $this->alias . '.user_id' => $userId,
93
+                    )
94
+                )
95
+            );
96
+            return $result == true;
97
+        }
98 98
 
99
-	}
99
+    }
Please login to merge, or discard this patch.
app/Model/Category.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,109 +1,109 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppSettingModel', 'Lib/Model');
4
-
5
-	class Category extends AppSettingModel {
6
-
7
-		public $name = 'Category';
8
-
9
-		public $actsAs = array('Containable');
10
-
11
-		public $cacheQueries = true;
12
-
13
-		public $hasMany = [
14
-			'Entry' => [
15
-				'className' => 'Entry',
16
-				'foreignKey' => 'category_id'
17
-			]
18
-		];
19
-
20
-		public $validate = [
21
-			'category_order' => [
22
-				'numeric' => [
23
-					'rule' => ['numeric']
24
-				]
25
-			],
26
-			'accession' => [
27
-				'numeric' => [
28
-					'rule' => ['numeric']
29
-				]
30
-			]
31
-		];
32
-
33
-		protected $_cache = [];
34
-
35
-		public function getCategoriesForAccession($accession) {
36
-			if (!empty($this->_cache[$accession])) {
37
-				return $this->_cache[$accession];
38
-			}
39
-			$this->_cache[$accession] = Cache::remember(
40
-				'Saito.Cache.CategoriesForAccession.' . $accession,
41
-				function () use ($accession) {
42
-					return $this->find('list', [
43
-						'conditions' => ['accession <=' => $accession],
44
-						'fields' => ['Category.id', 'Category.category'],
45
-						'order' => 'category_order ASC'
46
-					]);
47
-				});
48
-			return $this->_cache[$accession];
49
-		}
50
-
51
-		public function mergeIntoCategory($targetCategory) {
52
-			if (!isset($this->id)) {
53
-				return false;
54
-			}
55
-			if ((int)$targetCategory === (int)$this->id) {
56
-				return true;
57
-			}
58
-
59
-			$this->Entry->contain();
60
-			return $this->Entry->updateAll(
61
-				array('Entry.category' => $targetCategory),
62
-				array('Entry.category' => $this->id)
63
-			);
64
-		}
65
-
66
-		public function deleteWithAllEntries() {
67
-			if (!isset($this->id)) {
68
-				return false;
69
-			}
70
-
71
-			$this->Entry->contain();
72
-			$entriesDeleted = $this->Entry->deleteAll(
73
-				array('Entry.category' => $this->id),
74
-				false
75
-			);
76
-
77
-			return parent::delete($this->field('id'), false) && $entriesDeleted;
78
-		}
3
+    App::uses('AppSettingModel', 'Lib/Model');
4
+
5
+    class Category extends AppSettingModel {
6
+
7
+        public $name = 'Category';
8
+
9
+        public $actsAs = array('Containable');
10
+
11
+        public $cacheQueries = true;
12
+
13
+        public $hasMany = [
14
+            'Entry' => [
15
+                'className' => 'Entry',
16
+                'foreignKey' => 'category_id'
17
+            ]
18
+        ];
19
+
20
+        public $validate = [
21
+            'category_order' => [
22
+                'numeric' => [
23
+                    'rule' => ['numeric']
24
+                ]
25
+            ],
26
+            'accession' => [
27
+                'numeric' => [
28
+                    'rule' => ['numeric']
29
+                ]
30
+            ]
31
+        ];
32
+
33
+        protected $_cache = [];
34
+
35
+        public function getCategoriesForAccession($accession) {
36
+            if (!empty($this->_cache[$accession])) {
37
+                return $this->_cache[$accession];
38
+            }
39
+            $this->_cache[$accession] = Cache::remember(
40
+                'Saito.Cache.CategoriesForAccession.' . $accession,
41
+                function () use ($accession) {
42
+                    return $this->find('list', [
43
+                        'conditions' => ['accession <=' => $accession],
44
+                        'fields' => ['Category.id', 'Category.category'],
45
+                        'order' => 'category_order ASC'
46
+                    ]);
47
+                });
48
+            return $this->_cache[$accession];
49
+        }
50
+
51
+        public function mergeIntoCategory($targetCategory) {
52
+            if (!isset($this->id)) {
53
+                return false;
54
+            }
55
+            if ((int)$targetCategory === (int)$this->id) {
56
+                return true;
57
+            }
58
+
59
+            $this->Entry->contain();
60
+            return $this->Entry->updateAll(
61
+                array('Entry.category' => $targetCategory),
62
+                array('Entry.category' => $this->id)
63
+            );
64
+        }
65
+
66
+        public function deleteWithAllEntries() {
67
+            if (!isset($this->id)) {
68
+                return false;
69
+            }
70
+
71
+            $this->Entry->contain();
72
+            $entriesDeleted = $this->Entry->deleteAll(
73
+                array('Entry.category' => $this->id),
74
+                false
75
+            );
76
+
77
+            return parent::delete($this->field('id'), false) && $entriesDeleted;
78
+        }
79 79
 
80 80
 /**
81 81
  * Updates thread counter from entry table
82 82
  *
83 83
  * @return integer current thread count
84 84
  */
85
-		public function updateThreadCounter() {
86
-			// @performance
87
-			$count = $this->Entry->find(
88
-				'count',
89
-				[
90
-					'contain' => false,
91
-					'conditions' => [
92
-						'pid' => 0,
93
-						'Entry.category_id' => $this->id
94
-					]
95
-				]
96
-			);
97
-			$this->saveField('thread_count', $count);
98
-			return $count;
99
-		}
100
-
101
-		public function afterSave($created, $options = array()) {
102
-			// don't empty cache if it's only a thread count update
103
-			if (!$created && !isset($this->data[$this->alias]['category'])) {
104
-				$options['clearCache'] = false;
105
-			}
106
-			parent::afterSave($created, $options);
107
-		}
108
-
109
-	}
110 85
\ No newline at end of file
86
+        public function updateThreadCounter() {
87
+            // @performance
88
+            $count = $this->Entry->find(
89
+                'count',
90
+                [
91
+                    'contain' => false,
92
+                    'conditions' => [
93
+                        'pid' => 0,
94
+                        'Entry.category_id' => $this->id
95
+                    ]
96
+                ]
97
+            );
98
+            $this->saveField('thread_count', $count);
99
+            return $count;
100
+        }
101
+
102
+        public function afterSave($created, $options = array()) {
103
+            // don't empty cache if it's only a thread count update
104
+            if (!$created && !isset($this->data[$this->alias]['category'])) {
105
+                $options['clearCache'] = false;
106
+            }
107
+            parent::afterSave($created, $options);
108
+        }
109
+
110
+    }
111 111
\ No newline at end of file
Please login to merge, or discard this patch.
app/Locale/nondynamic_scan.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,20 +1,20 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-  /**
4
-   * Add any string here that may be dynamicaly created and not verbatim in the source.
5
-   *
6
-   * In source
7
-   *    $a = bar;
8
-   *    $a = baz;
9
-   *    …
10
-   *    __('foo-'.$a);
11
-   *
12
-   * becomes
13
-   *
14
-   *    __('foo-bar');
15
-   *    __('foo_baz');
16
-   *
17
-   * here.
18
-   */
3
+    /**
4
+     * Add any string here that may be dynamicaly created and not verbatim in the source.
5
+     *
6
+     * In source
7
+     *    $a = bar;
8
+     *    $a = baz;
9
+     *    …
10
+     *    __('foo-'.$a);
11
+     *
12
+     * becomes
13
+     *
14
+     *    __('foo-bar');
15
+     *    __('foo_baz');
16
+     *
17
+     * here.
18
+     */
19 19
 
20 20
 ?>
21 21
\ No newline at end of file
Please login to merge, or discard this patch.
app/Controller/BookmarksController.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppController', 'Controller');
3
+    App::uses('AppController', 'Controller');
4 4
 
5 5
 /**
6 6
  * Bookmarks Controller
@@ -9,127 +9,127 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class BookmarksController extends AppController {
11 11
 
12
-	public $helpers = ['EntryH'];
12
+    public $helpers = ['EntryH'];
13 13
 
14 14
 /**
15 15
  * @throws MethodNotAllowedException
16 16
  */
17
-	public function index() {
18
-		if (!$this->CurrentUser->isLoggedIn()) {
19
-			throw new MethodNotAllowedException;
20
-		}
21
-		$bookmarks = $this->Bookmark->find('all', [
22
-			'contain' => ['Entry' => ['Category', 'User']],
23
-			'conditions' => ['Bookmark.user_id' => $this->CurrentUser->getId()],
24
-			'order' => 'Bookmark.id DESC',
25
-		]);
26
-		$this->set('bookmarks', $bookmarks);
27
-	}
17
+    public function index() {
18
+        if (!$this->CurrentUser->isLoggedIn()) {
19
+            throw new MethodNotAllowedException;
20
+        }
21
+        $bookmarks = $this->Bookmark->find('all', [
22
+            'contain' => ['Entry' => ['Category', 'User']],
23
+            'conditions' => ['Bookmark.user_id' => $this->CurrentUser->getId()],
24
+            'order' => 'Bookmark.id DESC',
25
+        ]);
26
+        $this->set('bookmarks', $bookmarks);
27
+    }
28 28
 
29 29
 /**
30 30
  * @return bool
31 31
  * @throws MethodNotAllowedException
32 32
  * @throws BadRequestException
33 33
  */
34
-	public function add() {
35
-		if (!$this->request->is('ajax')) {
36
-			throw new BadRequestException;
37
-		}
38
-		if (!$this->CurrentUser->isLoggedIn()) {
39
-			throw new MethodNotAllowedException;
40
-		}
41
-		$this->autoRender = false;
42
-		if (!$this->request->is('post')) {
43
-			return false;
44
-		}
45
-
46
-		$data = [
47
-			'user_id' => $this->CurrentUser->getId(),
48
-			'entry_id' => $this->request->data['id'],
49
-		];
50
-		$this->Bookmark->create();
51
-		return (bool)$this->Bookmark->save($data);
52
-	}
53
-
54
-	/**
55
-	 * @param null $id
56
-	 * @throws NotFoundException
57
-	 * @throws MethodNotAllowedException
58
-	 */
59
-	public function edit($id = null) {
60
-		$bookmark = $this->_getBookmark($id);
61
-
62
-		if (!$this->request->is('post') && !$this->request->is('put')) {
63
-			$posting = array(
64
-				'Entry' => $bookmark['Entry'],
65
-				'Category' => $bookmark['Entry']['Category'],
66
-				'User' => $bookmark['Entry']['User'],
67
-			);
68
-			$this->set('entry', $this->dic->newInstance('\Saito\Posting\Posting',
69
-				['rawData' => $posting]));
70
-			$this->request->data = $bookmark;
71
-			return;
72
-		}
73
-
74
-		$data['Bookmark'] = [
75
-			'id' => $id,
76
-			'comment' => $this->request->data['Bookmark']['comment']
77
-		];
78
-		$success = $this->Bookmark->save($data);
79
-		if (!$success) {
80
-			$this->Session->setFlash(
81
-				__('The bookmark could not be saved. Please, try again.'));
82
-			return;
83
-		}
84
-		$this->redirect(['action' => 'index',
85
-			'#' => $bookmark['Bookmark']['entry_id']]);
86
-	}
34
+    public function add() {
35
+        if (!$this->request->is('ajax')) {
36
+            throw new BadRequestException;
37
+        }
38
+        if (!$this->CurrentUser->isLoggedIn()) {
39
+            throw new MethodNotAllowedException;
40
+        }
41
+        $this->autoRender = false;
42
+        if (!$this->request->is('post')) {
43
+            return false;
44
+        }
45
+
46
+        $data = [
47
+            'user_id' => $this->CurrentUser->getId(),
48
+            'entry_id' => $this->request->data['id'],
49
+        ];
50
+        $this->Bookmark->create();
51
+        return (bool)$this->Bookmark->save($data);
52
+    }
53
+
54
+    /**
55
+     * @param null $id
56
+     * @throws NotFoundException
57
+     * @throws MethodNotAllowedException
58
+     */
59
+    public function edit($id = null) {
60
+        $bookmark = $this->_getBookmark($id);
61
+
62
+        if (!$this->request->is('post') && !$this->request->is('put')) {
63
+            $posting = array(
64
+                'Entry' => $bookmark['Entry'],
65
+                'Category' => $bookmark['Entry']['Category'],
66
+                'User' => $bookmark['Entry']['User'],
67
+            );
68
+            $this->set('entry', $this->dic->newInstance('\Saito\Posting\Posting',
69
+                ['rawData' => $posting]));
70
+            $this->request->data = $bookmark;
71
+            return;
72
+        }
73
+
74
+        $data['Bookmark'] = [
75
+            'id' => $id,
76
+            'comment' => $this->request->data['Bookmark']['comment']
77
+        ];
78
+        $success = $this->Bookmark->save($data);
79
+        if (!$success) {
80
+            $this->Session->setFlash(
81
+                __('The bookmark could not be saved. Please, try again.'));
82
+            return;
83
+        }
84
+        $this->redirect(['action' => 'index',
85
+            '#' => $bookmark['Bookmark']['entry_id']]);
86
+    }
87 87
 
88 88
 /**
89 89
  * @param null $id
90 90
  * @return bool
91 91
  * @throws BadRequestException
92 92
  */
93
-	public function delete($id = null) {
94
-		if (!$this->request->is('ajax')) {
95
-			throw new BadRequestException;
96
-		}
97
-
98
-		$this->_getBookmark($id, $this->CurrentUser->getId());
99
-		$this->autoRender = false;
100
-		$this->Bookmark->id = $id;
101
-		return (bool)$this->Bookmark->delete();
102
-	}
103
-
104
-	public function beforeFilter() {
105
-		parent::beforeFilter();
106
-
107
-		$this->Security->unlockedActions = ['add'];
108
-	}
109
-
110
-	/**
111
-	 * @param $id
112
-	 * @throws NotFoundException
113
-	 * @throws MethodNotAllowedException
114
-	 * @throws Saito\Exception\SaitoForbiddenException
115
-	 * @return mixed
116
-	 */
117
-	protected function _getBookmark($id) {
118
-		if (!$this->CurrentUser->isLoggedIn()) {
119
-			throw new MethodNotAllowedException;
120
-		}
121
-
122
-		if (!$this->Bookmark->exists($id)) {
123
-			throw new NotFoundException(__('Invalid bookmark.'));
124
-		}
125
-
126
-		$this->Bookmark->contain(['Entry' => ['Category', 'User']]);
127
-		$bookmark = $this->Bookmark->findById($id);
128
-
129
-		if ($bookmark['Bookmark']['user_id'] != $this->CurrentUser->getId()) {
130
-			throw new Saito\Exception\SaitoForbiddenException("Attempt to edit bookmark $id.");
131
-		}
132
-		return $bookmark;
133
-	}
93
+    public function delete($id = null) {
94
+        if (!$this->request->is('ajax')) {
95
+            throw new BadRequestException;
96
+        }
97
+
98
+        $this->_getBookmark($id, $this->CurrentUser->getId());
99
+        $this->autoRender = false;
100
+        $this->Bookmark->id = $id;
101
+        return (bool)$this->Bookmark->delete();
102
+    }
103
+
104
+    public function beforeFilter() {
105
+        parent::beforeFilter();
106
+
107
+        $this->Security->unlockedActions = ['add'];
108
+    }
109
+
110
+    /**
111
+     * @param $id
112
+     * @throws NotFoundException
113
+     * @throws MethodNotAllowedException
114
+     * @throws Saito\Exception\SaitoForbiddenException
115
+     * @return mixed
116
+     */
117
+    protected function _getBookmark($id) {
118
+        if (!$this->CurrentUser->isLoggedIn()) {
119
+            throw new MethodNotAllowedException;
120
+        }
121
+
122
+        if (!$this->Bookmark->exists($id)) {
123
+            throw new NotFoundException(__('Invalid bookmark.'));
124
+        }
125
+
126
+        $this->Bookmark->contain(['Entry' => ['Category', 'User']]);
127
+        $bookmark = $this->Bookmark->findById($id);
128
+
129
+        if ($bookmark['Bookmark']['user_id'] != $this->CurrentUser->getId()) {
130
+            throw new Saito\Exception\SaitoForbiddenException("Attempt to edit bookmark $id.");
131
+        }
132
+        return $bookmark;
133
+    }
134 134
 
135 135
 }
136 136
\ No newline at end of file
Please login to merge, or discard this patch.
app/Controller/PagesController.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -36,23 +36,23 @@  discard block
 block discarded – undo
36 36
  *
37 37
  * @var string
38 38
  */
39
-	public $name = 'Pages';
39
+    public $name = 'Pages';
40 40
 
41 41
 /**
42 42
  * Default helper
43 43
  *
44 44
  * @var array
45 45
  */
46
-	public $helpers = array('Html', 'Session');
46
+    public $helpers = array('Html', 'Session');
47 47
 
48 48
 /**
49 49
  * This controller does not use a model
50 50
  *
51 51
  * @var array
52 52
  */
53
-	public $uses = array();
53
+    public $uses = array();
54 54
 
55
-	public $showDisclaimer = true;
55
+    public $showDisclaimer = true;
56 56
 
57 57
 /**
58 58
  * Displays a view
@@ -60,25 +60,25 @@  discard block
 block discarded – undo
60 60
  * @param mixed What page to display
61 61
  * @return void
62 62
  */
63
-	public function display() {
64
-		$path = func_get_args();
63
+    public function display() {
64
+        $path = func_get_args();
65 65
 
66
-		$count = count($path);
67
-		if (!$count) {
68
-			$this->redirect('/');
69
-		}
70
-		$page = $subpage = $title_for_layout = null;
66
+        $count = count($path);
67
+        if (!$count) {
68
+            $this->redirect('/');
69
+        }
70
+        $page = $subpage = $title_for_layout = null;
71 71
 
72
-		if (!empty($path[0])) {
73
-			$page = $path[0];
74
-		}
75
-		if (!empty($path[1])) {
76
-			$subpage = $path[1];
77
-		}
78
-		if (!empty($path[$count - 1])) {
79
-			$title_for_layout = Inflector::humanize($path[$count - 1]);
80
-		}
81
-		$this->set(compact('page', 'subpage', 'title_for_layout'));
82
-		$this->render(implode('/', $path));
83
-	}
72
+        if (!empty($path[0])) {
73
+            $page = $path[0];
74
+        }
75
+        if (!empty($path[1])) {
76
+            $subpage = $path[1];
77
+        }
78
+        if (!empty($path[$count - 1])) {
79
+            $title_for_layout = Inflector::humanize($path[$count - 1]);
80
+        }
81
+        $this->set(compact('page', 'subpage', 'title_for_layout'));
82
+        $this->render(implode('/', $path));
83
+    }
84 84
 }
Please login to merge, or discard this patch.
app/Controller/ToolsController.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,52 +1,52 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('AppController', 'Controller');
3
+    App::uses('AppController', 'Controller');
4 4
 
5 5
 /**
6 6
  * Tools Controller
7 7
  *
8 8
  * @property Tool $Tool
9 9
  */
10
-	class ToolsController extends AppController {
11
-
12
-		/**
13
-		 * Empty out all caches
14
-		 */
15
-		public function admin_emptyCaches() {
16
-			$this->CacheSupport->clear();
17
-			$this->Session->setFlash(__('Caches cleared.'), 'flash/success');
18
-			return $this->redirect($this->referer());
19
-		}
20
-
21
-		public function testJs() {
22
-			if (Configure::read('debug') === 0) {
23
-				echo 'Please activate debug mode.';
24
-				exit;
25
-			}
26
-
27
-			$this->autoLayout = false;
28
-		}
10
+    class ToolsController extends AppController {
11
+
12
+        /**
13
+         * Empty out all caches
14
+         */
15
+        public function admin_emptyCaches() {
16
+            $this->CacheSupport->clear();
17
+            $this->Session->setFlash(__('Caches cleared.'), 'flash/success');
18
+            return $this->redirect($this->referer());
19
+        }
20
+
21
+        public function testJs() {
22
+            if (Configure::read('debug') === 0) {
23
+                echo 'Please activate debug mode.';
24
+                exit;
25
+            }
26
+
27
+            $this->autoLayout = false;
28
+        }
29 29
 
30 30
 /**
31 31
  * Gives a deploy script a mean to empty PHP's APC-cache
32 32
  *
33 33
  * @link https://github.com/jadb/capcake/wiki/Capcake-and-PHP-APC>
34 34
  */
35
-		public function clearCache() {
36
-			if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
37
-				$this->CacheSupport->clear(['Apc', 'OpCache']);
38
-				echo json_encode(['Opcode Clear Cache' => true]);
39
-			}
40
-			exit;
41
-		}
42
-
43
-		public function beforeFilter() {
44
-			parent::beforeFilter();
45
-			$this->Auth->allow(
46
-				'clearCache',
47
-				'testJs',
48
-				'langJs'
49
-			);
50
-		}
51
-
52
-	}
53 35
\ No newline at end of file
36
+        public function clearCache() {
37
+            if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
38
+                $this->CacheSupport->clear(['Apc', 'OpCache']);
39
+                echo json_encode(['Opcode Clear Cache' => true]);
40
+            }
41
+            exit;
42
+        }
43
+
44
+        public function beforeFilter() {
45
+            parent::beforeFilter();
46
+            $this->Auth->allow(
47
+                'clearCache',
48
+                'testJs',
49
+                'langJs'
50
+            );
51
+        }
52
+
53
+    }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.
app/Controller/SearchesController.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,188 +1,188 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	use Saito\SimpleSearchString;
4
-
5
-	App::uses('AppController', 'Controller');
6
-
7
-	class SearchesController extends AppController {
8
-
9
-		public $components = [
10
-				'Paginator',
11
-				'Search.Prg' => [
12
-					'commonProcess' => [
13
-						'allowedParams' => ['nstrict'],
14
-						'keepPassed' => true,
15
-						'filterEmpty' => true,
16
-						'paramType' => 'querystring'
17
-					]
18
-				]
19
-		];
20
-
21
-		public $helpers = ['Form', 'Html', 'EntryH'];
22
-
23
-		public $uses = [
24
-				'Entry'
25
-		];
26
-
27
-		protected $_paginateConfig = [
28
-				'limit' => 25
29
-		];
30
-
31
-		public function beforeFilter() {
32
-			parent::beforeFilter();
33
-			$this->Auth->allow('simple');
34
-		}
35
-
36
-		public function simple() {
37
-			$defaults = [
38
-					'order' => 'time'
39
-			];
40
-			$this->set('order', $defaults['order']);
41
-
42
-			// @todo pgsql
43
-			$db = $this->Entry->getDataSource();
44
-			// @codingStandardsIgnoreStart
45
-			// on 5.5 phpcs assumes this is the deprecated PHP MySQL extension
46
-			if (!($db instanceof Mysql)) {
47
-				// @codingStandardsIgnoreEnd
48
-				$this->redirect(['action' => 'advanced']);
49
-				return;
50
-			}
51
-
52
-			$minWordLength = $this->Entry->query("SHOW VARIABLES LIKE 'ft_min_word_len'")[0];
53
-			$minWordLength = array_shift($minWordLength)['Value'];
54
-			$this->set(compact('minWordLength'));
55
-
56
-			if (!isset($this->request->query['q'])) {
57
-				// request for empty search form
58
-				return;
59
-			}
60
-
61
-			$this->_filterQuery(['q', 'page', 'order']);
62
-			$qRaw = $this->request->query['q'];
63
-			$query = $this->request->query += $defaults;
64
-			$this->set(['q' => $qRaw, 'order' => $query['order']]);
65
-
66
-			// test query is valid
67
-			$SearchString = new SimpleSearchString($qRaw, $minWordLength);
68
-			$this->set('minChars', $minWordLength);
69
-
70
-			$query['q'] = $SearchString->replaceOperators();
71
-			$omitted = $SearchString->getOmittedWords();
72
-			$this->set('omittedWords', $omitted);
73
-
74
-			// sanitize search-term for manual SQL-query
75
-			$query['q'] = $this->_sanitize($query['q']);
76
-
77
-			// build query
78
-			$q = $query['q'];
79
-			$order = '`Entry`.`time` DESC';
80
-			$fields = '*';
81
-			if ($query['order'] === 'rank') {
82
-				$order = 'rating DESC, ' . $order;
83
-				$fields = $fields . ", (MATCH (Entry.subject) AGAINST ('$q' IN BOOLEAN MODE)*2) + (MATCH (Entry.text) AGAINST ('$q' IN BOOLEAN MODE)) + (MATCH (Entry.name) AGAINST ('$q' IN BOOLEAN MODE)*4) AS rating";
84
-			}
85
-
86
-			// query
87
-			$this->Paginator->settings = [
88
-					'fields' => $fields,
89
-					'conditions' => [
90
-							"MATCH (Entry.subject, Entry.text, Entry.name) AGAINST ('$q' IN BOOLEAN MODE)",
91
-							'Entry.category_id' => $this->CurrentUser->Categories->getAllowed()
92
-					],
93
-					'order' => $order,
94
-					'paramType' => 'querystring'
95
-			];
96
-			$this->Paginator->settings += $this->_paginateConfig;
97
-			$results = $this->Paginator->paginate('Entry');
98
-			$this->set('results', $results);
99
-		}
100
-
101
-		/**
102
-		 * @throws NotFoundException
103
-		 * @throws BadRequestException
104
-		 */
105
-		public function advanced() {
106
-			// year for date drop-down
107
-			$first = $this->Entry->find('first',
108
-					['contain' => false, 'order' => 'Entry.id ASC']);
109
-			if ($first !== false) {
110
-				$startDate = strtotime($first['Entry']['time']);
111
-			} else {
112
-				$startDate = time();
113
-			}
114
-			$this->set('start_year', date('Y', $startDate));
115
-
116
-			// category drop-down
117
-			$categories = $this->CurrentUser->Categories->getAllowed('list');
118
-			$this->set('categories', $categories);
119
-
120
-			// calculate current month and year
121
-			if (isset($this->request->query['month'])) {
122
-				$month = $this->request->query['month'];
123
-				$year = $this->request->query['year'];
124
-			} else {
125
-				$month = date('n', $startDate);
126
-				$year = date('Y', $startDate);
127
-			}
128
-
129
-			$this->Prg->commonProcess();
130
-			$query = $this->Prg->parsedParams();
131
-
132
-			if (!empty($query['subject']) || !empty($query['text']) ||
133
-					!empty($query['name'])
134
-			) {
135
-				// strict username search: set before parseCriteria
136
-				if (!empty($this->request->query['nstrict'])) {
137
-					// presetVars controller var isn't working in Search v2.3
138
-					$this->Entry->filterArgs['name']['type'] = 'value';
139
-				}
140
-
141
-				$settings = [
142
-								'conditions' => $this->Entry->parseCriteria($query),
143
-								'order' => ['Entry.time' => 'DESC'],
144
-								'paramType' => 'querystring'
145
-						] + $this->_paginateConfig;
146
-
147
-				$time = mktime(0, 0, 0, $month, 1, $year);
148
-				if (!$time) {
149
-					throw new BadRequestException;
150
-				}
151
-				$settings['conditions']['time >'] = date(
152
-						'Y-m-d H:i:s',
153
-						mktime(0, 0, 0, $month, 1, $year));
154
-
155
-				if (isset($query['category_id']) && (int)$query['category_id'] !== 0) {
156
-					if (!isset($categories[(int)$query['category_id']])) {
157
-						throw new NotFoundException;
158
-					}
159
-				} else {
160
-					$settings['conditions']['Entry.category_id'] = $this->CurrentUser
161
-						->Categories->getAllowed();
162
-				}
163
-				$this->Paginator->settings = $settings;
164
-				unset(
165
-					$this->request->query['direction'],
166
-					$this->request->query['sort']
167
-				);
168
-				$this->set('results',
169
-					$this->Paginator->paginate(null, null, ['Entry.time']));
170
-			}
171
-
172
-			if (!isset($query['category_id'])) {
173
-				$this->request->data['Entry']['category_id'] = 0;
174
-			}
175
-
176
-			$this->set(compact('month', 'year'));
177
-		}
178
-
179
-		protected function _sanitize($string) {
180
-			return Sanitize::escape($string, $this->Entry->useDbConfig);
181
-		}
182
-
183
-		protected function _filterQuery($params) {
184
-			$this->request->query = array_intersect_key($this->request->query,
185
-					array_fill_keys($params, 1));
186
-		}
187
-
188
-	}
3
+    use Saito\SimpleSearchString;
4
+
5
+    App::uses('AppController', 'Controller');
6
+
7
+    class SearchesController extends AppController {
8
+
9
+        public $components = [
10
+                'Paginator',
11
+                'Search.Prg' => [
12
+                    'commonProcess' => [
13
+                        'allowedParams' => ['nstrict'],
14
+                        'keepPassed' => true,
15
+                        'filterEmpty' => true,
16
+                        'paramType' => 'querystring'
17
+                    ]
18
+                ]
19
+        ];
20
+
21
+        public $helpers = ['Form', 'Html', 'EntryH'];
22
+
23
+        public $uses = [
24
+                'Entry'
25
+        ];
26
+
27
+        protected $_paginateConfig = [
28
+                'limit' => 25
29
+        ];
30
+
31
+        public function beforeFilter() {
32
+            parent::beforeFilter();
33
+            $this->Auth->allow('simple');
34
+        }
35
+
36
+        public function simple() {
37
+            $defaults = [
38
+                    'order' => 'time'
39
+            ];
40
+            $this->set('order', $defaults['order']);
41
+
42
+            // @todo pgsql
43
+            $db = $this->Entry->getDataSource();
44
+            // @codingStandardsIgnoreStart
45
+            // on 5.5 phpcs assumes this is the deprecated PHP MySQL extension
46
+            if (!($db instanceof Mysql)) {
47
+                // @codingStandardsIgnoreEnd
48
+                $this->redirect(['action' => 'advanced']);
49
+                return;
50
+            }
51
+
52
+            $minWordLength = $this->Entry->query("SHOW VARIABLES LIKE 'ft_min_word_len'")[0];
53
+            $minWordLength = array_shift($minWordLength)['Value'];
54
+            $this->set(compact('minWordLength'));
55
+
56
+            if (!isset($this->request->query['q'])) {
57
+                // request for empty search form
58
+                return;
59
+            }
60
+
61
+            $this->_filterQuery(['q', 'page', 'order']);
62
+            $qRaw = $this->request->query['q'];
63
+            $query = $this->request->query += $defaults;
64
+            $this->set(['q' => $qRaw, 'order' => $query['order']]);
65
+
66
+            // test query is valid
67
+            $SearchString = new SimpleSearchString($qRaw, $minWordLength);
68
+            $this->set('minChars', $minWordLength);
69
+
70
+            $query['q'] = $SearchString->replaceOperators();
71
+            $omitted = $SearchString->getOmittedWords();
72
+            $this->set('omittedWords', $omitted);
73
+
74
+            // sanitize search-term for manual SQL-query
75
+            $query['q'] = $this->_sanitize($query['q']);
76
+
77
+            // build query
78
+            $q = $query['q'];
79
+            $order = '`Entry`.`time` DESC';
80
+            $fields = '*';
81
+            if ($query['order'] === 'rank') {
82
+                $order = 'rating DESC, ' . $order;
83
+                $fields = $fields . ", (MATCH (Entry.subject) AGAINST ('$q' IN BOOLEAN MODE)*2) + (MATCH (Entry.text) AGAINST ('$q' IN BOOLEAN MODE)) + (MATCH (Entry.name) AGAINST ('$q' IN BOOLEAN MODE)*4) AS rating";
84
+            }
85
+
86
+            // query
87
+            $this->Paginator->settings = [
88
+                    'fields' => $fields,
89
+                    'conditions' => [
90
+                            "MATCH (Entry.subject, Entry.text, Entry.name) AGAINST ('$q' IN BOOLEAN MODE)",
91
+                            'Entry.category_id' => $this->CurrentUser->Categories->getAllowed()
92
+                    ],
93
+                    'order' => $order,
94
+                    'paramType' => 'querystring'
95
+            ];
96
+            $this->Paginator->settings += $this->_paginateConfig;
97
+            $results = $this->Paginator->paginate('Entry');
98
+            $this->set('results', $results);
99
+        }
100
+
101
+        /**
102
+         * @throws NotFoundException
103
+         * @throws BadRequestException
104
+         */
105
+        public function advanced() {
106
+            // year for date drop-down
107
+            $first = $this->Entry->find('first',
108
+                    ['contain' => false, 'order' => 'Entry.id ASC']);
109
+            if ($first !== false) {
110
+                $startDate = strtotime($first['Entry']['time']);
111
+            } else {
112
+                $startDate = time();
113
+            }
114
+            $this->set('start_year', date('Y', $startDate));
115
+
116
+            // category drop-down
117
+            $categories = $this->CurrentUser->Categories->getAllowed('list');
118
+            $this->set('categories', $categories);
119
+
120
+            // calculate current month and year
121
+            if (isset($this->request->query['month'])) {
122
+                $month = $this->request->query['month'];
123
+                $year = $this->request->query['year'];
124
+            } else {
125
+                $month = date('n', $startDate);
126
+                $year = date('Y', $startDate);
127
+            }
128
+
129
+            $this->Prg->commonProcess();
130
+            $query = $this->Prg->parsedParams();
131
+
132
+            if (!empty($query['subject']) || !empty($query['text']) ||
133
+                    !empty($query['name'])
134
+            ) {
135
+                // strict username search: set before parseCriteria
136
+                if (!empty($this->request->query['nstrict'])) {
137
+                    // presetVars controller var isn't working in Search v2.3
138
+                    $this->Entry->filterArgs['name']['type'] = 'value';
139
+                }
140
+
141
+                $settings = [
142
+                                'conditions' => $this->Entry->parseCriteria($query),
143
+                                'order' => ['Entry.time' => 'DESC'],
144
+                                'paramType' => 'querystring'
145
+                        ] + $this->_paginateConfig;
146
+
147
+                $time = mktime(0, 0, 0, $month, 1, $year);
148
+                if (!$time) {
149
+                    throw new BadRequestException;
150
+                }
151
+                $settings['conditions']['time >'] = date(
152
+                        'Y-m-d H:i:s',
153
+                        mktime(0, 0, 0, $month, 1, $year));
154
+
155
+                if (isset($query['category_id']) && (int)$query['category_id'] !== 0) {
156
+                    if (!isset($categories[(int)$query['category_id']])) {
157
+                        throw new NotFoundException;
158
+                    }
159
+                } else {
160
+                    $settings['conditions']['Entry.category_id'] = $this->CurrentUser
161
+                        ->Categories->getAllowed();
162
+                }
163
+                $this->Paginator->settings = $settings;
164
+                unset(
165
+                    $this->request->query['direction'],
166
+                    $this->request->query['sort']
167
+                );
168
+                $this->set('results',
169
+                    $this->Paginator->paginate(null, null, ['Entry.time']));
170
+            }
171
+
172
+            if (!isset($query['category_id'])) {
173
+                $this->request->data['Entry']['category_id'] = 0;
174
+            }
175
+
176
+            $this->set(compact('month', 'year'));
177
+        }
178
+
179
+        protected function _sanitize($string) {
180
+            return Sanitize::escape($string, $this->Entry->useDbConfig);
181
+        }
182
+
183
+        protected function _filterQuery($params) {
184
+            $this->request->query = array_intersect_key($this->request->query,
185
+                    array_fill_keys($params, 1));
186
+        }
187
+
188
+    }
Please login to merge, or discard this patch.