Passed
Pull Request — master (#224)
by Kai
05:49
created
tests/Unit/Factories/EventFactory.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@
 block discarded – undo
27 27
  * General factory for the event model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Event')->setDefinitions([
30
-	'type' => 0,
31
-	'title' => Faker::sentence(10),
32
-	'description' => Faker::paragraph(),
33
-	'owner' => Faker::firstNameMale(),
34
-	'created' => function () {
35
-		$date = new DateTime('today');
36
-		return $date->format('Y-m-d H:i:s');
37
-	},
38
-	'access' => 'registered',
39
-	'expire' => function () {
40
-		$date = new DateTime('tomorrow');
41
-		return $date->format('Y-m-d H:i:s');
42
-	},
43
-	'hash' => Faker::regexify('[A-Za-z0-9]{16}'),
44
-	'isAnonymous' => 0,
45
-	'fullAnonymous' => 0
30
+    'type' => 0,
31
+    'title' => Faker::sentence(10),
32
+    'description' => Faker::paragraph(),
33
+    'owner' => Faker::firstNameMale(),
34
+    'created' => function () {
35
+        $date = new DateTime('today');
36
+        return $date->format('Y-m-d H:i:s');
37
+    },
38
+    'access' => 'registered',
39
+    'expire' => function () {
40
+        $date = new DateTime('tomorrow');
41
+        return $date->format('Y-m-d H:i:s');
42
+    },
43
+    'hash' => Faker::regexify('[A-Za-z0-9]{16}'),
44
+    'isAnonymous' => 0,
45
+    'fullAnonymous' => 0
46 46
 ]);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@
 block discarded – undo
31 31
 	'title' => Faker::sentence(10),
32 32
 	'description' => Faker::paragraph(),
33 33
 	'owner' => Faker::firstNameMale(),
