<?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);
}
}