| Total Complexity | 92 |
| Total Lines | 700 |
| Duplicated Lines | 10.57 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 1 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PageController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PageController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 56 | class PageController extends Controller { |
||
| 57 | |||
| 58 | private $userId; |
||
| 59 | private $commentMapper; |
||
| 60 | private $dateMapper; |
||
| 61 | private $eventMapper; |
||
| 62 | private $notificationMapper; |
||
| 63 | private $participationMapper; |
||
| 64 | private $participationTextMapper; |
||
| 65 | private $textMapper; |
||
| 66 | private $urlGenerator; |
||
| 67 | private $manager; |
||
| 68 | private $avatarManager; |
||
| 69 | private $logger; |
||
| 70 | private $trans; |
||
| 71 | private $userMgr; |
||
| 72 | private $groupManager; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * PageController constructor. |
||
| 76 | * @param $appName |
||
| 77 | * @param IRequest $request |
||
| 78 | * @param IUserManager $manager |
||
| 79 | * @param IGroupManager $groupManager |
||
| 80 | * @param IAvatarManager $avatarManager |
||
| 81 | * @param ILogger $logger |
||
| 82 | * @param IL10N $trans |
||
| 83 | * @param IURLGenerator $urlGenerator |
||
| 84 | * @param $userId |
||
| 85 | * @param CommentMapper $commentMapper |
||
| 86 | * @param DateMapper $dateMapper |
||
| 87 | * @param EventMapper $eventMapper |
||
| 88 | * @param NotificationMapper $notificationMapper |
||
| 89 | * @param ParticipationMapper $ParticipationMapper |
||
| 90 | * @param ParticipationTextMapper $ParticipationTextMapper |
||
| 91 | * @param TextMapper $textMapper |
||
| 92 | */ |
||
| 93 | public function __construct( |
||
| 94 | $appName, |
||
| 95 | IRequest $request, |
||
| 96 | IUserManager $manager, |
||
| 97 | IGroupManager $groupManager, |
||
| 98 | IAvatarManager $avatarManager, |
||
| 99 | ILogger $logger, |
||
| 100 | IL10N $trans, |
||
| 101 | IURLGenerator $urlGenerator, |
||
| 102 | $userId, |
||
| 103 | CommentMapper $commentMapper, |
||
| 104 | DateMapper $dateMapper, |
||
| 105 | EventMapper $eventMapper, |
||
| 106 | NotificationMapper $notificationMapper, |
||
| 107 | ParticipationMapper $ParticipationMapper, |
||
| 108 | ParticipationTextMapper $ParticipationTextMapper, |
||
| 109 | TextMapper $textMapper |
||
| 110 | ) { |
||
| 111 | parent::__construct($appName, $request); |
||
| 112 | $this->manager = $manager; |
||
| 113 | $this->groupManager = $groupManager; |
||
| 114 | $this->avatarManager = $avatarManager; |
||
| 115 | $this->logger = $logger; |
||
| 116 | $this->trans = $trans; |
||
| 117 | $this->urlGenerator = $urlGenerator; |
||
| 118 | $this->userId = $userId; |
||
| 119 | $this->commentMapper = $commentMapper; |
||
| 120 | $this->dateMapper = $dateMapper; |
||
| 121 | $this->eventMapper = $eventMapper; |
||
| 122 | $this->notificationMapper = $notificationMapper; |
||
| 123 | $this->participationMapper = $ParticipationMapper; |
||
| 124 | $this->participationTextMapper = $ParticipationTextMapper; |
||
| 125 | $this->textMapper = $textMapper; |
||
| 126 | $this->userMgr = \OC::$server->getUserManager(); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @NoAdminRequired |
||
| 131 | * @NoCSRFRequired |
||
| 132 | */ |
||
| 133 | public function index() { |
||
| 134 | $polls = $this->eventMapper->findAllForUserWithInfo($this->userId); |
||
| 135 | $comments = $this->commentMapper->findDistinctByUser($this->userId); |
||
| 136 | $partic = $this->participationMapper->findDistinctByUser($this->userId); |
||
| 137 | $particText = $this->participationTextMapper->findDistinctByUser($this->userId); |
||
| 138 | $response = new TemplateResponse('polls', 'main.tmpl', [ |
||
| 139 | 'polls' => $polls, |
||
| 140 | 'comments' => $comments, |
||
| 141 | 'participations' => $partic, |
||
| 142 | 'participations_text' => $particText, |
||
| 143 | 'userId' => $this->userId, |
||
| 144 | 'userMgr' => $this->manager, |
||
| 145 | 'urlGenerator' => $this->urlGenerator |
||
| 146 | ]); |
||
| 147 | if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
||
| 148 | $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
||
| 149 | $response->setContentSecurityPolicy($csp); |
||
| 150 | } |
||
| 151 | return $response; |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param string $pollId |
||
| 156 | * @param string $from |
||
| 157 | */ |
||
| 158 | private function sendNotifications($pollId, $from) { |
||
| 159 | $poll = $this->eventMapper->find($pollId); |
||
| 160 | $notifications = $this->notificationMapper->findAllByPoll($pollId); |
||
| 161 | foreach ($notifications as $notification) { |
||
| 162 | if ($from === $notification->getUserId()) { |
||
| 163 | continue; |
||
| 164 | } |
||
| 165 | $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email'); |
||
| 166 | if (strlen($email) === 0 || !isset($email)) { |
||
| 167 | continue; |
||
| 168 | } |
||
| 169 | $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll', |
||
| 170 | array('hash' => $poll->getHash()))); |
||
| 171 | |||
| 172 | $recUser = $this->userMgr->get($notification->getUserId()); |
||
| 173 | $sendUser = $this->userMgr->get($from); |
||
| 174 | $rec = ""; |
||
| 175 | if ($recUser !== null) { |
||
| 176 | $rec = $recUser->getDisplayName(); |
||
| 177 | } |
||
| 178 | if ($sendUser !== null) { |
||
| 179 | $sender = $sendUser->getDisplayName(); |
||
| 180 | } else { |
||
| 181 | $sender = $from; |
||
| 182 | } |
||
| 183 | $msg = $this->trans->t('Hello %s,<br/><br/><strong>%s</strong> participated in the poll \'%s\'.<br/><br/>To go directly to the poll, you can use this <a href="%s">link</a>', |
||
| 184 | array( |
||
| 185 | $rec, |
||
| 186 | $sender, |
||
| 187 | $poll->getTitle(), |
||
| 188 | $url |
||
| 189 | )); |
||
| 190 | |||
| 191 | $msg .= "<br/><br/>"; |
||
| 192 | |||
| 193 | $toName = $this->userMgr->get($notification->getUserId())->getDisplayName(); |
||
| 194 | $subject = $this->trans->t('Polls App - New Comment'); |
||
| 195 | $fromAddress = Util::getDefaultEmailAddress('no-reply'); |
||
| 196 | $fromName = $this->trans->t("Polls App") . ' (' . $from . ')'; |
||
| 197 | |||
| 198 | try { |
||
| 199 | $mailer = \OC::$server->getMailer(); |
||
| 200 | $message = $mailer->createMessage(); |
||
| 201 | $message->setSubject($subject); |
||
| 202 | $message->setFrom(array($fromAddress => $fromName)); |
||
| 203 | $message->setTo(array($email => $toName)); |
||
| 204 | $message->setHtmlBody($msg); |
||
| 205 | $mailer->send($message); |
||
| 206 | } catch (\Exception $e) { |
||
| 207 | $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')'; |
||
| 208 | Util::writeLog("polls", $message, Util::ERROR); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @NoAdminRequired |
||
| 215 | * @NoCSRFRequired |
||
| 216 | * @PublicPage |
||
| 217 | * @param string $hash |
||
| 218 | * @return TemplateResponse |
||
| 219 | */ |
||
| 220 | public function gotoPoll($hash) { |
||
| 221 | $poll = $this->eventMapper->findByHash($hash); |
||
| 222 | if ($poll->getType() == '0') { |
||
| 223 | $dates = $this->dateMapper->findByPoll($poll->getId()); |
||
| 224 | $votes = $this->participationMapper->findByPoll($poll->getId()); |
||
| 225 | } else { |
||
| 226 | $dates = $this->textMapper->findByPoll($poll->getId()); |
||
| 227 | $votes = $this->participationTextMapper->findByPoll($poll->getId()); |
||
| 228 | } |
||
| 229 | $comments = $this->commentMapper->findByPoll($poll->getId()); |
||
| 230 | try { |
||
| 231 | $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId); |
||
| 232 | } catch (DoesNotExistException $e) { |
||
| 233 | $notification = null; |
||
| 234 | } |
||
| 235 | if ($this->hasUserAccess($poll)) { |
||
| 236 | return new TemplateResponse('polls', 'goto.tmpl', [ |
||
| 237 | 'poll' => $poll, |
||
| 238 | 'dates' => $dates, |
||
| 239 | 'comments' => $comments, |
||
| 240 | 'votes' => $votes, |
||
| 241 | 'notification' => $notification, |
||
| 242 | 'userId' => $this->userId, |
||
| 243 | 'userMgr' => $this->manager, |
||
| 244 | 'urlGenerator' => $this->urlGenerator, |
||
| 245 | 'avatarManager' => $this->avatarManager |
||
| 246 | ]); |
||
| 247 | } else { |
||
| 248 | User::checkLoggedIn(); |
||
| 249 | return new TemplateResponse('polls', 'no.acc.tmpl', []); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @NoAdminRequired |
||
| 255 | * @NoCSRFRequired |
||
| 256 | * @param string $pollId |
||
| 257 | * @return RedirectResponse |
||
| 258 | */ |
||
| 259 | public function deletePoll($pollId) { |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @NoAdminRequired |
||
| 274 | * @NoCSRFRequired |
||
| 275 | * @param string $hash |
||
| 276 | * @return TemplateResponse |
||
| 277 | */ |
||
| 278 | public function editPoll($hash) { |
||
| 294 | ]); |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @NoAdminRequired |
||
| 299 | * @NoCSRFRequired |
||
| 300 | * @param $pollId |
||
| 301 | * @param $pollType |
||
| 302 | * @param $pollTitle |
||
| 303 | * @param $pollDesc |
||
| 304 | * @param $userId |
||
| 305 | * @param $chosenDates |
||
| 306 | * @param $expireTs |
||
| 307 | * @param $accessType |
||
| 308 | * @param $accessValues |
||
| 309 | * @param $isAnonymous |
||
| 310 | * @param $hideNames |
||
| 311 | * @return RedirectResponse |
||
| 312 | */ |
||
| 313 | public function updatePoll( |
||
| 314 | $pollId, |
||
| 315 | $pollType, |
||
| 316 | $pollTitle, |
||
| 317 | $pollDesc, |
||
| 318 | $userId, |
||
| 319 | $chosenDates, |
||
| 320 | $expireTs, |
||
| 321 | $accessType, |
||
| 322 | $accessValues, |
||
| 323 | $isAnonymous, |
||
| 324 | $hideNames |
||
| 325 | ) { |
||
| 326 | $event = $this->eventMapper->find($pollId); |
||
| 327 | $event->setTitle(htmlspecialchars($pollTitle)); |
||
| 328 | $event->setDescription(htmlspecialchars($pollDesc)); |
||
| 329 | $event->setIsAnonymous($isAnonymous ? 1 : 0); |
||
| 330 | $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
||
| 331 | |||
| 332 | View Code Duplication | if ($accessType === 'select') { |
|
| 333 | if (isset($accessValues)) { |
||
| 334 | $accessValues = json_decode($accessValues); |
||
| 335 | if ($accessValues !== null) { |
||
| 336 | $groups = array(); |
||
| 337 | $users = array(); |
||
| 338 | if ($accessValues->groups !== null) { |
||
| 339 | $groups = $accessValues->groups; |
||
| 340 | } |
||
| 341 | if ($accessValues->users !== null) { |
||
| 342 | $users = $accessValues->users; |
||
| 343 | } |
||
| 344 | $accessType = ''; |
||
| 345 | foreach ($groups as $gid) { |
||
| 346 | $accessType .= $gid . ';'; |
||
| 347 | } |
||
| 348 | foreach ($users as $uid) { |
||
| 349 | $accessType .= $uid . ';'; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | } |
||
| 353 | } |
||
| 354 | $event->setAccess($accessType); |
||
| 355 | |||
| 356 | $chosenDates = json_decode($chosenDates); |
||
| 357 | |||
| 358 | $expire = null; |
||
| 359 | View Code Duplication | if ($expireTs !== null && $expireTs !== '') { |
|
| 360 | $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
||
| 361 | } |
||
| 362 | $event->setExpire($expire); |
||
| 363 | |||
| 364 | $this->dateMapper->deleteByPoll($pollId); |
||
| 365 | $this->textMapper->deleteByPoll($pollId); |
||
| 366 | if ($pollType === 'event') { |
||
| 367 | $event->setType(0); |
||
| 368 | $this->eventMapper->update($event); |
||
| 369 | sort($chosenDates); |
||
| 370 | View Code Duplication | foreach ($chosenDates as $el) { |
|
| 371 | $date = new Date(); |
||
| 372 | $date->setPollId($pollId); |
||
| 373 | $date->setDt(date('Y-m-d H:i:s', $el)); |
||
| 374 | $this->dateMapper->insert($date); |
||
| 375 | } |
||
| 376 | } else { |
||
| 377 | $event->setType(1); |
||
| 378 | $this->eventMapper->update($event); |
||
| 379 | foreach ($chosenDates as $el) { |
||
| 380 | $text = new Text(); |
||
| 381 | $text->setText($el); |
||
| 382 | $text->setPollId($pollId); |
||
| 383 | $this->textMapper->insert($text); |
||
| 384 | } |
||
| 385 | } |
||
| 386 | $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
||
| 387 | return new RedirectResponse($url); |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @NoAdminRequired |
||
| 392 | * @NoCSRFRequired |
||
| 393 | */ |
||
| 394 | public function createPoll() { |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @NoAdminRequired |
||
| 401 | * @NoCSRFRequired |
||
| 402 | * @param $pollType |
||
| 403 | * @param $pollTitle |
||
| 404 | * @param $pollDesc |
||
| 405 | * @param $userId |
||
| 406 | * @param $chosenDates |
||
| 407 | * @param $expireTs |
||
| 408 | * @param $accessType |
||
| 409 | * @param $accessValues |
||
| 410 | * @param $isAnonymous |
||
| 411 | * @param $hideNames |
||
| 412 | * @return RedirectResponse |
||
| 413 | */ |
||
| 414 | public function insertPoll( |
||
| 415 | $pollType, |
||
| 416 | $pollTitle, |
||
| 417 | $pollDesc, |
||
| 418 | $userId, |
||
| 419 | $chosenDates, |
||
| 420 | $expireTs, |
||
| 421 | $accessType, |
||
| 422 | $accessValues, |
||
| 423 | $isAnonymous, |
||
| 424 | $hideNames |
||
| 425 | ) { |
||
| 426 | $event = new Event(); |
||
| 427 | $event->setTitle(htmlspecialchars($pollTitle)); |
||
| 428 | $event->setDescription(htmlspecialchars($pollDesc)); |
||
| 429 | $event->setOwner($userId); |
||
| 430 | $event->setCreated(date('Y-m-d H:i:s')); |
||
| 431 | $event->setHash(\OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(16, |
||
| 432 | ISecureRandom::CHAR_DIGITS . |
||
| 433 | ISecureRandom::CHAR_LOWER . |
||
| 434 | ISecureRandom::CHAR_UPPER)); |
||
| 435 | $event->setIsAnonymous($isAnonymous ? 1 : 0); |
||
| 436 | $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
||
| 437 | |||
| 438 | View Code Duplication | if ($accessType === 'select') { |
|
| 439 | if (isset($accessValues)) { |
||
| 440 | $accessValues = json_decode($accessValues); |
||
| 441 | if ($accessValues !== null) { |
||
| 442 | $groups = array(); |
||
| 443 | $users = array(); |
||
| 444 | if ($accessValues->groups !== null) { |
||
| 445 | $groups = $accessValues->groups; |
||
| 446 | } |
||
| 447 | if ($accessValues->users !== null) { |
||
| 448 | $users = $accessValues->users; |
||
| 449 | } |
||
| 450 | $accessType = ''; |
||
| 451 | foreach ($groups as $gid) { |
||
| 452 | $accessType .= $gid . ';'; |
||
| 453 | } |
||
| 454 | foreach ($users as $uid) { |
||
| 455 | $accessType .= $uid . ';'; |
||
| 456 | } |
||
| 457 | } |
||
| 458 | } |
||
| 459 | } |
||
| 460 | $event->setAccess($accessType); |
||
| 461 | |||
| 462 | $chosenDates = json_decode($chosenDates); |
||
| 463 | |||
| 464 | $expire = null; |
||
| 465 | View Code Duplication | if ($expireTs !== null && $expireTs !== '') { |
|
| 466 | $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
||
| 467 | } |
||
| 468 | $event->setExpire($expire); |
||
| 469 | |||
| 470 | if ($pollType === 'event') { |
||
| 471 | $event->setType(0); |
||
| 472 | $ins = $this->eventMapper->insert($event); |
||
| 473 | $poll_id = $ins->getId(); |
||
| 474 | sort($chosenDates); |
||
| 475 | View Code Duplication | foreach ($chosenDates as $el) { |
|
| 476 | $date = new Date(); |
||
| 477 | $date->setPollId($poll_id); |
||
| 478 | $date->setDt(date('Y-m-d H:i:s', $el)); |
||
| 479 | $this->dateMapper->insert($date); |
||
| 480 | } |
||
| 481 | } else { |
||
| 482 | $event->setType(1); |
||
| 483 | $ins = $this->eventMapper->insert($event); |
||
| 484 | $poll_id = $ins->getId(); |
||
| 485 | $cnt = 1; |
||
| 486 | foreach ($chosenDates as $el) { |
||
| 487 | $text = new Text(); |
||
| 488 | $text->setText($el . '_' . $cnt); |
||
| 489 | $text->setPollId($poll_id); |
||
| 490 | $this->textMapper->insert($text); |
||
| 491 | $cnt++; |
||
| 492 | } |
||
| 493 | } |
||
| 494 | $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
||
| 495 | return new RedirectResponse($url); |
||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @NoAdminRequired |
||
| 500 | * @NoCSRFRequired |
||
| 501 | * @PublicPage |
||
| 502 | * @param $pollId |
||
| 503 | * @param $userId |
||
| 504 | * @param $types |
||
| 505 | * @param $dates |
||
| 506 | * @param $receiveNotifications |
||
| 507 | * @param $changed |
||
| 508 | * @return RedirectResponse |
||
| 509 | */ |
||
| 510 | public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) { |
||
| 511 | if ($this->userId !== null) { |
||
| 512 | if ($receiveNotifications === 'true') { |
||
| 513 | try { |
||
| 514 | //check if user already set notification for this poll |
||
| 515 | $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
||
| 516 | } catch (DoesNotExistException $e) { |
||
| 517 | //insert if not exist |
||
| 518 | $not = new Notification(); |
||
| 519 | $not->setUserId($userId); |
||
| 520 | $not->setPollId($pollId); |
||
| 521 | $this->notificationMapper->insert($not); |
||
| 522 | } |
||
| 523 | } else { |
||
| 524 | try { |
||
| 525 | //delete if entry is in db |
||
| 526 | $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
||
| 527 | $this->notificationMapper->delete($not); |
||
| 528 | } catch (DoesNotExistException $e) { |
||
| 529 | //doesn't exist in db, nothing to do |
||
| 530 | } |
||
| 531 | } |
||
| 532 | } |
||
| 533 | $poll = $this->eventMapper->find($pollId); |
||
| 534 | if ($changed === 'true') { |
||
| 535 | $dates = json_decode($dates); |
||
| 536 | $types = json_decode($types); |
||
| 537 | $count_dates = count($dates); |
||
| 538 | if ($poll->getType() == '0') { |
||
| 539 | $this->participationMapper->deleteByPollAndUser($pollId, $userId); |
||
| 540 | } else { |
||
| 541 | $this->participationTextMapper->deleteByPollAndUser($pollId, $userId); |
||
| 542 | } |
||
| 543 | for ($i = 0; $i < $count_dates; $i++) { |
||
| 544 | if ($poll->getType() == '0') { |
||
| 545 | $part = new Participation(); |
||
| 546 | $part->setPollId($pollId); |
||
| 547 | $part->setUserId($userId); |
||
| 548 | $part->setDt(date('Y-m-d H:i:s', $dates[$i])); |
||
| 549 | $part->setType($types[$i]); |
||
| 550 | $this->participationMapper->insert($part); |
||
| 551 | } else { |
||
| 552 | $part = new ParticipationText(); |
||
| 553 | $part->setPollId($pollId); |
||
| 554 | $part->setUserId($userId); |
||
| 555 | $part->setText($dates[$i]); |
||
| 556 | $part->setType($types[$i]); |
||
| 557 | $this->participationTextMapper->insert($part); |
||
| 558 | } |
||
| 559 | |||
| 560 | } |
||
| 561 | $this->sendNotifications($pollId, $userId); |
||
| 562 | } |
||
| 563 | $hash = $poll->getHash(); |
||
| 564 | $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]); |
||
| 565 | return new RedirectResponse($url); |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @NoAdminRequired |
||
| 570 | * @NoCSRFRequired |
||
| 571 | * @PublicPage |
||
| 572 | * @param $pollId |
||
| 573 | * @param $userId |
||
| 574 | * @param $commentBox |
||
| 575 | * @return JSONResponse |
||
| 576 | */ |
||
| 577 | public function insertComment($pollId, $userId, $commentBox) { |
||
| 578 | $comment = new Comment(); |
||
| 579 | $comment->setPollId($pollId); |
||
| 580 | $comment->setUserId($userId); |
||
| 581 | $comment->setComment($commentBox); |
||
| 582 | $comment->setDt(date('Y-m-d H:i:s')); |
||
| 583 | $this->commentMapper->insert($comment); |
||
| 584 | $this->sendNotifications($pollId, $userId); |
||
| 585 | if ($this->manager->get($userId) !== null) { |
||
| 586 | $newUserId = $this->manager->get($userId)->getDisplayName(); |
||
| 587 | } else { |
||
| 588 | $newUserId = $userId; |
||
| 589 | } |
||
| 590 | return new JSONResponse(array( |
||
| 591 | 'comment' => $commentBox, |
||
| 592 | 'date' => date('Y-m-d H:i:s'), |
||
| 593 | 'userName' => $newUserId |
||
| 594 | )); |
||
| 595 | } |
||
| 596 | |||
| 597 | /** |
||
| 598 | * @NoAdminRequired |
||
| 599 | * @NoCSRFRequired |
||
| 600 | * @param $searchTerm |
||
| 601 | * @param $groups |
||
| 602 | * @param $users |
||
| 603 | * @return array |
||
| 604 | */ |
||
| 605 | public function search($searchTerm, $groups, $users) { |
||
| 606 | return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users)); |
||
| 607 | } |
||
| 608 | |||
| 609 | /** |
||
| 610 | * @NoAdminRequired |
||
| 611 | * @NoCSRFRequired |
||
| 612 | * @param $searchTerm |
||
| 613 | * @param $groups |
||
| 614 | * @return array |
||
| 615 | */ |
||
| 616 | public function searchForGroups($searchTerm, $groups) { |
||
| 617 | $selectedGroups = json_decode($groups); |
||
| 618 | $groups = $this->groupManager->search($searchTerm); |
||
| 619 | $gids = array(); |
||
| 620 | $sgids = array(); |
||
| 621 | foreach ($selectedGroups as $sg) { |
||
| 622 | $sgids[] = str_replace('group_', '', $sg); |
||
| 623 | } |
||
| 624 | foreach ($groups as $g) { |
||
| 625 | $gids[] = $g->getGID(); |
||
| 626 | } |
||
| 627 | $diffGids = array_diff($gids, $sgids); |
||
| 628 | $gids = array(); |
||
| 629 | foreach ($diffGids as $g) { |
||
| 630 | $gids[] = ['gid' => $g, 'isGroup' => true]; |
||
| 631 | } |
||
| 632 | return $gids; |
||
| 633 | } |
||
| 634 | |||
| 635 | /** |
||
| 636 | * @NoAdminRequired |
||
| 637 | * @NoCSRFRequired |
||
| 638 | * @param $searchTerm |
||
| 639 | * @param $users |
||
| 640 | * @return array |
||
| 641 | */ |
||
| 642 | public function searchForUsers($searchTerm, $users) { |
||
| 643 | $selectedUsers = json_decode($users); |
||
| 644 | Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR); |
||
| 645 | $userNames = $this->userMgr->searchDisplayName($searchTerm); |
||
| 646 | $users = array(); |
||
| 647 | $sUsers = array(); |
||
| 648 | foreach ($selectedUsers as $su) { |
||
| 649 | $sUsers[] = str_replace('user_', '', $su); |
||
| 650 | } |
||
| 651 | foreach ($userNames as $u) { |
||
| 652 | $alreadyAdded = false; |
||
| 653 | foreach ($sUsers as &$su) { |
||
| 654 | if ($su === $u->getUID()) { |
||
| 655 | unset($su); |
||
| 656 | $alreadyAdded = true; |
||
| 657 | break; |
||
| 658 | } |
||
| 659 | } |
||
| 660 | if (!$alreadyAdded) { |
||
| 661 | $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false); |
||
| 662 | } else { |
||
| 663 | continue; |
||
| 664 | } |
||
| 665 | } |
||
| 666 | return $users; |
||
| 667 | } |
||
| 668 | |||
| 669 | /** |
||
| 670 | * @NoAdminRequired |
||
| 671 | * @NoCSRFRequired |
||
| 672 | * @param $username |
||
| 673 | * @return string |
||
| 674 | */ |
||
| 675 | public function getDisplayName($username) { |
||
| 676 | return $this->manager->get($username)->getDisplayName(); |
||
| 677 | } |
||
| 678 | |||
| 679 | /** |
||
| 680 | * @return Event[] |
||
| 681 | */ |
||
| 682 | public function getPollsForUser() { |
||
| 683 | return $this->eventMapper->findAllForUser($this->userId); |
||
| 684 | } |
||
| 685 | |||
| 686 | /** |
||
| 687 | * @param $user |
||
| 688 | * @return Event[] |
||
| 689 | */ |
||
| 690 | public function getPollsForUserWithInfo($user = null) { |
||
| 691 | if ($user === null) { |
||
| 692 | return $this->eventMapper->findAllForUserWithInfo($this->userId); |
||
| 693 | } else { |
||
| 694 | return $this->eventMapper->findAllForUserWithInfo($user); |
||
| 695 | } |
||
| 696 | } |
||
| 697 | /** |
||
| 698 | * @return array |
||
| 699 | */ |
||
| 700 | View Code Duplication | public function getGroups() { |
|
| 711 | } |
||
| 712 | |||
| 713 | /** |
||
| 714 | * @param $poll |
||
| 715 | * @return bool |
||
| 716 | */ |
||
| 717 | private function hasUserAccess($poll) { |
||
| 718 | $access = $poll->getAccess(); |
||
| 756 | } |
||
| 757 | } |
||
| 758 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths