@@ -28,55 +28,55 @@ 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 | - * @return Event |
|
| 55 | - */ |
|
| 56 | - public function findByHash($hash, $limit = null, $offset = null) { |
|
| 57 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?'; |
|
| 58 | - return $this->findEntity($sql, [$hash], $limit, $offset); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * @param $hash |
|
| 52 | + * @param int $limit |
|
| 53 | + * @param int $offset |
|
| 54 | + * @return Event |
|
| 55 | + */ |
|
| 56 | + public function findByHash($hash, $limit = null, $offset = null) { |
|
| 57 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?'; |
|
| 58 | + return $this->findEntity($sql, [$hash], $limit, $offset); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param $userId |
|
| 63 | - * @param int $limit |
|
| 64 | - * @param int $offset |
|
| 65 | - * @return Event[] |
|
| 66 | - */ |
|
| 67 | - public function findAllForUser($userId, $limit = null, $offset = null) { |
|
| 68 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?'; |
|
| 69 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * @param $userId |
|
| 63 | + * @param int $limit |
|
| 64 | + * @param int $offset |
|
| 65 | + * @return Event[] |
|
| 66 | + */ |
|
| 67 | + public function findAllForUser($userId, $limit = null, $offset = null) { |
|
| 68 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?'; |
|
| 69 | + return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param string $userId |
|
| 74 | - * @param int $limit |
|
| 75 | - * @param int $offset |
|
| 76 | - * @return Event[] |
|
| 77 | - */ |
|
| 78 | - public function findAllForUserWithInfo($userId, $limit = null, $offset = null) { |
|
| 79 | - $sql = 'SELECT DISTINCT *PREFIX*polls_events.id, |
|
| 72 | + /** |
|
| 73 | + * @param string $userId |
|
| 74 | + * @param int $limit |
|
| 75 | + * @param int $offset |
|
| 76 | + * @return Event[] |
|
| 77 | + */ |
|
| 78 | + public function findAllForUserWithInfo($userId, $limit = null, $offset = null) { |
|
| 79 | + $sql = 'SELECT DISTINCT *PREFIX*polls_events.id, |
|
| 80 | 80 | *PREFIX*polls_events.hash, |
| 81 | 81 | *PREFIX*polls_events.type, |
| 82 | 82 | *PREFIX*polls_events.title, |
@@ -101,6 +101,6 @@ discard block |
||
| 101 | 101 | OR |
| 102 | 102 | *PREFIX*polls_comments.user_id = ? |
| 103 | 103 | ORDER BY created'; |
| 104 | - return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset); |
|
| 105 | - } |
|
| 104 | + return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function find($id) { |
| 46 | 46 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?'; |
| 47 | - return $this->findEntity($sql, [$id]); |
|
| 47 | + return $this->findEntity($sql, [ $id ]); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function findByHash($hash, $limit = null, $offset = null) { |
| 57 | 57 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?'; |
| 58 | - return $this->findEntity($sql, [$hash], $limit, $offset); |
|
| 58 | + return $this->findEntity($sql, [ $hash ], $limit, $offset); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function findAllForUser($userId, $limit = null, $offset = null) { |
| 68 | 68 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?'; |
| 69 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 69 | + return $this->findEntities($sql, [ $userId ], $limit, $offset); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -101,6 +101,6 @@ discard block |
||
| 101 | 101 | OR |
| 102 | 102 | *PREFIX*polls_comments.user_id = ? |
| 103 | 103 | ORDER BY created'; |
| 104 | - return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset); |
|
| 104 | + return $this->findEntities($sql, [ 'hidden', $userId, 'hidden', $userId, $userId ], $limit, $offset); |
|
| 105 | 105 | } |
| 106 | 106 | } |
@@ -28,50 +28,50 @@ |
||
| 28 | 28 | |
| 29 | 29 | class ParticipationTextMapper extends Mapper { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * ParticipationTextMapper constructor. |
|
| 33 | - * @param IDBConnection $db |
|
| 34 | - */ |
|
| 35 | - public function __construct(IDBConnection $db) { |
|
| 36 | - parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText'); |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * ParticipationTextMapper constructor. |
|
| 33 | + * @param IDBConnection $db |
|
| 34 | + */ |
|
| 35 | + public function __construct(IDBConnection $db) { |
|
| 36 | + parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $pollId |
|
| 41 | - * @param int $limit |
|
| 42 | - * @param int $offset |
|
| 43 | - * @return ParticipationText[] |
|
| 44 | - */ |
|
| 45 | - public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 46 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 47 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $pollId |
|
| 41 | + * @param int $limit |
|
| 42 | + * @param int $offset |
|
| 43 | + * @return ParticipationText[] |
|
| 44 | + */ |
|
| 45 | + public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 46 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 47 | + return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $userId |
|
| 52 | - * @param int $limit |
|
| 53 | - * @param int $offset |
|
| 54 | - * @return ParticipationText[] |
|
| 55 | - */ |
|
| 56 | - public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 57 | - $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 58 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $userId |
|
| 52 | + * @param int $limit |
|
| 53 | + * @param int $offset |
|
| 54 | + * @return ParticipationText[] |
|
| 55 | + */ |
|
| 56 | + public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 57 | + $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 58 | + return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param string $pollId |
|
| 63 | - */ |
|
| 64 | - public function deleteByPoll($pollId) { |
|
| 65 | - $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 66 | - $this->execute($sql, [$pollId]); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * @param string $pollId |
|
| 63 | + */ |
|
| 64 | + public function deleteByPoll($pollId) { |
|
| 65 | + $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 66 | + $this->execute($sql, [$pollId]); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param string $pollId |
|
| 71 | - * @param string $userId |
|
| 72 | - */ |
|
| 73 | - public function deleteByPollAndUser($pollId, $userId) { |
|
| 74 | - $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
| 75 | - $this->execute($sql, [$pollId, $userId]); |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * @param string $pollId |
|
| 71 | + * @param string $userId |
|
| 72 | + */ |
|
| 73 | + public function deleteByPollAndUser($pollId, $userId) { |
|
| 74 | + $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
|
| 75 | + $this->execute($sql, [$pollId, $userId]); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function findByPoll($pollId, $limit = null, $offset = null) { |
| 46 | 46 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
| 47 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 47 | + return $this->findEntities($sql, [ $pollId ], $limit, $offset); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function findDistinctByUser($userId, $limit = null, $offset = null) { |
| 57 | 57 | $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
| 58 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 58 | + return $this->findEntities($sql, [ $userId ], $limit, $offset); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function deleteByPoll($pollId) { |
| 65 | 65 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
| 66 | - $this->execute($sql, [$pollId]); |
|
| 66 | + $this->execute($sql, [ $pollId ]); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -72,6 +72,6 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function deleteByPollAndUser($pollId, $userId) { |
| 74 | 74 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?'; |
| 75 | - $this->execute($sql, [$pollId, $userId]); |
|
| 75 | + $this->execute($sql, [ $pollId, $userId ]); |
|
| 76 | 76 | } |
| 77 | 77 | } |
@@ -28,30 +28,30 @@ |
||
| 28 | 28 | |
| 29 | 29 | class DateMapper extends Mapper { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * DateMapper constructor. |
|
| 33 | - * @param IDBConnection $db |
|
| 34 | - */ |
|
| 35 | - public function __construct(IDBConnection $db) { |
|
| 36 | - parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date'); |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * DateMapper constructor. |
|
| 33 | + * @param IDBConnection $db |
|
| 34 | + */ |
|
| 35 | + public function __construct(IDBConnection $db) { |
|
| 36 | + parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $pollId |
|
| 41 | - * @param int $limit |
|
| 42 | - * @param int $offset |
|
| 43 | - * @return Date[] |
|
| 44 | - */ |
|
| 45 | - public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 46 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 47 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $pollId |
|
| 41 | + * @param int $limit |
|
| 42 | + * @param int $offset |
|
| 43 | + * @return Date[] |
|
| 44 | + */ |
|
| 45 | + public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 46 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 47 | + return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $pollId |
|
| 52 | - */ |
|
| 53 | - public function deleteByPoll($pollId) { |
|
| 54 | - $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 55 | - $this->execute($sql, [$pollId]); |
|
| 56 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $pollId |
|
| 52 | + */ |
|
| 53 | + public function deleteByPoll($pollId) { |
|
| 54 | + $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 55 | + $this->execute($sql, [$pollId]); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function findByPoll($pollId, $limit = null, $offset = null) { |
| 46 | 46 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
| 47 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 47 | + return $this->findEntities($sql, [ $pollId ], $limit, $offset); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,6 +52,6 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function deleteByPoll($pollId) { |
| 54 | 54 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
| 55 | - $this->execute($sql, [$pollId]); |
|
| 55 | + $this->execute($sql, [ $pollId ]); |
|
| 56 | 56 | } |
| 57 | 57 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | |
| 29 | 29 | class CommentMapper extends Mapper { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * CommentMapper constructor. |
|
| 33 | - * @param IDBConnection $db |
|
| 34 | - */ |
|
| 35 | - public function __construct(IDBConnection $db) { |
|
| 36 | - parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment'); |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * CommentMapper constructor. |
|
| 33 | + * @param IDBConnection $db |
|
| 34 | + */ |
|
| 35 | + public function __construct(IDBConnection $db) { |
|
| 36 | + parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $userId |
|
| 41 | - * @param int $limit |
|
| 42 | - * @param int $offset |
|
| 43 | - * @return Comment[] |
|
| 44 | - */ |
|
| 45 | - public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 46 | - $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 47 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $userId |
|
| 41 | + * @param int $limit |
|
| 42 | + * @param int $offset |
|
| 43 | + * @return Comment[] |
|
| 44 | + */ |
|
| 45 | + public function findDistinctByUser($userId, $limit = null, $offset = null) { |
|
| 46 | + $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
|
| 47 | + return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $pollId |
|
| 52 | - * @param int $limit |
|
| 53 | - * @param int $offset |
|
| 54 | - * @return Comment[] |
|
| 55 | - */ |
|
| 56 | - public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 57 | - $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? ORDER BY Dt DESC'; |
|
| 58 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * @param string $pollId |
|
| 52 | + * @param int $limit |
|
| 53 | + * @param int $offset |
|
| 54 | + * @return Comment[] |
|
| 55 | + */ |
|
| 56 | + public function findByPoll($pollId, $limit = null, $offset = null) { |
|
| 57 | + $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? ORDER BY Dt DESC'; |
|
| 58 | + return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param string $pollId |
|
| 63 | - */ |
|
| 64 | - public function deleteByPoll($pollId) { |
|
| 65 | - $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 66 | - $this->execute($sql, [$pollId]); |
|
| 67 | - } |
|
| 61 | + /** |
|
| 62 | + * @param string $pollId |
|
| 63 | + */ |
|
| 64 | + public function deleteByPoll($pollId) { |
|
| 65 | + $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
|
| 66 | + $this->execute($sql, [$pollId]); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function findDistinctByUser($userId, $limit = null, $offset = null) { |
| 46 | 46 | $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?'; |
| 47 | - return $this->findEntities($sql, [$userId], $limit, $offset); |
|
| 47 | + return $this->findEntities($sql, [ $userId ], $limit, $offset); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function findByPoll($pollId, $limit = null, $offset = null) { |
| 57 | 57 | $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? ORDER BY Dt DESC'; |
| 58 | - return $this->findEntities($sql, [$pollId], $limit, $offset); |
|
| 58 | + return $this->findEntities($sql, [ $pollId ], $limit, $offset); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,6 +63,6 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public function deleteByPoll($pollId) { |
| 65 | 65 | $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?'; |
| 66 | - $this->execute($sql, [$pollId]); |
|
| 66 | + $this->execute($sql, [ $pollId ]); |
|
| 67 | 67 | } |
| 68 | 68 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | ]); |
| 247 | 247 | } else { |
| 248 | 248 | User::checkLoggedIn(); |
| 249 | - return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
| 249 | + return new TemplateResponse('polls', 'no.acc.tmpl', [ ]); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function createPoll() { |
| 395 | 395 | return new TemplateResponse('polls', 'create.tmpl', |
| 396 | - ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]); |
|
| 396 | + [ 'userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator ]); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -545,15 +545,15 @@ discard block |
||
| 545 | 545 | $part = new Participation(); |
| 546 | 546 | $part->setPollId($pollId); |
| 547 | 547 | $part->setUserId($userId); |
| 548 | - $part->setDt(date('Y-m-d H:i:s', $dates[$i])); |
|
| 549 | - $part->setType($types[$i]); |
|
| 548 | + $part->setDt(date('Y-m-d H:i:s', $dates[ $i ])); |
|
| 549 | + $part->setType($types[ $i ]); |
|
| 550 | 550 | $this->participationMapper->insert($part); |
| 551 | 551 | } else { |
| 552 | 552 | $part = new ParticipationText(); |
| 553 | 553 | $part->setPollId($pollId); |
| 554 | 554 | $part->setUserId($userId); |
| 555 | - $part->setText($dates[$i]); |
|
| 556 | - $part->setType($types[$i]); |
|
| 555 | + $part->setText($dates[ $i ]); |
|
| 556 | + $part->setType($types[ $i ]); |
|
| 557 | 557 | $this->participationTextMapper->insert($part); |
| 558 | 558 | } |
| 559 | 559 | |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | $this->sendNotifications($pollId, $userId); |
| 562 | 562 | } |
| 563 | 563 | $hash = $poll->getHash(); |
| 564 | - $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]); |
|
| 564 | + $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', [ 'hash' => $hash ]); |
|
| 565 | 565 | return new RedirectResponse($url); |
| 566 | 566 | } |
| 567 | 567 | |
@@ -619,15 +619,15 @@ discard block |
||
| 619 | 619 | $gids = array(); |
| 620 | 620 | $sgids = array(); |
| 621 | 621 | foreach ($selectedGroups as $sg) { |
| 622 | - $sgids[] = str_replace('group_', '', $sg); |
|
| 622 | + $sgids[ ] = str_replace('group_', '', $sg); |
|
| 623 | 623 | } |
| 624 | 624 | foreach ($groups as $g) { |
| 625 | - $gids[] = $g->getGID(); |
|
| 625 | + $gids[ ] = $g->getGID(); |
|
| 626 | 626 | } |
| 627 | 627 | $diffGids = array_diff($gids, $sgids); |
| 628 | 628 | $gids = array(); |
| 629 | 629 | foreach ($diffGids as $g) { |
| 630 | - $gids[] = ['gid' => $g, 'isGroup' => true]; |
|
| 630 | + $gids[ ] = [ 'gid' => $g, 'isGroup' => true ]; |
|
| 631 | 631 | } |
| 632 | 632 | return $gids; |
| 633 | 633 | } |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $users = array(); |
| 647 | 647 | $sUsers = array(); |
| 648 | 648 | foreach ($selectedUsers as $su) { |
| 649 | - $sUsers[] = str_replace('user_', '', $su); |
|
| 649 | + $sUsers[ ] = str_replace('user_', '', $su); |
|
| 650 | 650 | } |
| 651 | 651 | foreach ($userNames as $u) { |
| 652 | 652 | $alreadyAdded = false; |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | } |
| 659 | 659 | } |
| 660 | 660 | if (!$alreadyAdded) { |
| 661 | - $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false); |
|
| 661 | + $users[ ] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false); |
|
| 662 | 662 | } else { |
| 663 | 663 | continue; |
| 664 | 664 | } |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | } |
| 706 | 706 | // Nextcloud >= 12 |
| 707 | 707 | $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser()); |
| 708 | - return array_map(function ($group) { |
|
| 708 | + return array_map(function($group) { |
|
| 709 | 709 | return $group->getGID(); |
| 710 | 710 | }, $groups); |
| 711 | 711 | } |
@@ -56,704 +56,704 @@ |
||
| 56 | 56 | |
| 57 | 57 | class PageController extends Controller { |
| 58 | 58 | |
| 59 | - private $userId; |
|
| 60 | - private $commentMapper; |
|
| 61 | - private $dateMapper; |
|
| 62 | - private $eventMapper; |
|
| 63 | - private $notificationMapper; |
|
| 64 | - private $participationMapper; |
|
| 65 | - private $participationTextMapper; |
|
| 66 | - private $textMapper; |
|
| 67 | - private $urlGenerator; |
|
| 68 | - private $manager; |
|
| 69 | - private $avatarManager; |
|
| 70 | - private $logger; |
|
| 71 | - private $trans; |
|
| 72 | - private $userMgr; |
|
| 73 | - private $groupManager; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * PageController constructor. |
|
| 77 | - * @param $appName |
|
| 78 | - * @param IRequest $request |
|
| 79 | - * @param IUserManager $manager |
|
| 80 | - * @param IGroupManager $groupManager |
|
| 81 | - * @param IAvatarManager $avatarManager |
|
| 82 | - * @param ILogger $logger |
|
| 83 | - * @param IL10N $trans |
|
| 84 | - * @param IURLGenerator $urlGenerator |
|
| 85 | - * @param $userId |
|
| 86 | - * @param CommentMapper $commentMapper |
|
| 87 | - * @param DateMapper $dateMapper |
|
| 88 | - * @param EventMapper $eventMapper |
|
| 89 | - * @param NotificationMapper $notificationMapper |
|
| 90 | - * @param ParticipationMapper $ParticipationMapper |
|
| 91 | - * @param ParticipationTextMapper $ParticipationTextMapper |
|
| 92 | - * @param TextMapper $textMapper |
|
| 93 | - */ |
|
| 94 | - public function __construct( |
|
| 95 | - $appName, |
|
| 96 | - IRequest $request, |
|
| 97 | - IUserManager $manager, |
|
| 98 | - IGroupManager $groupManager, |
|
| 99 | - IAvatarManager $avatarManager, |
|
| 100 | - ILogger $logger, |
|
| 101 | - IL10N $trans, |
|
| 102 | - IURLGenerator $urlGenerator, |
|
| 103 | - $userId, |
|
| 104 | - CommentMapper $commentMapper, |
|
| 105 | - DateMapper $dateMapper, |
|
| 106 | - EventMapper $eventMapper, |
|
| 107 | - NotificationMapper $notificationMapper, |
|
| 108 | - ParticipationMapper $ParticipationMapper, |
|
| 109 | - ParticipationTextMapper $ParticipationTextMapper, |
|
| 110 | - TextMapper $textMapper |
|
| 111 | - ) { |
|
| 112 | - parent::__construct($appName, $request); |
|
| 113 | - $this->manager = $manager; |
|
| 114 | - $this->groupManager = $groupManager; |
|
| 115 | - $this->avatarManager = $avatarManager; |
|
| 116 | - $this->logger = $logger; |
|
| 117 | - $this->trans = $trans; |
|
| 118 | - $this->urlGenerator = $urlGenerator; |
|
| 119 | - $this->userId = $userId; |
|
| 120 | - $this->commentMapper = $commentMapper; |
|
| 121 | - $this->dateMapper = $dateMapper; |
|
| 122 | - $this->eventMapper = $eventMapper; |
|
| 123 | - $this->notificationMapper = $notificationMapper; |
|
| 124 | - $this->participationMapper = $ParticipationMapper; |
|
| 125 | - $this->participationTextMapper = $ParticipationTextMapper; |
|
| 126 | - $this->textMapper = $textMapper; |
|
| 127 | - $this->userMgr = \OC::$server->getUserManager(); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @NoAdminRequired |
|
| 132 | - * @NoCSRFRequired |
|
| 133 | - */ |
|
| 134 | - public function index() { |
|
| 135 | - $polls = $this->eventMapper->findAllForUserWithInfo($this->userId); |
|
| 136 | - $comments = $this->commentMapper->findDistinctByUser($this->userId); |
|
| 137 | - $partic = $this->participationMapper->findDistinctByUser($this->userId); |
|
| 138 | - $particText = $this->participationTextMapper->findDistinctByUser($this->userId); |
|
| 139 | - $response = new TemplateResponse('polls', 'main.tmpl', [ |
|
| 140 | - 'polls' => $polls, |
|
| 141 | - 'comments' => $comments, |
|
| 142 | - 'participations' => $partic, |
|
| 143 | - 'participations_text' => $particText, |
|
| 144 | - 'userId' => $this->userId, |
|
| 145 | - 'userMgr' => $this->manager, |
|
| 146 | - 'urlGenerator' => $this->urlGenerator |
|
| 147 | - ]); |
|
| 148 | - if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
|
| 149 | - $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
| 150 | - $response->setContentSecurityPolicy($csp); |
|
| 151 | - } |
|
| 152 | - return $response; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param string $pollId |
|
| 157 | - * @param string $from |
|
| 158 | - */ |
|
| 159 | - private function sendNotifications($pollId, $from) { |
|
| 160 | - $poll = $this->eventMapper->find($pollId); |
|
| 161 | - $notifications = $this->notificationMapper->findAllByPoll($pollId); |
|
| 162 | - foreach ($notifications as $notification) { |
|
| 163 | - if ($from === $notification->getUserId()) { |
|
| 164 | - continue; |
|
| 165 | - } |
|
| 166 | - $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email'); |
|
| 167 | - if (strlen($email) === 0 || !isset($email)) { |
|
| 168 | - continue; |
|
| 169 | - } |
|
| 170 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll', |
|
| 171 | - array('hash' => $poll->getHash()))); |
|
| 172 | - |
|
| 173 | - $recUser = $this->userMgr->get($notification->getUserId()); |
|
| 174 | - $sendUser = $this->userMgr->get($from); |
|
| 175 | - $rec = ""; |
|
| 176 | - if ($recUser !== null) { |
|
| 177 | - $rec = $recUser->getDisplayName(); |
|
| 178 | - } |
|
| 179 | - if ($sendUser !== null) { |
|
| 180 | - $sender = $sendUser->getDisplayName(); |
|
| 181 | - } else { |
|
| 182 | - $sender = $from; |
|
| 183 | - } |
|
| 184 | - $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>', |
|
| 185 | - array( |
|
| 186 | - $rec, |
|
| 187 | - $sender, |
|
| 188 | - $poll->getTitle(), |
|
| 189 | - $url |
|
| 190 | - )); |
|
| 191 | - |
|
| 192 | - $msg .= "<br/><br/>"; |
|
| 193 | - |
|
| 194 | - $toName = $this->userMgr->get($notification->getUserId())->getDisplayName(); |
|
| 195 | - $subject = $this->trans->t('Polls App - New Comment'); |
|
| 196 | - $fromAddress = Util::getDefaultEmailAddress('no-reply'); |
|
| 197 | - $fromName = $this->trans->t("Polls App") . ' (' . $from . ')'; |
|
| 198 | - |
|
| 199 | - try { |
|
| 200 | - $mailer = \OC::$server->getMailer(); |
|
| 201 | - $message = $mailer->createMessage(); |
|
| 202 | - $message->setSubject($subject); |
|
| 203 | - $message->setFrom(array($fromAddress => $fromName)); |
|
| 204 | - $message->setTo(array($email => $toName)); |
|
| 205 | - $message->setHtmlBody($msg); |
|
| 206 | - $mailer->send($message); |
|
| 207 | - } catch (\Exception $e) { |
|
| 208 | - $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')'; |
|
| 209 | - Util::writeLog("polls", $message, Util::ERROR); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @NoAdminRequired |
|
| 216 | - * @NoCSRFRequired |
|
| 217 | - * @PublicPage |
|
| 218 | - * @param string $hash |
|
| 219 | - * @return TemplateResponse |
|
| 220 | - */ |
|
| 221 | - public function gotoPoll($hash) { |
|
| 222 | - $poll = $this->eventMapper->findByHash($hash); |
|
| 223 | - if ($poll->getType() == '0') { |
|
| 224 | - $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
| 225 | - $votes = $this->participationMapper->findByPoll($poll->getId()); |
|
| 226 | - } else { |
|
| 227 | - $dates = $this->textMapper->findByPoll($poll->getId()); |
|
| 228 | - $votes = $this->participationTextMapper->findByPoll($poll->getId()); |
|
| 229 | - } |
|
| 230 | - $comments = $this->commentMapper->findByPoll($poll->getId()); |
|
| 231 | - try { |
|
| 232 | - $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId); |
|
| 233 | - } catch (DoesNotExistException $e) { |
|
| 234 | - $notification = null; |
|
| 235 | - } |
|
| 236 | - if ($this->hasUserAccess($poll)) { |
|
| 237 | - return new TemplateResponse('polls', 'goto.tmpl', [ |
|
| 238 | - 'poll' => $poll, |
|
| 239 | - 'dates' => $dates, |
|
| 240 | - 'comments' => $comments, |
|
| 241 | - 'votes' => $votes, |
|
| 242 | - 'notification' => $notification, |
|
| 243 | - 'userId' => $this->userId, |
|
| 244 | - 'userMgr' => $this->manager, |
|
| 245 | - 'urlGenerator' => $this->urlGenerator, |
|
| 246 | - 'avatarManager' => $this->avatarManager |
|
| 247 | - ]); |
|
| 248 | - } else { |
|
| 249 | - User::checkLoggedIn(); |
|
| 250 | - return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @NoAdminRequired |
|
| 256 | - * @NoCSRFRequired |
|
| 257 | - * @param string $pollId |
|
| 258 | - * @return RedirectResponse |
|
| 259 | - */ |
|
| 260 | - public function deletePoll($pollId) { |
|
| 261 | - $poll = new Event(); |
|
| 262 | - $poll->setId($pollId); |
|
| 263 | - $this->eventMapper->delete($poll); |
|
| 264 | - $this->textMapper->deleteByPoll($pollId); |
|
| 265 | - $this->dateMapper->deleteByPoll($pollId); |
|
| 266 | - $this->participationMapper->deleteByPoll($pollId); |
|
| 267 | - $this->participationTextMapper->deleteByPoll($pollId); |
|
| 268 | - $this->commentMapper->deleteByPoll($pollId); |
|
| 269 | - $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
| 270 | - return new RedirectResponse($url); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * @NoAdminRequired |
|
| 275 | - * @NoCSRFRequired |
|
| 276 | - * @param string $hash |
|
| 277 | - * @return TemplateResponse |
|
| 278 | - */ |
|
| 279 | - public function editPoll($hash) { |
|
| 280 | - $poll = $this->eventMapper->findByHash($hash); |
|
| 281 | - if ($this->userId !== $poll->getOwner()) { |
|
| 282 | - return new TemplateResponse('polls', 'no.create.tmpl'); |
|
| 283 | - } |
|
| 284 | - if ($poll->getType() == '0') { |
|
| 285 | - $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
| 286 | - } else { |
|
| 287 | - $dates = $this->textMapper->findByPoll($poll->getId()); |
|
| 288 | - } |
|
| 289 | - return new TemplateResponse('polls', 'create.tmpl', [ |
|
| 290 | - 'poll' => $poll, |
|
| 291 | - 'dates' => $dates, |
|
| 292 | - 'userId' => $this->userId, |
|
| 293 | - 'userMgr' => $this->manager, |
|
| 294 | - 'urlGenerator' => $this->urlGenerator |
|
| 295 | - ]); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @NoAdminRequired |
|
| 300 | - * @NoCSRFRequired |
|
| 301 | - * @param $pollId |
|
| 302 | - * @param $pollType |
|
| 303 | - * @param $pollTitle |
|
| 304 | - * @param $pollDesc |
|
| 305 | - * @param $userId |
|
| 306 | - * @param $chosenDates |
|
| 307 | - * @param $expireTs |
|
| 308 | - * @param $accessType |
|
| 309 | - * @param $accessValues |
|
| 310 | - * @param $isAnonymous |
|
| 311 | - * @param $hideNames |
|
| 312 | - * @return RedirectResponse |
|
| 313 | - */ |
|
| 314 | - public function updatePoll( |
|
| 315 | - $pollId, |
|
| 316 | - $pollType, |
|
| 317 | - $pollTitle, |
|
| 318 | - $pollDesc, |
|
| 319 | - $userId, |
|
| 320 | - $chosenDates, |
|
| 321 | - $expireTs, |
|
| 322 | - $accessType, |
|
| 323 | - $accessValues, |
|
| 324 | - $isAnonymous, |
|
| 325 | - $hideNames |
|
| 326 | - ) { |
|
| 327 | - $event = $this->eventMapper->find($pollId); |
|
| 328 | - $event->setTitle(htmlspecialchars($pollTitle)); |
|
| 329 | - $event->setDescription(htmlspecialchars($pollDesc)); |
|
| 330 | - $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
| 331 | - $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
| 332 | - |
|
| 333 | - if ($accessType === 'select') { |
|
| 334 | - if (isset($accessValues)) { |
|
| 335 | - $accessValues = json_decode($accessValues); |
|
| 336 | - if ($accessValues !== null) { |
|
| 337 | - $groups = array(); |
|
| 338 | - $users = array(); |
|
| 339 | - if ($accessValues->groups !== null) { |
|
| 340 | - $groups = $accessValues->groups; |
|
| 341 | - } |
|
| 342 | - if ($accessValues->users !== null) { |
|
| 343 | - $users = $accessValues->users; |
|
| 344 | - } |
|
| 345 | - $accessType = ''; |
|
| 346 | - foreach ($groups as $gid) { |
|
| 347 | - $accessType .= $gid . ';'; |
|
| 348 | - } |
|
| 349 | - foreach ($users as $uid) { |
|
| 350 | - $accessType .= $uid . ';'; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - $event->setAccess($accessType); |
|
| 356 | - |
|
| 357 | - $chosenDates = json_decode($chosenDates); |
|
| 358 | - |
|
| 359 | - $expire = null; |
|
| 360 | - if ($expireTs !== null && $expireTs !== '') { |
|
| 361 | - $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
| 362 | - } |
|
| 363 | - $event->setExpire($expire); |
|
| 364 | - |
|
| 365 | - $this->dateMapper->deleteByPoll($pollId); |
|
| 366 | - $this->textMapper->deleteByPoll($pollId); |
|
| 367 | - if ($pollType === 'event') { |
|
| 368 | - $event->setType(0); |
|
| 369 | - $this->eventMapper->update($event); |
|
| 370 | - sort($chosenDates); |
|
| 371 | - foreach ($chosenDates as $el) { |
|
| 372 | - $date = new Date(); |
|
| 373 | - $date->setPollId($pollId); |
|
| 374 | - $date->setDt(date('Y-m-d H:i:s', $el)); |
|
| 375 | - $this->dateMapper->insert($date); |
|
| 376 | - } |
|
| 377 | - } else { |
|
| 378 | - $event->setType(1); |
|
| 379 | - $this->eventMapper->update($event); |
|
| 380 | - foreach ($chosenDates as $el) { |
|
| 381 | - $text = new Text(); |
|
| 382 | - $text->setText($el); |
|
| 383 | - $text->setPollId($pollId); |
|
| 384 | - $this->textMapper->insert($text); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
| 388 | - return new RedirectResponse($url); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @NoAdminRequired |
|
| 393 | - * @NoCSRFRequired |
|
| 394 | - */ |
|
| 395 | - public function createPoll() { |
|
| 396 | - return new TemplateResponse('polls', 'create.tmpl', |
|
| 397 | - ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @NoAdminRequired |
|
| 402 | - * @NoCSRFRequired |
|
| 403 | - * @param $pollType |
|
| 404 | - * @param $pollTitle |
|
| 405 | - * @param $pollDesc |
|
| 406 | - * @param $userId |
|
| 407 | - * @param $chosenDates |
|
| 408 | - * @param $expireTs |
|
| 409 | - * @param $accessType |
|
| 410 | - * @param $accessValues |
|
| 411 | - * @param $isAnonymous |
|
| 412 | - * @param $hideNames |
|
| 413 | - * @return RedirectResponse |
|
| 414 | - */ |
|
| 415 | - public function insertPoll( |
|
| 416 | - $pollType, |
|
| 417 | - $pollTitle, |
|
| 418 | - $pollDesc, |
|
| 419 | - $userId, |
|
| 420 | - $chosenDates, |
|
| 421 | - $expireTs, |
|
| 422 | - $accessType, |
|
| 423 | - $accessValues, |
|
| 424 | - $isAnonymous, |
|
| 425 | - $hideNames |
|
| 426 | - ) { |
|
| 427 | - $secureRandom = new SecureRandom(); |
|
| 428 | - $event = new Event(); |
|
| 429 | - $event->setTitle(htmlspecialchars($pollTitle)); |
|
| 430 | - $event->setDescription(htmlspecialchars($pollDesc)); |
|
| 431 | - $event->setOwner($userId); |
|
| 432 | - $event->setCreated(date('Y-m-d H:i:s')); |
|
| 433 | - $event->setHash($secureRandom->generate( |
|
| 434 | - 16, |
|
| 435 | - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
|
| 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 | - } |
|
| 59 | + private $userId; |
|
| 60 | + private $commentMapper; |
|
| 61 | + private $dateMapper; |
|
| 62 | + private $eventMapper; |
|
| 63 | + private $notificationMapper; |
|
| 64 | + private $participationMapper; |
|
| 65 | + private $participationTextMapper; |
|
| 66 | + private $textMapper; |
|
| 67 | + private $urlGenerator; |
|
| 68 | + private $manager; |
|
| 69 | + private $avatarManager; |
|
| 70 | + private $logger; |
|
| 71 | + private $trans; |
|
| 72 | + private $userMgr; |
|
| 73 | + private $groupManager; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * PageController constructor. |
|
| 77 | + * @param $appName |
|
| 78 | + * @param IRequest $request |
|
| 79 | + * @param IUserManager $manager |
|
| 80 | + * @param IGroupManager $groupManager |
|
| 81 | + * @param IAvatarManager $avatarManager |
|
| 82 | + * @param ILogger $logger |
|
| 83 | + * @param IL10N $trans |
|
| 84 | + * @param IURLGenerator $urlGenerator |
|
| 85 | + * @param $userId |
|
| 86 | + * @param CommentMapper $commentMapper |
|
| 87 | + * @param DateMapper $dateMapper |
|
| 88 | + * @param EventMapper $eventMapper |
|
| 89 | + * @param NotificationMapper $notificationMapper |
|
| 90 | + * @param ParticipationMapper $ParticipationMapper |
|
| 91 | + * @param ParticipationTextMapper $ParticipationTextMapper |
|
| 92 | + * @param TextMapper $textMapper |
|
| 93 | + */ |
|
| 94 | + public function __construct( |
|
| 95 | + $appName, |
|
| 96 | + IRequest $request, |
|
| 97 | + IUserManager $manager, |
|
| 98 | + IGroupManager $groupManager, |
|
| 99 | + IAvatarManager $avatarManager, |
|
| 100 | + ILogger $logger, |
|
| 101 | + IL10N $trans, |
|
| 102 | + IURLGenerator $urlGenerator, |
|
| 103 | + $userId, |
|
| 104 | + CommentMapper $commentMapper, |
|
| 105 | + DateMapper $dateMapper, |
|
| 106 | + EventMapper $eventMapper, |
|
| 107 | + NotificationMapper $notificationMapper, |
|
| 108 | + ParticipationMapper $ParticipationMapper, |
|
| 109 | + ParticipationTextMapper $ParticipationTextMapper, |
|
| 110 | + TextMapper $textMapper |
|
| 111 | + ) { |
|
| 112 | + parent::__construct($appName, $request); |
|
| 113 | + $this->manager = $manager; |
|
| 114 | + $this->groupManager = $groupManager; |
|
| 115 | + $this->avatarManager = $avatarManager; |
|
| 116 | + $this->logger = $logger; |
|
| 117 | + $this->trans = $trans; |
|
| 118 | + $this->urlGenerator = $urlGenerator; |
|
| 119 | + $this->userId = $userId; |
|
| 120 | + $this->commentMapper = $commentMapper; |
|
| 121 | + $this->dateMapper = $dateMapper; |
|
| 122 | + $this->eventMapper = $eventMapper; |
|
| 123 | + $this->notificationMapper = $notificationMapper; |
|
| 124 | + $this->participationMapper = $ParticipationMapper; |
|
| 125 | + $this->participationTextMapper = $ParticipationTextMapper; |
|
| 126 | + $this->textMapper = $textMapper; |
|
| 127 | + $this->userMgr = \OC::$server->getUserManager(); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @NoAdminRequired |
|
| 132 | + * @NoCSRFRequired |
|
| 133 | + */ |
|
| 134 | + public function index() { |
|
| 135 | + $polls = $this->eventMapper->findAllForUserWithInfo($this->userId); |
|
| 136 | + $comments = $this->commentMapper->findDistinctByUser($this->userId); |
|
| 137 | + $partic = $this->participationMapper->findDistinctByUser($this->userId); |
|
| 138 | + $particText = $this->participationTextMapper->findDistinctByUser($this->userId); |
|
| 139 | + $response = new TemplateResponse('polls', 'main.tmpl', [ |
|
| 140 | + 'polls' => $polls, |
|
| 141 | + 'comments' => $comments, |
|
| 142 | + 'participations' => $partic, |
|
| 143 | + 'participations_text' => $particText, |
|
| 144 | + 'userId' => $this->userId, |
|
| 145 | + 'userMgr' => $this->manager, |
|
| 146 | + 'urlGenerator' => $this->urlGenerator |
|
| 147 | + ]); |
|
| 148 | + if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { |
|
| 149 | + $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
| 150 | + $response->setContentSecurityPolicy($csp); |
|
| 151 | + } |
|
| 152 | + return $response; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param string $pollId |
|
| 157 | + * @param string $from |
|
| 158 | + */ |
|
| 159 | + private function sendNotifications($pollId, $from) { |
|
| 160 | + $poll = $this->eventMapper->find($pollId); |
|
| 161 | + $notifications = $this->notificationMapper->findAllByPoll($pollId); |
|
| 162 | + foreach ($notifications as $notification) { |
|
| 163 | + if ($from === $notification->getUserId()) { |
|
| 164 | + continue; |
|
| 165 | + } |
|
| 166 | + $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email'); |
|
| 167 | + if (strlen($email) === 0 || !isset($email)) { |
|
| 168 | + continue; |
|
| 169 | + } |
|
| 170 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll', |
|
| 171 | + array('hash' => $poll->getHash()))); |
|
| 172 | + |
|
| 173 | + $recUser = $this->userMgr->get($notification->getUserId()); |
|
| 174 | + $sendUser = $this->userMgr->get($from); |
|
| 175 | + $rec = ""; |
|
| 176 | + if ($recUser !== null) { |
|
| 177 | + $rec = $recUser->getDisplayName(); |
|
| 178 | + } |
|
| 179 | + if ($sendUser !== null) { |
|
| 180 | + $sender = $sendUser->getDisplayName(); |
|
| 181 | + } else { |
|
| 182 | + $sender = $from; |
|
| 183 | + } |
|
| 184 | + $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>', |
|
| 185 | + array( |
|
| 186 | + $rec, |
|
| 187 | + $sender, |
|
| 188 | + $poll->getTitle(), |
|
| 189 | + $url |
|
| 190 | + )); |
|
| 191 | + |
|
| 192 | + $msg .= "<br/><br/>"; |
|
| 193 | + |
|
| 194 | + $toName = $this->userMgr->get($notification->getUserId())->getDisplayName(); |
|
| 195 | + $subject = $this->trans->t('Polls App - New Comment'); |
|
| 196 | + $fromAddress = Util::getDefaultEmailAddress('no-reply'); |
|
| 197 | + $fromName = $this->trans->t("Polls App") . ' (' . $from . ')'; |
|
| 198 | + |
|
| 199 | + try { |
|
| 200 | + $mailer = \OC::$server->getMailer(); |
|
| 201 | + $message = $mailer->createMessage(); |
|
| 202 | + $message->setSubject($subject); |
|
| 203 | + $message->setFrom(array($fromAddress => $fromName)); |
|
| 204 | + $message->setTo(array($email => $toName)); |
|
| 205 | + $message->setHtmlBody($msg); |
|
| 206 | + $mailer->send($message); |
|
| 207 | + } catch (\Exception $e) { |
|
| 208 | + $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')'; |
|
| 209 | + Util::writeLog("polls", $message, Util::ERROR); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @NoAdminRequired |
|
| 216 | + * @NoCSRFRequired |
|
| 217 | + * @PublicPage |
|
| 218 | + * @param string $hash |
|
| 219 | + * @return TemplateResponse |
|
| 220 | + */ |
|
| 221 | + public function gotoPoll($hash) { |
|
| 222 | + $poll = $this->eventMapper->findByHash($hash); |
|
| 223 | + if ($poll->getType() == '0') { |
|
| 224 | + $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
| 225 | + $votes = $this->participationMapper->findByPoll($poll->getId()); |
|
| 226 | + } else { |
|
| 227 | + $dates = $this->textMapper->findByPoll($poll->getId()); |
|
| 228 | + $votes = $this->participationTextMapper->findByPoll($poll->getId()); |
|
| 229 | + } |
|
| 230 | + $comments = $this->commentMapper->findByPoll($poll->getId()); |
|
| 231 | + try { |
|
| 232 | + $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId); |
|
| 233 | + } catch (DoesNotExistException $e) { |
|
| 234 | + $notification = null; |
|
| 235 | + } |
|
| 236 | + if ($this->hasUserAccess($poll)) { |
|
| 237 | + return new TemplateResponse('polls', 'goto.tmpl', [ |
|
| 238 | + 'poll' => $poll, |
|
| 239 | + 'dates' => $dates, |
|
| 240 | + 'comments' => $comments, |
|
| 241 | + 'votes' => $votes, |
|
| 242 | + 'notification' => $notification, |
|
| 243 | + 'userId' => $this->userId, |
|
| 244 | + 'userMgr' => $this->manager, |
|
| 245 | + 'urlGenerator' => $this->urlGenerator, |
|
| 246 | + 'avatarManager' => $this->avatarManager |
|
| 247 | + ]); |
|
| 248 | + } else { |
|
| 249 | + User::checkLoggedIn(); |
|
| 250 | + return new TemplateResponse('polls', 'no.acc.tmpl', []); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @NoAdminRequired |
|
| 256 | + * @NoCSRFRequired |
|
| 257 | + * @param string $pollId |
|
| 258 | + * @return RedirectResponse |
|
| 259 | + */ |
|
| 260 | + public function deletePoll($pollId) { |
|
| 261 | + $poll = new Event(); |
|
| 262 | + $poll->setId($pollId); |
|
| 263 | + $this->eventMapper->delete($poll); |
|
| 264 | + $this->textMapper->deleteByPoll($pollId); |
|
| 265 | + $this->dateMapper->deleteByPoll($pollId); |
|
| 266 | + $this->participationMapper->deleteByPoll($pollId); |
|
| 267 | + $this->participationTextMapper->deleteByPoll($pollId); |
|
| 268 | + $this->commentMapper->deleteByPoll($pollId); |
|
| 269 | + $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
| 270 | + return new RedirectResponse($url); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * @NoAdminRequired |
|
| 275 | + * @NoCSRFRequired |
|
| 276 | + * @param string $hash |
|
| 277 | + * @return TemplateResponse |
|
| 278 | + */ |
|
| 279 | + public function editPoll($hash) { |
|
| 280 | + $poll = $this->eventMapper->findByHash($hash); |
|
| 281 | + if ($this->userId !== $poll->getOwner()) { |
|
| 282 | + return new TemplateResponse('polls', 'no.create.tmpl'); |
|
| 283 | + } |
|
| 284 | + if ($poll->getType() == '0') { |
|
| 285 | + $dates = $this->dateMapper->findByPoll($poll->getId()); |
|
| 286 | + } else { |
|
| 287 | + $dates = $this->textMapper->findByPoll($poll->getId()); |
|
| 288 | + } |
|
| 289 | + return new TemplateResponse('polls', 'create.tmpl', [ |
|
| 290 | + 'poll' => $poll, |
|
| 291 | + 'dates' => $dates, |
|
| 292 | + 'userId' => $this->userId, |
|
| 293 | + 'userMgr' => $this->manager, |
|
| 294 | + 'urlGenerator' => $this->urlGenerator |
|
| 295 | + ]); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @NoAdminRequired |
|
| 300 | + * @NoCSRFRequired |
|
| 301 | + * @param $pollId |
|
| 302 | + * @param $pollType |
|
| 303 | + * @param $pollTitle |
|
| 304 | + * @param $pollDesc |
|
| 305 | + * @param $userId |
|
| 306 | + * @param $chosenDates |
|
| 307 | + * @param $expireTs |
|
| 308 | + * @param $accessType |
|
| 309 | + * @param $accessValues |
|
| 310 | + * @param $isAnonymous |
|
| 311 | + * @param $hideNames |
|
| 312 | + * @return RedirectResponse |
|
| 313 | + */ |
|
| 314 | + public function updatePoll( |
|
| 315 | + $pollId, |
|
| 316 | + $pollType, |
|
| 317 | + $pollTitle, |
|
| 318 | + $pollDesc, |
|
| 319 | + $userId, |
|
| 320 | + $chosenDates, |
|
| 321 | + $expireTs, |
|
| 322 | + $accessType, |
|
| 323 | + $accessValues, |
|
| 324 | + $isAnonymous, |
|
| 325 | + $hideNames |
|
| 326 | + ) { |
|
| 327 | + $event = $this->eventMapper->find($pollId); |
|
| 328 | + $event->setTitle(htmlspecialchars($pollTitle)); |
|
| 329 | + $event->setDescription(htmlspecialchars($pollDesc)); |
|
| 330 | + $event->setIsAnonymous($isAnonymous ? 1 : 0); |
|
| 331 | + $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0); |
|
| 332 | + |
|
| 333 | + if ($accessType === 'select') { |
|
| 334 | + if (isset($accessValues)) { |
|
| 335 | + $accessValues = json_decode($accessValues); |
|
| 336 | + if ($accessValues !== null) { |
|
| 337 | + $groups = array(); |
|
| 338 | + $users = array(); |
|
| 339 | + if ($accessValues->groups !== null) { |
|
| 340 | + $groups = $accessValues->groups; |
|
| 341 | + } |
|
| 342 | + if ($accessValues->users !== null) { |
|
| 343 | + $users = $accessValues->users; |
|
| 344 | + } |
|
| 345 | + $accessType = ''; |
|
| 346 | + foreach ($groups as $gid) { |
|
| 347 | + $accessType .= $gid . ';'; |
|
| 348 | + } |
|
| 349 | + foreach ($users as $uid) { |
|
| 350 | + $accessType .= $uid . ';'; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + $event->setAccess($accessType); |
|
| 356 | + |
|
| 357 | + $chosenDates = json_decode($chosenDates); |
|
| 358 | + |
|
| 359 | + $expire = null; |
|
| 360 | + if ($expireTs !== null && $expireTs !== '') { |
|
| 361 | + $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day |
|
| 362 | + } |
|
| 363 | + $event->setExpire($expire); |
|
| 364 | + |
|
| 365 | + $this->dateMapper->deleteByPoll($pollId); |
|
| 366 | + $this->textMapper->deleteByPoll($pollId); |
|
| 367 | + if ($pollType === 'event') { |
|
| 368 | + $event->setType(0); |
|
| 369 | + $this->eventMapper->update($event); |
|
| 370 | + sort($chosenDates); |
|
| 371 | + foreach ($chosenDates as $el) { |
|
| 372 | + $date = new Date(); |
|
| 373 | + $date->setPollId($pollId); |
|
| 374 | + $date->setDt(date('Y-m-d H:i:s', $el)); |
|
| 375 | + $this->dateMapper->insert($date); |
|
| 376 | + } |
|
| 377 | + } else { |
|
| 378 | + $event->setType(1); |
|
| 379 | + $this->eventMapper->update($event); |
|
| 380 | + foreach ($chosenDates as $el) { |
|
| 381 | + $text = new Text(); |
|
| 382 | + $text->setText($el); |
|
| 383 | + $text->setPollId($pollId); |
|
| 384 | + $this->textMapper->insert($text); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + $url = $this->urlGenerator->linkToRoute('polls.page.index'); |
|
| 388 | + return new RedirectResponse($url); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @NoAdminRequired |
|
| 393 | + * @NoCSRFRequired |
|
| 394 | + */ |
|
| 395 | + public function createPoll() { |
|
| 396 | + return new TemplateResponse('polls', 'create.tmpl', |
|
| 397 | + ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @NoAdminRequired |
|
| 402 | + * @NoCSRFRequired |
|
| 403 | + * @param $pollType |
|
| 404 | + * @param $pollTitle |
|
| 405 | + * @param $pollDesc |
|
| 406 | + * @param $userId |
|
| 407 | + * @param $chosenDates |
|
| 408 | + * @param $expireTs |
|
| 409 | + * @param $accessType |
|
| 410 | + * @param $accessValues |
|
| 411 | + * @param $isAnonymous |
|
| 412 | + * @param $hideNames |
|
| 413 | + * @return RedirectResponse |
|
| 414 | + */ |
|
| 415 | + public function insertPoll( |
|
| 416 | + $pollType, |
|
| 417 | + $pollTitle, |
|
| 418 | + $pollDesc, |
|
| 419 | + $userId, |
|
| 420 | + $chosenDates, |
|
| 421 | + $expireTs, |
|
| 422 | + $accessType, |
|
| 423 | + $accessValues, |
|
| 424 | + $isAnonymous, |
|
| 425 | + $hideNames |
|
| 426 | + ) { |
|
| 427 | + $secureRandom = new SecureRandom(); |
|
| 428 | + $event = new Event(); |
|
| 429 | + $event->setTitle(htmlspecialchars($pollTitle)); |
|
| 430 | + $event->setDescription(htmlspecialchars($pollDesc)); |
|
| 431 | + $event->setOwner($userId); |
|
| 432 | + $event->setCreated(date('Y-m-d H:i:s')); |
|
| 433 | + $event->setHash($secureRandom->generate( |
|
| 434 | + 16, |
|
| 435 | + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
|
| 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 | } |
@@ -1,27 +1,27 @@ |
||
| 1 | 1 | <?php |
| 2 | - /** |
|
| 3 | - * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]> |
|
| 4 | - * |
|
| 5 | - * @author Vinzenz Rosenkranz <[email protected]> |
|
| 6 | - * |
|
| 7 | - * @license GNU AGPL version 3 or any later version |
|
| 8 | - * |
|
| 9 | - * This program is free software: you can redistribute it and/or modify |
|
| 10 | - * it under the terms of the GNU Affero General Public License as |
|
| 11 | - * published by the Free Software Foundation, either version 3 of the |
|
| 12 | - * License, or (at your option) any later version. |
|
| 13 | - * |
|
| 14 | - * This program is distributed in the hope that it will be useful, |
|
| 15 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 | - * GNU Affero General Public License for more details. |
|
| 18 | - * |
|
| 19 | - * You should have received a copy of the GNU Affero General Public License |
|
| 20 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 | - * |
|
| 22 | - */ |
|
| 2 | + /** |
|
| 3 | + * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]> |
|
| 4 | + * |
|
| 5 | + * @author Vinzenz Rosenkranz <[email protected]> |
|
| 6 | + * |
|
| 7 | + * @license GNU AGPL version 3 or any later version |
|
| 8 | + * |
|
| 9 | + * This program is free software: you can redistribute it and/or modify |
|
| 10 | + * it under the terms of the GNU Affero General Public License as |
|
| 11 | + * published by the Free Software Foundation, either version 3 of the |
|
| 12 | + * License, or (at your option) any later version. |
|
| 13 | + * |
|
| 14 | + * This program is distributed in the hope that it will be useful, |
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 17 | + * GNU Affero General Public License for more details. |
|
| 18 | + * |
|
| 19 | + * You should have received a copy of the GNU Affero General Public License |
|
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 21 | + * |
|
| 22 | + */ |
|
| 23 | 23 | |
| 24 | - \OCP\Util::addStyle('polls', 'main'); |
|
| 24 | + \OCP\Util::addStyle('polls', 'main'); |
|
| 25 | 25 | ?> |
| 26 | 26 | <div id="app"> |
| 27 | 27 | <div id="app-content"> |
@@ -34,8 +34,8 @@ |
||
| 34 | 34 | * @method void setPollId(integer $value) |
| 35 | 35 | */ |
| 36 | 36 | class Comment extends Model { |
| 37 | - protected $userId; |
|
| 38 | - protected $dt; |
|
| 39 | - protected $comment; |
|
| 40 | - protected $pollId; |
|
| 37 | + protected $userId; |
|
| 38 | + protected $dt; |
|
| 39 | + protected $comment; |
|
| 40 | + protected $pollId; |
|
| 41 | 41 | } |
@@ -30,6 +30,6 @@ |
||
| 30 | 30 | * @method void setPollId(integer $value) |
| 31 | 31 | */ |
| 32 | 32 | class Date extends Model { |
| 33 | - protected $dt; |
|
| 34 | - protected $pollId; |
|
| 33 | + protected $dt; |
|
| 34 | + protected $pollId; |
|
| 35 | 35 | } |
@@ -26,14 +26,14 @@ |
||
| 26 | 26 | use OCP\AppFramework\Db\Entity; |
| 27 | 27 | |
| 28 | 28 | class Model extends Entity { |
| 29 | - /** |
|
| 30 | - * FactoryMuffin checks for the existence of setters with method_exists($obj, $attr) but that returns false. |
|
| 31 | - * By overwriting the __set() magic method we can trigger the changed flag on $obj->attr assignment. |
|
| 32 | - * |
|
| 33 | - * @param $name |
|
| 34 | - * @param $value |
|
| 35 | - */ |
|
| 36 | - public function __set($name, $value) { |
|
| 37 | - $this->setter($name, [$value]); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * FactoryMuffin checks for the existence of setters with method_exists($obj, $attr) but that returns false. |
|
| 31 | + * By overwriting the __set() magic method we can trigger the changed flag on $obj->attr assignment. |
|
| 32 | + * |
|
| 33 | + * @param $name |
|
| 34 | + * @param $value |
|
| 35 | + */ |
|
| 36 | + public function __set($name, $value) { |
|
| 37 | + $this->setter($name, [$value]); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -34,6 +34,6 @@ |
||
| 34 | 34 | * @param $value |
| 35 | 35 | */ |
| 36 | 36 | public function __set($name, $value) { |
| 37 | - $this->setter($name, [$value]); |
|
| 37 | + $this->setter($name, [ $value ]); |
|
| 38 | 38 | } |
| 39 | 39 | } |