Skip to content

Commit

Permalink
Decide whether or not to display comment based on trusted commenter
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobemerick committed Jun 12, 2016
1 parent 1e04fd1 commit 9fb6a24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/Controller/Comment.php
Expand Up @@ -41,17 +41,18 @@ public function createComment(Request $req, Response $res)

// todo option to pass in by commenter id
$commenterModel = new CommenterModel($this->container->get('dbal'));
$commenterId = $commenterModel->findByFields(
$commenter = $commenterModel->findByFields(
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
if (!$commenterId) {
if (!$commenter) {
$commenterId = $commenterModel->create(
$body['commenter']['name'],
$body['commenter']['email'],
$body['commenter']['website']
);
$commenter = $commenterModel->findById($commenterId);
}

$bodyModel = new CommentBodyModel($this->container->get('dbal'));
Expand Down Expand Up @@ -103,15 +104,20 @@ public function createComment(Request $req, Response $res)
);
}

$shouldDisplay = $commenter['is_trusted'];
if (!empty($body['should_display'])) {
$shouldDisplay = (int) $body['should_display'];
}

$commentModel = new CommentModel($this->container->get('dbal'));
$commentId = $commentModel->create(
$commenterId,
$commenter['id'],
$bodyId,
$locationId,
$commentRequestId,
$body['url'],
(int) $body['should_notify'],
(int) $body['should_display'],
$shouldDisplay,
time()
);

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Commenter.php
Expand Up @@ -73,7 +73,7 @@ public function findById($id)
public function findByFields($name, $email, $website)
{
$query = "
SELECT `id`
SELECT *
FROM `commenter`
WHERE `name` = :name AND
`email` = :email AND
Expand All @@ -86,7 +86,7 @@ public function findByFields($name, $email, $website)
'website' => $website,
];

return $this->extendedPdo->fetchValue($query, $bindings);
return $this->extendedPdo->fetchOne($query, $bindings);
}

/**
Expand Down

0 comments on commit 9fb6a24

Please sign in to comment.