Completed
Pull Request — master (#215)
by René
02:34
created
templates/main.tmpl.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -1,35 +1,35 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	/**
3
-	 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
-	 *
5
-	 * @author Vinzenz Rosenkranz <[email protected]>
6
-	 *
7
-	 * @license GNU AGPL version 3 or any later version
8
-	 *
9
-	 *  This program is free software: you can redistribute it and/or modify
10
-	 *  it under the terms of the GNU Affero General Public License as
11
-	 *  published by the Free Software Foundation, either version 3 of the
12
-	 *  License, or (at your option) any later version.
13
-	 *
14
-	 *  This program is distributed in the hope that it will be useful,
15
-	 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-	 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
-	 *  GNU Affero General Public License for more details.
18
-	 *
19
-	 *  You should have received a copy of the GNU Affero General Public License
20
-	 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
-	 *
22
-	 */
2
+    /**
3
+     * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
+     *
5
+     * @author Vinzenz Rosenkranz <[email protected]>
6
+     *
7
+     * @license GNU AGPL version 3 or any later version
8
+     *
9
+     *  This program is free software: you can redistribute it and/or modify
10
+     *  it under the terms of the GNU Affero General Public License as
11
+     *  published by the Free Software Foundation, either version 3 of the
12
+     *  License, or (at your option) any later version.
13
+     *
14
+     *  This program is distributed in the hope that it will be useful,
15
+     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+     *  GNU Affero General Public License for more details.
18
+     *
19
+     *  You should have received a copy of the GNU Affero General Public License
20
+     *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+     *
22
+     */
23 23
 
24
-	use OCP\User;
24
+    use OCP\User;
25 25
 
26
-	\OCP\Util::addStyle('polls', 'main');
27
-	\OCP\Util::addStyle('polls', 'list');
28
-	\OCP\Util::addScript('polls', 'start');
26
+    \OCP\Util::addStyle('polls', 'main');
27
+    \OCP\Util::addStyle('polls', 'list');
28
+    \OCP\Util::addScript('polls', 'start');
29 29
 
30
-	$userId = $_['userId'];
31
-	$userMgr = $_['userMgr'];
32
-	$urlGenerator = $_['urlGenerator'];
30
+    $userId = $_['userId'];
31
+    $userMgr = $_['userMgr'];
32
+    $urlGenerator = $_['urlGenerator'];
33 33
 ?>
34 34
 	<div id="app-content">
35 35
 		<div id="app-content-wrapper">
@@ -83,61 +83,61 @@  discard block
 block discarded – undo
83 83
 
84 84
 				<?php foreach ($_['polls'] as $poll) : ?>
85 85
 					<?php
86
-						if (!userHasAccess($poll, $userId)) continue;
87
-						// direct url to poll
88
-						$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash()));
89
-						$owner = $poll->getOwner();
86
+                        if (!userHasAccess($poll, $userId)) continue;
87
+                        // direct url to poll
88
+                        $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash()));
89
+                        $owner = $poll->getOwner();
90 90
 
91
-						$expiry_style = '';
92
-						if ($poll->getType() == '0') {
93
-							$participated = $_['participations'];
94
-						} else {
95
-							$participated = $_['participations_text'];
96
-						}
97
-						$participated_class = 'partic_no';
98
-						$participated_title = $l->t('You did not vote');
99
-						$participated_count = count($participated);
91
+                        $expiry_style = '';
92
+                        if ($poll->getType() == '0') {
93
+                            $participated = $_['participations'];
94
+                        } else {
95
+                            $participated = $_['participations_text'];
96
+                        }
97
+                        $participated_class = 'partic_no';
98
+                        $participated_title = $l->t('You did not vote');
99
+                        $participated_count = count($participated);
100 100
 
101
-						$comments = $_['comments'];
102
-						$commented_class = 'commented_no';
103
-						$commented_title = $l->t('You did not comment');
104
-						$commented_count = count($comments);
101
+                        $comments = $_['comments'];
102
+                        $commented_class = 'commented_no';
103
+                        $commented_title = $l->t('You did not comment');
104
+                        $commented_count = count($comments);
105 105
 
106
-						if ($owner == $userId) {
107
-							$owner = $l->t('Yourself');
108
-						}
106
+                        if ($owner == $userId) {
107
+                            $owner = $l->t('Yourself');
108
+                        }
109 109
 
110
-						if ($poll->getExpire() != null) {
111
-							// $expiry_date = date('d.m.Y', strtotime($poll->getExpire()));
112
-							$expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs
113
-							$expiry_style = ' progress';
114
-							if (date('U') > strtotime($poll->getExpire())) {
115
-								$expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire()));
116
-								$expiry_style = ' expired';
117
-							}
118
-						} else {
119
-							$expiry_style = ' endless';
120
-							$expiry_date = $l->t('Never');
121
-						}
110
+                        if ($poll->getExpire() != null) {
111
+                            // $expiry_date = date('d.m.Y', strtotime($poll->getExpire()));
112
+                            $expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs
113
+                            $expiry_style = ' progress';
114
+                            if (date('U') > strtotime($poll->getExpire())) {
115
+                                $expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire()));
116
+                                $expiry_style = ' expired';
117
+                            }
118
+                        } else {
119
+                            $expiry_style = ' endless';
120
+                            $expiry_date = $l->t('Never');
121
+                        }
122 122
 
123
-						for ($i = 0; $i < count($participated); $i++) {
124
-							if ($poll->getId() == intval($participated[$i]->getPollId())) {
125
-								$participated_class = 'partic_yes';
126
-								$participated_title = $l->t('You voted');
127
-								array_splice($participated, $i, 1);
128
-								break;
129
-							}
130
-						}
123
+                        for ($i = 0; $i < count($participated); $i++) {
124
+                            if ($poll->getId() == intval($participated[$i]->getPollId())) {
125
+                                $participated_class = 'partic_yes';
126
+                                $participated_title = $l->t('You voted');
127
+                                array_splice($participated, $i, 1);
128
+                                break;
129
+                            }
130
+                        }
131 131
 
132
-						for ($i = 0; $i < count($comments); $i++) {
133
-							if ($poll->getId() == intval($comments[$i]->getPollId())) {
134
-								$commented_class = 'commented_yes';
135
-								$commented_title = $l->t('You commented');
136
-								array_splice($comments, $i, 1);
137
-								break;
138
-							}
139
-						}
140
-					?>
132
+                        for ($i = 0; $i < count($comments); $i++) {
133
+                            if ($poll->getId() == intval($comments[$i]->getPollId())) {
134
+                                $commented_class = 'commented_yes';
135
+                                $commented_title = $l->t('You commented');
136
+                                array_splice($comments, $i, 1);
137
+                                break;
138
+                            }
139
+                        }
140
+                    ?>
141 141
 
142 142
 
143 143
 					<div class="row table-body">
@@ -213,16 +213,16 @@  discard block
 block discarded – undo
213 213
  * @return array with groups
214 214
  */
215 215
 function getGroups($userId) {
216
-	// $this->requireLogin();
217
-	if (class_exists('\OC_Group', true)) {
218
-		// Nextcloud <= 11, ownCloud
219
-		return \OC_Group::getUserGroups($userId);
220
-	}
221
-	// Nextcloud >= 12
222
-	$groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
223
-	return array_map(function ($group) {
224
-		return $group->getGID();
225
-	}, $groups);
216
+    // $this->requireLogin();
217
+    if (class_exists('\OC_Group', true)) {
218
+        // Nextcloud <= 11, ownCloud
219
+        return \OC_Group::getUserGroups($userId);
220
+    }
221
+    // Nextcloud >= 12
222
+    $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
223
+    return array_map(function ($group) {
224
+        return $group->getGID();
225
+    }, $groups);
226 226
 }
227 227
 
228 228
 /**
@@ -231,42 +231,42 @@  discard block
 block discarded – undo
231 231
  * @return boolean 
232 232
  */
233 233
 function userHasAccess($poll, $userId) {
234
-	if ($poll == null) {
235
-		return false;
236
-	}
237
-	$access = $poll->getAccess();
238
-	$owner = $poll->getOwner();
239
-	if (!User::isLoggedIn()) {
240
-		return false;
241
-	}
242
-	if ($access == 'public') {
243
-		return true;
244
-	}
245
-	if ($access == 'hidden') {
246
-		return true;
247
-	}
248
-	if ($access == 'registered') {
249
-		return true;
250
-	}
251
-	if ($owner == $userId) {
252
-		return true;
253
-	}
254
-	$user_groups = getGroups($userId);
234
+    if ($poll == null) {
235
+        return false;
236
+    }
237
+    $access = $poll->getAccess();
238
+    $owner = $poll->getOwner();
239
+    if (!User::isLoggedIn()) {
240
+        return false;
241
+    }
242
+    if ($access == 'public') {
243
+        return true;
244
+    }
245
+    if ($access == 'hidden') {
246
+        return true;
247
+    }
248
+    if ($access == 'registered') {
249
+        return true;
250
+    }
251
+    if ($owner == $userId) {
252
+        return true;
253
+    }
254
+    $user_groups = getGroups($userId);
255 255
 
256
-	$arr = explode(';', $access);
256
+    $arr = explode(';', $access);
257 257
 
258
-	foreach ($arr as $item) {
259
-		if (strpos($item, 'group_') == 0) {
260
-			$grp = substr($item, 6);
261
-			foreach ($user_groups as $user_group) {
262
-				if ($user_group == $grp) return true;
263
-			}
264
-		}
265
-		else if (strpos($item, 'user_') == 0) {
266
-			$usr = substr($item, 5);
267
-			if ($usr == $userId) return true;
268
-		}
269
-	}
270
-	return false;
258
+    foreach ($arr as $item) {
259
+        if (strpos($item, 'group_') == 0) {
260
+            $grp = substr($item, 6);
261
+            foreach ($user_groups as $user_group) {
262
+                if ($user_group == $grp) return true;
263
+            }
264
+        }
265
+        else if (strpos($item, 'user_') == 0) {
266
+            $usr = substr($item, 5);
267
+            if ($usr == $userId) return true;
268
+        }
269
+    }
270
+    return false;
271 271
 }
