[WIP] Setup of skeleton
This commit is contained in:
217
app/Repositories/Shop/Products.php
Normal file
217
app/Repositories/Shop/Products.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Product;
|
||||
|
||||
class Products
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Product::with(['sections'])->orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
{
|
||||
return Product::select('id','name','active')->orderBy('name','asc')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Product::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getId($Product = false)
|
||||
{
|
||||
$Product = self::get($Product);
|
||||
return $Product ? $Product->id : false;
|
||||
}
|
||||
|
||||
public static function get($Product = false)
|
||||
{
|
||||
$website = self::getWebsite($Product);
|
||||
return $website ? Product::byWebsite($website->id)->first() : false;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
if (!$id) {
|
||||
$Product_id = self::create($data);
|
||||
} else {
|
||||
$Product_id = self::update($data);
|
||||
}
|
||||
|
||||
ApplicationProducts::associate($Product_id, $data['applications']);
|
||||
|
||||
return $Product_id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$slug = Str::slug($data['slug'],'-');
|
||||
$url = $slug . '.' . Partners::getDomain();
|
||||
$website = Websites::create($url);
|
||||
$item = [];
|
||||
$item['website_id'] = $website->id;
|
||||
$item['name'] = $data['name'];
|
||||
$item['slug'] = $slug;
|
||||
$item['repository'] = $slug;
|
||||
$item['session_name'] = $slug . '_sess';
|
||||
$item['logo_image'] = 'logo.png';
|
||||
$item['background_image'] = 'login-background.jpg';
|
||||
$item['custom_css'] = 'Product.css';
|
||||
$item['active'] = true;
|
||||
$Product = Product::create($item);
|
||||
|
||||
$DB_system = Partners::getDBName();
|
||||
$sql = "GRANT SELECT ON `$DB_system`.* TO '" . $website->uuid . "'@localhost";
|
||||
DB::connection('system')->statement($sql);
|
||||
// GRANT SELECT ON `legstack`.* TO '828656d3463e45c0a33e9cc8b5c2f265'@'127.0.0.1';
|
||||
return $Product->id;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
|
||||
}
|
||||
|
||||
public static function getPublicPath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalPath() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPrivatePath renvoie le chemin complet du repertoire du tenant ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPrivatePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getPrivateDir($repository, $Product);
|
||||
}
|
||||
|
||||
public static function getPrivateDir($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalDir() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getRelativePath renvoie le chemin relatif au storage ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getRelativePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getTenancyRoot() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPath renvoie le chemin relatif à la tenancy root]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPath($repository = false, $Product = false)
|
||||
{
|
||||
$path = '/'. self::getSlug($Product);
|
||||
$path .= $repository ? $repository : '';
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* [getStorage revoie le storage du tenant (local, S3, ...)]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getStorage()
|
||||
{
|
||||
return Storage::disk('tenant');
|
||||
}
|
||||
|
||||
public static function getDirectory()
|
||||
{
|
||||
return app(\Hyn\Tenancy\Website\Directory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalDir renvoie le chemin complet vers la tenancy sur le disque]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalDir()
|
||||
{
|
||||
return storage_path('app' . self::getTenancyRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalPath revnoie le chemin public vers la tenancy publique]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalPath()
|
||||
{
|
||||
return '/storage' . self::getTenancyRoot();
|
||||
}
|
||||
|
||||
public static function getSlug($Product = false)
|
||||
{
|
||||
if ($Product) {
|
||||
return $Product;
|
||||
}
|
||||
|
||||
$website = self::getWebsite();
|
||||
if ($website) {
|
||||
return($website->uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
// regarde si le Product existe et qu'il possède au moins une licence valide pour une des applications
|
||||
$host = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : 'legtech.legtech';
|
||||
$url_hostname = explode(".", $host); // décompose l'url de base
|
||||
$slug = $url_hostname[0];
|
||||
if ($slug == 'legstack') {
|
||||
$slug = 'legtech';
|
||||
}
|
||||
return $slug;
|
||||
*/
|
||||
}
|
||||
|
||||
// récupère les informations de connexion à la base du Product
|
||||
public static function getDatabaseEnvironment($Product_id)
|
||||
{
|
||||
return Product::byId($Product_id)->first()->toArray();
|
||||
}
|
||||
|
||||
public static function isProduct()
|
||||
{
|
||||
$website = self::getWebsite();
|
||||
$is_Product = $website ? true : false;
|
||||
return $is_Product;
|
||||
}
|
||||
|
||||
public static function getWebsite()
|
||||
{
|
||||
return \Hyn\Tenancy\Facades\TenancyFacade::website();
|
||||
}
|
||||
|
||||
public static function getWebsiteByProduct($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
return Website::find($Product->website_id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user