Skip to content

Commit

Permalink
check for notification before other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
v1r0x committed Mar 16, 2016
1 parent 893bd67 commit c133262
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,31 @@ public function insertPoll($pollType, $pollTitle, $pollDesc, $userId, $chosenDat
* @PublicPage
*/
public function insertVote($pollId, $userId, $types, $dates, $notif, $changed) {
if($changed === 'true') {
if($this->userId !== null) {
if($notif === 'true') {
try {
//check if user already set notification for this poll
$this->notificationMapper->findByUserAndPoll($pollId, $userId);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
//insert if not exist
$not = new Notification();
$not->setUserId($userId);
$not->setPollId($pollId);
$this->notificationMapper->insert($not);
}
} else {
try {
//delete if entry is in db
$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
$this->notificationMapper->delete($not);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
//doesn't exist in db, nothing to do
}
if($this->userId !== null) {
if($notif === 'true') {
try {
//check if user already set notification for this poll
$this->notificationMapper->findByUserAndPoll($pollId, $userId);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
//insert if not exist
$not = new Notification();
$not->setUserId($userId);
$not->setPollId($pollId);
$this->notificationMapper->insert($not);
}
} else {
$userId = $userId . ' (extern)';
try {
//delete if entry is in db
$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
$this->notificationMapper->delete($not);
} catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
//doesn't exist in db, nothing to do
}
}
} else {
$userId = $userId . ' (extern)';
}
if($changed === 'true') {
$poll = $this->eventMapper->find($pollId);
$dates = json_decode($dates);
$types = json_decode($types);
Expand Down

0 comments on commit c133262

Please sign in to comment.