Completed
Push — master ( 1e6f6d...887061 )
by René
29s
created

PageController::gotoPoll()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 32
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 27
nc 5
nop 1
dl 0
loc 32
rs 9.488
c 0
b 0
f 0
ccs 0
cts 25
cp 0
crap 20
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
 */
23
24
namespace OCA\Polls\Controller;
25
26
use OCA\Polls\Db\Comment;
27
use OCA\Polls\Db\CommentMapper;
28
use OCA\Polls\Db\Event;
29
use OCA\Polls\Db\EventMapper;
30
use OCA\Polls\Db\Notification;
31
use OCA\Polls\Db\NotificationMapper;
32
use OCA\Polls\Db\Option;
33
use OCA\Polls\Db\OptionMapper;
34
use OCA\Polls\Db\Vote;
35
use OCA\Polls\Db\VoteMapper;
36
use OCP\AppFramework\Controller;
37
use OCP\AppFramework\Db\DoesNotExistException;
38
use OCP\AppFramework\Http\ContentSecurityPolicy;
39
use OCP\AppFramework\Http\JSONResponse;
40
use OCP\AppFramework\Http\RedirectResponse;
41
use OCP\AppFramework\Http\TemplateResponse;
42
use OCP\IAvatarManager;
43
use OCP\IConfig;
44
use OCP\IGroupManager;
45
use OCP\IL10N;
46
use OCP\ILogger;
47
use OCP\IRequest;
48
use OCP\IURLGenerator;
49
use OCP\IUser;
50
use OCP\IUserManager;
51
use OCP\L10N\IFactory;
52
use OCP\Mail\IMailer;
53
use OCP\Security\ISecureRandom;
54
use OCP\User; //To do: replace according to API
55
use OCP\Util;
56
57
class PageController extends Controller {
58
59
	private $userId;
60
	private $config;
61
	private $commentMapper;
62
	private $eventMapper;
63
	private $notificationMapper;
64
	private $optionMapper;
65
	private $voteMapper;
66
	private $urlGenerator;
67
	private $userMgr;
68
	private $avatarManager;
69
	private $logger;
70
	private $trans;
71
	private $transFactory;
72
	private $groupManager;
73
	private $mailer;
74
75
	/**
76
	 * PageController constructor.
77
	 * @param string $appName
78
	 * @param IRequest $request
79
	 * @param IConfig $config
80
	 * @param IUserManager $userMgr
81
	 * @param IGroupManager $groupManager
82
	 * @param IAvatarManager $avatarManager
83
	 * @param ILogger $logger
84
	 * @param IL10N $trans
85
	 * @param IFactory $transFactory
86
	 * @param IURLGenerator $urlGenerator
87
	 * @param string $userId
88
	 * @param CommentMapper $commentMapper
89
	 * @param OptionMapper $optionMapper
90
	 * @param EventMapper $eventMapper
91
	 * @param NotificationMapper $notificationMapper
92
	 * @param VoteMapper $VoteMapper
93
	 * @param IMailer $mailer
94
	 */
95 1
	public function __construct(
96
		$appName,
97
		IRequest $request,
98
		IConfig $config,
99
		IUserManager $userMgr,
100
		IGroupManager $groupManager,
101
		IAvatarManager $avatarManager,
102
		ILogger $logger,
103
		IL10N $trans,
104
		IFactory $transFactory,
105
		IURLGenerator $urlGenerator,
106
		$userId,
107
		CommentMapper $commentMapper,
108
		OptionMapper $optionMapper,
109
		EventMapper $eventMapper,
110
		NotificationMapper $notificationMapper,
111
		VoteMapper $VoteMapper,
112
		IMailer $mailer
113
	) {
114 1
		parent::__construct($appName, $request);
115 1
		$this->request = $request;
116 1
		$this->config = $config;
117 1
		$this->userMgr = $userMgr;
118 1
		$this->groupManager = $groupManager;
119 1
		$this->avatarManager = $avatarManager;
120 1
		$this->logger = $logger;
121 1
		$this->trans = $trans;
122 1
		$this->transFactory = $transFactory;
123 1
		$this->urlGenerator = $urlGenerator;
124 1
		$this->userId = $userId;
125 1
		$this->commentMapper = $commentMapper;
126 1
		$this->optionMapper = $optionMapper;
127 1
		$this->eventMapper = $eventMapper;
128 1
		$this->notificationMapper = $notificationMapper;
129 1
		$this->voteMapper = $VoteMapper;
130 1
		$this->mailer = $mailer;
131 1
	}
132
133
	/**
134
	* @NoAdminRequired
135
	* @NoCSRFRequired
136
	*/
137 1
	public function index() {
138 1
		return new TemplateResponse('polls', 'polls.tmpl',
139 1
		['urlGenerator' => $this->urlGenerator]);
140
	}
141
142
	/**
143
	* @NoAdminRequired
144
	* @NoCSRFRequired
145
	*/
146
	public function createPoll() {
147
		return new TemplateResponse('polls', 'polls.tmpl',
148
		['urlGenerator' => $this->urlGenerator]);
149
	}
150
151
	/**
152
	* @NoAdminRequired
153
	* @NoCSRFRequired
154
	*/
155
	public function clonePoll() {
156
		return new TemplateResponse('polls', 'polls.tmpl',
157
		['urlGenerator' => $this->urlGenerator]);
158
	}
159
160
	/**
161
	 * @NoAdminRequired
162
	 * @NoCSRFRequired
163
	 * @param string $hash
164
	 * @return TemplateResponse
165
	 */
166
	public function editPoll($hash) {
167
		return new TemplateResponse('polls', 'polls.tmpl', [
168
			'urlGenerator' => $this->urlGenerator,
169
 			'hash' => $hash
170
		]);
171
	}
172
173
	/**
174
	 * @param int $pollId
175
	 * @param string $from
176
	 */
177
	private function sendNotifications($pollId, $from) {
178
		$poll = $this->eventMapper->find($pollId);
179
		$notifications = $this->notificationMapper->findAllByPoll($pollId);
180
		foreach ($notifications as $notification) {
181
			if ($from === $notification->getUserId()) {
182
				continue;
183
			}
184
			$recUser = $this->userMgr->get($notification->getUserId());
185
			if (!$recUser instanceof IUser) {
186
				continue;
187
			}
188
			$email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
189
			if ($email === null || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
190
				continue;
191
			}
192
			$url = $this->urlGenerator->getAbsoluteURL(
193
				$this->urlGenerator->linkToRoute('polls.page.goto_poll',
194
					array('hash' => $poll->getHash()))
195
			);
196
197
			$sendUser = $this->userMgr->get($from);
198
			$sender = $from;
199
			if ($sendUser instanceof IUser) {
200
				$sender = $sendUser->getDisplayName();
201
			}
202
203
			$lang = $this->config->getUserValue($notification->getUserId(), 'core', 'lang');
204
			$trans = $this->transFactory->get('polls', $lang);
205
			$emailTemplate = $this->mailer->createEMailTemplate('polls.Notification', [
206
				'user' => $sender,
207
				'title' => $poll->getTitle(),
208
				'link' => $url,
209
			]);
210
			$emailTemplate->setSubject($trans->t('Polls App - New Activity'));
211
			$emailTemplate->addHeader();
212
			$emailTemplate->addHeading($trans->t('Polls App - New Activity'), false);
213
214
			$emailTemplate->addBodyText(str_replace(
215
				['{user}', '{title}'],
216
				[$sender, $poll->getTitle()],
217
				$trans->t('{user} participated in the poll "{title}"')
218
			));
219
220
			$emailTemplate->addBodyButton(
221
				htmlspecialchars($trans->t('Go to poll')),
222
				$url,
223
				false
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $plainText of OCP\Mail\IEMailTemplate::addBodyButton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

223
				/** @scrutinizer ignore-type */ false
Loading history...
224
			);
225
226
			$emailTemplate->addFooter();
227
			try {
228
				$message = $this->mailer->createMessage();
229
				$message->setTo([$email => $recUser->getDisplayName()]);
230
				$message->useTemplate($emailTemplate);
231
				$this->mailer->send($message);
232
			} catch (\Exception $e) {
233
				$this->logger->logException($e, ['app' => 'polls']);
234
			}
235
		}
236
	}
237
238
	/**
239
	 * @NoAdminRequired
240
	 * @NoCSRFRequired
241
	 * @PublicPage
242
	 * @param string $hash
243
	 * @return TemplateResponse
244
	 */
245
	public function gotoPoll($hash) {
246
		try {
247
			$poll = $this->eventMapper->findByHash($hash);
248
		} catch (DoesNotExistException $e) {
249
			return new TemplateResponse('polls', 'no.acc.tmpl', []);
250
		}
251
		$options = $this->optionMapper->findByPoll($poll->getId());
252
		$votes = $this->voteMapper->findByPoll($poll->getId());
253
		$participants = $this->voteMapper->findParticipantsByPoll($poll->getId());
254
		$comments = $this->commentMapper->findByPoll($poll->getId());
255
256
		try {
257
			$notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
258
		} catch (DoesNotExistException $e) {
259
			$notification = null;
260
		}
261
		if ($this->hasUserAccess($poll)) {
262
			return new TemplateResponse('polls', 'vote.tmpl', [
263
				'poll' => $poll,
264
				'options' => $options,
265
				'comments' => $comments,
266
				'votes' => $votes,
267
				'participant' => $participants,
268
				'notification' => $notification,
269
				'userId' => $this->userId,
270
				'userMgr' => $this->userMgr,
271
				'urlGenerator' => $this->urlGenerator,
272
				'avatarManager' => $this->avatarManager
273
			]);
274
		} else {
275
			User::checkLoggedIn();
0 ignored issues
show
Deprecated Code introduced by
The function OCP\User::checkLoggedIn() has been deprecated: 13.0.0 Use annotation based ACLs from the AppFramework instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

275
			/** @scrutinizer ignore-deprecated */ User::checkLoggedIn();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
276
			return new TemplateResponse('polls', 'no.acc.tmpl', []);
277
		}
278
	}
279
280
	/**
281
	 * @NoAdminRequired
282
	 * @NoCSRFRequired
283
	 * @param int $pollId
284
	 * @return TemplateResponse|RedirectResponse
285
	 */
286
	public function deletePoll($pollId) {
287
		$pollToDelete = $this->eventMapper->find($pollId);
288
		if ($this->userId !== $pollToDelete->getOwner() && !$this->groupManager->isAdmin($this->userId)) {
289
			return new TemplateResponse('polls', 'no.delete.tmpl');
290
		}
291
		$poll = new Event();
292
		$poll->setId($pollId);
293
		$this->commentMapper->deleteByPoll($pollId);
294
		$this->voteMapper->deleteByPoll($pollId);
295
		$this->optionMapper->deleteByPoll($pollId);
296
		$this->eventMapper->delete($poll);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::delete() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

296
		/** @scrutinizer ignore-deprecated */ $this->eventMapper->delete($poll);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
297
		$url = $this->urlGenerator->linkToRoute('polls.page.index');
298
		return new RedirectResponse($url);
299
	}
300
301
	/**
302
	 * @NoAdminRequired
303
	 * @NoCSRFRequired
304
	 * @PublicPage
305
	 * @param int $pollId
306
	 * @param string $userId
307
	 * @param string $answers
308
	 * @param string $options
309
	 * @param bool $receiveNotifications
310
	 * @param bool $changed
311
	 * @return RedirectResponse
312
	 */
313
	public function insertVote($pollId, $userId, $answers, $options, $receiveNotifications, $changed) {
314
		if ($this->userId !== null) {
315
			if ($receiveNotifications) {
316
				try {
317
					//check if user already set notification for this poll
318
					$this->notificationMapper->findByUserAndPoll($pollId, $userId);
319
				} catch (DoesNotExistException $e) {
320
					//insert if not exist
321
					$not = new Notification();
322
					$not->setUserId($userId);
323
					$not->setPollId($pollId);
324
					$this->notificationMapper->insert($not);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

324
					/** @scrutinizer ignore-deprecated */ $this->notificationMapper->insert($not);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
325
				}
326
			} else {
327
				try {
328
					//delete if entry is in db
329
					$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
330
					$this->notificationMapper->delete($not);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::delete() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

330
					/** @scrutinizer ignore-deprecated */ $this->notificationMapper->delete($not);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
331
				} catch (DoesNotExistException $e) {
332
					//doesn't exist in db, nothing to do
333
				}
334
			}
335
		}
336
		$poll = $this->eventMapper->find($pollId);
337
338
		if ($changed) {
339
			$options = json_decode($options);
340
			$answers = json_decode($answers);
341
			$count_options = count($options);
342
			$this->voteMapper->deleteByPollAndUser($pollId, $userId);
343
344
			for ($i = 0; $i < $count_options; $i++) {
345
				$vote = new Vote();
346
				$vote->setPollId($pollId);
347
				$vote->setUserId($userId);
348
				$vote->setVoteOptionText(htmlspecialchars($options[$i]));
349
				$vote->setVoteAnswer($answers[$i]);
350
				$this->voteMapper->insert($vote);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

350
				/** @scrutinizer ignore-deprecated */ $this->voteMapper->insert($vote);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
351
352
			}
353
			$this->sendNotifications($pollId, $userId);
354
		}
355
		$hash = $poll->getHash();
356
		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
357
		return new RedirectResponse($url);
358
	}
359
360
	/**
361
	 * @NoAdminRequired
362
	 * @NoCSRFRequired
363
	 * @PublicPage
364
	 * @param int $pollId
365
	 * @param string $userId
366
	 * @param string $commentBox
367
	 * @return JSONResponse
368
	 */
369
	public function insertComment($pollId, $userId, $commentBox) {
370
		$comment = new Comment();
371
		$comment->setPollId($pollId);
372
		$comment->setUserId($userId);
373
		$comment->setComment($commentBox);
374
		$comment->setDt(date('Y-m-d H:i:s'));
375
		$this->commentMapper->insert($comment);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\AppFramework\Db\Mapper::insert() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

375
		/** @scrutinizer ignore-deprecated */ $this->commentMapper->insert($comment);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
376
		$this->sendNotifications($pollId, $userId);
377
		$timeStamp = time();
378
		$displayName = $userId;
379
		$user = $this->userMgr->get($userId);
380
		if ($user !== null) {
381
			$displayName = $user->getDisplayName();
382
		}
383
		return new JSONResponse(array(
384
			'userId' => $userId,
385
			'displayName' => $displayName,
386
			'timeStamp' => $timeStamp * 100,
387
			'date' => date('Y-m-d H:i:s', $timeStamp),
388
			'relativeNow' => $this->trans->t('just now'),
389
			'comment' => $commentBox
390
		));
391
	}
392
393
	/**
394
	 * @NoAdminRequired
395
	 * @NoCSRFRequired
396
	 * @param string $searchTerm
397
	 * @param string $groups
398
	 * @param string $users
399
	 * @return array
400
	 */
401
	public function search($searchTerm, $groups, $users) {
402
		return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
403
	}
404
405
	/**
406
	 * @NoAdminRequired
407
	 * @NoCSRFRequired
408
	 * @param string $searchTerm
409
	 * @param string $groups
410
	 * @return array
411
	 */
412
	public function searchForGroups($searchTerm, $groups) {
413
		$selectedGroups = json_decode($groups);
414
		$groups = $this->groupManager->search($searchTerm);
415
		$gids = array();
416
		$sgids = array();
417
		foreach ($selectedGroups as $sg) {
418
			$sgids[] = str_replace('group_', '', $sg);
419
		}
420
		foreach ($groups as $g) {
421
			$gids[] = $g->getGID();
422
		}
423
		$diffGids = array_diff($gids, $sgids);
424
		$gids = array();
425
		foreach ($diffGids as $g) {
426
			$gids[] = ['gid' => $g, 'isGroup' => true];
427
		}
428
		return $gids;
429
	}
430
431
	/**
432
	 * @NoAdminRequired
433
	 * @NoCSRFRequired
434
	 * @param string $searchTerm
435
	 * @param string $users
436
	 * @return array
437
	 */
438
	public function searchForUsers($searchTerm, $users) {
439
		$selectedUsers = json_decode($users);
440
		Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

440
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

440
		Util::writeLog('polls', print_r($selectedUsers, true), /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
441
		$userNames = $this->userMgr->searchDisplayName($searchTerm);
442
		$users = array();
443
		$sUsers = array();
444
		foreach ($selectedUsers as $su) {
445
			$sUsers[] = str_replace('user_', '', $su);
446
		}
447
		foreach ($userNames as $u) {
448
			$allreadyAdded = false;
449
			foreach ($sUsers as &$su) {
450
				if ($su === $u->getUID()) {
451
					unset($su);
452
					$allreadyAdded = true;
453
					break;
454
				}
455
			}
456
			if (!$allreadyAdded) {
457
				$users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
458
			} else {
459
				continue;
460
			}
461
		}
462
		return $users;
463
	}
464
465
	/**
466
	 * @NoAdminRequired
467
	 * @NoCSRFRequired
468
	 * @param string $username
469
	 * @return string
470
	 */
471
	public function getDisplayName($username) {
472
		return $this->userMgr->get($username)->getDisplayName();
473
	}
474
475
	/**
476
	 * @return \OCP\IGroup[]
477
	 */
478
	private function getGroups() {
479
		if (class_exists('\OC_Group')) {
480
			// Nextcloud <= 11, ownCloud
481
			return \OC_Group::getUserGroups($this->userId);
0 ignored issues
show
Bug introduced by
The type OC_Group was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
482
		}
483
		// Nextcloud >= 12
484
		$groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
485
		return array_map(function($group) {
486
			return $group->getGID();
487
		}, $groups);
488
	}
489
490
	/**
491
	 * Check if user has access to this poll
492
	 *
493
	 * @param Event $poll
494
	 * @return bool
495
	 */
496
	private function hasUserAccess($poll) {
497
		$access = $poll->getAccess();
498
		$owner = $poll->getOwner();
499
		if ($access === 'public' || $access === 'hidden') {
500
			return true;
501
		}
502
		if ($this->userId === null) {
503
			return false;
504
		}
505
		if ($access === 'registered') {
506
			return true;
507
		}
508
		if ($owner === $this->userId) {
509
			return true;
510
		}
511
		Util::writeLog('polls', $this->userId, Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

511
		Util::writeLog('polls', $this->userId, /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

511
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', $this->userId, Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
512
		$userGroups = $this->getGroups();
513
		$arr = explode(';', $access);
514
		foreach ($arr as $item) {
515
			if (strpos($item, 'group_') === 0) {
516
				$grp = substr($item, 6);
517
				foreach ($userGroups as $userGroup) {
518
					if ($userGroup === $grp) {
519
						return true;
520
					}
521
				}
522
			} else {
523
				if (strpos($item, 'user_') === 0) {
524
					$usr = substr($item, 5);
525
					if ($usr === $this->userId) {
526
						return true;
527
					}
528
				}
529
			}
530
		}
531
		return false;
532
	}
533
	/**
534
	 * Check if user is owner of this poll
535
	 *
536
	 * @param Event $poll
537
	 * @return bool
538
	 */
539
540
	private function userIsOwner($poll) {
541
		$owner = $poll->getOwner();
542
543
		if ($owner === $this->userId) {
544
			return true;
545
		}
546
		Util::writeLog('polls', $this->userId, Util::ERROR);
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Util::ERROR has been deprecated: 14.0.0 use \OCP\ILogger::ERROR ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

546
		Util::writeLog('polls', $this->userId, /** @scrutinizer ignore-deprecated */ Util::ERROR);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

546
		/** @scrutinizer ignore-deprecated */ Util::writeLog('polls', $this->userId, Util::ERROR);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
547
		return false;
548
	}
549
}
550