added comment to helper

pull/22/head
A1Gard 1 year ago
parent 05f2e51e01
commit a9f5a13bfa

@ -9,9 +9,15 @@ 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')) {
@ -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();
@ -33,6 +45,12 @@ function getSettingCategory($key)
}
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();
@ -43,12 +61,20 @@ function getSettingCat($key)
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,7 +87,13 @@ function metaing($metaz)
return $out;
}
function getPriceableMeta(Product $pro){
/***
* get just pricable meta of product
* @param Product $pro
* @return array
*/
function getPriceableMeta(Product $pro)
{
$metas = $pro->getAllMeta()->toArray();
if (count($metas) == 0) {
return [];
@ -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 = '';
@ -255,12 +314,21 @@ function MenuShowItems($items)
return $out;
}
/***
* show menu by name
* @param $menu_name
* @return string
*/
function MenuShowByName($menu_name)
{
$menu = Menu::whereName($menu_name)->firstOrFail();
return MenuShowItems($menu->menuItems()->whereNull('parent')->get());
}
/***
* make breadcrumbs for admin panel
* @return void
*/
function lastCrump()
{
$routes = explode('.', Route::currentRouteName());
@ -335,11 +403,24 @@ function lastCrump()
}
/***
* get main product categories
* @param int $limit
* @return Cat[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection|\LaravelIdea\Helper\App\Models\_IH_Cat_C
*/
function getMainCats($limit = 10)
{
return Cat::whereNull('parent_id')->limit($limit)->get();
}
/***
* get products by category id
* @param int $id
* @param string $order
* @param string $orderMethod
* @param int $limit
* @return Product[]|array|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Product_C
*/
function getProductByCat($id, $order = 'id', $orderMethod = 'desc', $limit = 10)
{
$cat = Cat::where('id', $id)->first();
@ -350,6 +431,14 @@ function getProductByCat($id, $order = 'id', $orderMethod = 'desc', $limit = 10)
return $cat->active_products()->where('active', 1)
->orderBy($order, $orderMethod)->limit($limit)->get();
}
/***
* get product by category id where `stock_quantity` more than 0
* @param int $id
* @param string $order
* @param int $limit
* @return Product[]|array|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Product_C
*/
function getProductByCatQ($id, $order = 'id', $limit = 10)
{
$cat = Cat::where('id', $id)->first();
@ -361,22 +450,43 @@ function getProductByCatQ($id, $order = 'id', $limit = 10)
->orderByDesc('id')->limit($limit)->get();
}
/***
* get sub product categories by id
* @param $id
* @return Cat[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Cat_C
*/
function getSubCats($id)
{
return Cat::where('parent_id', $id)->get();
}
/***
* get products with sort
* @param string $order
* @param string $orderMethod
* @param int $limit
* @return Product[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection|\LaravelIdea\Helper\App\Models\_IH_Product_C
*/
function getProducts($order = 'id', $orderMethod = 'desc', $limit = 10)
{
return Product::orderBy($order, $orderMethod)->limit($limit)->get();
}
/***
* get property by name
* @param string $name
* @return Prop|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
*/
function getProp($name)
{
return Prop::where('name', $name)->first();
}
/***
* get unit of property by name
* @param string $name
* @return \Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed|string|null
*/
function getPropUnit($name)
{
if (Prop::where('name', $name)->count() == 0) {
@ -385,6 +495,11 @@ function getPropUnit($name)
return Prop::where('name', $name)->first()->unit;
}
/***
* get label of property by name
* @param string $name
* @return array|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Translation\Translator|\Illuminate\Database\Eloquent\HigherOrderBuilderProxy|mixed|string|null
*/
function getPropLabel($name)
{
if (Prop::where('name', $name)->count() == 0) {
@ -402,12 +517,22 @@ function getPropLabel($name)
}
}
/***
* check is json or not
* @param string $str
* @return bool
*/
function isJson($str)
{
$json = json_decode($str);
return $json && $str != $json;
}
/***
* json decode and sort
* @param array $json
* @return mixed
*/
function jsonOrder($json)
{
$data = json_decode($json, true);
@ -415,7 +540,14 @@ function jsonOrder($json)
return $data;
}
function showMetaValue($key, $value){
/***
* get meta value
* @param string $key
* @param string $value
* @return void
*/
function getMetaValue($key, $value)
{
$p = Prop::whereName($key)->first();
foreach (json_decode($p->options) as $n) {
if ($n->value == $value) {
@ -423,6 +555,13 @@ function showMetaValue($key, $value){
}
}
}
/***
* show meta with values
* @param string $key
* @param string $value
* @return string
*/
function showMeta($key, $value)
{
@ -456,13 +595,24 @@ function showMeta($key, $value)
return trim($txt . ' ' . getPropUnit($key));
}
/***
* time to persian date
* @param $date
* @param $format
* @return float|int|string|\Xmen\StarterKit\Helpers\timestamp
*/
function time2persian($date, $format = 'Y/m/d')
{
$dt = new TDate();
return $dt->PDate($format, $date);
}
function getColors(){
/***
* get colors
* @return array
*/
function getColors()
{
$colors = Prop::where('name', 'color')->first();
if ($colors == null) {
return [];
@ -474,7 +624,14 @@ function getColors(){
}
return $result;
}
function getColorName($colorVal){
/***
* get color name
* @param $colorVal
* @return mixed|string
*/
function getColorName($colorVal)
{
$colors = Prop::where('name', 'color')->first();
if ($colors == null) {
return 'رنگ';
@ -488,6 +645,11 @@ function getColorName($colorVal){
return 'رنگ';
}
/***
* make chartjs
* @param $pro
* @return string
*/
function makeChart($pro)
{
$times = $pro->prices_history()->pluck('created_at')->toArray();
@ -506,7 +668,13 @@ TXT;
return $text;
}
function makeProductBreadcrumb($p, $c)
/***
* make breadcrumb
* @param Product $p
* @param Cat $c
* @return array[]
*/
function makeProductBreadcrumb(Product $p, Cat $c)
{
$items = [
[
@ -530,6 +698,11 @@ function makeProductBreadcrumb($p, $c)
return $items;
}
/***
* show markup breadcrumb
* @param $itemz
* @return void
*/
function showBreadcrumb($itemz = [])
{
$text = <<<DOC
@ -561,13 +734,24 @@ DOC;
echo str_replace('ITEMS', $items, $text);
}
function cardCount(){
/***
* get items count in shoppig card
* @return int
*/
function cardCount()
{
return count(array_merge(unserialize(session('card', serialize([]))), unserialize(session('qcard', serialize([])))));
}
function sendSMSText($number,$content){
/***
* send sms
* @param string $number phone number
* @param string $content sms content
* @return bool|string
*/
function sendSMSText($number, $content)
{
$url = 'http://rest.payamak-panel.com/api/SendSMS/SendSMS';
@ -601,11 +785,25 @@ function sendSMSText($number,$content){
return $result;
}
function remTitle($str){
/***
* remove title of html code
* @param $str
* @return array|string|string[]|null
*/
function remTitle($str)
{
$re = '/<title>(.*?)<\/title>/m';
return preg_replace($re, '', $str);
}
function showJsonByKey($json,$key){
/***
* show json by key
* @param $json
* @param $key
* @return mixed|string
*/
function showJsonByKey($json, $key)
{
$x = json_decode($json);
$x = json_decode($x->data, true);
$items = json_decode(\App\Helpers\getProp('size')->options, true);
@ -616,7 +814,14 @@ function showJsonByKey($json,$key){
}
return 'x';
}
function findLink($html){
/***
* find html links
* @param $html
* @return string|null
*/
function findLink($html)
{
$url = preg_match('/<a href="(.+)">/', $html, $match);

Loading…
Cancel
Save