Skip to content

Commit

Permalink
add a quarter vote for every comment and every topic you post
Browse files Browse the repository at this point in the history
this helps for the notifications.
related to #157
  • Loading branch information
tpokorra committed Nov 27, 2021
1 parent 1019a9b commit 415080b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/classes/DBO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions src/classes/Nomination.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 415080b

Please sign in to comment.