/** * get tags by parent id * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function getTreeTag(Request $request) { $tagService = new tagService(); $relationType = $request->get('relationType', 0); $tagId = $request->get('node', 0); try { $return = $tagService->getSubTagsWithAdminData($tagId, $relationType); } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['error'] = $e->getMessage(); $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }
/** * @param $tagId * @param $typeId * @param $productId * @return array */ public function getProductTreeMenu($tagId, $typeId, $productId) { $tagService = new tagService(); $productModel = new productModel(); $tags = $tagService->getSubTagsWithAdminData($tagId, $typeId); $tagOfProducts = $productModel->getProductById($productId, false)->tag; $tagProductArray = []; foreach ($tagOfProducts as $tagOfProduct) { if ($tagOfProduct->pivot->type == KACANA_PRODUCT_TAG_TYPE_MENU) { array_push($tagProductArray, $tagOfProduct->id); } } $tagActive = array(); foreach ($tags as $tag) { if ($tag->relation_status) { if (in_array($tag->child_id, $tagProductArray)) { $tag->checked = true; } array_push($tagActive, $tag); } } return $tagActive; }