272 272
 ?>
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	\OCP\Util::addStyle('polls', 'list');
28 28
 	\OCP\Util::addScript('polls', 'start');
29 29
 
30
-	$userId = $_['userId'];
31
-	$userMgr = $_['userMgr'];
32
-	$urlGenerator = $_['urlGenerator'];
30
+	$userId = $_[ 'userId' ];
31
+	$userMgr = $_[ 'userMgr' ];
32
+	$urlGenerator = $_[ 'urlGenerator' ];
33 33
 ?>
34 34
 	<div id="app-content">
35 35
 		<div id="app-content-wrapper">
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 						<input class="stop icon-close" style="display:none" value="" type="button">
49 49
 					</div>
50 50
 				</div>
51
-	<?php if (count($_['polls']) == 0) : ?>
51
+	<?php if (count($_[ 'polls' ]) == 0) : ?>
52 52
 		<div id="emptycontent" class="">
53 53
 			<div class="icon-polls"></div>
54 54
 			<h2><?php p($l->t('No existing polls.')); ?></h2>
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 					 </div>
82 82
 				</div>
83 83
 
84
-				<?php foreach ($_['polls'] as $poll) : ?>
84
+				<?php foreach ($_[ 'polls' ] as $poll) : ?>
85 85
 					<?php
86 86
 						if (!userHasAccess($poll, $userId)) continue;
87 87
 						// direct url to poll
@@ -90,15 +90,15 @@  discard block
 block discarded – undo
90 90
 
91 91
 						$expiry_style = '';
92 92
 						if ($poll->getType() == '0') {
93
-							$participated = $_['participations'];
93
+							$participated = $_[ 'participations' ];
94 94
 						} else {
95
-							$participated = $_['participations_text'];
95
+							$participated = $_[ 'participations_text' ];
96 96
 						}
97 97
 						$participated_class = 'partic_no';
98 98
 						$participated_title = $l->t('You did not vote');
99 99
 						$participated_count = count($participated);
100 100
 
101
-						$comments = $_['comments'];
101
+						$comments = $_[ 'comments' ];
102 102
 						$commented_class = 'commented_no';
103 103
 						$commented_title = $l->t('You did not comment');
104 104
 						$commented_count = count($comments);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 						}
122 122
 
123 123
 						for ($i = 0; $i < count($participated); $i++) {
124
-							if ($poll->getId() == intval($participated[$i]->getPollId())) {
124
+							if ($poll->getId() == intval($participated[ $i ]->getPollId())) {
125 125
 								$participated_class = 'partic_yes';
126 126
 								$participated_title = $l->t('You voted');
127 127
 								array_splice($participated, $i, 1);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 						}
131 131
 
132 132
 						for ($i = 0; $i < count($comments); $i++) {
133
-							if ($poll->getId() == intval($comments[$i]->getPollId())) {
133
+							if ($poll->getId() == intval($comments[ $i ]->getPollId())) {
134 134
 								$commented_class = 'commented_yes';
135 135
 								$commented_title = $l->t('You commented');
136 136
 								array_splice($comments, $i, 1);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 					<div class="row table-body">
144 144
 						<div class="wrapper group-master">
145 145
 							<div class="wrapper group-1">
146
-								<div class="thumbnail <?php p($expiry_style . " " . $commented_class. " " . $participated_class); ?>"></div>  <!-- Image to display status or type of poll */ -->
146
+								<div class="thumbnail <?php p($expiry_style . " " . $commented_class . " " . $participated_class); ?>"></div>  <!-- Image to display status or type of poll */ -->
147 147
 								<a href="<?php p($pollUrl); ?>" class="wrapper group-1-1">
148 148
 									<div class="column name">						  <?php p($poll->getTitle()); ?></div>
149 149
 									<div class="column description">				   <?php p($poll->getDescription()); ?></div>
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 												</button>
167 167
 											</li>
168 168
 											<li>
169
-												<a href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>" class="menuitem action permanent" id="id_edit_<?php p($poll->getId()); ?>">
169
+												<a href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', [ 'hash' => $poll->getHash() ])); ?>" class="menuitem action permanent" id="id_edit_<?php p($poll->getId()); ?>">
170 170
 													<span class="icon-rename"></span>
171 171
 													<span>Edit Poll</span>
172 172
 												</a>
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	}
221 221
 	// Nextcloud >= 12
222 222
 	$groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
223
-	return array_map(function ($group) {
223
+	return array_map(function($group) {
224 224
 		return $group->getGID();
225 225
 	}, $groups);
226 226
 }
Please login to merge, or discard this patch.