From 49718403ba0db0d212c7e06093c4733b7b0d30f4 Mon Sep 17 00:00:00 2001 From: Sebastian Fey Date: Thu, 29 Oct 2020 20:22:32 +0100 Subject: [PATCH 1/5] Added comments, changed variable of categories database Signed-off-by: Sebastian Fey --- lib/Db/RecipeDb.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index 0b677c227..1849ca2bd 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -139,12 +139,13 @@ public function findAllKeywords(string $user_id) { public function findAllCategories(string $user_id) { $qb = $this->db->getQueryBuilder(); - $qb->select('k.name') - ->selectAlias($qb->createFunction('COUNT(k.recipe_id)'), 'recipe_count') - ->from(self::DB_TABLE_CATEGORIES, 'k') - ->where('user_id = :user AND k.name != \'\'') - ->groupBy('k.name') - ->orderBy('k.name'); + // Get all named categories + $qb->select('c.name') + ->selectAlias($qb->createFunction('COUNT(c.recipe_id)'), 'recipe_count') + ->from(self::DB_TABLE_CATEGORIES, 'c') + ->where('user_id = :user') + ->groupBy('c.name') + ->orderBy('c.name'); $qb->setParameter('user', $user_id, TYPE::STRING); $cursor = $qb->execute(); @@ -153,6 +154,7 @@ public function findAllCategories(string $user_id) { $qb = $this->db->getQueryBuilder(); + // Get count of recipes without category $qb->select($qb->createFunction('COUNT(1) as cnt')) ->from(self::DB_TABLE_RECIPES, 'r') ->leftJoin( @@ -177,7 +179,7 @@ public function findAllCategories(string $user_id) { 'name' => '*', 'recipe_count' => $row['cnt'] ); - + $result = array_unique($result, SORT_REGULAR); $result = array_filter($result); From 51c80052b5bb2316cc4e7c3f045a15bb5356e534 Mon Sep 17 00:00:00 2001 From: Sebastian Fey Date: Thu, 29 Oct 2020 20:24:51 +0100 Subject: [PATCH 2/5] Requesting category 'None' returns recipes without category Signed-off-by: Sebastian Fey --- lib/Db/RecipeDb.php | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index 1849ca2bd..f85017cb5 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -192,17 +192,39 @@ public function findAllCategories(string $user_id) { public function getRecipesByCategory(string $category, string $user_id) { $qb = $this->db->getQueryBuilder(); - $qb->select(['r.recipe_id', 'r.name']) - ->from(self::DB_TABLE_CATEGORIES, 'k') - ->where('k.name = :category') - ->andWhere('k.user_id = :user') - ->setParameter('category', $category, TYPE::STRING) - ->setParameter('user', $user_id, TYPE::STRING); - - $qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id'); + if ($category != 'None') + { + $qb->select(['r.recipe_id', 'r.name']) + ->from(self::DB_TABLE_CATEGORIES, 'k') + ->where('k.name = :category') + ->andWhere('k.user_id = :user') + ->setParameter('category', $category, TYPE::STRING) + ->setParameter('user', $user_id, TYPE::STRING); + + $qb->join('k', self::DB_TABLE_RECIPES, 'r', 'k.recipe_id = r.recipe_id'); - $qb->groupBy(['r.name', 'r.recipe_id']); - $qb->orderBy('r.name'); + $qb->groupBy(['r.name', 'r.recipe_id']); + $qb->orderBy('r.name'); + } + else + { + + $qb->select(['r.recipe_id', 'r.name']) + ->from(self::DB_TABLE_RECIPES, 'r') + ->leftJoin( + 'r', + self::DB_TABLE_CATEGORIES, + 'c', + $qb->expr()->andX( + 'r.user_id = c.user_id', + 'r.recipe_id = c.recipe_id' + ) + ) + ->where( + $qb->expr()->eq('r.user_id', $qb->expr()->literal($user_id)), + $qb->expr()->isNull('c.name') + ); + } $cursor = $qb->execute(); $result = $cursor->fetchAll(); From 7173809cd002296f74364f9eda026a1dd8269252 Mon Sep 17 00:00:00 2001 From: Sebastian Fey Date: Thu, 29 Oct 2020 20:26:10 +0100 Subject: [PATCH 3/5] Added Uncategorized recipes item to category navigation Signed-off-by: Sebastian Fey --- src/components/AppNavi.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/AppNavi.vue b/src/components/AppNavi.vue index 06bea97b5..5a48c5ab7 100644 --- a/src/components/AppNavi.vue +++ b/src/components/AppNavi.vue @@ -22,6 +22,9 @@ {{ totalRecipeCount }} + + {{ uncatRecipes }} + Date: Thu, 29 Oct 2020 20:39:21 +0100 Subject: [PATCH 4/5] Using underscore in url as placeholder for uncategorized recipes Signed-off-by: Sebastian Fey --- lib/Db/RecipeDb.php | 4 +++- src/components/AppControls.vue | 2 +- src/components/AppNavi.vue | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Db/RecipeDb.php b/lib/Db/RecipeDb.php index f85017cb5..05208a389 100755 --- a/lib/Db/RecipeDb.php +++ b/lib/Db/RecipeDb.php @@ -188,11 +188,13 @@ public function findAllCategories(string $user_id) { /** * @throws \OCP\AppFramework\Db\DoesNotExistException if not found + * + * Using '_' as a placeholder for recipes w/o category */ public function getRecipesByCategory(string $category, string $user_id) { $qb = $this->db->getQueryBuilder(); - if ($category != 'None') + if ($category != '_') { $qb->select(['r.recipe_id', 'r.name']) ->from(self::DB_TABLE_CATEGORIES, 'k') diff --git a/src/components/AppControls.vue b/src/components/AppControls.vue index ce657d375..22a8ba2a3 100644 --- a/src/components/AppControls.vue +++ b/src/components/AppControls.vue @@ -13,7 +13,7 @@ - + diff --git a/src/components/AppNavi.vue b/src/components/AppNavi.vue index 5a48c5ab7..c7aff49a0 100644 --- a/src/components/AppNavi.vue +++ b/src/components/AppNavi.vue @@ -22,7 +22,7 @@ {{ totalRecipeCount }} - + {{ uncatRecipes }} Date: Thu, 29 Oct 2020 20:48:13 +0100 Subject: [PATCH 5/5] removed unnecessary rename of uncategorized recipes category name Signed-off-by: Sebastian Fey --- src/components/AppNavi.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/AppNavi.vue b/src/components/AppNavi.vue index c7aff49a0..b34566dcc 100644 --- a/src/components/AppNavi.vue +++ b/src/components/AppNavi.vue @@ -245,7 +245,6 @@ export default { for (let i=0; i