diff --git a/lib/Db/Answer.php b/lib/Db/Answer.php index 7f812f8..e340612 100644 --- a/lib/Db/Answer.php +++ b/lib/Db/Answer.php @@ -1,4 +1,6 @@ * @@ -35,10 +37,18 @@ use OCP\AppFramework\Db\Entity; * @method integer getTimestamp() * @method void setTimestamp(integer $value) */ -class Answer extends Model { +class Answer extends Entity { + + /** @var int */ protected $formId; + + /** @var int */ protected $questionId; + + /** @var string */ protected $text; + + /** @var int */ protected $timestamp; /** @@ -51,7 +61,7 @@ class Answer extends Model { $this->addType('timestamp', 'integer'); } - public function read() { + public function read(): array { return [ 'id' => $this->getId(), 'formId' => $this->getFormId(), diff --git a/lib/Db/AnswerMapper.php b/lib/Db/AnswerMapper.php index e7e830f..f002ea0 100644 --- a/lib/Db/AnswerMapper.php +++ b/lib/Db/AnswerMapper.php @@ -1,4 +1,6 @@ * @@ -35,7 +37,7 @@ class AnswerMapper extends QBMapper { * @param IDBConnection $db */ public function __construct(IDBConnection $db) { - parent::__construct($db, 'forms_answers', '\OCA\Forms\Db\Answer'); + parent::__construct($db, 'forms_answers', Answer::class); } // TODO: Change below functions to search by form and question id @@ -47,7 +49,7 @@ class AnswerMapper extends QBMapper { * @return Answer[] */ - public function findByForm($formId, $questionId) { + public function findByForm(int $formId, int $questionId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -66,7 +68,7 @@ class AnswerMapper extends QBMapper { * @param int $formId * @param int $questionId */ - public function deleteByFormAndQuestion($formId, $questionId) { + public function deleteByFormAndQuestion(int $formId, int $questionId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) @@ -83,7 +85,7 @@ class AnswerMapper extends QBMapper { /** * @param int $formId */ - public function deleteByForm($formId) { + public function deleteByForm(int $formId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) diff --git a/lib/Db/Event.php b/lib/Db/Event.php index 6d0f5b7..d05e911 100644 --- a/lib/Db/Event.php +++ b/lib/Db/Event.php @@ -1,4 +1,5 @@ * @@ -45,7 +46,7 @@ use OCP\AppFramework\Db\Entity; * @method integer getIsAnonymous() * @method void setIsAnonymous(integer $value) */ -class Event extends Model { +class Event extends Entity { protected $title; protected $description; protected $owner; diff --git a/lib/Db/EventMapper.php b/lib/Db/EventMapper.php index 9cf76ea..e342d4e 100644 --- a/lib/Db/EventMapper.php +++ b/lib/Db/EventMapper.php @@ -35,7 +35,7 @@ class EventMapper extends QBMapper { * @param IDBConnection $db */ public function __construct(IDBConnection $db) { - parent::__construct($db, 'forms_events', '\OCA\Forms\Db\Event'); + parent::__construct($db, 'forms_events', Event::class); } /** @@ -44,7 +44,7 @@ class EventMapper extends QBMapper { * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Event */ - public function find($id) { + public function find(int $id): Event { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -62,7 +62,7 @@ class EventMapper extends QBMapper { * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Event */ - public function findByHash($hash) { + public function findByHash(string $hash): Event { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -78,7 +78,7 @@ class EventMapper extends QBMapper { * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @return Event[] */ - public function findAll() { + public function findAll(): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') diff --git a/lib/Db/Model.php b/lib/Db/Model.php deleted file mode 100644 index e392310..0000000 --- a/lib/Db/Model.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * @author Kai Schröer - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -namespace OCA\Forms\Db; - -use OCP\AppFramework\Db\Entity; - -abstract class Model extends Entity { - /** - * FactoryMuffin checks for the existence of setters with method_exists($obj, $attr) but that returns false. - * By overwriting the __set() magic method we can trigger the changed flag on $obj->attr assignment. - * - * @param $name - * @param $value - */ - public function __set($name, $value) { - $this->setter($name, [$value]); - } -} diff --git a/lib/Db/Notification.php b/lib/Db/Notification.php index 5571ffb..51b6be9 100644 --- a/lib/Db/Notification.php +++ b/lib/Db/Notification.php @@ -1,4 +1,5 @@ * @@ -32,7 +33,7 @@ use OCP\AppFramework\Db\Entity; * @method integer getFormId() * @method void setFormId(integer $value) */ -class Notification extends Model { +class Notification extends Entity { protected $userId; protected $formId; diff --git a/lib/Db/NotificationMapper.php b/lib/Db/NotificationMapper.php index c3a2837..f76c6e8 100644 --- a/lib/Db/NotificationMapper.php +++ b/lib/Db/NotificationMapper.php @@ -1,4 +1,5 @@ * @@ -31,7 +32,7 @@ use OCP\AppFramework\Db\QBMapper; class NotificationMapper extends QBMapper { public function __construct(IDBConnection $db) { - parent::__construct($db, 'forms_notif', '\OCA\Forms\Db\Notification'); + parent::__construct($db, 'forms_notif', Notification::class); } /** @@ -41,7 +42,7 @@ class NotificationMapper extends QBMapper { * @return Notification[] */ - public function findAllByForm($formId) { + public function findAllByForm(int $formId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -59,9 +60,9 @@ class NotificationMapper extends QBMapper { * @param string $userId * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result - * @return Notification + * @return Notification[] */ - public function findByUserAndForm($formId, $userId) { + public function findByUserAndForm(int $formId, string $userId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -79,7 +80,7 @@ class NotificationMapper extends QBMapper { /** * @param int $formId */ - public function deleteByForm($formId) { + public function deleteByForm(int $formId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) diff --git a/lib/Db/Question.php b/lib/Db/Question.php index 8dc9a9a..4062edd 100644 --- a/lib/Db/Question.php +++ b/lib/Db/Question.php @@ -1,4 +1,5 @@ * @@ -35,7 +36,7 @@ use OCP\AppFramework\Db\Entity; * @method integer getTimestamp() * @method void setTimestamp(integer $value) */ -class Question extends Model { +class Question extends Entity { protected $formId; protected $formQuestionType; protected $formQuestionText; @@ -49,7 +50,7 @@ class Question extends Model { $this->addType('timestamp', 'integer'); } - public function read() { + public function read(): array { return [ 'id' => $this->getId(), 'formId' => $this->getFormId(), diff --git a/lib/Db/QuestionMapper.php b/lib/Db/QuestionMapper.php index 6ea92b8..cadd59e 100644 --- a/lib/Db/QuestionMapper.php +++ b/lib/Db/QuestionMapper.php @@ -35,7 +35,7 @@ class QuestionMapper extends QBMapper { * @param IDBConnection $db */ public function __construct(IDBConnection $db) { - parent::__construct($db, 'forms_questions', '\OCA\Forms\Db\Question'); + parent::__construct($db, 'forms_questions', Question::class); } /** @@ -44,7 +44,7 @@ class QuestionMapper extends QBMapper { * @return Option[] */ - public function findByForm($formId) { + public function findByForm(int $formId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -59,7 +59,7 @@ class QuestionMapper extends QBMapper { /** * @param int $formId */ - public function deleteByForm($formId) { + public function deleteByForm(int $formId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) diff --git a/lib/Db/Vote.php b/lib/Db/Vote.php index 85544a4..49560fd 100644 --- a/lib/Db/Vote.php +++ b/lib/Db/Vote.php @@ -1,4 +1,6 @@ * @@ -41,7 +43,7 @@ use OCP\AppFramework\Db\Entity; * @method string getVoteOptionType() * @method void setVoteOptionType(string $value) */ -class Vote extends Model { +class Vote extends Entity { protected $formId; protected $userId; protected $voteOptionId; @@ -57,7 +59,7 @@ class Vote extends Model { $this->addType('voteOptionId', 'integer'); } - public function read() { + public function read(): array { return [ 'id' => $this->getId(), 'userId' => $this->getUserId(), diff --git a/lib/Db/VoteMapper.php b/lib/Db/VoteMapper.php index 4ad723a..fb44542 100644 --- a/lib/Db/VoteMapper.php +++ b/lib/Db/VoteMapper.php @@ -35,7 +35,7 @@ class VoteMapper extends QBMapper { * @param IDBConnection $db */ public function __construct(IDBConnection $db) { - parent::__construct($db, 'forms_votes', '\OCA\Forms\Db\Vote'); + parent::__construct($db, 'forms_votes', VoteMapper::class); } /** @@ -44,7 +44,7 @@ class VoteMapper extends QBMapper { * @return Comment[] */ - public function findByForm($formId) { + public function findByForm(int $formId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -59,9 +59,9 @@ class VoteMapper extends QBMapper { /** * @param int $formId * @throws \OCP\AppFramework\Db\DoesNotExistException if not found - * @return Array + * @return array */ - public function findParticipantsByForm($formId, $limit = null, $offset = null) { + public function findParticipantsByForm(int $formId, $limit = null, $offset = null): array { $qb = $this->db->getQueryBuilder(); $qb->select('user_id') @@ -77,7 +77,7 @@ class VoteMapper extends QBMapper { * @param int $formId * @param string $userId */ - public function deleteByFormAndUser($formId, $userId) { + public function deleteByFormAndUser(int $formId, string $userId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName()) @@ -94,7 +94,7 @@ class VoteMapper extends QBMapper { /** * @param int $formId */ - public function deleteByForm($formId) { + public function deleteByForm(int $formId): void { $qb = $this->db->getQueryBuilder(); $qb->delete($this->getTableName())