34
-	'created' => function () {
34
+	'created' => function() {
35 35
 		$date = new DateTime('today');
36 36
 		return $date->format('Y-m-d H:i:s');
37 37
 	},
38 38
 	'access' => 'registered',
39
-	'expire' => function () {
39
+	'expire' => function() {
40 40
 		$date = new DateTime('tomorrow');
41 41
 		return $date->format('Y-m-d H:i:s');
42 42
 	},
Please login to merge, or discard this patch.
tests/Unit/Controller/PageControllerTest.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -29,85 +29,85 @@
 block discarded – undo
29 29
 
30 30
 class PageControllerTest extends UnitTestCase {
31 31
 
32
-	/** @var PageController */
33
-	private $controller;
32
+    /** @var PageController */
33
+    private $controller;
34 34
 
35
-	private $userId = 'john';
35
+    private $userId = 'john';
36 36
 
37
-	/**
38
-	 * {@inheritDoc}
39
-	 */
40
-	public function setUp() {
41
-		$request = $this->getMockBuilder('OCP\IRequest')
42
-			->disableOriginalConstructor()
43
-			->getMock();
44
-		$userManager = $this->getMockBuilder('OCP\IUserManager')
45
-			->disableOriginalConstructor()
46
-			->getMock();
47
-		$groupManager = $this->getMockBuilder('OCP\IGroupManager')
48
-			->disableOriginalConstructor()
49
-			->getMock();
50
-		$avatarManager = $this->getMockBuilder('OCP\IAvatarManager')
51
-			->disableOriginalConstructor()
52
-			->getMock();
53
-		$logger = $this->getMockBuilder('OCP\ILogger')
54
-			->disableOriginalConstructor()
55
-			->getMock();
56
-		$l10n = $this->getMockBuilder('OCP\IL10N')
57
-			->disableOriginalConstructor()
58
-			->getMock();
59
-		$urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')
60
-			->disableOriginalConstructor()
61
-			->getMock();
62
-		$commentMapper = $this->getMockBuilder('OCA\Polls\Db\CommentMapper')
63
-			->disableOriginalConstructor()
64
-			->getMock();
65
-		$dateMapper = $this->getMockBuilder('OCA\Polls\Db\DateMapper')
66
-			->disableOriginalConstructor()
67
-			->getMock();
68
-		$eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper')
69
-			->disableOriginalConstructor()
70
-			->getMock();
71
-		$notificationMapper = $this->getMockBuilder('OCA\Polls\Db\NotificationMapper')
72
-			->disableOriginalConstructor()
73
-			->getMock();
74
-		$participationMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationMapper')
75
-			->disableOriginalConstructor()
76
-			->getMock();
77
-		$participationTextMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationTextMapper')
78
-			->disableOriginalConstructor()
79
-			->getMock();
80
-		$textMapper = $this->getMockBuilder('OCA\Polls\Db\TextMapper')
81
-			->disableOriginalConstructor()
82
-			->getMock();
37
+    /**
38
+     * {@inheritDoc}
39
+     */
40
+    public function setUp() {
41
+        $request = $this->getMockBuilder('OCP\IRequest')
42
+            ->disableOriginalConstructor()
43
+            ->getMock();
44
+        $userManager = $this->getMockBuilder('OCP\IUserManager')
45
+            ->disableOriginalConstructor()
46
+            ->getMock();
47
+        $groupManager = $this->getMockBuilder('OCP\IGroupManager')
48
+            ->disableOriginalConstructor()
49
+            ->getMock();
50
+        $avatarManager = $this->getMockBuilder('OCP\IAvatarManager')
51
+            ->disableOriginalConstructor()
52
+            ->getMock();
53
+        $logger = $this->getMockBuilder('OCP\ILogger')
54
+            ->disableOriginalConstructor()
55
+            ->getMock();
56
+        $l10n = $this->getMockBuilder('OCP\IL10N')
57
+            ->disableOriginalConstructor()
58
+            ->getMock();
59
+        $urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')
60
+            ->disableOriginalConstructor()
61
+            ->getMock();
62
+        $commentMapper = $this->getMockBuilder('OCA\Polls\Db\CommentMapper')
63
+            ->disableOriginalConstructor()
64
+            ->getMock();
65
+        $dateMapper = $this->getMockBuilder('OCA\Polls\Db\DateMapper')
66
+            ->disableOriginalConstructor()
67
+            ->getMock();
68
+        $eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper')
69
+            ->disableOriginalConstructor()
70
+            ->getMock();
71
+        $notificationMapper = $this->getMockBuilder('OCA\Polls\Db\NotificationMapper')
72
+            ->disableOriginalConstructor()
73
+            ->getMock();
74
+        $participationMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationMapper')
75
+            ->disableOriginalConstructor()
76
+            ->getMock();
77
+        $participationTextMapper = $this->getMockBuilder('OCA\Polls\Db\ParticipationTextMapper')
78
+            ->disableOriginalConstructor()
79
+            ->getMock();
80
+        $textMapper = $this->getMockBuilder('OCA\Polls\Db\TextMapper')
81
+            ->disableOriginalConstructor()
82
+            ->getMock();
83 83
 
84
-		$this->controller = new PageController(
85
-			'polls',
86
-			$request,
87
-			$userManager,
88
-			$groupManager,
89
-			$avatarManager,
90
-			$logger,
91
-			$l10n,
92
-			$urlGenerator,
93
-			$this->userId,
94
-			$commentMapper,
95
-			$dateMapper,
96
-			$eventMapper,
97
-			$notificationMapper,
98
-			$participationMapper,
99
-			$participationTextMapper,
100
-			$textMapper
101
-		);
102
-	}
84
+        $this->controller = new PageController(
85
+            'polls',
86
+            $request,
87
+            $userManager,
88
+            $groupManager,
89
+            $avatarManager,
90
+            $logger,
91
+            $l10n,
92
+            $urlGenerator,
93
+            $this->userId,
94
+            $commentMapper,
95
+            $dateMapper,
96
+            $eventMapper,
97
+            $notificationMapper,
98
+            $participationMapper,
99
+            $participationTextMapper,
100
+            $textMapper
101
+        );
102
+    }
103 103
 
104
-	/**
105
-	 * Basic controller index route test.
106
-	 */
107
-	public function testIndex() {
108
-		$result = $this->controller->index();
104
+    /**
105
+     * Basic controller index route test.
106
+     */
107
+    public function testIndex() {
108
+        $result = $this->controller->index();
109 109
 
110
-		$this->assertEquals('main.tmpl', $result->getTemplateName());
111
-		$this->assertInstanceOf(TemplateResponse::class, $result);
112
-	}
110
+        $this->assertEquals('main.tmpl', $result->getTemplateName());
111
+        $this->assertInstanceOf(TemplateResponse::class, $result);
112
+    }
113 113
 }
Please login to merge, or discard this patch.
tests/Unit/UnitTestCase.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,15 +28,15 @@
 block discarded – undo
28 28
 
29 29
 abstract class UnitTestCase extends PHPUnit_Framework_TestCase {
30 30
 
31
-	/** @var FactoryMuffin */
32
-	protected $fm;
31
+    /** @var FactoryMuffin */
32
+    protected $fm;
33 33
 
34
-	/**
35
-	 * {@inheritDoc}
36
-	 */
37
-	public function setUp() {
38
-		parent::setUp();
39
-		$this->fm = new FactoryMuffin();
40
-		$this->fm->loadFactories(__DIR__ . '/Factories');
41
-	}
34
+    /**
35
+     * {@inheritDoc}
36
+     */
37
+    public function setUp() {
38
+        parent::setUp();
39
+        $this->fm = new FactoryMuffin();
40
+        $this->fm->loadFactories(__DIR__ . '/Factories');
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/AppInfo/Application.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -37,130 +37,130 @@
 block discarded – undo
37 37
 
38 38
 class Application extends App {
39 39
 
40
-	/**
41
-	 * Application constructor.
42
-	 * @param array $urlParams
43
-	 */
44
-	public function __construct(array $urlParams = array()) {
45
-		parent::__construct('polls', $urlParams);
46
-
47
-		$container = $this->getContainer();
48
-		$server = $container->getServer();
49
-
50
-		/**
51
-		 * Controllers
52
-		 */
53
-		$container->registerService('PageController', function ($c) use ($server) {
54
-			/** @var SimpleContainer $c */
55
-			return new PageController(
56
-				$c->query('AppName'),
57
-				$c->query('Request'),
58
-				$c->query('UserManager'),
59
-				$c->query('GroupManager'),
60
-				$c->query('AvatarManager'),
61
-				$c->query('Logger'),
62
-				$c->query('L10N'),
63
-				$c->query('ServerContainer')->getURLGenerator(),
64
-				$c->query('UserId'),
65
-				$c->query('CommentMapper'),
66
-				$c->query('DateMapper'),
67
-				$c->query('EventMapper'),
68
-				$c->query('NotificationMapper'),
69
-				$c->query('ParticipationMapper'),
70
-				$c->query('ParticipationTextMapper'),
71
-				$c->query('TextMapper')
72
-			);
73
-		});
74
-
75
-		$container->registerService('UserManager', function ($c) {
76
-			/** @var SimpleContainer $c */
77
-			return $c->query('ServerContainer')->getUserManager();
78
-		});
79
-
80
-		$container->registerService('GroupManager', function ($c) {
81
-			/** @var SimpleContainer $c */
82
-			return $c->query('ServerContainer')->getGroupManager();
83
-		});
84
-
85
-		$container->registerService('AvatarManager', function ($c) {
86
-			/** @var SimpleContainer $c */
87
-			return $c->query('ServerContainer')->getAvatarManager();
88
-		});
89
-
90
-		$container->registerService('Logger', function ($c) {
91
-			/** @var SimpleContainer $c */
92
-			return $c->query('ServerContainer')->getLogger();
93
-		});
94
-
95
-		$container->registerService('L10N', function ($c) {
96
-			return $c->query('ServerContainer')->getL10N($c->query('AppName'));
97
-		});
98
-
99
-		$container->registerService('CommentMapper', function ($c) use ($server) {
100
-			/** @var SimpleContainer $c */
101
-			return new CommentMapper(
102
-				$server->getDatabaseConnection()
103
-			);
104
-		});
105
-
106
-		$container->registerService('DateMapper', function ($c) use ($server) {
107
-			/** @var SimpleContainer $c */
108
-			return new DateMapper(
109
-				$server->getDatabaseConnection()
110
-			);
111
-		});
112
-
113
-		$container->registerService('EventMapper', function ($c) use ($server) {
114
-			/** @var SimpleContainer $c */
115
-			return new EventMapper(
116
-				$server->getDatabaseConnection()
117
-			);
118
-		});
119
-
120
-		$container->registerService('NotificationMapper', function ($c) use ($server) {
121
-			/** @var SimpleContainer $c */
122
-			return new NotificationMapper(
123
-				$server->getDatabaseConnection()
124
-			);
125
-		});
126
-
127
-		$container->registerService('ParticipationMapper', function ($c) use ($server) {
128
-			/** @var SimpleContainer $c */
129
-			return new ParticipationMapper(
130
-				$server->getDatabaseConnection()
131
-			);
132
-		});
133
-
134
-		$container->registerService('ParticipationTextMapper', function ($c) use ($server) {
135
-			/** @var SimpleContainer $c */
136
-			return new ParticipationTextMapper(
137
-				$server->getDatabaseConnection()
138
-			);
139
-		});
140
-
141
-		$container->registerService('TextMapper', function ($c) use ($server) {
142
-			/** @var SimpleContainer $c */
143
-			return new TextMapper(
144
-				$server->getDatabaseConnection()
145
-			);
146
-		});
147
-	}
148
-
149
-	/**
150
-	 * Register navigation entry for main navigation.
151
-	 */
152
-	public function registerNavigationEntry() {
153
-		$container = $this->getContainer();
154
-		$container->query('OCP\INavigationManager')->add(function () use ($container) {
155
-			$urlGenerator = $container->query('OCP\IURLGenerator');
156
-			$l10n = $container->query('OCP\IL10N');
157
-			return [
158
-				'id' => 'polls',
159
-				'order' => 77,
160
-				'href' => $urlGenerator->linkToRoute('polls.page.index'),
161
-				'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
162
-				'name' => $l10n->t('Polls')
163
-			];
164
-		});
165
-	}
40
+    /**
41
+     * Application constructor.
42
+     * @param array $urlParams
43
+     */
44
+    public function __construct(array $urlParams = array()) {
45
+        parent::__construct('polls', $urlParams);
46
+
47
+        $container = $this->getContainer();
48
+        $server = $container->getServer();
49
+
50
+        /**
51
+         * Controllers
52
+         */
53
+        $container->registerService('PageController', function ($c) use ($server) {
54
+            /** @var SimpleContainer $c */
55
+            return new PageController(
56
+                $c->query('AppName'),
57
+                $c->query('Request'),
58
+                $c->query('UserManager'),
59
+                $c->query('GroupManager'),
60
+                $c->query('AvatarManager'),
61
+                $c->query('Logger'),
62
+                $c->query('L10N'),
63
+                $c->query('ServerContainer')->getURLGenerator(),
64
+                $c->query('UserId'),
65
+                $c->query('CommentMapper'),
66
+                $c->query('DateMapper'),
67
+                $c->query('EventMapper'),
68
+                $c->query('NotificationMapper'),
69
+                $c->query('ParticipationMapper'),
70
+                $c->query('ParticipationTextMapper'),
71
+                $c->query('TextMapper')
72
+            );
73
+        });
74
+
75
+        $container->registerService('UserManager', function ($c) {
76
+            /** @var SimpleContainer $c */
77
+            return $c->query('ServerContainer')->getUserManager();
78
+        });
79
+
80
+        $container->registerService('GroupManager', function ($c) {
81
+            /** @var SimpleContainer $c */
82
+            return $c->query('ServerContainer')->getGroupManager();
83
+        });
84
+
85
+        $container->registerService('AvatarManager', function ($c) {
86
+            /** @var SimpleContainer $c */
87
+            return $c->query('ServerContainer')->getAvatarManager();
88
+        });
89
+
90
+        $container->registerService('Logger', function ($c) {
91
+            /** @var SimpleContainer $c */
92
+            return $c->query('ServerContainer')->getLogger();
93
+        });
94
+
95
+        $container->registerService('L10N', function ($c) {
96
+            return $c->query('ServerContainer')->getL10N($c->query('AppName'));
97
+        });
98
+
99
+        $container->registerService('CommentMapper', function ($c) use ($server) {
100
+            /** @var SimpleContainer $c */
101
+            return new CommentMapper(
102
+                $server->getDatabaseConnection()
103
+            );
104
+        });
105
+
106
+        $container->registerService('DateMapper', function ($c) use ($server) {
107
+            /** @var SimpleContainer $c */
108
+            return new DateMapper(
109
+                $server->getDatabaseConnection()
110
+            );
111
+        });
112
+
113
+        $container->registerService('EventMapper', function ($c) use ($server) {
114
+            /** @var SimpleContainer $c */
115
+            return new EventMapper(
116
+                $server->getDatabaseConnection()
117
+            );
118
+        });
119
+
120
+        $container->registerService('NotificationMapper', function ($c) use ($server) {
121
+            /** @var SimpleContainer $c */
122
+            return new NotificationMapper(
123
+                $server->getDatabaseConnection()
124
+            );
125
+        });
126
+
127
+        $container->registerService('ParticipationMapper', function ($c) use ($server) {
128
+            /** @var SimpleContainer $c */
129
+            return new ParticipationMapper(
130
+                $server->getDatabaseConnection()
131
+            );
132
+        });
133
+
134
+        $container->registerService('ParticipationTextMapper', function ($c) use ($server) {
135
+            /** @var SimpleContainer $c */
136
+            return new ParticipationTextMapper(
137
+                $server->getDatabaseConnection()
138
+            );
139
+        });
140
+
141
+        $container->registerService('TextMapper', function ($c) use ($server) {
142
+            /** @var SimpleContainer $c */
143
+            return new TextMapper(
144
+                $server->getDatabaseConnection()
145
+            );
146
+        });
147
+    }
148
+
149
+    /**
150
+     * Register navigation entry for main navigation.
151
+     */
152
+    public function registerNavigationEntry() {
153
+        $container = $this->getContainer();
154
+        $container->query('OCP\INavigationManager')->add(function () use ($container) {
155
+            $urlGenerator = $container->query('OCP\IURLGenerator');
156
+            $l10n = $container->query('OCP\IL10N');
157
+            return [
158
+                'id' => 'polls',
159
+                'order' => 77,
160
+                'href' => $urlGenerator->linkToRoute('polls.page.index'),
161
+                'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
162
+                'name' => $l10n->t('Polls')
163
+            ];
164
+        });
165
+    }
166 166
 }
Please login to merge, or discard this patch.
lib/Controller/PageController.php 1 patch
Indentation   +701 added lines, -701 removed lines patch added patch discarded remove patch
@@ -55,705 +55,705 @@
 block discarded – undo
55 55
 
56 56
 class PageController extends Controller {
57 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) {
260
-		$poll = new Event();
261
-		$poll->setId($pollId);
262
-		$this->eventMapper->delete($poll);
263
-		$this->textMapper->deleteByPoll($pollId);
264
-		$this->dateMapper->deleteByPoll($pollId);
265
-		$this->participationMapper->deleteByPoll($pollId);
266
-		$this->participationTextMapper->deleteByPoll($pollId);
267
-		$this->commentMapper->deleteByPoll($pollId);
268
-		$url = $this->urlGenerator->linkToRoute('polls.page.index');
269
-		return new RedirectResponse($url);
270
-	}
271
-
272
-	/**
273
-	 * @NoAdminRequired
274
-	 * @NoCSRFRequired
275
-	 * @param string $hash
276
-	 * @return TemplateResponse
277
-	 */
278
-	public function editPoll($hash) {
279
-		$poll = $this->eventMapper->findByHash($hash);
280
-		if ($this->userId !== $poll->getOwner()) {
281
-			return new TemplateResponse('polls', 'no.create.tmpl');
282
-		}
283
-		if ($poll->getType() == '0') {
284
-			$dates = $this->dateMapper->findByPoll($poll->getId());
285
-		} else {
286
-			$dates = $this->textMapper->findByPoll($poll->getId());
287
-		}
288
-		return new TemplateResponse('polls', 'create.tmpl', [
289
-			'poll' => $poll,
290
-			'dates' => $dates,
291
-			'userId' => $this->userId,
292
-			'userMgr' => $this->manager,
293
-			'urlGenerator' => $this->urlGenerator
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
-		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
-		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
-			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() {
395
-		return new TemplateResponse('polls', 'create.tmpl',
396
-			['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
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()->generate(
432
-			16,
433
-			ISecureRandom::CHAR_DIGITS .
434
-			ISecureRandom::CHAR_LOWER .
435
-			ISecureRandom::CHAR_UPPER
436
-		));
437
-		$event->setIsAnonymous($isAnonymous ? 1 : 0);
438
-		$event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
439
-
440
-		if ($accessType === 'select') {
441
-			if (isset($accessValues)) {
442
-				$accessValues = json_decode($accessValues);
443
-				if ($accessValues !== null) {
444
-					$groups = array();
445
-					$users = array();
446
-					if ($accessValues->groups !== null) {
447
-						$groups = $accessValues->groups;
448
-					}
449
-					if ($accessValues->users !== null) {
450
-						$users = $accessValues->users;
451
-					}
452
-					$accessType = '';
453
-					foreach ($groups as $gid) {
454
-						$accessType .= $gid . ';';
455
-					}
456
-					foreach ($users as $uid) {
457
-						$accessType .= $uid . ';';
458
-					}
459
-				}
460
-			}
461
-		}
462
-		$event->setAccess($accessType);
463
-
464
-		$chosenDates = json_decode($chosenDates);
465
-
466
-		$expire = null;
467
-		if ($expireTs !== null && $expireTs !== '') {
468
-			$expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
469
-		}
470
-		$event->setExpire($expire);
471
-
472
-		if ($pollType === 'event') {
473
-			$event->setType(0);
474
-			$ins = $this->eventMapper->insert($event);
475
-			$poll_id = $ins->getId();
476
-			sort($chosenDates);
477
-			foreach ($chosenDates as $el) {
478
-				$date = new Date();
479
-				$date->setPollId($poll_id);
480
-				$date->setDt(date('Y-m-d H:i:s', $el));
481
-				$this->dateMapper->insert($date);
482
-			}
483
-		} else {
484
-			$event->setType(1);
485
-			$ins = $this->eventMapper->insert($event);
486
-			$poll_id = $ins->getId();
487
-			$cnt = 1;
488
-			foreach ($chosenDates as $el) {
489
-				$text = new Text();
490
-				$text->setText($el . '_' . $cnt);
491
-				$text->setPollId($poll_id);
492
-				$this->textMapper->insert($text);
493
-				$cnt++;
494
-			}
495
-		}
496
-		$url = $this->urlGenerator->linkToRoute('polls.page.index');
497
-		return new RedirectResponse($url);
498
-	}
499
-
500
-	/**
501
-	 * @NoAdminRequired
502
-	 * @NoCSRFRequired
503
-	 * @PublicPage
504
-	 * @param $pollId
505
-	 * @param $userId
506
-	 * @param $types
507
-	 * @param $dates
508
-	 * @param $receiveNotifications
509
-	 * @param $changed
510
-	 * @return RedirectResponse
511
-	 */
512
-	public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
513
-		if ($this->userId !== null) {
514
-			if ($receiveNotifications === 'true') {
515
-				try {
516
-					//check if user already set notification for this poll
517
-					$this->notificationMapper->findByUserAndPoll($pollId, $userId);
518
-				} catch (DoesNotExistException $e) {
519
-					//insert if not exist
520
-					$not = new Notification();
521
-					$not->setUserId($userId);
522
-					$not->setPollId($pollId);
523
-					$this->notificationMapper->insert($not);
524
-				}
525
-			} else {
526
-				try {
527
-					//delete if entry is in db
528
-					$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
529
-					$this->notificationMapper->delete($not);
530
-				} catch (DoesNotExistException $e) {
531
-					//doesn't exist in db, nothing to do
532
-				}
533
-			}
534
-		}
535
-		$poll = $this->eventMapper->find($pollId);
536
-		if ($changed === 'true') {
537
-			$dates = json_decode($dates);
538
-			$types = json_decode($types);
539
-			$count_dates = count($dates);
540
-			if ($poll->getType() == '0') {
541
-				$this->participationMapper->deleteByPollAndUser($pollId, $userId);
542
-			} else {
543
-				$this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
544
-			}
545
-			for ($i = 0; $i < $count_dates; $i++) {
546
-				if ($poll->getType() == '0') {
547
-					$part = new Participation();
548
-					$part->setPollId($pollId);
549
-					$part->setUserId($userId);
550
-					$part->setDt(date('Y-m-d H:i:s', $dates[$i]));
551
-					$part->setType($types[$i]);
552
-					$this->participationMapper->insert($part);
553
-				} else {
554
-					$part = new ParticipationText();
555
-					$part->setPollId($pollId);
556
-					$part->setUserId($userId);
557
-					$part->setText($dates[$i]);
558
-					$part->setType($types[$i]);
559
-					$this->participationTextMapper->insert($part);
560
-				}
561
-
562
-			}
563
-			$this->sendNotifications($pollId, $userId);
564
-		}
565
-		$hash = $poll->getHash();
566
-		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
567
-		return new RedirectResponse($url);
568
-	}
569
-
570
-	/**
571
-	 * @NoAdminRequired
572
-	 * @NoCSRFRequired
573
-	 * @PublicPage
574
-	 * @param $pollId
575
-	 * @param $userId
576
-	 * @param $commentBox
577
-	 * @return JSONResponse
578
-	 */
579
-	public function insertComment($pollId, $userId, $commentBox) {
580
-		$comment = new Comment();
581
-		$comment->setPollId($pollId);
582
-		$comment->setUserId($userId);
583
-		$comment->setComment($commentBox);
584
-		$comment->setDt(date('Y-m-d H:i:s'));
585
-		$this->commentMapper->insert($comment);
586
-		$this->sendNotifications($pollId, $userId);
587
-		if ($this->manager->get($userId) !== null) {
588
-			$newUserId = $this->manager->get($userId)->getDisplayName();
589
-		} else {
590
-			$newUserId = $userId;
591
-		}
592
-		return new JSONResponse(array(
593
-			'comment' => $commentBox,
594
-			'date' => date('Y-m-d H:i:s'),
595
-			'userName' => $newUserId
596
-		));
597
-	}
598
-
599
-	/**
600
-	 * @NoAdminRequired
601
-	 * @NoCSRFRequired
602
-	 * @param $searchTerm
603
-	 * @param $groups
604
-	 * @param $users
605
-	 * @return array
606
-	 */
607
-	 public function search($searchTerm, $groups, $users) {
608
-		return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
609
-	}
610
-
611
-	/**
612
-	 * @NoAdminRequired
613
-	 * @NoCSRFRequired
614
-	 * @param $searchTerm
615
-	 * @param $groups
616
-	 * @return array
617
-	 */
618
-	 public function searchForGroups($searchTerm, $groups) {
619
-		$selectedGroups = json_decode($groups);
620
-		$groups = $this->groupManager->search($searchTerm);
621
-		$gids = array();
622
-		$sgids = array();
623
-		foreach ($selectedGroups as $sg) {
624
-			$sgids[] = str_replace('group_', '', $sg);
625
-		}
626
-		foreach ($groups as $g) {
627
-			$gids[] = $g->getGID();
628
-		}
629
-		$diffGids = array_diff($gids, $sgids);
630
-		$gids = array();
631
-		foreach ($diffGids as $g) {
632
-			$gids[] = ['gid' => $g, 'isGroup' => true];
633
-		}
634
-		return $gids;
635
-	}
636
-
637
-	/**
638
-	 * @NoAdminRequired
639
-	 * @NoCSRFRequired
640
-	 * @param $searchTerm
641
-	 * @param $users
642
-	 * @return array
643
-	 */
644
-	 public function searchForUsers($searchTerm, $users) {
645
-		$selectedUsers = json_decode($users);
646
-		Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
647
-		$userNames = $this->userMgr->searchDisplayName($searchTerm);
648
-		$users = array();
649
-		$sUsers = array();
650
-		foreach ($selectedUsers as $su) {
651
-			$sUsers[] = str_replace('user_', '', $su);
652
-		}
653
-		foreach ($userNames as $u) {
654
-			$alreadyAdded = false;
655
-			foreach ($sUsers as &$su) {
656
-				if ($su === $u->getUID()) {
657
-					unset($su);
658
-					$alreadyAdded = true;
659
-					break;
660
-				}
661
-			}
662
-			if (!$alreadyAdded) {
663
-				$users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
664
-			} else {
665
-				continue;
666
-			}
667
-		}
668
-		return $users;
669
-	}
670
-
671
-	/**
672
-	 * @NoAdminRequired
673
-	 * @NoCSRFRequired
674
-	 * @param $username
675
-	 * @return string
676
-	 */
677
-	 public function getDisplayName($username) {
678
-		return $this->manager->get($username)->getDisplayName();
679
-	}
680
-
681
-	/**
682
-	 * @return Event[]
683
-	 */
684
-	 public function getPollsForUser() {
685
-		return $this->eventMapper->findAllForUser($this->userId);
686
-	}
687
-
688
-	/**
689
-	 * @param $user
690
-	 * @return Event[]
691
-	 */
692
-	 public function getPollsForUserWithInfo($user = null) {
693
-		if ($user === null) {
694
-			return $this->eventMapper->findAllForUserWithInfo($this->userId);
695
-		} else {
696
-			return $this->eventMapper->findAllForUserWithInfo($user);
697
-		}
698
-	}
699
-	/**
700
-	 * @return array
701
-	 */
702
-	 public function getGroups() {
703
-		// $this->requireLogin();
704
-		if (class_exists('\OC_Group', true)) {
705
-			// Nextcloud <= 11, ownCloud
706
-			return \OC_Group::getUserGroups($this->userId);
707
-		}
708
-		// Nextcloud >= 12
709
-		$groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
710
-		return array_map(function ($group) {
711
-			return $group->getGID();
712
-		}, $groups);
713
-	}
714
-
715
-	/**
716
-	 * @param $poll
717
-	 * @return bool
718
-	 */
719
-	private function hasUserAccess($poll) {
720
-		$access = $poll->getAccess();
721
-		$owner = $poll->getOwner();
722
-		if ($access === 'public') {
723
-			return true;
724
-		}
725
-		if ($access === 'hidden') {
726
-			return true;
727
-		}
728
-		if ($this->userId === null) {
729
-			return false;
730
-		}
731
-		if ($access === 'registered') {
732
-			return true;
733
-		}
734
-		if ($owner === $this->userId) {
735
-			return true;
736
-		}
737
-		Util::writeLog("polls", $this->userId, Util::ERROR);
738
-		$user_groups = $this->getGroups();
739
-		$arr = explode(';', $access);
740
-		foreach ($arr as $item) {
741
-			if (strpos($item, 'group_') === 0) {
742
-				$grp = substr($item, 6);
743
-				foreach ($user_groups as $user_group) {
744
-					if ($user_group === $grp) {
745
-						return true;
746
-					}
747
-				}
748
-			} else {
749
-				if (strpos($item, 'user_') === 0) {
750
-					$usr = substr($item, 5);
751
-					if ($usr === User::getUser()) {
752
-						return true;
753
-					}
754
-				}
755
-			}
756
-		}
757
-		return false;
758
-	}
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) {
260
+        $poll = new Event();
261
+        $poll->setId($pollId);
262
+        $this->eventMapper->delete($poll);
263
+        $this->textMapper->deleteByPoll($pollId);
264
+        $this->dateMapper->deleteByPoll($pollId);
265
+        $this->participationMapper->deleteByPoll($pollId);
266
+        $this->participationTextMapper->deleteByPoll($pollId);
267
+        $this->commentMapper->deleteByPoll($pollId);
268
+        $url = $this->urlGenerator->linkToRoute('polls.page.index');
269
+        return new RedirectResponse($url);
270
+    }
271
+
272
+    /**
273
+     * @NoAdminRequired
274
+     * @NoCSRFRequired
275
+     * @param string $hash
276
+     * @return TemplateResponse
277
+     */
278
+    public function editPoll($hash) {
279
+        $poll = $this->eventMapper->findByHash($hash);
280
+        if ($this->userId !== $poll->getOwner()) {
281
+            return new TemplateResponse('polls', 'no.create.tmpl');
282
+        }
283
+        if ($poll->getType() == '0') {
284
+            $dates = $this->dateMapper->findByPoll($poll->getId());
285
+        } else {
286
+            $dates = $this->textMapper->findByPoll($poll->getId());
287
+        }
288
+        return new TemplateResponse('polls', 'create.tmpl', [
289
+            'poll' => $poll,
290
+            'dates' => $dates,
291
+            'userId' => $this->userId,
292
+            'userMgr' => $this->manager,
293
+            'urlGenerator' => $this->urlGenerator
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
+        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
+        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
+            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() {
395
+        return new TemplateResponse('polls', 'create.tmpl',
396
+            ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
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()->generate(
432
+            16,
433
+            ISecureRandom::CHAR_DIGITS .
434
+            ISecureRandom::CHAR_LOWER .
435
+            ISecureRandom::CHAR_UPPER
436
+        ));
437
+        $event->setIsAnonymous($isAnonymous ? 1 : 0);
438
+        $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
439
+
440
+        if ($accessType === 'select') {
441
+            if (isset($accessValues)) {
442
+                $accessValues = json_decode($accessValues);
443
+                if ($accessValues !== null) {
444
+                    $groups = array();
445
+                    $users = array();
446
+                    if ($accessValues->groups !== null) {
447
+                        $groups = $accessValues->groups;
448
+                    }
449
+                    if ($accessValues->users !== null) {
450
+                        $users = $accessValues->users;
451
+                    }
452
+                    $accessType = '';
453
+                    foreach ($groups as $gid) {
454
+                        $accessType .= $gid . ';';
455
+                    }
456
+                    foreach ($users as $uid) {
457
+                        $accessType .= $uid . ';';
458
+                    }
459
+                }
460
+            }
461
+        }
462
+        $event->setAccess($accessType);
463
+
464
+        $chosenDates = json_decode($chosenDates);
465
+
466
+        $expire = null;
467
+        if ($expireTs !== null && $expireTs !== '') {
468
+            $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
469
+        }
470
+        $event->setExpire($expire);
471
+
472
+        if ($pollType === 'event') {
473
+            $event->setType(0);
474
+            $ins = $this->eventMapper->insert($event);
475
+            $poll_id = $ins->getId();
476
+            sort($chosenDates);
477
+            foreach ($chosenDates as $el) {
478
+                $date = new Date();
479
+                $date->setPollId($poll_id);
480
+                $date->setDt(date('Y-m-d H:i:s', $el));
481
+                $this->dateMapper->insert($date);
482
+            }
483
+        } else {
484
+            $event->setType(1);
485
+            $ins = $this->eventMapper->insert($event);
486
+            $poll_id = $ins->getId();
487
+            $cnt = 1;
488
+            foreach ($chosenDates as $el) {
489
+                $text = new Text();
490
+                $text->setText($el . '_' . $cnt);
491
+                $text->setPollId($poll_id);
492
+                $this->textMapper->insert($text);
493
+                $cnt++;
494
+            }
495
+        }
496
+        $url = $this->urlGenerator->linkToRoute('polls.page.index');
497
+        return new RedirectResponse($url);
498
+    }
499
+
500
+    /**
501
+     * @NoAdminRequired
502
+     * @NoCSRFRequired
503
+     * @PublicPage
504
+     * @param $pollId
505
+     * @param $userId
506
+     * @param $types
507
+     * @param $dates
508
+     * @param $receiveNotifications
509
+     * @param $changed
510
+     * @return RedirectResponse
511
+     */
512
+    public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
513
+        if ($this->userId !== null) {
514
+            if ($receiveNotifications === 'true') {
515
+                try {
516
+                    //check if user already set notification for this poll
517
+                    $this->notificationMapper->findByUserAndPoll($pollId, $userId);
518
+                } catch (DoesNotExistException $e) {
519
+                    //insert if not exist
520
+                    $not = new Notification();
521
+                    $not->setUserId($userId);
522
+                    $not->setPollId($pollId);
523
+                    $this->notificationMapper->insert($not);
524
+                }
525
+            } else {
526
+                try {
527
+                    //delete if entry is in db
528
+                    $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
529
+                    $this->notificationMapper->delete($not);
530
+                } catch (DoesNotExistException $e) {
531
+                    //doesn't exist in db, nothing to do
532
+                }
533
+            }
534
+        }
535
+        $poll = $this->eventMapper->find($pollId);
536
+        if ($changed === 'true') {
537
+            $dates = json_decode($dates);
538
+            $types = json_decode($types);
539
+            $count_dates = count($dates);
540
+            if ($poll->getType() == '0') {
541
+                $this->participationMapper->deleteByPollAndUser($pollId, $userId);
542
+            } else {
543
+                $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
544
+            }
545
+            for ($i = 0; $i < $count_dates; $i++) {
546
+                if ($poll->getType() == '0') {
547
+                    $part = new Participation();
548
+                    $part->setPollId($pollId);
549
+                    $part->setUserId($userId);
550
+                    $part->setDt(date('Y-m-d H:i:s', $dates[$i]));
551
+                    $part->setType($types[$i]);
552
+                    $this->participationMapper->insert($part);
553
+                } else {
554
+                    $part = new ParticipationText();
555
+                    $part->setPollId($pollId);
556
+                    $part->setUserId($userId);
557
+                    $part->setText($dates[$i]);
558
+                    $part->setType($types[$i]);
559
+                    $this->participationTextMapper->insert($part);
560
+                }
561
+
562
+            }
563
+            $this->sendNotifications($pollId, $userId);
564
+        }
565
+        $hash = $poll->getHash();
566
+        $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
567
+        return new RedirectResponse($url);
568
+    }
569
+
570
+    /**
571
+     * @NoAdminRequired
572
+     * @NoCSRFRequired
573
+     * @PublicPage
574
+     * @param $pollId
575
+     * @param $userId
576
+     * @param $commentBox
577
+     * @return JSONResponse
578
+     */
579
+    public function insertComment($pollId, $userId, $commentBox) {
580
+        $comment = new Comment();
581
+        $comment->setPollId($pollId);
582
+        $comment->setUserId($userId);
583
+        $comment->setComment($commentBox);
584
+        $comment->setDt(date('Y-m-d H:i:s'));
585
+        $this->commentMapper->insert($comment);
586
+        $this->sendNotifications($pollId, $userId);
587
+        if ($this->manager->get($userId) !== null) {
588
+            $newUserId = $this->manager->get($userId)->getDisplayName();
589
+        } else {
590
+            $newUserId = $userId;
591
+        }
592
+        return new JSONResponse(array(
593
+            'comment' => $commentBox,
594
+            'date' => date('Y-m-d H:i:s'),
595
+            'userName' => $newUserId
596
+        ));
597
+    }
598
+
599
+    /**
600
+     * @NoAdminRequired
601
+     * @NoCSRFRequired
602
+     * @param $searchTerm
603
+     * @param $groups
604
+     * @param $users
605
+     * @return array
606
+     */
607
+        public function search($searchTerm, $groups, $users) {
608
+        return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
609
+    }
610
+
611
+    /**
612
+     * @NoAdminRequired
613
+     * @NoCSRFRequired
614
+     * @param $searchTerm
615
+     * @param $groups
616
+     * @return array
617
+     */
618
+        public function searchForGroups($searchTerm, $groups) {
619
+        $selectedGroups = json_decode($groups);
620
+        $groups = $this->groupManager->search($searchTerm);
621
+        $gids = array();
622
+        $sgids = array();
623
+        foreach ($selectedGroups as $sg) {
624
+            $sgids[] = str_replace('group_', '', $sg);
625
+        }
626
+        foreach ($groups as $g) {
627
+            $gids[] = $g->getGID();
628
+        }
629
+        $diffGids = array_diff($gids, $sgids);
630
+        $gids = array();
631
+        foreach ($diffGids as $g) {
632
+            $gids[] = ['gid' => $g, 'isGroup' => true];
633
+        }
634
+        return $gids;
635
+    }
636
+
637
+    /**
638
+     * @NoAdminRequired
639
+     * @NoCSRFRequired
640
+     * @param $searchTerm
641
+     * @param $users
642
+     * @return array
643
+     */
644
+        public function searchForUsers($searchTerm, $users) {
645
+        $selectedUsers = json_decode($users);
646
+        Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
647
+        $userNames = $this->userMgr->searchDisplayName($searchTerm);
648
+        $users = array();
649
+        $sUsers = array();
650
+        foreach ($selectedUsers as $su) {
651
+            $sUsers[] = str_replace('user_', '', $su);
652
+        }
653
+        foreach ($userNames as $u) {
654
+            $alreadyAdded = false;
655
+            foreach ($sUsers as &$su) {
656
+                if ($su === $u->getUID()) {
657
+                    unset($su);
658
+                    $alreadyAdded = true;
659
+                    break;
660
+                }
661
+            }
662
+            if (!$alreadyAdded) {
663
+                $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
664
+            } else {
665
+                continue;
666
+            }
667
+        }
668
+        return $users;
669
+    }
670
+
671
+    /**
672
+     * @NoAdminRequired
673
+     * @NoCSRFRequired
674
+     * @param $username
675
+     * @return string
676
+     */
677
+        public function getDisplayName($username) {
678
+        return $this->manager->get($username)->getDisplayName();
679
+    }
680
+
681
+    /**
682
+     * @return Event[]
683
+     */
684
+        public function getPollsForUser() {
685
+        return $this->eventMapper->findAllForUser($this->userId);
686
+    }
687
+
688
+    /**
689
+     * @param $user
690
+     * @return Event[]
691
+     */
692
+        public function getPollsForUserWithInfo($user = null) {
693
+        if ($user === null) {
694
+            return $this->eventMapper->findAllForUserWithInfo($this->userId);
695
+        } else {
696
+            return $this->eventMapper->findAllForUserWithInfo($user);
697
+        }
698
+    }
699
+    /**
700
+     * @return array
701
+     */
702
+        public function getGroups() {
703
+        // $this->requireLogin();
704
+        if (class_exists('\OC_Group', true)) {
705
+            // Nextcloud <= 11, ownCloud
706
+            return \OC_Group::getUserGroups($this->userId);
707
+        }
708
+        // Nextcloud >= 12
709
+        $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
710
+        return array_map(function ($group) {
711
+            return $group->getGID();
712
+        }, $groups);
713
+    }
714
+
715
+    /**
716
+     * @param $poll
717
+     * @return bool
718
+     */
719
+    private function hasUserAccess($poll) {
720
+        $access = $poll->getAccess();
721
+        $owner = $poll->getOwner();
722
+        if ($access === 'public') {
723
+            return true;
724
+        }
725
+        if ($access === 'hidden') {
726
+            return true;
727
+        }
728
+        if ($this->userId === null) {
729
+            return false;
730
+        }
731
+        if ($access === 'registered') {
732
+            return true;
733
+        }
734
+        if ($owner === $this->userId) {
735
+            return true;
736
+        }
737
+        Util::writeLog("polls", $this->userId, Util::ERROR);
738
+        $user_groups = $this->getGroups();
739
+        $arr = explode(';', $access);
740
+        foreach ($arr as $item) {
741
+            if (strpos($item, 'group_') === 0) {
742
+                $grp = substr($item, 6);
743
+                foreach ($user_groups as $user_group) {
744
+                    if ($user_group === $grp) {
745
+                        return true;
746
+                    }
747
+                }
748
+            } else {
749
+                if (strpos($item, 'user_') === 0) {
750
+                    $usr = substr($item, 5);
751
+                    if ($usr === User::getUser()) {
752
+                        return true;
753
+                    }
754
+                }
755
+            }
756
+        }
757
+        return false;
758
+    }
759 759
 }
Please login to merge, or discard this patch.
tests/Unit/Factories/TextFactory.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,5 +27,5 @@
 block discarded – undo
27 27
  * General factory for the text model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Text')->setDefinitions([
30
-	'text' => Faker::paragraph()
30
+    'text' => Faker::paragraph()
31 31
 ]);
Please login to merge, or discard this patch.
tests/Unit/Factories/ParticipationTextFactory.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
  * General factory for the participation text model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\ParticipationText')->setDefinitions([
30
-	'text' => Faker::paragraph(),
31
-	'userId' => Faker::firstNameMale(),
32
-	'type' => 0
30
+    'text' => Faker::paragraph(),
31
+    'userId' => Faker::firstNameMale(),
32
+    'type' => 0
33 33
 ]);
Please login to merge, or discard this patch.
tests/Unit/Factories/ParticipationFactory.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@
 block discarded – undo
27 27
  * General factory for the participation model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Participation')->setDefinitions([
30
-	'userId' => Faker::firstNameMale(),
31
-	'dt' => function () {
32
-		$date = new DateTime('today');
33
-		return $date->format('Y-m-d H:i:s');
34
-	},
35
-	'type' => 0
30
+    'userId' => Faker::firstNameMale(),
31
+    'dt' => function () {
32
+        $date = new DateTime('today');
33
+        return $date->format('Y-m-d H:i:s');
34
+    },
35
+    'type' => 0
36 36
 ]);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Participation')->setDefinitions([
30 30
 	'userId' => Faker::firstNameMale(),
31
-	'dt' => function () {
31
+	'dt' => function() {
32 32
 		$date = new DateTime('today');
33 33
 		return $date->format('Y-m-d H:i:s');
34 34
 	},
Please login to merge, or discard this patch.
tests/Unit/Factories/NotificationFactory.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,5 +27,5 @@
 block discarded – undo
27 27
  * General factory for the notification model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Notification')->setDefinitions([
30
-	'userId' => Faker::firstNameMale(),
30
+    'userId' => Faker::firstNameMale(),
31 31
 ]);
Please login to merge, or discard this patch.