@@ -33,65 +33,65 @@ |
||
33 | 33 | |
34 | 34 | class NotificationMapperTest extends UnitTestCase { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $con; |
|
38 | - /** @var NotificationMapper */ |
|
39 | - private $notificationMapper; |
|
40 | - /** @var EventMapper */ |
|
41 | - private $eventMapper; |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $con; |
|
38 | + /** @var NotificationMapper */ |
|
39 | + private $notificationMapper; |
|
40 | + /** @var EventMapper */ |
|
41 | + private $eventMapper; |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - */ |
|
46 | - public function setUp() { |
|
47 | - parent::setUp(); |
|
48 | - $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | - $this->notificationMapper = new NotificationMapper($this->con); |
|
50 | - $this->eventMapper = new EventMapper($this->con); |
|
51 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + */ |
|
46 | + public function setUp() { |
|
47 | + parent::setUp(); |
|
48 | + $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | + $this->notificationMapper = new NotificationMapper($this->con); |
|
50 | + $this->eventMapper = new EventMapper($this->con); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Create some fake data and persist them to the database. |
|
55 | - * |
|
56 | - * @return Notification |
|
57 | - */ |
|
58 | - public function testCreate() { |
|
59 | - /** @var Event $event */ |
|
60 | - $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | - $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
53 | + /** |
|
54 | + * Create some fake data and persist them to the database. |
|
55 | + * |
|
56 | + * @return Notification |
|
57 | + */ |
|
58 | + public function testCreate() { |
|
59 | + /** @var Event $event */ |
|
60 | + $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
62 | 62 | |
63 | - /** @var Notification $notification */ |
|
64 | - $notification = $this->fm->instance('OCA\Polls\Db\Notification'); |
|
65 | - $notification->setPollId($event->getId()); |
|
66 | - $this->assertInstanceOf(Notification::class, $this->notificationMapper->insert($notification)); |
|
63 | + /** @var Notification $notification */ |
|
64 | + $notification = $this->fm->instance('OCA\Polls\Db\Notification'); |
|
65 | + $notification->setPollId($event->getId()); |
|
66 | + $this->assertInstanceOf(Notification::class, $this->notificationMapper->insert($notification)); |
|
67 | 67 | |
68 | - return $notification; |
|
69 | - } |
|
68 | + return $notification; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Update the previously created entry and persist the changes. |
|
73 | - * |
|
74 | - * @depends testCreate |
|
75 | - * @param Notification $notification |
|
76 | - * @return Notification |
|
77 | - */ |
|
78 | - public function testUpdate(Notification $notification) { |
|
79 | - $newUserId = Faker::firstNameMale(); |
|
80 | - $notification->setUserId($newUserId()); |
|
81 | - $this->notificationMapper->update($notification); |
|
71 | + /** |
|
72 | + * Update the previously created entry and persist the changes. |
|
73 | + * |
|
74 | + * @depends testCreate |
|
75 | + * @param Notification $notification |
|
76 | + * @return Notification |
|
77 | + */ |
|
78 | + public function testUpdate(Notification $notification) { |
|
79 | + $newUserId = Faker::firstNameMale(); |
|
80 | + $notification->setUserId($newUserId()); |
|
81 | + $this->notificationMapper->update($notification); |
|
82 | 82 | |
83 | - return $notification; |
|
84 | - } |
|
83 | + return $notification; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Delete the previously created entries from the database. |
|
88 | - * |
|
89 | - * @depends testUpdate |
|
90 | - * @param Notification $notification |
|
91 | - */ |
|
92 | - public function testDelete(Notification $notification) { |
|
93 | - $event = $this->eventMapper->find($notification->getPollId()); |
|
94 | - $this->notificationMapper->delete($notification); |
|
95 | - $this->eventMapper->delete($event); |
|
96 | - } |
|
86 | + /** |
|
87 | + * Delete the previously created entries from the database. |
|
88 | + * |
|
89 | + * @depends testUpdate |
|
90 | + * @param Notification $notification |
|
91 | + */ |
|
92 | + public function testDelete(Notification $notification) { |
|
93 | + $event = $this->eventMapper->find($notification->getPollId()); |
|
94 | + $this->notificationMapper->delete($notification); |
|
95 | + $this->eventMapper->delete($event); |
|
96 | + } |
|
97 | 97 | } |
@@ -33,65 +33,65 @@ |
||
33 | 33 | |
34 | 34 | class TextMapperTest extends UnitTestCase { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $con; |
|
38 | - /** @var TextMapper */ |
|
39 | - private $textMapper; |
|
40 | - /** @var EventMapper */ |
|
41 | - private $eventMapper; |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $con; |
|
38 | + /** @var TextMapper */ |
|
39 | + private $textMapper; |
|
40 | + /** @var EventMapper */ |
|
41 | + private $eventMapper; |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - */ |
|
46 | - public function setUp() { |
|
47 | - parent::setUp(); |
|
48 | - $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | - $this->textMapper = new TextMapper($this->con); |
|
50 | - $this->eventMapper = new EventMapper($this->con); |
|
51 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + */ |
|
46 | + public function setUp() { |
|
47 | + parent::setUp(); |
|
48 | + $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | + $this->textMapper = new TextMapper($this->con); |
|
50 | + $this->eventMapper = new EventMapper($this->con); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Create some fake data and persist them to the database. |
|
55 | - * |
|
56 | - * @return Text |
|
57 | - */ |
|
58 | - public function testCreate() { |
|
59 | - /** @var Event $event */ |
|
60 | - $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | - $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
53 | + /** |
|
54 | + * Create some fake data and persist them to the database. |
|
55 | + * |
|
56 | + * @return Text |
|
57 | + */ |
|
58 | + public function testCreate() { |
|
59 | + /** @var Event $event */ |
|
60 | + $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
62 | 62 | |
63 | - /** @var Text $text */ |
|
64 | - $text = $this->fm->instance('OCA\Polls\Db\Text'); |
|
65 | - $text->setPollId($event->getId()); |
|
66 | - $this->assertInstanceOf(Text::class, $this->textMapper->insert($text)); |
|
63 | + /** @var Text $text */ |
|
64 | + $text = $this->fm->instance('OCA\Polls\Db\Text'); |
|
65 | + $text->setPollId($event->getId()); |
|
66 | + $this->assertInstanceOf(Text::class, $this->textMapper->insert($text)); |
|
67 | 67 | |
68 | - return $text; |
|
69 | - } |
|
68 | + return $text; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Update the previously created entry and persist the changes. |
|
73 | - * |
|
74 | - * @depends testCreate |
|
75 | - * @param Text $text |
|
76 | - * @return Text |
|
77 | - */ |
|
78 | - public function testUpdate(Text $text) { |
|
79 | - $newText = Faker::paragraph(); |
|
80 | - $text->setText($newText()); |
|
81 | - $this->textMapper->update($text); |
|
71 | + /** |
|
72 | + * Update the previously created entry and persist the changes. |
|
73 | + * |
|
74 | + * @depends testCreate |
|
75 | + * @param Text $text |
|
76 | + * @return Text |
|
77 | + */ |
|
78 | + public function testUpdate(Text $text) { |
|
79 | + $newText = Faker::paragraph(); |
|
80 | + $text->setText($newText()); |
|
81 | + $this->textMapper->update($text); |
|
82 | 82 | |
83 | - return $text; |
|
84 | - } |
|
83 | + return $text; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Delete the previously created entries from the database. |
|
88 | - * |
|
89 | - * @depends testUpdate |
|
90 | - * @param Text $text |
|
91 | - */ |
|
92 | - public function testDelete(Text $text) { |
|
93 | - $event = $this->eventMapper->find($text->getPollId()); |
|
94 | - $this->textMapper->delete($text); |
|
95 | - $this->eventMapper->delete($event); |
|
96 | - } |
|
86 | + /** |
|
87 | + * Delete the previously created entries from the database. |
|
88 | + * |
|
89 | + * @depends testUpdate |
|
90 | + * @param Text $text |
|
91 | + */ |
|
92 | + public function testDelete(Text $text) { |
|
93 | + $event = $this->eventMapper->find($text->getPollId()); |
|
94 | + $this->textMapper->delete($text); |
|
95 | + $this->eventMapper->delete($event); |
|
96 | + } |
|
97 | 97 | } |
@@ -33,65 +33,65 @@ |
||
33 | 33 | |
34 | 34 | class ParticipationTextMapperTest extends UnitTestCase { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $con; |
|
38 | - /** @var ParticipationTextMapper */ |
|
39 | - private $participationTextMapper; |
|
40 | - /** @var EventMapper */ |
|
41 | - private $eventMapper; |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $con; |
|
38 | + /** @var ParticipationTextMapper */ |
|
39 | + private $participationTextMapper; |
|
40 | + /** @var EventMapper */ |
|
41 | + private $eventMapper; |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - */ |
|
46 | - public function setUp() { |
|
47 | - parent::setUp(); |
|
48 | - $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | - $this->participationTextMapper = new ParticipationTextMapper($this->con); |
|
50 | - $this->eventMapper = new EventMapper($this->con); |
|
51 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + */ |
|
46 | + public function setUp() { |
|
47 | + parent::setUp(); |
|
48 | + $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | + $this->participationTextMapper = new ParticipationTextMapper($this->con); |
|
50 | + $this->eventMapper = new EventMapper($this->con); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Create some fake data and persist them to the database. |
|
55 | - * |
|
56 | - * @return ParticipationText |
|
57 | - */ |
|
58 | - public function testCreate() { |
|
59 | - /** @var Event $event */ |
|
60 | - $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | - $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
53 | + /** |
|
54 | + * Create some fake data and persist them to the database. |
|
55 | + * |
|
56 | + * @return ParticipationText |
|
57 | + */ |
|
58 | + public function testCreate() { |
|
59 | + /** @var Event $event */ |
|
60 | + $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
62 | 62 | |
63 | - /** @var ParticipationText $participationText */ |
|
64 | - $participationText = $this->fm->instance('OCA\Polls\Db\ParticipationText'); |
|
65 | - $participationText->setPollId($event->getId()); |
|
66 | - $this->assertInstanceOf(ParticipationText::class, $this->participationTextMapper->insert($participationText)); |
|
63 | + /** @var ParticipationText $participationText */ |
|
64 | + $participationText = $this->fm->instance('OCA\Polls\Db\ParticipationText'); |
|
65 | + $participationText->setPollId($event->getId()); |
|
66 | + $this->assertInstanceOf(ParticipationText::class, $this->participationTextMapper->insert($participationText)); |
|
67 | 67 | |
68 | - return $participationText; |
|
69 | - } |
|
68 | + return $participationText; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Update the previously created entry and persist the changes. |
|
73 | - * |
|
74 | - * @depends testCreate |
|
75 | - * @param ParticipationText $participationText |
|
76 | - * @return ParticipationText |
|
77 | - */ |
|
78 | - public function testUpdate(ParticipationText $participationText) { |
|
79 | - $newText = Faker::paragraph(); |
|
80 | - $participationText->setText($newText()); |
|
81 | - $this->participationTextMapper->update($participationText); |
|
71 | + /** |
|
72 | + * Update the previously created entry and persist the changes. |
|
73 | + * |
|
74 | + * @depends testCreate |
|
75 | + * @param ParticipationText $participationText |
|
76 | + * @return ParticipationText |
|
77 | + */ |
|
78 | + public function testUpdate(ParticipationText $participationText) { |
|
79 | + $newText = Faker::paragraph(); |
|
80 | + $participationText->setText($newText()); |
|
81 | + $this->participationTextMapper->update($participationText); |
|
82 | 82 | |
83 | - return $participationText; |
|
84 | - } |
|
83 | + return $participationText; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Delete the previously created entries from the database. |
|
88 | - * |
|
89 | - * @depends testUpdate |
|
90 | - * @param ParticipationText $participationText |
|
91 | - */ |
|
92 | - public function testDelete(ParticipationText $participationText) { |
|
93 | - $event = $this->eventMapper->find($participationText->getPollId()); |
|
94 | - $this->participationTextMapper->delete($participationText); |
|
95 | - $this->eventMapper->delete($event); |
|
96 | - } |
|
86 | + /** |
|
87 | + * Delete the previously created entries from the database. |
|
88 | + * |
|
89 | + * @depends testUpdate |
|
90 | + * @param ParticipationText $participationText |
|
91 | + */ |
|
92 | + public function testDelete(ParticipationText $participationText) { |
|
93 | + $event = $this->eventMapper->find($participationText->getPollId()); |
|
94 | + $this->participationTextMapper->delete($participationText); |
|
95 | + $this->eventMapper->delete($event); |
|
96 | + } |
|
97 | 97 | } |
@@ -33,65 +33,65 @@ |
||
33 | 33 | |
34 | 34 | class ParticipationMapperTest extends UnitTestCase { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $con; |
|
38 | - /** @var ParticipationMapper */ |
|
39 | - private $participationMapper; |
|
40 | - /** @var EventMapper */ |
|
41 | - private $eventMapper; |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $con; |
|
38 | + /** @var ParticipationMapper */ |
|
39 | + private $participationMapper; |
|
40 | + /** @var EventMapper */ |
|
41 | + private $eventMapper; |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - */ |
|
46 | - public function setUp() { |
|
47 | - parent::setUp(); |
|
48 | - $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | - $this->participationMapper = new ParticipationMapper($this->con); |
|
50 | - $this->eventMapper = new EventMapper($this->con); |
|
51 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + */ |
|
46 | + public function setUp() { |
|
47 | + parent::setUp(); |
|
48 | + $this->con = \OC::$server->getDatabaseConnection(); |
|
49 | + $this->participationMapper = new ParticipationMapper($this->con); |
|
50 | + $this->eventMapper = new EventMapper($this->con); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Create some fake data and persist them to the database. |
|
55 | - * |
|
56 | - * @return Participation |
|
57 | - */ |
|
58 | - public function testCreate() { |
|
59 | - /** @var Event $event */ |
|
60 | - $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | - $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
53 | + /** |
|
54 | + * Create some fake data and persist them to the database. |
|
55 | + * |
|
56 | + * @return Participation |
|
57 | + */ |
|
58 | + public function testCreate() { |
|
59 | + /** @var Event $event */ |
|
60 | + $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
61 | + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
62 | 62 | |
63 | - /** @var Participation $participation */ |
|
64 | - $participation = $this->fm->instance('OCA\Polls\Db\Participation'); |
|
65 | - $participation->setPollId($event->getId()); |
|
66 | - $this->assertInstanceOf(Participation::class, $this->participationMapper->insert($participation)); |
|
63 | + /** @var Participation $participation */ |
|
64 | + $participation = $this->fm->instance('OCA\Polls\Db\Participation'); |
|
65 | + $participation->setPollId($event->getId()); |
|
66 | + $this->assertInstanceOf(Participation::class, $this->participationMapper->insert($participation)); |
|
67 | 67 | |
68 | - return $participation; |
|
69 | - } |
|
68 | + return $participation; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Update the previously created entry and persist the changes. |
|
73 | - * |
|
74 | - * @depends testCreate |
|
75 | - * @param Participation $participation |
|
76 | - * @return Participation |
|
77 | - */ |
|
78 | - public function testUpdate(Participation $participation) { |
|
79 | - $newDt = Faker::date('Y-m-d H:i:s'); |
|
80 | - $participation->setDt($newDt()); |
|
81 | - $this->participationMapper->update($participation); |
|
71 | + /** |
|
72 | + * Update the previously created entry and persist the changes. |
|
73 | + * |
|
74 | + * @depends testCreate |
|
75 | + * @param Participation $participation |
|
76 | + * @return Participation |
|
77 | + */ |
|
78 | + public function testUpdate(Participation $participation) { |
|
79 | + $newDt = Faker::date('Y-m-d H:i:s'); |
|
80 | + $participation->setDt($newDt()); |
|
81 | + $this->participationMapper->update($participation); |
|
82 | 82 | |
83 | - return $participation; |
|
84 | - } |
|
83 | + return $participation; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Delete the previously created entries from the database. |
|
88 | - * |
|
89 | - * @depends testUpdate |
|
90 | - * @param Participation $participation |
|
91 | - */ |
|
92 | - public function testDelete(Participation $participation) { |
|
93 | - $event = $this->eventMapper->find($participation->getPollId()); |
|
94 | - $this->participationMapper->delete($participation); |
|
95 | - $this->eventMapper->delete($event); |
|
96 | - } |
|
86 | + /** |
|
87 | + * Delete the previously created entries from the database. |
|
88 | + * |
|
89 | + * @depends testUpdate |
|
90 | + * @param Participation $participation |
|
91 | + */ |
|
92 | + public function testDelete(Participation $participation) { |
|
93 | + $event = $this->eventMapper->find($participation->getPollId()); |
|
94 | + $this->participationMapper->delete($participation); |
|
95 | + $this->eventMapper->delete($event); |
|
96 | + } |
|
97 | 97 | } |
@@ -31,57 +31,57 @@ |
||
31 | 31 | |
32 | 32 | class EventMapperTest extends UnitTestCase { |
33 | 33 | |
34 | - /** @var IDBConnection */ |
|
35 | - private $con; |
|
36 | - /** @var EventMapper */ |
|
37 | - private $eventMapper; |
|
34 | + /** @var IDBConnection */ |
|
35 | + private $con; |
|
36 | + /** @var EventMapper */ |
|
37 | + private $eventMapper; |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - */ |
|
42 | - public function setUp() { |
|
43 | - parent::setUp(); |
|
44 | - $this->con = \OC::$server->getDatabaseConnection(); |
|
45 | - $this->eventMapper = new EventMapper($this->con); |
|
46 | - } |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + */ |
|
42 | + public function setUp() { |
|
43 | + parent::setUp(); |
|
44 | + $this->con = \OC::$server->getDatabaseConnection(); |
|
45 | + $this->eventMapper = new EventMapper($this->con); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Create some fake data and persist them to the database. |
|
50 | - * |
|
51 | - * @return Event |
|
52 | - */ |
|
53 | - public function testCreate() { |
|
54 | - /** @var Event $event */ |
|
55 | - $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
56 | - $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
48 | + /** |
|
49 | + * Create some fake data and persist them to the database. |
|
50 | + * |
|
51 | + * @return Event |
|
52 | + */ |
|
53 | + public function testCreate() { |
|
54 | + /** @var Event $event */ |
|
55 | + $event = $this->fm->instance('OCA\Polls\Db\Event'); |
|
56 | + $this->assertInstanceOf(Event::class, $this->eventMapper->insert($event)); |
|
57 | 57 | |
58 | - return $event; |
|
59 | - } |
|
58 | + return $event; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Update the previously created entry and persist the changes. |
|
63 | - * |
|
64 | - * @depends testCreate |
|
65 | - * @param Event $event |
|
66 | - * @return Event |
|
67 | - */ |
|
68 | - public function testUpdate(Event $event) { |
|
69 | - $newTitle = Faker::sentence(10); |
|
70 | - $newDescription = Faker::paragraph(); |
|
71 | - $event->setTitle($newTitle()); |
|
72 | - $event->setDescription($newDescription()); |
|
73 | - $this->eventMapper->update($event); |
|
61 | + /** |
|
62 | + * Update the previously created entry and persist the changes. |
|
63 | + * |
|
64 | + * @depends testCreate |
|
65 | + * @param Event $event |
|
66 | + * @return Event |
|
67 | + */ |
|
68 | + public function testUpdate(Event $event) { |
|
69 | + $newTitle = Faker::sentence(10); |
|
70 | + $newDescription = Faker::paragraph(); |
|
71 | + $event->setTitle($newTitle()); |
|
72 | + $event->setDescription($newDescription()); |
|
73 | + $this->eventMapper->update($event); |
|
74 | 74 | |
75 | - return $event; |
|
76 | - } |
|
75 | + return $event; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Delete the previously created entry from the database. |
|
80 | - * |
|
81 | - * @depends testUpdate |
|
82 | - * @param Event $event |
|
83 | - */ |
|
84 | - public function testDelete(Event $event) { |
|
85 | - $this->eventMapper->delete($event); |
|
86 | - } |
|
78 | + /** |
|
79 | + * Delete the previously created entry from the database. |
|
80 | + * |
|
81 | + * @depends testUpdate |
|
82 | + * @param Event $event |
|
83 | + */ |
|
84 | + public function testDelete(Event $event) { |
|
85 | + $this->eventMapper->delete($event); |
|
86 | + } |
|
87 | 87 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | if (!defined('PHPUNIT_RUN')) { |
25 | - define('PHPUNIT_RUN', 1); |
|
25 | + define('PHPUNIT_RUN', 1); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | require_once __DIR__ . '/../../../lib/base.php'; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | \OC_App::loadApp('polls'); |
33 | 33 | |
34 | 34 | if (!class_exists('PHPUnit_Framework_TestCase')) { |
35 | - require_once 'PHPUnit/Autoload.php'; |
|
35 | + require_once 'PHPUnit/Autoload.php'; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | \OC_Hook::clear(); |
@@ -55,709 +55,709 @@ |
||
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 | - try { |
|
222 | - $poll = $this->eventMapper->findByHash($hash); |
|
223 | - } catch(DoesNotExistException $e) { |
|
224 | - return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
225 | - } |
|
226 | - if ($poll->getType() == '0') { |
|
227 | - $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
228 | - $votes = $this->participationMapper->findByPoll($poll->getId()); |
|
229 | - } else { |
|
230 | - $dates = $this->textMapper->findByPoll($poll->getId()); |
|
231 | - $votes = $this->participationTextMapper->findByPoll($poll->getId()); |
|
232 | - } |
|
233 | - $comments = $this->commentMapper->findByPoll($poll->getId()); |
|
234 | - try { |
|
235 | - $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId); |
|
236 | - } catch (DoesNotExistException $e) { |
|
237 | - $notification = null; |
|
238 | - } |
|
239 | - if ($this->hasUserAccess($poll)) { |
|
240 | - return new TemplateResponse('polls', 'goto.tmpl', [ |
|
241 | - 'poll' => $poll, |
|
242 | - 'dates' => $dates, |
|
243 | - 'comments' => $comments, |
|
244 | - 'votes' => $votes, |
|
245 | - 'notification' => $notification, |
|
246 | - 'userId' => $this->userId, |
|
247 | - 'userMgr' => $this->manager, |
|
248 | - 'urlGenerator' => $this->urlGenerator, |
|
249 | - 'avatarManager' => $this->avatarManager |
|
250 | - ]); |
|
251 | - } else { |
|
252 | - User::checkLoggedIn(); |
|
253 | - return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @NoAdminRequired |
|
259 | - * @NoCSRFRequired |
|
260 | - * @param string $pollId |
|
261 | - * @return RedirectResponse |
|
262 | - */ |
|
263 | - public function deletePoll($pollId) { |
|
264 | - $poll = new Event(); |
|
265 | - $poll->setId($pollId); |
|
266 | - $this->eventMapper->delete($poll); |
|
267 | - $this->textMapper->deleteByPoll($pollId); |
|
268 | - $this->dateMapper->deleteByPoll($pollId); |
|
269 | - $this->participationMapper->deleteByPoll($pollId); |
|
270 | - $this->participationTextMapper->deleteByPoll($pollId); |
|
271 | - $this->commentMapper->deleteByPoll($pollId); |
|
272 | - $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
273 | - return new RedirectResponse($url); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @NoAdminRequired |
|
278 | - * @NoCSRFRequired |
|
279 | - * @param string $hash |
|
280 | - * @return TemplateResponse |
|
281 | - */ |
|
282 | - public function editPoll($hash) { |
|
283 | - $poll = $this->eventMapper->findByHash($hash); |
|
284 | - if ($this->userId !== $poll->getOwner()) { |
|
285 | - return new TemplateResponse('polls', 'no.create.tmpl'); |
|
286 | - } |
|
287 | - if ($poll->getType() == '0') { |
|
288 | - $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
289 | - } else { |
|
290 | - $dates = $this->textMapper->findByPoll($poll->getId()); |
|
291 | - } |
|
292 | - return new TemplateResponse('polls', 'create.tmpl', [ |
|
293 | - 'poll' => $poll, |
|
294 | - 'dates' => $dates, |
|
295 | - 'userId' => $this->userId, |
|
296 | - 'userMgr' => $this->manager, |
|
297 | - 'urlGenerator' => $this->urlGenerator |
|
298 | - ]); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @NoAdminRequired |
|
303 | - * @NoCSRFRequired |
|
304 | - * @param $pollId |
|
305 | - * @param $pollType |
|
306 | - * @param $pollTitle |
|
307 | - * @param $pollDesc |
|
308 | - * @param $userId |
|
309 | - * @param $chosenDates |
|
310 | - * @param $expireTs |
|
311 | - * @param $accessType |
|
312 | - * @param $accessValues |
|
313 | - * @param $isAnonymous |
|
314 | - * @param $hideNames |
|
315 | - * @return RedirectResponse |
|
316 | - */ |
|
317 | - public function updatePoll( |
|
318 | - $pollId, |
|
319 | - $pollType, |
|
320 | - $pollTitle, |
|
321 | - $pollDesc, |
|
322 | - $userId, |
|
323 | - $chosenDates, |
|
324 | - $expireTs, |
|
325 | - $accessType, |
|
326 | - $accessValues, |
|
327 | - $isAnonymous, |
|
328 | - $hideNames |
|
329 | - ) { |
|
330 | - $event = $this->eventMapper->find($pollId); |
|
331 | - $event->setTitle(htmlspecialchars($pollTitle)); |
|
332 | - $event->setDescription(htmlspecialchars($pollDesc)); |
|
333 | - $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
334 | - $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
335 | - |
|
336 | - if ($accessType === 'select') { |
|
337 | - if (isset($accessValues)) { |
|
338 | - $accessValues = json_decode($accessValues); |
|
339 | - if ($accessValues !== null) { |
|
340 | - $groups = array(); |
|
341 | - $users = array(); |
|
342 | - if ($accessValues->groups !== null) { |
|
343 | - $groups = $accessValues->groups; |
|
344 | - } |
|
345 | - if ($accessValues->users !== null) { |
|
346 | - $users = $accessValues->users; |
|
347 | - } |
|
348 | - $accessType = ''; |
|
349 | - foreach ($groups as $gid) { |
|
350 | - $accessType .= $gid . ';'; |
|
351 | - } |
|
352 | - foreach ($users as $uid) { |
|
353 | - $accessType .= $uid . ';'; |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - $event->setAccess($accessType); |
|
359 | - |
|
360 | - $chosenDates = json_decode($chosenDates); |
|
361 | - |
|
362 | - $expire = null; |
|
363 | - if ($expireTs !== null && $expireTs !== '') { |
|
364 | - $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
365 | - } |
|
366 | - $event->setExpire($expire); |
|
367 | - |
|
368 | - $this->dateMapper->deleteByPoll($pollId); |
|
369 | - $this->textMapper->deleteByPoll($pollId); |
|
370 | - if ($pollType === 'event') { |
|
371 | - $event->setType(0); |
|
372 | - $this->eventMapper->update($event); |
|
373 | - sort($chosenDates); |
|
374 | - foreach ($chosenDates as $el) { |
|
375 | - $date = new Date(); |
|
376 | - $date->setPollId($pollId); |
|
377 | - $date->setDt(date('Y-m-d H:i:s', $el)); |
|
378 | - $this->dateMapper->insert($date); |
|
379 | - } |
|
380 | - } else { |
|
381 | - $event->setType(1); |
|
382 | - $this->eventMapper->update($event); |
|
383 | - foreach ($chosenDates as $el) { |
|
384 | - $text = new Text(); |
|
385 | - $text->setText($el); |
|
386 | - $text->setPollId($pollId); |
|
387 | - $this->textMapper->insert($text); |
|
388 | - } |
|
389 | - } |
|
390 | - $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
391 | - return new RedirectResponse($url); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @NoAdminRequired |
|
396 | - * @NoCSRFRequired |
|
397 | - */ |
|
398 | - public function createPoll() { |
|
399 | - return new TemplateResponse('polls', 'create.tmpl', |
|
400 | - ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @NoAdminRequired |
|
405 | - * @NoCSRFRequired |
|
406 | - * @param $pollType |
|
407 | - * @param $pollTitle |
|
408 | - * @param $pollDesc |
|
409 | - * @param $userId |
|
410 | - * @param $chosenDates |
|
411 | - * @param $expireTs |
|
412 | - * @param $accessType |
|
413 | - * @param $accessValues |
|
414 | - * @param $isAnonymous |
|
415 | - * @param $hideNames |
|
416 | - * @return RedirectResponse |
|
417 | - */ |
|
418 | - public function insertPoll( |
|
419 | - $pollType, |
|
420 | - $pollTitle, |
|
421 | - $pollDesc, |
|
422 | - $userId, |
|
423 | - $chosenDates, |
|
424 | - $expireTs, |
|
425 | - $accessType, |
|
426 | - $accessValues, |
|
427 | - $isAnonymous, |
|
428 | - $hideNames |
|
429 | - ) { |
|
430 | - $event = new Event(); |
|
431 | - $event->setTitle(htmlspecialchars($pollTitle)); |
|
432 | - $event->setDescription(htmlspecialchars($pollDesc)); |
|
433 | - $event->setOwner($userId); |
|
434 | - $event->setCreated(date('Y-m-d H:i:s')); |
|
435 | - $event->setHash(\OC::$server->getSecureRandom()->generate( |
|
436 | - 16, |
|
437 | - ISecureRandom::CHAR_DIGITS . |
|
438 | - ISecureRandom::CHAR_LOWER . |
|
439 | - ISecureRandom::CHAR_UPPER |
|
440 | - )); |
|
441 | - $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
442 | - $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
443 | - |
|
444 | - if ($accessType === 'select') { |
|
445 | - if (isset($accessValues)) { |
|
446 | - $accessValues = json_decode($accessValues); |
|
447 | - if ($accessValues !== null) { |
|
448 | - $groups = array(); |
|
449 | - $users = array(); |
|
450 | - if ($accessValues->groups !== null) { |
|
451 | - $groups = $accessValues->groups; |
|
452 | - } |
|
453 | - if ($accessValues->users !== null) { |
|
454 | - $users = $accessValues->users; |
|
455 | - } |
|
456 | - $accessType = ''; |
|
457 | - foreach ($groups as $gid) { |
|
458 | - $accessType .= $gid . ';'; |
|
459 | - } |
|
460 | - foreach ($users as $uid) { |
|
461 | - $accessType .= $uid . ';'; |
|
462 | - } |
|
463 | - } |
|
464 | - } |
|
465 | - } |
|
466 | - $event->setAccess($accessType); |
|
467 | - |
|
468 | - $chosenDates = json_decode($chosenDates); |
|
469 | - |
|
470 | - $expire = null; |
|
471 | - if ($expireTs !== null && $expireTs !== '') { |
|
472 | - $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
473 | - } |
|
474 | - $event->setExpire($expire); |
|
475 | - |
|
476 | - if ($pollType === 'event') { |
|
477 | - $event->setType(0); |
|
478 | - $ins = $this->eventMapper->insert($event); |
|
479 | - $poll_id = $ins->getId(); |
|
480 | - sort($chosenDates); |
|
481 | - foreach ($chosenDates as $el) { |
|
482 | - $date = new Date(); |
|
483 | - $date->setPollId($poll_id); |
|
484 | - $date->setDt(date('Y-m-d H:i:s', $el)); |
|
485 | - $this->dateMapper->insert($date); |
|
486 | - } |
|
487 | - } else { |
|
488 | - $event->setType(1); |
|
489 | - $ins = $this->eventMapper->insert($event); |
|
490 | - $poll_id = $ins->getId(); |
|
491 | - $cnt = 1; |
|
492 | - foreach ($chosenDates as $el) { |
|
493 | - $text = new Text(); |
|
494 | - $text->setText($el . '_' . $cnt); |
|
495 | - $text->setPollId($poll_id); |
|
496 | - $this->textMapper->insert($text); |
|
497 | - $cnt++; |
|
498 | - } |
|
499 | - } |
|
500 | - $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
501 | - return new RedirectResponse($url); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * @NoAdminRequired |
|
506 | - * @NoCSRFRequired |
|
507 | - * @PublicPage |
|
508 | - * @param $pollId |
|
509 | - * @param $userId |
|
510 | - * @param $types |
|
511 | - * @param $dates |
|
512 | - * @param $receiveNotifications |
|
513 | - * @param $changed |
|
514 | - * @return RedirectResponse |
|
515 | - */ |
|
516 | - public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) { |
|
517 | - if ($this->userId !== null) { |
|
518 | - if ($receiveNotifications === 'true') { |
|
519 | - try { |
|
520 | - //check if user already set notification for this poll |
|
521 | - $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
|
522 | - } catch (DoesNotExistException $e) { |
|
523 | - //insert if not exist |
|
524 | - $not = new Notification(); |
|
525 | - $not->setUserId($userId); |
|
526 | - $not->setPollId($pollId); |
|
527 | - $this->notificationMapper->insert($not); |
|
528 | - } |
|
529 | - } else { |
|
530 | - try { |
|
531 | - //delete if entry is in db |
|
532 | - $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
|
533 | - $this->notificationMapper->delete($not); |
|
534 | - } catch (DoesNotExistException $e) { |
|
535 | - //doesn't exist in db, nothing to do |
|
536 | - } |
|
537 | - } |
|
538 | - } |
|
539 | - $poll = $this->eventMapper->find($pollId); |
|
540 | - if ($changed === 'true') { |
|
541 | - $dates = json_decode($dates); |
|
542 | - $types = json_decode($types); |
|
543 | - $count_dates = count($dates); |
|
544 | - if ($poll->getType() == '0') { |
|
545 | - $this->participationMapper->deleteByPollAndUser($pollId, $userId); |
|
546 | - } else { |
|
547 | - $this->participationTextMapper->deleteByPollAndUser($pollId, $userId); |
|
548 | - } |
|
549 | - for ($i = 0; $i < $count_dates; $i++) { |
|
550 | - if ($poll->getType() == '0') { |
|
551 | - $part = new Participation(); |
|
552 | - $part->setPollId($pollId); |
|
553 | - $part->setUserId($userId); |
|
554 | - $part->setDt(date('Y-m-d H:i:s', $dates[$i])); |
|
555 | - $part->setType($types[$i]); |
|
556 | - $this->participationMapper->insert($part); |
|
557 | - } else { |
|
558 | - $part = new ParticipationText(); |
|
559 | - $part->setPollId($pollId); |
|
560 | - $part->setUserId($userId); |
|
561 | - $part->setText($dates[$i]); |
|
562 | - $part->setType($types[$i]); |
|
563 | - $this->participationTextMapper->insert($part); |
|
564 | - } |
|
565 | - |
|
566 | - } |
|
567 | - $this->sendNotifications($pollId, $userId); |
|
568 | - } |
|
569 | - $hash = $poll->getHash(); |
|
570 | - $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]); |
|
571 | - return new RedirectResponse($url); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * @NoAdminRequired |
|
576 | - * @NoCSRFRequired |
|
577 | - * @PublicPage |
|
578 | - * @param $pollId |
|
579 | - * @param $userId |
|
580 | - * @param $commentBox |
|
581 | - * @return JSONResponse |
|
582 | - */ |
|
583 | - public function insertComment($pollId, $userId, $commentBox) { |
|
584 | - $comment = new Comment(); |
|
585 | - $comment->setPollId($pollId); |
|
586 | - $comment->setUserId($userId); |
|
587 | - $comment->setComment($commentBox); |
|
588 | - $comment->setDt(date('Y-m-d H:i:s')); |
|
589 | - $this->commentMapper->insert($comment); |
|
590 | - $this->sendNotifications($pollId, $userId); |
|
591 | - if ($this->manager->get($userId) !== null) { |
|
592 | - $newUserId = $this->manager->get($userId)->getDisplayName(); |
|
593 | - } else { |
|
594 | - $newUserId = $userId; |
|
595 | - } |
|
596 | - return new JSONResponse(array( |
|
597 | - 'comment' => $commentBox, |
|
598 | - 'date' => date('Y-m-d H:i:s'), |
|
599 | - 'userName' => $newUserId |
|
600 | - )); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * @NoAdminRequired |
|
605 | - * @NoCSRFRequired |
|
606 | - * @param $searchTerm |
|
607 | - * @param $groups |
|
608 | - * @param $users |
|
609 | - * @return array |
|
610 | - */ |
|
611 | - public function search($searchTerm, $groups, $users) { |
|
612 | - return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users)); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * @NoAdminRequired |
|
617 | - * @NoCSRFRequired |
|
618 | - * @param $searchTerm |
|
619 | - * @param $groups |
|
620 | - * @return array |
|
621 | - */ |
|
622 | - public function searchForGroups($searchTerm, $groups) { |
|
623 | - $selectedGroups = json_decode($groups); |
|
624 | - $groups = $this->groupManager->search($searchTerm); |
|
625 | - $gids = array(); |
|
626 | - $sgids = array(); |
|
627 | - foreach ($selectedGroups as $sg) { |
|
628 | - $sgids[] = str_replace('group_', '', $sg); |
|
629 | - } |
|
630 | - foreach ($groups as $g) { |
|
631 | - $gids[] = $g->getGID(); |
|
632 | - } |
|
633 | - $diffGids = array_diff($gids, $sgids); |
|
634 | - $gids = array(); |
|
635 | - foreach ($diffGids as $g) { |
|
636 | - $gids[] = ['gid' => $g, 'isGroup' => true]; |
|
637 | - } |
|
638 | - return $gids; |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * @NoAdminRequired |
|
643 | - * @NoCSRFRequired |
|
644 | - * @param $searchTerm |
|
645 | - * @param $users |
|
646 | - * @return array |
|
647 | - */ |
|
648 | - public function searchForUsers($searchTerm, $users) { |
|
649 | - $selectedUsers = json_decode($users); |
|
650 | - Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR); |
|
651 | - $userNames = $this->userMgr->searchDisplayName($searchTerm); |
|
652 | - $users = array(); |
|
653 | - $sUsers = array(); |
|
654 | - foreach ($selectedUsers as $su) { |
|
655 | - $sUsers[] = str_replace('user_', '', $su); |
|
656 | - } |
|
657 | - foreach ($userNames as $u) { |
|
658 | - $alreadyAdded = false; |
|
659 | - foreach ($sUsers as &$su) { |
|
660 | - if ($su === $u->getUID()) { |
|
661 | - unset($su); |
|
662 | - $alreadyAdded = true; |
|
663 | - break; |
|
664 | - } |
|
665 | - } |
|
666 | - if (!$alreadyAdded) { |
|
667 | - $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false); |
|
668 | - } else { |
|
669 | - continue; |
|
670 | - } |
|
671 | - } |
|
672 | - return $users; |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * @NoAdminRequired |
|
677 | - * @NoCSRFRequired |
|
678 | - * @param $username |
|
679 | - * @return string |
|
680 | - */ |
|
681 | - public function getDisplayName($username) { |
|
682 | - return $this->manager->get($username)->getDisplayName(); |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * @return Event[] |
|
687 | - */ |
|
688 | - public function getPollsForUser() { |
|
689 | - return $this->eventMapper->findAllForUser($this->userId); |
|
690 | - } |
|
691 | - |
|
692 | - /** |
|
693 | - * @param $user |
|
694 | - * @return Event[] |
|
695 | - */ |
|
696 | - public function getPollsForUserWithInfo($user = null) { |
|
697 | - if ($user === null) { |
|
698 | - return $this->eventMapper->findAllForUserWithInfo($this->userId); |
|
699 | - } else { |
|
700 | - return $this->eventMapper->findAllForUserWithInfo($user); |
|
701 | - } |
|
702 | - } |
|
703 | - /** |
|
704 | - * @return array |
|
705 | - */ |
|
706 | - public function getGroups() { |
|
707 | - // $this->requireLogin(); |
|
708 | - if (class_exists('\OC_Group', true)) { |
|
709 | - // Nextcloud <= 11, ownCloud |
|
710 | - return \OC_Group::getUserGroups($this->userId); |
|
711 | - } |
|
712 | - // Nextcloud >= 12 |
|
713 | - $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser()); |
|
714 | - return array_map(function ($group) { |
|
715 | - return $group->getGID(); |
|
716 | - }, $groups); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * @param $poll |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - private function hasUserAccess($poll) { |
|
724 | - $access = $poll->getAccess(); |
|
725 | - $owner = $poll->getOwner(); |
|
726 | - if ($access === 'public') { |
|
727 | - return true; |
|
728 | - } |
|
729 | - if ($access === 'hidden') { |
|
730 | - return true; |
|
731 | - } |
|
732 | - if ($this->userId === null) { |
|
733 | - return false; |
|
734 | - } |
|
735 | - if ($access === 'registered') { |
|
736 | - return true; |
|
737 | - } |
|
738 | - if ($owner === $this->userId) { |
|
739 | - return true; |
|
740 | - } |
|
741 | - Util::writeLog("polls", $this->userId, Util::ERROR); |
|
742 | - $user_groups = $this->getGroups(); |
|
743 | - $arr = explode(';', $access); |
|
744 | - foreach ($arr as $item) { |
|
745 | - if (strpos($item, 'group_') === 0) { |
|
746 | - $grp = substr($item, 6); |
|
747 | - foreach ($user_groups as $user_group) { |
|
748 | - if ($user_group === $grp) { |
|
749 | - return true; |
|
750 | - } |
|
751 | - } |
|
752 | - } else { |
|
753 | - if (strpos($item, 'user_') === 0) { |
|
754 | - $usr = substr($item, 5); |
|
755 | - if ($usr === User::getUser()) { |
|
756 | - return true; |
|
757 | - } |
|
758 | - } |
|
759 | - } |
|
760 | - } |
|
761 | - return false; |
|
762 | - } |
|
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 | + try { |
|
222 | + $poll = $this->eventMapper->findByHash($hash); |
|
223 | + } catch(DoesNotExistException $e) { |
|
224 | + return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
225 | + } |
|
226 | + if ($poll->getType() == '0') { |
|
227 | + $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
228 | + $votes = $this->participationMapper->findByPoll($poll->getId()); |
|
229 | + } else { |
|
230 | + $dates = $this->textMapper->findByPoll($poll->getId()); |
|
231 | + $votes = $this->participationTextMapper->findByPoll($poll->getId()); |
|
232 | + } |
|
233 | + $comments = $this->commentMapper->findByPoll($poll->getId()); |
|
234 | + try { |
|
235 | + $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId); |
|
236 | + } catch (DoesNotExistException $e) { |
|
237 | + $notification = null; |
|
238 | + } |
|
239 | + if ($this->hasUserAccess($poll)) { |
|
240 | + return new TemplateResponse('polls', 'goto.tmpl', [ |
|
241 | + 'poll' => $poll, |
|
242 | + 'dates' => $dates, |
|
243 | + 'comments' => $comments, |
|
244 | + 'votes' => $votes, |
|
245 | + 'notification' => $notification, |
|
246 | + 'userId' => $this->userId, |
|
247 | + 'userMgr' => $this->manager, |
|
248 | + 'urlGenerator' => $this->urlGenerator, |
|
249 | + 'avatarManager' => $this->avatarManager |
|
250 | + ]); |
|
251 | + } else { |
|
252 | + User::checkLoggedIn(); |
|
253 | + return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @NoAdminRequired |
|
259 | + * @NoCSRFRequired |
|
260 | + * @param string $pollId |
|
261 | + * @return RedirectResponse |
|
262 | + */ |
|
263 | + public function deletePoll($pollId) { |
|
264 | + $poll = new Event(); |
|
265 | + $poll->setId($pollId); |
|
266 | + $this->eventMapper->delete($poll); |
|
267 | + $this->textMapper->deleteByPoll($pollId); |
|
268 | + $this->dateMapper->deleteByPoll($pollId); |
|
269 | + $this->participationMapper->deleteByPoll($pollId); |
|
270 | + $this->participationTextMapper->deleteByPoll($pollId); |
|
271 | + $this->commentMapper->deleteByPoll($pollId); |
|
272 | + $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
273 | + return new RedirectResponse($url); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @NoAdminRequired |
|
278 | + * @NoCSRFRequired |
|
279 | + * @param string $hash |
|
280 | + * @return TemplateResponse |
|
281 | + */ |
|
282 | + public function editPoll($hash) { |
|
283 | + $poll = $this->eventMapper->findByHash($hash); |
|
284 | + if ($this->userId !== $poll->getOwner()) { |
|
285 | + return new TemplateResponse('polls', 'no.create.tmpl'); |
|
286 | + } |
|
287 | + if ($poll->getType() == '0') { |
|
288 | + $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
289 | + } else { |
|
290 | + $dates = $this->textMapper->findByPoll($poll->getId()); |
|
291 | + } |
|
292 | + return new TemplateResponse('polls', 'create.tmpl', [ |
|
293 | + 'poll' => $poll, |
|
294 | + 'dates' => $dates, |
|
295 | + 'userId' => $this->userId, |
|
296 | + 'userMgr' => $this->manager, |
|
297 | + 'urlGenerator' => $this->urlGenerator |
|
298 | + ]); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @NoAdminRequired |
|
303 | + * @NoCSRFRequired |
|
304 | + * @param $pollId |
|
305 | + * @param $pollType |
|
306 | + * @param $pollTitle |
|
307 | + * @param $pollDesc |
|
308 | + * @param $userId |
|
309 | + * @param $chosenDates |
|
310 | + * @param $expireTs |
|
311 | + * @param $accessType |
|
312 | + * @param $accessValues |
|
313 | + * @param $isAnonymous |
|
314 | + * @param $hideNames |
|
315 | + * @return RedirectResponse |
|
316 | + */ |
|
317 | + public function updatePoll( |
|
318 | + $pollId, |
|
319 | + $pollType, |
|
320 | + $pollTitle, |
|
321 | + $pollDesc, |
|
322 | + $userId, |
|
323 | + $chosenDates, |
|
324 | + $expireTs, |
|
325 | + $accessType, |
|
326 | + $accessValues, |
|
327 | + $isAnonymous, |
|
328 | + $hideNames |
|
329 | + ) { |
|
330 | + $event = $this->eventMapper->find($pollId); |
|
331 | + $event->setTitle(htmlspecialchars($pollTitle)); |
|
332 | + $event->setDescription(htmlspecialchars($pollDesc)); |
|
333 | + $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
334 | + $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
335 | + |
|
336 | + if ($accessType === 'select') { |
|
337 | + if (isset($accessValues)) { |
|
338 | + $accessValues = json_decode($accessValues); |
|
339 | + if ($accessValues !== null) { |
|
340 | + $groups = array(); |
|
341 | + $users = array(); |
|
342 | + if ($accessValues->groups !== null) { |
|
343 | + $groups = $accessValues->groups; |
|
344 | + } |
|
345 | + if ($accessValues->users !== null) { |
|
346 | + $users = $accessValues->users; |
|
347 | + } |
|
348 | + $accessType = ''; |
|
349 | + foreach ($groups as $gid) { |
|
350 | + $accessType .= $gid . ';'; |
|
351 | + } |
|
352 | + foreach ($users as $uid) { |
|
353 | + $accessType .= $uid . ';'; |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + $event->setAccess($accessType); |
|
359 | + |
|
360 | + $chosenDates = json_decode($chosenDates); |
|
361 | + |
|
362 | + $expire = null; |
|
363 | + if ($expireTs !== null && $expireTs !== '') { |
|
364 | + $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
365 | + } |
|
366 | + $event->setExpire($expire); |
|
367 | + |
|
368 | + $this->dateMapper->deleteByPoll($pollId); |
|
369 | + $this->textMapper->deleteByPoll($pollId); |
|
370 | + if ($pollType === 'event') { |
|
371 | + $event->setType(0); |
|
372 | + $this->eventMapper->update($event); |
|
373 | + sort($chosenDates); |
|
374 | + foreach ($chosenDates as $el) { |
|
375 | + $date = new Date(); |
|
376 | + $date->setPollId($pollId); |
|
377 | + $date->setDt(date('Y-m-d H:i:s', $el)); |
|
378 | + $this->dateMapper->insert($date); |
|
379 | + } |
|
380 | + } else { |
|
381 | + $event->setType(1); |
|
382 | + $this->eventMapper->update($event); |
|
383 | + foreach ($chosenDates as $el) { |
|
384 | + $text = new Text(); |
|
385 | + $text->setText($el); |
|
386 | + $text->setPollId($pollId); |
|
387 | + $this->textMapper->insert($text); |
|
388 | + } |
|
389 | + } |
|
390 | + $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
391 | + return new RedirectResponse($url); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @NoAdminRequired |
|
396 | + * @NoCSRFRequired |
|
397 | + */ |
|
398 | + public function createPoll() { |
|
399 | + return new TemplateResponse('polls', 'create.tmpl', |
|
400 | + ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @NoAdminRequired |
|
405 | + * @NoCSRFRequired |
|
406 | + * @param $pollType |
|
407 | + * @param $pollTitle |
|
408 | + * @param $pollDesc |
|
409 | + * @param $userId |
|
410 | + * @param $chosenDates |
|
411 | + * @param $expireTs |
|
412 | + * @param $accessType |
|
413 | + * @param $accessValues |
|
414 | + * @param $isAnonymous |
|
415 | + * @param $hideNames |
|
416 | + * @return RedirectResponse |
|
417 | + */ |
|
418 | + public function insertPoll( |
|
419 | + $pollType, |
|
420 | + $pollTitle, |
|
421 | + $pollDesc, |
|
422 | + $userId, |
|
423 | + $chosenDates, |
|
424 | + $expireTs, |
|
425 | + $accessType, |
|
426 | + $accessValues, |
|
427 | + $isAnonymous, |
|
428 | + $hideNames |
|
429 | + ) { |
|
430 | + $event = new Event(); |
|
431 | + $event->setTitle(htmlspecialchars($pollTitle)); |
|
432 | + $event->setDescription(htmlspecialchars($pollDesc)); |
|
433 | + $event->setOwner($userId); |
|
434 | + $event->setCreated(date('Y-m-d H:i:s')); |
|
435 | + $event->setHash(\OC::$server->getSecureRandom()->generate( |
|
436 | + 16, |
|
437 | + ISecureRandom::CHAR_DIGITS . |
|
438 | + ISecureRandom::CHAR_LOWER . |
|
439 | + ISecureRandom::CHAR_UPPER |
|
440 | + )); |
|
441 | + $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
442 | + $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
443 | + |
|
444 | + if ($accessType === 'select') { |
|
445 | + if (isset($accessValues)) { |
|
446 | + $accessValues = json_decode($accessValues); |
|
447 | + if ($accessValues !== null) { |
|
448 | + $groups = array(); |
|
449 | + $users = array(); |
|
450 | + if ($accessValues->groups !== null) { |
|
451 | + $groups = $accessValues->groups; |
|
452 | + } |
|
453 | + if ($accessValues->users !== null) { |
|
454 | + $users = $accessValues->users; |
|
455 | + } |
|
456 | + $accessType = ''; |
|
457 | + foreach ($groups as $gid) { |
|
458 | + $accessType .= $gid . ';'; |
|
459 | + } |
|
460 | + foreach ($users as $uid) { |
|
461 | + $accessType .= $uid . ';'; |
|
462 | + } |
|
463 | + } |
|
464 | + } |
|
465 | + } |
|
466 | + $event->setAccess($accessType); |
|
467 | + |
|
468 | + $chosenDates = json_decode($chosenDates); |
|
469 | + |
|
470 | + $expire = null; |
|
471 | + if ($expireTs !== null && $expireTs !== '') { |
|
472 | + $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
473 | + } |
|
474 | + $event->setExpire($expire); |
|
475 | + |
|
476 | + if ($pollType === 'event') { |
|
477 | + $event->setType(0); |
|
478 | + $ins = $this->eventMapper->insert($event); |
|
479 | + $poll_id = $ins->getId(); |
|
480 | + sort($chosenDates); |
|
481 | + foreach ($chosenDates as $el) { |
|
482 | + $date = new Date(); |
|
483 | + $date->setPollId($poll_id); |
|
484 | + $date->setDt(date('Y-m-d H:i:s', $el)); |
|
485 | + $this->dateMapper->insert($date); |
|
486 | + } |
|
487 | + } else { |
|
488 | + $event->setType(1); |
|
489 | + $ins = $this->eventMapper->insert($event); |
|
490 | + $poll_id = $ins->getId(); |
|
491 | + $cnt = 1; |
|
492 | + foreach ($chosenDates as $el) { |
|
493 | + $text = new Text(); |
|
494 | + $text->setText($el . '_' . $cnt); |
|
495 | + $text->setPollId($poll_id); |
|
496 | + $this->textMapper->insert($text); |
|
497 | + $cnt++; |
|
498 | + } |
|
499 | + } |
|
500 | + $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
501 | + return new RedirectResponse($url); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * @NoAdminRequired |
|
506 | + * @NoCSRFRequired |
|
507 | + * @PublicPage |
|
508 | + * @param $pollId |
|
509 | + * @param $userId |
|
510 | + * @param $types |
|
511 | + * @param $dates |
|
512 | + * @param $receiveNotifications |
|
513 | + * @param $changed |
|
514 | + * @return RedirectResponse |
|
515 | + */ |
|
516 | + public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) { |
|
517 | + if ($this->userId !== null) { |
|
518 | + if ($receiveNotifications === 'true') { |
|
519 | + try { |
|
520 | + //check if user already set notification for this poll |
|
521 | + $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
|
522 | + } catch (DoesNotExistException $e) { |
|
523 | + //insert if not exist |
|
524 | + $not = new Notification(); |
|
525 | + $not->setUserId($userId); |
|
526 | + $not->setPollId($pollId); |
|
527 | + $this->notificationMapper->insert($not); |
|
528 | + } |
|
529 | + } else { |
|
530 | + try { |
|
531 | + //delete if entry is in db |
|
532 | + $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId); |
|
533 | + $this->notificationMapper->delete($not); |
|
534 | + } catch (DoesNotExistException $e) { |
|
535 | + //doesn't exist in db, nothing to do |
|
536 | + } |
|
537 | + } |
|
538 | + } |
|
539 | + $poll = $this->eventMapper->find($pollId); |
|
540 | + if ($changed === 'true') { |
|
541 | + $dates = json_decode($dates); |
|
542 | + $types = json_decode($types); |
|
543 | + $count_dates = count($dates); |
|
544 | + if ($poll->getType() == '0') { |
|
545 | + $this->participationMapper->deleteByPollAndUser($pollId, $userId); |
|
546 | + } else { |
|
547 | + $this->participationTextMapper->deleteByPollAndUser($pollId, $userId); |
|
548 | + } |
|
549 | + for ($i = 0; $i < $count_dates; $i++) { |
|
550 | + if ($poll->getType() == '0') { |
|
551 | + $part = new Participation(); |
|
552 | + $part->setPollId($pollId); |
|
553 | + $part->setUserId($userId); |
|
554 | + $part->setDt(date('Y-m-d H:i:s', $dates[$i])); |
|
555 | + $part->setType($types[$i]); |
|
556 | + $this->participationMapper->insert($part); |
|
557 | + } else { |
|
558 | + $part = new ParticipationText(); |
|
559 | + $part->setPollId($pollId); |
|
560 | + $part->setUserId($userId); |
|
561 | + $part->setText($dates[$i]); |
|
562 | + $part->setType($types[$i]); |
|
563 | + $this->participationTextMapper->insert($part); |
|
564 | + } |
|
565 | + |
|
566 | + } |
|
567 | + $this->sendNotifications($pollId, $userId); |
|
568 | + } |
|
569 | + $hash = $poll->getHash(); |
|
570 | + $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]); |
|
571 | + return new RedirectResponse($url); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * @NoAdminRequired |
|
576 | + * @NoCSRFRequired |
|
577 | + * @PublicPage |
|
578 | + * @param $pollId |
|
579 | + * @param $userId |
|
580 | + * @param $commentBox |
|
581 | + * @return JSONResponse |
|
582 | + */ |
|
583 | + public function insertComment($pollId, $userId, $commentBox) { |
|
584 | + $comment = new Comment(); |
|
585 | + $comment->setPollId($pollId); |
|
586 | + $comment->setUserId($userId); |
|
587 | + $comment->setComment($commentBox); |
|
588 | + $comment->setDt(date('Y-m-d H:i:s')); |
|
589 | + $this->commentMapper->insert($comment); |
|
590 | + $this->sendNotifications($pollId, $userId); |
|
591 | + if ($this->manager->get($userId) !== null) { |
|
592 | + $newUserId = $this->manager->get($userId)->getDisplayName(); |
|
593 | + } else { |
|
594 | + $newUserId = $userId; |
|
595 | + } |
|
596 | + return new JSONResponse(array( |
|
597 | + 'comment' => $commentBox, |
|
598 | + 'date' => date('Y-m-d H:i:s'), |
|
599 | + 'userName' => $newUserId |
|
600 | + )); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * @NoAdminRequired |
|
605 | + * @NoCSRFRequired |
|
606 | + * @param $searchTerm |
|
607 | + * @param $groups |
|
608 | + * @param $users |
|
609 | + * @return array |
|
610 | + */ |
|
611 | + public function search($searchTerm, $groups, $users) { |
|
612 | + return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users)); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * @NoAdminRequired |
|
617 | + * @NoCSRFRequired |
|
618 | + * @param $searchTerm |
|
619 | + * @param $groups |
|
620 | + * @return array |
|
621 | + */ |
|
622 | + public function searchForGroups($searchTerm, $groups) { |
|
623 | + $selectedGroups = json_decode($groups); |
|
624 | + $groups = $this->groupManager->search($searchTerm); |
|
625 | + $gids = array(); |
|
626 | + $sgids = array(); |
|
627 | + foreach ($selectedGroups as $sg) { |
|
628 | + $sgids[] = str_replace('group_', '', $sg); |
|
629 | + } |
|
630 | + foreach ($groups as $g) { |
|
631 | + $gids[] = $g->getGID(); |
|
632 | + } |
|
633 | + $diffGids = array_diff($gids, $sgids); |
|
634 | + $gids = array(); |
|
635 | + foreach ($diffGids as $g) { |
|
636 | + $gids[] = ['gid' => $g, 'isGroup' => true]; |
|
637 | + } |
|
638 | + return $gids; |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * @NoAdminRequired |
|
643 | + * @NoCSRFRequired |
|
644 | + * @param $searchTerm |
|
645 | + * @param $users |
|
646 | + * @return array |
|
647 | + */ |
|
648 | + public function searchForUsers($searchTerm, $users) { |
|
649 | + $selectedUsers = json_decode($users); |
|
650 | + Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR); |
|
651 | + $userNames = $this->userMgr->searchDisplayName($searchTerm); |
|
652 | + $users = array(); |
|
653 | + $sUsers = array(); |
|
654 | + foreach ($selectedUsers as $su) { |
|
655 | + $sUsers[] = str_replace('user_', '', $su); |
|
656 | + } |
|
657 | + foreach ($userNames as $u) { |
|
658 | + $alreadyAdded = false; |
|
659 | + foreach ($sUsers as &$su) { |
|
660 | + if ($su === $u->getUID()) { |
|
661 | + unset($su); |
|
662 | + $alreadyAdded = true; |
|
663 | + break; |
|
664 | + } |
|
665 | + } |
|
666 | + if (!$alreadyAdded) { |
|
667 | + $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false); |
|
668 | + } else { |
|
669 | + continue; |
|
670 | + } |
|
671 | + } |
|
672 | + return $users; |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * @NoAdminRequired |
|
677 | + * @NoCSRFRequired |
|
678 | + * @param $username |
|
679 | + * @return string |
|
680 | + */ |
|
681 | + public function getDisplayName($username) { |
|
682 | + return $this->manager->get($username)->getDisplayName(); |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * @return Event[] |
|
687 | + */ |
|
688 | + public function getPollsForUser() { |
|
689 | + return $this->eventMapper->findAllForUser($this->userId); |
|
690 | + } |
|
691 | + |
|
692 | + /** |
|
693 | + * @param $user |
|
694 | + * @return Event[] |
|
695 | + */ |
|
696 | + public function getPollsForUserWithInfo($user = null) { |
|
697 | + if ($user === null) { |
|
698 | + return $this->eventMapper->findAllForUserWithInfo($this->userId); |
|
699 | + } else { |
|
700 | + return $this->eventMapper->findAllForUserWithInfo($user); |
|
701 | + } |
|
702 | + } |
|
703 | + /** |
|
704 | + * @return array |
|
705 | + */ |
|
706 | + public function getGroups() { |
|
707 | + // $this->requireLogin(); |
|
708 | + if (class_exists('\OC_Group', true)) { |
|
709 | + // Nextcloud <= 11, ownCloud |
|
710 | + return \OC_Group::getUserGroups($this->userId); |
|
711 | + } |
|
712 | + // Nextcloud >= 12 |
|
713 | + $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser()); |
|
714 | + return array_map(function ($group) { |
|
715 | + return $group->getGID(); |
|
716 | + }, $groups); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * @param $poll |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + private function hasUserAccess($poll) { |
|
724 | + $access = $poll->getAccess(); |
|
725 | + $owner = $poll->getOwner(); |
|
726 | + if ($access === 'public') { |
|
727 | + return true; |
|
728 | + } |
|
729 | + if ($access === 'hidden') { |
|
730 | + return true; |
|
731 | + } |
|
732 | + if ($this->userId === null) { |
|
733 | + return false; |
|
734 | + } |
|
735 | + if ($access === 'registered') { |
|
736 | + return true; |
|
737 | + } |
|
738 | + if ($owner === $this->userId) { |
|
739 | + return true; |
|
740 | + } |
|
741 | + Util::writeLog("polls", $this->userId, Util::ERROR); |
|
742 | + $user_groups = $this->getGroups(); |
|
743 | + $arr = explode(';', $access); |
|
744 | + foreach ($arr as $item) { |
|
745 | + if (strpos($item, 'group_') === 0) { |
|
746 | + $grp = substr($item, 6); |
|
747 | + foreach ($user_groups as $user_group) { |
|
748 | + if ($user_group === $grp) { |
|
749 | + return true; |
|
750 | + } |
|
751 | + } |
|
752 | + } else { |
|
753 | + if (strpos($item, 'user_') === 0) { |
|
754 | + $usr = substr($item, 5); |
|
755 | + if ($usr === User::getUser()) { |
|
756 | + return true; |
|
757 | + } |
|
758 | + } |
|
759 | + } |
|
760 | + } |
|
761 | + return false; |
|
762 | + } |
|
763 | 763 | } |
@@ -28,64 +28,64 @@ |
||
28 | 28 | |
29 | 29 | class NotificationMapper extends Mapper { |
30 | 30 | |
31 | - public function __construct(IDBConnection $db) { |
|
32 | - parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification'); |
|
33 | - } |
|
31 | + public function __construct(IDBConnection $db) { |
|
32 | + parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification'); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param int $id |
|
37 | - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
38 | - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
39 | - * @return Notification |
|
40 | - */ |
|
41 | - public function find($id) { |
|
42 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
|
43 | - return $this->findEntity($sql, [$id]); |
|
44 | - } |
|
35 | + /** |
|
36 | + * @param int $id |
|
37 | + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
38 | + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
39 | + * @return Notification |
|
40 | + */ |
|
41 | + public function find($id) { |
|
42 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
|
43 | + return $this->findEntity($sql, [$id]); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $userId |
|
48 | - * @param string $from |
|
49 | - * @param string $until |
|
50 | - * @param int $limit |
|
51 | - * @param int $offset |
|
52 | - * @return Notification[] |
|
53 | - */ |
|
54 | - public function findBetween($userId, $from, $until, $limit = null, $offset = null) { |
|
55 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE userId = ? AND timestamp BETWEEN ? AND ?'; |
|
56 | - return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset); |
|
57 | - } |
|
46 | + /** |
|
47 | + * @param string $userId |
|
48 | + * @param string $from |
|
49 | + * @param string $until |
|
50 | + * @param int $limit |
|
51 | + * @param int $offset |
|
52 | + * @return Notification[] |
|
53 | + */ |
|
54 | + public function findBetween($userId, $from, $until, $limit = null, $offset = null) { |
|
55 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE userId = ? AND timestamp BETWEEN ? AND ?'; |
|
56 | + return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param int $limit |
|
61 | - * @param int $offset |
|
62 | - * @return Notification[] |
|
63 | - */ |
|
64 | - public function findAll($limit = null, $offset = null) { |
|
65 | - $sql = 'SELECT * FROM ' . $this->getTableName(); |
|
66 | - return $this->findEntities($sql, [], $limit, $offset); |
|
67 | - } |
|
59 | + /** |
|
60 | + * @param int $limit |
|
61 | + * @param int $offset |
|
62 | + * @return Notification[] |
|
63 | + */ |
|
64 | + public function findAll($limit = null, $offset = null) { |
|
65 | + $sql = 'SELECT * FROM ' . $this->getTableName(); |
|
66 | + return $this->findEntities($sql, [], $limit, $offset); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $pollId |
|
71 | - * @param int $limit |
|
72 | - * @param int $offset |
|
73 | - * @return Notification[] |
|
74 | - */ |
|
75 | - public function findAllByPoll($pollId, $limit = null, $offset = null) { |
|
76 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
77 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
78 | - } |
|
69 | + /** |
|
70 | + * @param string $pollId |
|
71 | + * @param int $limit |
|
72 | + * @param int $offset |
|
73 | + * @return Notification[] |
|
74 | + */ |
|
75 | + public function findAllByPoll($pollId, $limit = null, $offset = null) { |
|
76 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
77 | + return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $pollId |
|
82 | - * @param string $userId |
|
83 | - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
84 | - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
85 | - * @return Notification |
|
86 | - */ |
|
87 | - public function findByUserAndPoll($pollId, $userId) { |
|
88 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
89 | - return $this->findEntity($sql, [$pollId, $userId]); |
|
90 | - } |
|
80 | + /** |
|
81 | + * @param string $pollId |
|
82 | + * @param string $userId |
|
83 | + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
84 | + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
85 | + * @return Notification |
|
86 | + */ |
|
87 | + public function findByUserAndPoll($pollId, $userId) { |
|
88 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
89 | + return $this->findEntity($sql, [$pollId, $userId]); |
|
90 | + } |
|
91 | 91 | } |
@@ -28,57 +28,57 @@ discard block |
||
28 | 28 | |
29 | 29 | class EventMapper extends Mapper { |
30 | 30 | |
31 | - /** |
|
32 | - * EventMapper constructor. |
|
33 | - * @param IDBConnection $db |
|
34 | - */ |
|
35 | - public function __construct(IDBConnection $db) { |
|
36 | - parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event'); |
|
37 | - } |
|
31 | + /** |
|
32 | + * EventMapper constructor. |
|
33 | + * @param IDBConnection $db |
|
34 | + */ |
|
35 | + public function __construct(IDBConnection $db) { |
|
36 | + parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param int $id |
|
41 | - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
42 | - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
43 | - * @return Event |
|
44 | - */ |
|
45 | - public function find($id) { |
|
46 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
|
47 | - return $this->findEntity($sql, [$id]); |
|
48 | - } |
|
39 | + /** |
|
40 | + * @param int $id |
|
41 | + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
42 | + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
43 | + * @return Event |
|
44 | + */ |
|
45 | + public function find($id) { |
|
46 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
|
47 | + return $this->findEntity($sql, [$id]); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param $hash |
|
52 | - * @param int $limit |
|
53 | - * @param int $offset |
|
54 | - * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
55 | - * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
56 | - * @return Event |
|
57 | - */ |
|
58 | - public function findByHash($hash, $limit = null, $offset = null) { |
|
59 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?'; |
|
60 | - return $this->findEntity($sql, [$hash], $limit, $offset); |
|
61 | - } |
|
50 | + /** |
|
51 | + * @param $hash |
|
52 | + * @param int $limit |
|
53 | + * @param int $offset |
|
54 | + * @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
55 | + * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
56 | + * @return Event |
|
57 | + */ |
|
58 | + public function findByHash($hash, $limit = null, $offset = null) { |
|
59 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?'; |
|
60 | + return $this->findEntity($sql, [$hash], $limit, $offset); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param $userId |
|
65 | - * @param int $limit |
|
66 | - * @param int $offset |
|
67 | - * @return Event[] |
|
68 | - */ |
|
69 | - public function findAllForUser($userId, $limit = null, $offset = null) { |
|
70 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?'; |
|
71 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
72 | - } |
|
63 | + /** |
|
64 | + * @param $userId |
|
65 | + * @param int $limit |
|
66 | + * @param int $offset |
|
67 | + * @return Event[] |
|
68 | + */ |
|
69 | + public function findAllForUser($userId, $limit = null, $offset = null) { |
|
70 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?'; |
|
71 | + return $this->findEntities($sql, [$userId], $limit, $offset); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $userId |
|
76 | - * @param int $limit |
|
77 | - * @param int $offset |
|
78 | - * @return Event[] |
|
79 | - */ |
|
80 | - public function findAllForUserWithInfo($userId, $limit = null, $offset = null) { |
|
81 | - $sql = 'SELECT DISTINCT *PREFIX*polls_events.id, |
|
74 | + /** |
|
75 | + * @param string $userId |
|
76 | + * @param int $limit |
|
77 | + * @param int $offset |
|
78 | + * @return Event[] |
|
79 | + */ |
|
80 | + public function findAllForUserWithInfo($userId, $limit = null, $offset = null) { |
|
81 | + $sql = 'SELECT DISTINCT *PREFIX*polls_events.id, |
|
82 | 82 | *PREFIX*polls_events.hash, |
83 | 83 | *PREFIX*polls_events.type, |
84 | 84 | *PREFIX*polls_events.title, |
@@ -103,6 +103,6 @@ discard block |
||
103 | 103 | OR |
104 | 104 | *PREFIX*polls_comments.user_id = ? |
105 | 105 | ORDER BY created'; |
106 | - return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset); |
|
107 | - } |
|
106 | + return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset); |
|
107 | + } |
|
108 | 108 | } |