199 lines
5.8 KiB
PHP
199 lines
5.8 KiB
PHP
<?php
|
|
|
|
use App\Models\MenuCategories;
|
|
use App\Models\MenuImages;
|
|
use App\Models\MenuItemCategories;
|
|
use App\Models\MenuItemOptionsGroups;
|
|
use App\Models\MenuItems;
|
|
use App\Models\MenuItemTags;
|
|
use App\Models\MenuItemVariations;
|
|
use App\Models\OptionsGroups;
|
|
use App\Models\RegularItemAvailability;
|
|
use App\Models\SeasonalItemAvailability;
|
|
use App\Models\Tags;
|
|
use App\Models\VariationOptionsGroups;
|
|
use App\Models\VariationTags;
|
|
|
|
if (!function_exists('getMenuImage')) {
|
|
|
|
function getMenuImage($id)
|
|
{
|
|
$menu_images = new MenuImages();
|
|
$images_data = $menu_images->where('menu_item_id', $id)
|
|
->where('deleted_at', NULL)
|
|
->findAll();
|
|
|
|
$data = [];
|
|
foreach ($images_data as $image) {
|
|
$data[] = [
|
|
'id' => $image['id'],
|
|
'image_url' => getImagePath('menu_images', $image['image_url']),
|
|
'order_index' => $image['order_index']
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getMenuCategory')) {
|
|
|
|
function getMenuCategory($id)
|
|
{
|
|
$menu_item_category = new MenuItemCategories();
|
|
$category = new MenuCategories();
|
|
$category_data = $menu_item_category->where('menu_item_id', $id)
|
|
->where('deleted_at', NULL)
|
|
->findAll();
|
|
|
|
$data = [];
|
|
foreach ($category_data as $menu_category) {
|
|
$category_detail = $category->withDeleted()->find($menu_category['category_id']);
|
|
if ($category_detail) {
|
|
$data[] = [
|
|
'id' => $menu_category['category_id'],
|
|
'title' => $category_detail['title']
|
|
];
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getImagePath')) {
|
|
|
|
function getImagePath($path, $name)
|
|
{
|
|
$full_path = '';
|
|
if ($name) {
|
|
$full_path = 'https://' . $_SERVER['SERVER_NAME'] . '/backend/uploads/' . $path . '/' . $name;
|
|
}
|
|
return $full_path;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getVariationRelation')) {
|
|
function getVariationRelation($menu_item_id)
|
|
{
|
|
$array = [];
|
|
|
|
$menu_varition = new MenuItemVariations();
|
|
$variation_tag = new VariationTags();
|
|
$variation_option_group = new VariationOptionsGroups();
|
|
$tagModel = new Tags();
|
|
$optionGroupModel = new OptionsGroups();
|
|
|
|
$menu_variation_data = $menu_varition
|
|
->where('menu_item_id', $menu_item_id)
|
|
->findAll();
|
|
|
|
foreach ($menu_variation_data as $menu_variation) {
|
|
$variation_id = $menu_variation['id'];
|
|
|
|
$variation_tags = $variation_tag
|
|
->where('variation_id', $variation_id)
|
|
->findAll();
|
|
|
|
$tags = [];
|
|
foreach ($variation_tags as $vt) {
|
|
$tag = $tagModel->find($vt['tag_id']);
|
|
if ($tag) {
|
|
$tags[] = $tag;
|
|
}
|
|
}
|
|
|
|
$variation_option_groups = $variation_option_group
|
|
->where('variation_id', $variation_id)
|
|
->findAll();
|
|
|
|
$option_groups = [];
|
|
foreach ($variation_option_groups as $vog) {
|
|
$group = $optionGroupModel->find($vog['option_group_id']);
|
|
if ($group) {
|
|
$group['order_index'] = $vog['order_index'];
|
|
$option_groups[] = $group;
|
|
}
|
|
}
|
|
|
|
// Sort $option_groups by 'order_index' ascending
|
|
usort($option_groups, function ($a, $b) {
|
|
return $a['order_index'] <=> $b['order_index'];
|
|
});
|
|
|
|
$array[] = [
|
|
'variation' => $menu_variation,
|
|
'tags' => $tags,
|
|
'option_groups' => $option_groups,
|
|
];
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getMenuTag')) {
|
|
|
|
function getMenuTag($id)
|
|
{
|
|
$menu_item_tag = new MenuItemTags();
|
|
$tags = new Tags();
|
|
$menu_item_tag_data = $menu_item_tag->where('menu_item_id', $id)
|
|
->where('deleted_at', NULL)
|
|
->findAll();
|
|
|
|
$data = [];
|
|
foreach ($menu_item_tag_data as $menu_tag) {
|
|
$tag = $tags->withDeleted()->find($menu_tag['tag_id']);
|
|
$data[] = [
|
|
'id' => $menu_tag['tag_id'],
|
|
'title' => $tag['title'],
|
|
'icon_url' => getImagePath('tags', $tag['icon_url'])
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getMenuOptionGroup')) {
|
|
|
|
function getMenuOptionGroup($id)
|
|
{
|
|
$menu_item_option_group = new MenuItemOptionsGroups();
|
|
$option_groups = new OptionsGroups();
|
|
$option_groups_data = $menu_item_option_group->where('menu_item_id', $id)
|
|
->where('deleted_at', NULL)
|
|
->orderBy('order_index', 'ASC')
|
|
->findAll();
|
|
|
|
$data = [];
|
|
foreach ($option_groups_data as $option_group) {
|
|
$option_group_detail = $option_groups->withDeleted()->find($option_group['option_group_id']);
|
|
$data[] = [
|
|
'id' => $option_group['option_group_id'],
|
|
'title' => $option_group_detail['title'],
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('getAvailability')) {
|
|
|
|
function getAvailability($menu_item_id, $type)
|
|
{
|
|
$regular_item_availability = new RegularItemAvailability();
|
|
$seasonal_item_availability = new SeasonalItemAvailability();
|
|
|
|
$data = [];
|
|
|
|
if ($type == 'seasonal') {
|
|
$seasonal = $seasonal_item_availability->where('menu_item_id', $menu_item_id)->first();
|
|
$data[] = $seasonal;
|
|
} else {
|
|
$regular = $regular_item_availability->where('menu_item_id', $menu_item_id)->findAll();
|
|
$data[] = $regular;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|