From 415080b79574e039df3e5738c603dd87c6ceb5e6 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Sat, 27 Nov 2021 06:41:17 +0100 Subject: [PATCH] add a quarter vote for every comment and every topic you post this helps for the notifications. related to #157 --- src/classes/DBO.php | 30 ++++++++++++++++++++++++++---- src/classes/Nomination.php | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/classes/DBO.php b/src/classes/DBO.php index 5ce49ed..cd00557 100644 --- a/src/classes/DBO.php +++ b/src/classes/DBO.php @@ -32,14 +32,14 @@ function __construct($db) { */ public function addFacilitator($workshop, $participant) { $sql = 'INSERT INTO `workshop_participant` (`workshop_id`,`participant_id`,`leader`, participant) - VALUES (:workshop_id, :participant_id, 1, 0) - ON DUPLICATE KEY UPDATE `leader` = 1'; + VALUES (:workshop_id, :participant_id, 1, 0.25) + ON DUPLICATE KEY UPDATE `leader` = 1, `participant` = GREATEST(0.25, `participant`)'; if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) === 'sqlite') { $sql = 'INSERT INTO workshop_participant (workshop_id, participant_id, leader, participant) - VALUES(:workshop_id, :participant_id, 1, 0) + VALUES(:workshop_id, :participant_id, 1, 0.25) ON CONFLICT(workshop_id, participant_id) DO UPDATE - SET leader = 1'; + SET leader = 1, participant = MAX(0.25, participant)'; } $query = $this->db->prepare($sql); @@ -49,6 +49,28 @@ public function addFacilitator($workshop, $participant) { $query->execute(); } + /** + * this adds a quarter vote for the creator of a topic, and for the commentator of a topic + * this is useful for the notifications. people can unsubscribe from the notification by removing their vote + */ + public function addQuarterVote($workshop, $participant) { + $sql = 'INSERT INTO `workshop_participant` (`workshop_id`,`participant_id`, `participant`) + VALUES (:workshop_id, :participant_id, 0.25) + ON DUPLICATE KEY UPDATE `participant` = GREATEST(0.25, `participant`)'; + if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) === 'sqlite') { + $sql = 'INSERT INTO workshop_participant + (workshop_id, participant_id, participant) + VALUES(:workshop_id, :participant_id, 0.25) + ON CONFLICT(workshop_id, participant_id) DO UPDATE SET participant = MAX(0.25, participant)'; + } + + $query = $this->db->prepare($sql); + $query->bindValue('workshop_id', (int) $workshop, PDO::PARAM_INT); + $query->bindValue('participant_id', (int) $participant, PDO::PARAM_INT); + + $query->execute(); + } + /** * Adds auser to the participant table * diff --git a/src/classes/Nomination.php b/src/classes/Nomination.php index e858ff5..dae9be5 100644 --- a/src/classes/Nomination.php +++ b/src/classes/Nomination.php @@ -33,6 +33,7 @@ public function nominate($request, $response, $args) { try { $topic_id = $this->dbo->nominate($title, $description, $userid); + $this->dbo->addQuarterVote($topic_id, $userid); $this->send_notification('new_post', $userid, $topic_id, -1); return $this->view->render($response, 'nomination_response.html', [ 'loggedin' => True, @@ -120,6 +121,7 @@ public function addComment($request, $response, $args) { try { $comment_id = $this->dbo->comment_add($topic_id, $comment, $userid); + $this->dbo->addQuarterVote($topic_id, $userid); $this->send_notification('new_comment', $userid, $topic_id, $comment_id); return $response->withRedirect($this->router->pathFor('edittopic', ['id' => $topic_id]), 302); }