db->where_in('categoryID', $categoryId)->get('cm_category')->row(); } public function getAll($categoryId) { $categoryId = is_array($categoryId) ? $categoryId : [$categoryId]; return get_instance()->db->where_in('categoryID', $categoryId)->get('cm_category')->result(); } public function getSubcategoriesByCategoryId(int $categoryId) { return $this->db->where('parentID', $categoryId)->get('cm_category')->result(); } public function getTableCategoryTitle(&$rows) { $categories = get_instance()->db->get('cm_category')->result(); array_map(function ($r) use (&$rows, $categories) { foreach ($rows as $k => $row) { if ($row['postID'] == $r->postID) { $rows[$k]['categoryID'] = $r->categoryID; $rows[$k]['categories'][] = $r->categoryID; foreach ($categories as $c) { if ($c->categoryID == $r->categoryID) { $rows[$k]['categoryTitle'] = (empty($rows[$k]['categoryTitle']) ? '' : $rows[$k]['categoryTitle'] . ', ') . $c->categoryTitle; } } } } }, $this->getPostCategoryByPostIdIn(array_column($rows, 'postID'))); } private function getPostCategoryByPostIdIn($postIds) { if (count($postIds) == 0) return []; return $this->db->from('cm_post_category pc')->where_in('pc.postID', $postIds)->get()->result(); } public function getCategoriesBySlug($slug) { $slug = is_array($slug) ? $slug : [$slug]; return $this->db->where_in('categorySlug', $slug)->from($this->table); } }