@@ -23,129 +23,129 @@ |
||
| 23 | 23 | * @template-extends QBMapper<Reminder> |
| 24 | 24 | */ |
| 25 | 25 | class ReminderMapper extends QBMapper { |
| 26 | - public const TABLE_NAME = 'files_reminders'; |
|
| 27 | - |
|
| 28 | - public function __construct(IDBConnection $db) { |
|
| 29 | - parent::__construct( |
|
| 30 | - $db, |
|
| 31 | - static::TABLE_NAME, |
|
| 32 | - Reminder::class, |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function markNotified(Reminder $reminder): Reminder { |
|
| 37 | - $reminderUpdate = new Reminder(); |
|
| 38 | - $reminderUpdate->setId($reminder->getId()); |
|
| 39 | - $reminderUpdate->setNotified(true); |
|
| 40 | - return $this->update($reminderUpdate); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @throws DoesNotExistException |
|
| 45 | - */ |
|
| 46 | - public function findDueForUser(IUser $user, int $fileId): Reminder { |
|
| 47 | - $qb = $this->db->getQueryBuilder(); |
|
| 48 | - |
|
| 49 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 50 | - ->from($this->getTableName()) |
|
| 51 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 52 | - ->andWhere($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) |
|
| 53 | - ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))); |
|
| 54 | - |
|
| 55 | - return $this->findEntity($qb); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return Reminder[] |
|
| 60 | - */ |
|
| 61 | - public function findAll() { |
|
| 62 | - $qb = $this->db->getQueryBuilder(); |
|
| 63 | - |
|
| 64 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 65 | - ->from($this->getTableName()) |
|
| 66 | - ->orderBy('due_date', 'ASC'); |
|
| 67 | - |
|
| 68 | - return $this->findEntities($qb); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return Reminder[] |
|
| 73 | - */ |
|
| 74 | - public function findAllForUser(IUser $user) { |
|
| 75 | - $qb = $this->db->getQueryBuilder(); |
|
| 76 | - |
|
| 77 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 78 | - ->from($this->getTableName()) |
|
| 79 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 80 | - ->orderBy('due_date', 'ASC'); |
|
| 81 | - |
|
| 82 | - return $this->findEntities($qb); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return Reminder[] |
|
| 87 | - */ |
|
| 88 | - public function findAllForNode(Node $node) { |
|
| 89 | - try { |
|
| 90 | - $nodeId = $node->getId(); |
|
| 91 | - } catch (NotFoundException $e) { |
|
| 92 | - return []; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $qb = $this->db->getQueryBuilder(); |
|
| 96 | - |
|
| 97 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 98 | - ->from($this->getTableName()) |
|
| 99 | - ->where($qb->expr()->eq('file_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))) |
|
| 100 | - ->orderBy('due_date', 'ASC'); |
|
| 101 | - |
|
| 102 | - return $this->findEntities($qb); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return Reminder[] |
|
| 107 | - */ |
|
| 108 | - public function findOverdue() { |
|
| 109 | - $qb = $this->db->getQueryBuilder(); |
|
| 110 | - |
|
| 111 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 112 | - ->from($this->getTableName()) |
|
| 113 | - ->where($qb->expr()->lt('due_date', $qb->createFunction('NOW()'))) |
|
| 114 | - ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))) |
|
| 115 | - ->orderBy('due_date', 'ASC'); |
|
| 116 | - |
|
| 117 | - return $this->findEntities($qb); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return Reminder[] |
|
| 122 | - */ |
|
| 123 | - public function findNotified(DateTime $buffer, ?int $limit = null) { |
|
| 124 | - $qb = $this->db->getQueryBuilder(); |
|
| 125 | - |
|
| 126 | - $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 127 | - ->from($this->getTableName()) |
|
| 128 | - ->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))) |
|
| 129 | - ->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATETIME_MUTABLE))) |
|
| 130 | - ->orderBy('due_date', 'ASC') |
|
| 131 | - ->setMaxResults($limit); |
|
| 132 | - |
|
| 133 | - return $this->findEntities($qb); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @return Reminder[] |
|
| 138 | - */ |
|
| 139 | - public function findAllInFolder(IUser $user, Folder $folder) { |
|
| 140 | - $qb = $this->db->getQueryBuilder(); |
|
| 141 | - |
|
| 142 | - $qb->select('r.id', 'r.user_id', 'r.file_id', 'r.due_date', 'r.updated_at', 'r.created_at', 'r.notified') |
|
| 143 | - ->from($this->getTableName(), 'r') |
|
| 144 | - ->innerJoin('r', 'oc_filecache', 'f', $qb->expr()->eq('r.file_id', 'f.fileid')) |
|
| 145 | - ->where($qb->expr()->eq('r.user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 146 | - ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folder->getId(), IQueryBuilder::PARAM_INT))) |
|
| 147 | - ->orderBy('r.due_date', 'ASC'); |
|
| 148 | - |
|
| 149 | - return $this->findEntities($qb); |
|
| 150 | - } |
|
| 26 | + public const TABLE_NAME = 'files_reminders'; |
|
| 27 | + |
|
| 28 | + public function __construct(IDBConnection $db) { |
|
| 29 | + parent::__construct( |
|
| 30 | + $db, |
|
| 31 | + static::TABLE_NAME, |
|
| 32 | + Reminder::class, |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function markNotified(Reminder $reminder): Reminder { |
|
| 37 | + $reminderUpdate = new Reminder(); |
|
| 38 | + $reminderUpdate->setId($reminder->getId()); |
|
| 39 | + $reminderUpdate->setNotified(true); |
|
| 40 | + return $this->update($reminderUpdate); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @throws DoesNotExistException |
|
| 45 | + */ |
|
| 46 | + public function findDueForUser(IUser $user, int $fileId): Reminder { |
|
| 47 | + $qb = $this->db->getQueryBuilder(); |
|
| 48 | + |
|
| 49 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 50 | + ->from($this->getTableName()) |
|
| 51 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 52 | + ->andWhere($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) |
|
| 53 | + ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))); |
|
| 54 | + |
|
| 55 | + return $this->findEntity($qb); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return Reminder[] |
|
| 60 | + */ |
|
| 61 | + public function findAll() { |
|
| 62 | + $qb = $this->db->getQueryBuilder(); |
|
| 63 | + |
|
| 64 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 65 | + ->from($this->getTableName()) |
|
| 66 | + ->orderBy('due_date', 'ASC'); |
|
| 67 | + |
|
| 68 | + return $this->findEntities($qb); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return Reminder[] |
|
| 73 | + */ |
|
| 74 | + public function findAllForUser(IUser $user) { |
|
| 75 | + $qb = $this->db->getQueryBuilder(); |
|
| 76 | + |
|
| 77 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 78 | + ->from($this->getTableName()) |
|
| 79 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 80 | + ->orderBy('due_date', 'ASC'); |
|
| 81 | + |
|
| 82 | + return $this->findEntities($qb); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return Reminder[] |
|
| 87 | + */ |
|
| 88 | + public function findAllForNode(Node $node) { |
|
| 89 | + try { |
|
| 90 | + $nodeId = $node->getId(); |
|
| 91 | + } catch (NotFoundException $e) { |
|
| 92 | + return []; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $qb = $this->db->getQueryBuilder(); |
|
| 96 | + |
|
| 97 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 98 | + ->from($this->getTableName()) |
|
| 99 | + ->where($qb->expr()->eq('file_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))) |
|
| 100 | + ->orderBy('due_date', 'ASC'); |
|
| 101 | + |
|
| 102 | + return $this->findEntities($qb); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return Reminder[] |
|
| 107 | + */ |
|
| 108 | + public function findOverdue() { |
|
| 109 | + $qb = $this->db->getQueryBuilder(); |
|
| 110 | + |
|
| 111 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 112 | + ->from($this->getTableName()) |
|
| 113 | + ->where($qb->expr()->lt('due_date', $qb->createFunction('NOW()'))) |
|
| 114 | + ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))) |
|
| 115 | + ->orderBy('due_date', 'ASC'); |
|
| 116 | + |
|
| 117 | + return $this->findEntities($qb); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return Reminder[] |
|
| 122 | + */ |
|
| 123 | + public function findNotified(DateTime $buffer, ?int $limit = null) { |
|
| 124 | + $qb = $this->db->getQueryBuilder(); |
|
| 125 | + |
|
| 126 | + $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified') |
|
| 127 | + ->from($this->getTableName()) |
|
| 128 | + ->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))) |
|
| 129 | + ->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATETIME_MUTABLE))) |
|
| 130 | + ->orderBy('due_date', 'ASC') |
|
| 131 | + ->setMaxResults($limit); |
|
| 132 | + |
|
| 133 | + return $this->findEntities($qb); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @return Reminder[] |
|
| 138 | + */ |
|
| 139 | + public function findAllInFolder(IUser $user, Folder $folder) { |
|
| 140 | + $qb = $this->db->getQueryBuilder(); |
|
| 141 | + |
|
| 142 | + $qb->select('r.id', 'r.user_id', 'r.file_id', 'r.due_date', 'r.updated_at', 'r.created_at', 'r.notified') |
|
| 143 | + ->from($this->getTableName(), 'r') |
|
| 144 | + ->innerJoin('r', 'oc_filecache', 'f', $qb->expr()->eq('r.file_id', 'f.fileid')) |
|
| 145 | + ->where($qb->expr()->eq('r.user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) |
|
| 146 | + ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folder->getId(), IQueryBuilder::PARAM_INT))) |
|
| 147 | + ->orderBy('r.due_date', 'ASC'); |
|
| 148 | + |
|
| 149 | + return $this->findEntities($qb); |
|
| 150 | + } |
|
| 151 | 151 | } |