Skip to content

Commit

Permalink
add InvestRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeig committed Nov 14, 2023
1 parent 254a663 commit 8789af9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Goteo/Repository/InvestRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Goteo\Repository;

use Goteo\Model\Blog\Post;
use Goteo\Model\User;

class InvestRepository extends BaseRepository
{
public function hasInvestToPostRewards(User $user, Post $post): bool
{
$sql = "SELECT true
FROM invest i
INNER JOIN invest_reward ir ON ir.invest = i.id
INNER JOIN reward r on ir.reward = r.id
INNER JOIN post_reward_access pra ON pra.reward_id = r.id
WHERE i.`user` = :user AND pra.post_id = :post and i.status = 1
and (r.subscribable = 0 or (r.subscribable = 1 and i.invested >= DATE_SUB(NOW(), INTERVAL 1 MONTH)))
";

return (bool) $this->query($sql, [':user' => $user->id, ':post' => $post->id])->fetchColumn();
}
}

0 comments on commit 8789af9

Please sign in to comment.