~cypheon/nextcloud-chores-app

ref: d19a6603c01e63c7545582e5ff313ef4aec0bf9f nextcloud-chores-app/lib/Db/ChoreMapper.php -rw-r--r-- 1.3 KiB
d19a6603 — Johann Rudloff Make overdue sidebar badge dynamic, switch badges to `CounterBubble` component 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace OCA\Chores\Db;

use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;

class ChoreMapper extends QBMapper {

  public function __construct(IDBConnection $db) {
    parent::__construct($db, 'chores_chores', Chore::class);
  }

  public function findById(int $teamId, int $choreId): Chore {
    $qb = $this->db->getQueryBuilder();

    $qb->select('c.*')
       ->from($this->tableName, 'c')
       ->where(
         $qb->expr()->eq('team_id', $qb->createNamedParameter($teamId))
       )
       ->andWhere(
         $qb->expr()->eq('id', $qb->createNamedParameter($choreId))
       )
       ;

    return $this->findEntity($qb);
  }

  public function findAll(string $teamId) {
    $qb = $this->db->getQueryBuilder();

    $qb->select('c.*')
       ->from($this->tableName, 'c')
       ->where(
         $qb->expr()->eq('team_id', $qb->createNamedParameter($teamId))
       )
       ->orderBy('due', 'ASC')
       ;

    return $this->findEntities($qb);
  }

  public function updateDueDate(int $choreId, \DateTimeImmutable $dueDate) {
    $due = $dueDate->format('c');
    $qb = $this->db->getQueryBuilder();
    $qb->update($this->tableName)
       ->where(
         $qb->expr()->eq('id', $qb->createNamedParameter($choreId))
       )
       ->set('due', $qb->func()->greatest('due',
         $qb->createNamedParameter($due)
       ))
       ->execute();
  }

}