~cypheon/nextcloud-chores-app

ref: d19a6603c01e63c7545582e5ff313ef4aec0bf9f nextcloud-chores-app/lib/Db/WorkMapper.php -rw-r--r-- 1019 bytes
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
<?php
namespace OCA\Chores\Db;

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

class WorkMapper extends QBMapper {

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

  public function itemExists(string $id): bool {
    $qb = $this->db->getQueryBuilder();

    $qb->select('id')
       ->from($this->tableName)
       ->where(
         $qb->expr()->eq('id', $qb->createNamedParameter($id))
       );

    $result = $this->findEntities($qb);
    return (count($result) > 0);
  }

  public function findAllByTeam(int $teamId): array {
    $qb = $this->db->getQueryBuilder();

    $qb->select('w.*', 'c.name')
       ->from($this->tableName, 'w')
       ->where(
         $qb->expr()->eq('w.team_id', $qb->createNamedParameter($teamId))
       )
       ->leftJoin('w', 'chores_chores', 'c', 'c.id = w.chore_id')
       ->orderBy('submit_timestamp', 'DESC')
       ->setMaxResults(1000)
     ;

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

}