Skip to content

Commit e3b70e7

Browse files
Merge pull request #261 from tobiasKaminsky/wip
wip
2 parents 1cea605 + 208b111 commit e3b70e7

File tree

9 files changed

+7790
-302
lines changed

9 files changed

+7790
-302
lines changed

lib/Controller/GroceryListController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ public function showGroceryListSettings($id)
7979
*/
8080
public function lists()
8181
{
82-
return new DataResponse($this->groceryListMapper->findAll());
82+
$lists = $this->groceryListMapper->findAll();
83+
84+
foreach ($lists as $list) {
85+
$list->setUncheckedCount($this->itemMapper->findAllUnchecked($list->getId()));
86+
}
87+
88+
return new DataResponse($lists);
8389
}
8490

8591
/**
@@ -173,6 +179,16 @@ public function listItems(int $id)
173179
return new DataResponse($this->itemMapper->findAll($id));
174180
}
175181

182+
/**
183+
* @NoAdminRequired
184+
* @NoCSRFRequired
185+
* @param int $id
186+
*/
187+
public function countUnckedItems(int $id)
188+
{
189+
return new DataResponse($this->itemMapper->findAllUnchecked($id));
190+
}
191+
176192
/**
177193
* @NoAdminRequired
178194
* @param int $id

lib/Db/GroceryList.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ class GroceryList extends Entity implements JsonSerializable {
2828
*/
2929
protected $showOnlyUnchecked;
3030

31+
/**
32+
* @var int
33+
*/
34+
protected $uncheckedCount;
35+
3136
public function __construct() {
3237
$this->addType('title', 'string');
3338
$this->addType('userId', 'string');
3439
$this->addType('showOnlyUnchecked', 'int');
40+
$this->addType('uncheckedCount', 'int');
3541
}
3642

3743
public function getShowOnlyUnchecked(): bool {
@@ -42,12 +48,18 @@ public function setShowOnlyUnchecked(bool $showOnlyUnchecked): void {
4248
$this->setter('showOnlyUnchecked', [$showOnlyUnchecked ? 1 : 0]);
4349
}
4450

51+
public function setUncheckedCount(int $count): void {
52+
$this->setter('uncheckedCount', [$count]);
53+
}
54+
55+
4556
public function jsonSerialize(): array {
4657
return [
4758
'id' => $this->getId(),
4859
'title' => $this->getTitle(),
4960
'userId' => $this->getUserId(),
5061
'showOnlyUnchecked' => $this->getShowOnlyUnchecked(),
62+
'uncheckedCount' => $this->uncheckedCount,
5163
];
5264
}
5365
}

lib/Db/GroceryListMapper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ private function findById(int $id) {
4848
return $this->findEntity($qb);
4949
}
5050

51-
public function findAll() {
51+
/**
52+
* @return GroceryList[]
53+
*/
54+
public function findAll() : array {
5255
$qb = $this->db->getQueryBuilder();
5356

5457
$qb->select('*')

lib/Db/ItemMapper.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public function find(int $id): Item {
3131
}
3232

3333
/**
34-
* @throws Exception
35-
*/
34+
* @return GroceryList[]
35+
* @throws Exception
36+
*/
3637
public function findAll(int $id): array {
3738
$qb = $this->db->getQueryBuilder();
3839

@@ -44,6 +45,20 @@ public function findAll(int $id): array {
4445
return $this->findEntities($qb);
4546
}
4647

48+
/**
49+
* @throws Exception
50+
*/
51+
public function findAllUnchecked(int $id): int {
52+
$qb = $this->db->getQueryBuilder();
53+
54+
$qb->select('*')
55+
->from($this->getTableName())
56+
->where($qb->expr()->eq('list', $qb->createNamedParameter($id)))
57+
->andWhere($qb->expr()->eq('checked', $qb->createNamedParameter(0)));
58+
59+
return sizeof($this->findEntities($qb));
60+
}
61+
4762
public function categoryUsed(int $id): bool {
4863
$qb = $this->db->getQueryBuilder();
4964

0 commit comments

Comments
 (0)