From a9f5a13bfa4a6746abdef73b460a08ab875282a0 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Sun, 3 Sep 2023 04:33:22 +0330 Subject: [PATCH] added comment to helper --- app/Helpers/Helper.php | 329 +++++++++++++++++++++++++++++++++-------- 1 file changed, 267 insertions(+), 62 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 5ac3e9e..1cd8b49 100755 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -9,12 +9,18 @@ use App\Models\Setting; use Xmen\StarterKit\Helpers\TDate; use Xmen\StarterKit\Models\Category; use Xmen\StarterKit\Models\Menu; +use Xmen\StarterKit\Models\MenuItem; use Xmen\StarterKit\Models\Post; use Illuminate\Support\Facades\Route; +/*** + * get setting by key + * @param string $key setting key + * @return false|\Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed|string|null + */ function getSetting($key) { - if ( !isset($_SERVER['SERVER_NAME']) || !\Schema::hasTable('settings')){ + if (!isset($_SERVER['SERVER_NAME']) || !\Schema::hasTable('settings')) { return false; } $x = Setting::where('key', $key)->first(); @@ -24,6 +30,12 @@ function getSetting($key) } return $x->value; } + +/*** + * get category form setting by key + * @param string $key setting key + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|string|Category|null + */ function getSettingCategory($key) { $x = Setting::where('key', $key)->first(); @@ -31,8 +43,14 @@ function getSettingCategory($key) $a = new \stdClass(); return ''; } - return Category::where('id',$x->value)->first(); + return Category::where('id', $x->value)->first(); } + +/*** + * get product category by setting key + * @param string $key setting key + * @return Cat|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|string|null + */ function getSettingCat($key) { $x = Setting::where('key', $key)->first(); @@ -40,15 +58,23 @@ function getSettingCat($key) $a = new \stdClass(); return ''; } - return Cat::where('id',$x->value)->first(); + return Cat::where('id', $x->value)->first(); } - +/*** + * get stock types + * @return array + */ function stockTypes() { return ["IN_STOCK" => __("In stock"), "OUT_STOCK" => __("Out stock"), "BACK_ORDER" => __("Back order")]; } +/*** + * make meta with key and value + * @param $metaz + * @return array + */ function metaing($metaz) { $out = []; @@ -61,16 +87,22 @@ function metaing($metaz) return $out; } -function getPriceableMeta(Product $pro){ - $metas = $pro->getAllMeta()->toArray(); - if ( count($metas) == 0 ){ - return []; +/*** + * get just pricable meta of product + * @param Product $pro + * @return array + */ +function getPriceableMeta(Product $pro) +{ + $metas = $pro->getAllMeta()->toArray(); + if (count($metas) == 0) { + return []; } - $pricables = $pro->category->props()->where('priceable',1)->pluck('name')->toArray(); + $pricables = $pro->category->props()->where('priceable', 1)->pluck('name')->toArray(); $result = []; - if (is_array($pricables)){ - foreach ($pricables as $price){ - if (isset($metas[$price])){ + if (is_array($pricables)) { + foreach ($pricables as $price) { + if (isset($metas[$price])) { $result[$price] = $metas[$price]; } } @@ -78,7 +110,13 @@ function getPriceableMeta(Product $pro){ return $result; } - +/*** + * show product categories in node with ul-li + * @param $cats category node + * @param $liClass class of lis + * @param $ulClass class of uls + * @return string + */ function showCats($cats = [], $liClass = '', $ulClass = '') { if ($cats == []) { @@ -101,6 +139,11 @@ function showCats($cats = [], $liClass = '', $ulClass = '') return $txt; } +/*** + * show menu node for manage + * @param $arr + * @return string + */ function showMenuMange($arr) { $back = ''; @@ -127,6 +170,11 @@ LI; return $back; } +/*** + * show menu node + * @param array $arr + * @return string + */ function showMenu($arr) { $back = ''; @@ -182,6 +230,12 @@ LI; return $back; } + +/*** + * show input products categories node + * @param Cat[] $arr + * @return string + */ function showCatNode($arr) { $ret = ''; @@ -195,6 +249,11 @@ function showCatNode($arr) return $ret; } +/*** + * show menu items as types + * @param MenuItem[] $items + * @return string + */ function MenuShowItems($items) { $out = ''; @@ -234,7 +293,7 @@ function MenuShowItems($items) $out .= ''; break; case "cat-news": - $out .= ''.$item->title .''; + $out .= '' . $item->title . ''; $cat = Category::whereId($item->menuable_id)->firstOrFail(); $news = $cat->posts()->limit(10)->get(['slug', 'title']); $out .= '