*/ class TaskNotificationMapper extends QBMapper { public function __construct( IDBConnection $db, ) { parent::__construct($db, 'assistant_task_notif', TaskNotification::class); } /** * @param int $ocpTaskId * @return ?TaskNotification * @throws Exception * @throws MultipleObjectsReturnedException */ public function getByTaskId(int $ocpTaskId): ?TaskNotification { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()) ->where( $qb->expr()->eq('ocp_task_id', $qb->createNamedParameter($ocpTaskId, IQueryBuilder::PARAM_INT)) ); try { return $this->findEntity($qb); } catch (DoesNotExistException $e) { return null; } } /** * @param int $ocpTaskId * @return void * @throws Exception * @throws MultipleObjectsReturnedException */ public function deleteByTaskId(int $ocpTaskId): void { $existingEntry = $this->getByTaskId($ocpTaskId); if ($existingEntry !== null) { $this->delete($existingEntry); } } /** * @param int $ocpTaskId * @return TaskNotification|null * @throws Exception * @throws MultipleObjectsReturnedException */ public function createTaskNotification(int $ocpTaskId): ?TaskNotification { $existingEntry = $this->getByTaskId($ocpTaskId); if ($existingEntry !== null) { return $existingEntry; } $nowTimestamp = (new DateTime())->getTimestamp(); $newEntry = new TaskNotification(); $newEntry->setOcpTaskId($ocpTaskId); $newEntry->setTimestamp($nowTimestamp); $this->insert($newEntry); return $this->getByTaskId($ocpTaskId); } }