Updates to 03-2025

This commit is contained in:
Kevin Adametz 2025-04-01 10:36:47 +02:00
parent bfa3bb1df4
commit 9ae662f63e
243 changed files with 12580 additions and 12018 deletions

View file

@ -0,0 +1,89 @@
<?php
namespace App\Repositories;
use Carbon;
use App\Models\UserAbo;
use App\Services\AboHelper;
class AboRepository extends BaseRepository {
public function __construct()
{
//$this->model = $model;
}
public function setModel(UserAbo $model){
$this->model = $model;
}
public function update($data)
{
if(isset($data['action'])){
if($data['action'] === 'abo_update_settings'){
if($this->validate($data)){
$this->updateStatus($data);
$this->model->abo_interval = $data['abo_interval'];
$this->model->next_date = AboHelper::setNextDate(now(), $data['abo_interval']);
$this->model ->save();
\Session()->flash('alert-success', 'Einstellungen gespeichert');
return true;
}
return false;
}
}
return false;
}
public function create($data){
}
private function updateStatus($data){
$active = (isset($data['abo_is_active']) && $data['abo_is_active']) ? true : false;
//if status is active and active is false, set status to inactive
if($this->model->active && !$active){
if($this->model->status = 2){ //okay
$this->model->status = 6; //
}
}
if(!$this->model->active && $active){
if($this->model->status = 6){ //inactive
$this->model->status = 2; //okay
}
}
$this->model->active = $active;
return;
}
private function validate($data){
if($data['view'] !== 'admin'){
if($this->model->is_for === 'me' && $this->model->user_id !== \Auth::user()->id){
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
return false;
}
if($this->model->is_for === 'ot' && $this->model->member_id !== \Auth::user()->id){
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
return false;
}
if($data['view'] === 'me' && $this->model->is_for !== 'me'){
\Session()->flash('alert-error', 'Unauthorized action. Is not for me');
return false;
}
if($data['view'] === 'ot' && $this->model->is_for !== 'ot'){
\Session()->flash('alert-error', 'Unauthorized action. Is not your customer');
return false;
}
}
if(!in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)){
//to check if user is not admin
\Session()->flash('alert-error', __('abo.error_abo_interval'));
return false;
}
return true;
}
}

View file

@ -0,0 +1,376 @@
<?php
namespace App\Repositories;
use Yard;
use App\Services\Util;
use App\Models\ShoppingUser;
use App\Models\Homeparty;
use App\Models\ShoppingCollectOrder;
use App\Models\PaymentMethod;
use App\Models\ShoppingOrder;
use Illuminate\Session\SessionManager;
use App\Models\ShoppingOrderItem;
use Illuminate\Support\Collection;
class CheckoutRepository extends BaseRepository {
private $session;
private $instance;
public function __construct(SessionManager $session)
{
$this->session = $session;
$this->instance = sprintf('%s.%s', 'cart', 'payments');
}
public function makeShoppingOrder($shopping_user, $data){
$user_shop = Util::getUserShop();
if($shopping_user->is_from === 'homeparty'){
//get data
$homeparty = Homeparty::find($shopping_user->homeparty_id);
//set Data!
$total = Yard::instance('shopping')->total(2, '.', ''); //ek_price
$data = [
'shopping_user_id' => $shopping_user->id,
'auth_user_id' => $shopping_user->auth_user_id,
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'user_shop_id' => $user_shop->id,
'payment_for' => $shopping_user->getOrderPaymentFor(),
'homeparty_id' => $shopping_user->homeparty_id,
'total' => $total,
'subtotal' => $homeparty->order['ek_price_net'],
'shipping' => $homeparty->order['shipping_price'],
'shipping_net' => $homeparty->order['shipping_price_net'],
'subtotal_ws' => 0,
'tax' => $total - $homeparty->order['ek_price_net'],
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
'points' => $homeparty->order['points'] - $homeparty->order['bonus_points_diff'],
'weight' => 0,
'txaction' => 'prev',
'mode' => Util::getUserShoppingMode(),
];
}elseif($shopping_user->is_from === 'collection'){
//get data
$ShoppingCollectOrder = ShoppingCollectOrder::find($shopping_user->shopping_collect_order_id);
//set Data!
$total = Yard::instance('shopping')->total(2, '.', ''); //ek_price
$data = [
'shopping_user_id' => $shopping_user->id,
'auth_user_id' => $shopping_user->auth_user_id,
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'user_shop_id' => $user_shop->id,
'payment_for' => $shopping_user->getOrderPaymentFor(),
'total' => $total,
'subtotal' => $ShoppingCollectOrder->price_total_net,
'shipping' => 0,
'shipping_net' => 0,
'subtotal_ws' => $ShoppingCollectOrder->price_total_net,
'tax' => $ShoppingCollectOrder->tax_total,
'tax_split' => $ShoppingCollectOrder->tax_split,
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
'points' => $ShoppingCollectOrder->points,
'weight' => 0,
'txaction' => 'prev',
'mode' => Util::getUserShoppingMode(),
];
}else{
$data = [
'shopping_user_id' => $shopping_user->id,
'auth_user_id' => $shopping_user->auth_user_id,
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'user_shop_id' => $user_shop->id,
'payment_for' => $shopping_user->getOrderPaymentFor(),
'total' => Yard::instance('shopping')->total(2, '.', ''),
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
'shipping_net' => Yard::instance('shopping')->shippingNet(2, '.', ''),
'subtotal_ws' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
'tax' => Yard::instance('shopping')->taxWithShipping(2, '.', ''),
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
'points' => Yard::instance('shopping')->points(),
'weight' => Yard::instance('shopping')->weight(),
'is_abo' => isset($data['is_abo']) ? $data['is_abo'] : false,
'abo_interval' => isset($data['abo_interval']) ? $data['abo_interval'] : null,
'txaction' => 'prev',
'mode' => Util::getUserShoppingMode(),
];
}
$shopping_order= false;
if($this->getSessionPayments('shopping_order_id')){
$shopping_order = ShoppingOrder::find($this->getSessionPayments('shopping_order_id'));
if($shopping_order){
$shopping_order->fill($data);
$shopping_order->save();
}
}
if(!$shopping_order){
$shopping_order = ShoppingOrder::create($data);
if($shopping_user->is_from === 'collection' && $ShoppingCollectOrder){
$ShoppingCollectOrder->shopping_order_id = $shopping_order->id;
$ShoppingCollectOrder->save();
}
}
$this->putSessionPayments('shopping_order_id', $shopping_order->id);
$items = Yard::instance('shopping')->getContentByOrder();
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order, $shopping_user) {
foreach ($items as $item) {
if ($model->row_id === $item->rowId) {
$price_net = Yard::instance('shopping')->rowPriceNet($item, 2, '.', '');
$tax = $item->price - $price_net;
$data = [
'shopping_order_id' => $shopping_order->id,
'row_id' => $item->rowId,
'product_id' => $item->id,
'comp' => $item->options->comp,
'qty' => $item->qty,
'price' => $item->price,
'price_net' => $price_net,
'tax_rate' => $item->taxRate,
'tax' => $tax,
'price_vk_net' => $shopping_order->getPriceVkNetBy($item->id),
'discount' => $item->options->no_commission ? 0 : $shopping_order->getUserDiscount(),
'points' => $item->options->points,
'slug' => $item->options->slug,
];
if($shopping_user->is_from === 'homeparty'){
$data['homeparty_id'] = (int) $shopping_user->homeparty_id;
$data['product_id'] = null;
}
if($shopping_user->is_from === 'collection'){
$data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id;
$data['product_id'] = null;
}
$model->fill($data)->save();
return false;
}
}
return $model->delete();
});
foreach ($items as $item) {
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()){
$price_net = Yard::instance('shopping')->rowPriceNet($item, 2, '.', '');
$tax = $item->price - $price_net;
$data = [
'shopping_order_id' => $shopping_order->id,
'row_id' => $item->rowId,
'product_id' => $item->id,
'comp' => $item->options->comp,
'qty' => $item->qty,
'price' => $item->price,
'price_net' => $price_net,
'tax_rate' => $item->taxRate,
'tax' => $tax,
'price_vk_net' => $shopping_order->getPriceVkNetBy($item->id),
'discount' => $item->options->no_commission ? 0 : $shopping_order->getUserDiscount(),
'points' => $item->options->points,
'slug' => $item->options->slug
];
if($shopping_user->is_from === 'homeparty'){
$data['homeparty_id'] = (int) $shopping_user->homeparty_id;
$data['price_vk_net'] = 0;
$data['product_id'] = null;
}
if($shopping_user->is_from === 'collection'){
$data['price_vk_net'] = 0;
$data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id;
$data['product_id'] = null;
}
$shopping_order_item = ShoppingOrderItem::create($data);
}
}
if($shopping_user->is_from === 'homeparty'){
$shopping_order->makeHomepartyTaxSplit();
}elseif($shopping_user->is_from === 'collection'){
//is set on create / filll.
}else{
$shopping_order->makeTaxSplit();
}
return $shopping_order;
}
public function makeShoppingUser($data){
$data['same_as_billing'] = isset($data['same_as_billing']) ? false : true; //reinvert
$data['accepted_data_checkbox'] = isset($data['accepted_data_checkbox']) ? true : false;
$shopping_user = false;
if($this->getSessionPayments('shopping_user_id')){
$shopping_user = ShoppingUser::find($this->getSessionPayments('shopping_user_id'));
if($shopping_user){
$shopping_user->fill($data);
$shopping_user->mode = null;
$shopping_user->save();
}
}
if(!$shopping_user){
$shopping_user = ShoppingUser::create($data);
}
$this->putSessionPayments('shopping_user_id', $shopping_user->id);
return $shopping_user;
}
public function getPaymentsMethods($is_from, $is_abo = false){
$payment_methods = [];
if($is_from !== 'shopping' && Util::getAuthUser()){
$user = Util::getAuthUser();
$payment_methods['default'] = $user->payment_methods;
$payment_methods['data'] = $user->account->payment_data;
}else{
$payment_methods['default'] = PaymentMethod::getDefaultAsArray($is_abo)->toArray();
$payment_methods['data'] = false;
}
if($is_abo){
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->where('is_abo', true)->get()->pluck( 'id', 'short')->toArray();
}else{
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->get()->pluck( 'id', 'short')->toArray();
}
return $payment_methods;
}
public function isPaymentsMethodsActive($payment_method, $is_from, $is_abo = false){
$payment_names = ['wlt#PPE' => 'PP', 'cc' => 'CC', 'sb#PNT' => 'SB', 'elv' => 'SEPA', 'vor' => 'VOR', 'fnc#MIV' => 'FNC'];
$payment_methods = $this->getPaymentsMethods($is_from, $is_abo);
if(isset($payment_names[$payment_method])){
$payment_with = $payment_names[$payment_method];
if(array_key_exists($payment_with, $payment_methods['active']) && in_array($payment_methods['active'][$payment_with], $payment_methods['default'])){
return true;
}
}
abort(404);
}
public function makeCustomerShoppingUser($shopping_data){
// $shopping_user = ShoppingUser::findOrFail($shopping_data['shopping_user_id']);
$shopping_user = new ShoppingUser();
$shopping_user->fill($shopping_data);
$shopping_user->faker_mail = false;
$shopping_user->auth_user_id = null;
$shopping_user->homeparty_id = null;
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
// $shopping_user->id = null;
$shopping_user->accepted_data_checkbox = 1;
return $shopping_user;
}
public function shoppingUserAuthData($is_from, $is_for, $data = []){
$user = Util::getAuthUser();
$shopping_user = new ShoppingUser();
$shopping_user->auth_user_id = $user->id;
$shopping_user->mode = 'prev';
$shopping_user->language = \App::getLocale();
$shopping_user->billing_salutation = $user->account->salutation;
$shopping_user->billing_company = $user->account->company;
$shopping_user->billing_firstname = $user->account->first_name;
$shopping_user->billing_lastname = $user->account->last_name;
$shopping_user->billing_address = $user->account->address;
$shopping_user->billing_address_2 = $user->account->address_2;
$shopping_user->billing_zipcode = $user->account->zipcode;
$shopping_user->billing_city = $user->account->city;
$shopping_user->billing_country_id = $user->account->country_id;
$shopping_user->billing_phone = $user->account->phone;
$shopping_user->billing_email = $user->email;
$shopping_user->faker_mail = false;
$shopping_user->shipping_email = $user->email;
$shopping_user->accepted_data_checkbox = 1;
$shopping_user->is_for = $is_for;
$shopping_user->is_from = $is_from;
$shopping_user->homeparty_id = isset($data['homeparty_id']) ? $data['homeparty_id'] : null;
$shopping_user->shopping_collect_order_id = isset($data['shopping_collect_order_id']) ? $data['shopping_collect_order_id'] : null;
//Lieferadresse
if($is_from === 'user_order'){
if(isset($data['shopping_user_id']) && strpos($data['is_for'], 'ot') !== false){
$s_user = ShoppingUser::findOrFail($data['shopping_user_id']);
/* $shopping_user->billing_salutation = $s_user->billing_salutation;
$shopping_user->billing_company = $s_user->billing_company;
$shopping_user->billing_firstname = $s_user->billing_firstname;
$shopping_user->billing_lastname = $s_user->billing_lastname;
$shopping_user->billing_address = $s_user->billing_address;
$shopping_user->billing_address_2 = $s_user->billing_address_2;
$shopping_user->billing_zipcode = $s_user->billing_zipcode;
$shopping_user->billing_city = $s_user->billing_city;
$shopping_user->billing_country_id = $s_user->billing_country_id;
$shopping_user->billing_phone = $s_user->billing_phone;
$shopping_user->billing_email = $s_user->billing_email;
;*/
$shopping_user->faker_mail = $s_user->faker_mail;
if(!$s_user->faker_mail){
$shopping_user->shipping_email = $s_user->billing_email;
}
$shopping_user->shopping_user_id = $data['shopping_user_id'];
$shopping_user->member_id = $s_user->member_id;
}
$shopping_user->same_as_billing = true;
$shopping_user->shipping_salutation = isset($data['shipping_salutation']) ? $data['shipping_salutation'] : '';
$shopping_user->shipping_company = isset($data['shipping_company']) ? $data['shipping_company'] : '';
$shopping_user->shipping_firstname = isset($data['shipping_firstname']) ? $data['shipping_firstname'] : '';
$shopping_user->shipping_lastname = isset($data['shipping_lastname']) ? $data['shipping_lastname'] : '';
$shopping_user->shipping_address = isset($data['shipping_address']) ? $data['shipping_address'] : '';
$shopping_user->shipping_address_2 = isset($data['shipping_address_2']) ? $data['shipping_address_2'] : '';
$shopping_user->shipping_zipcode = isset($data['shipping_zipcode']) ? $data['shipping_zipcode'] : '';
$shopping_user->shipping_city = isset($data['shipping_city']) ? $data['shipping_city'] : '';
$shopping_user->shipping_country_id = Yard::instance('shopping')->getShippingCountryCountryId();
$shopping_user->shipping_phone = isset($data['shipping_phone']) ? $data['shipping_phone'] : '';
}else{
$shopping_user->same_as_billing = $user->account->same_as_billing ? false : true;
$shopping_user->shipping_salutation = $user->account->shipping_salutation;
$shopping_user->shipping_company = $user->account->shipping_company;
$shopping_user->shipping_firstname = $user->account->shipping_firstname;
$shopping_user->shipping_lastname = $user->account->shipping_lastname;
$shopping_user->shipping_address = $user->account->shipping_address;
$shopping_user->shipping_address_2 = $user->account->shipping_address_2;
$shopping_user->shipping_zipcode = $user->account->shipping_zipcode;
$shopping_user->shipping_city = $user->account->shipping_city;
$shopping_user->shipping_country_id = $user->account->shipping_country_id;
$shopping_user->shipping_phone = $user->account->shipping_phone;
}
return $shopping_user;
}
public function putSessionPayments($key, $value){
$content = $this->getContent();
$content->put($key, $value);
$this->session->put($this->instance, $content);
}
public function getSessionPayments($key){
$content = $this->getContent();
if ($content->has($key)){
return $content->get($key);
}
return false;
}
public function sessionDestroy()
{
$this->session->remove($this->instance);
}
private function getContent()
{
if (is_null($this->session->get($this->instance))) {
return new Collection([]);
}
return $this->session->get($this->instance);
}
}

View file

@ -2,24 +2,36 @@
namespace App\Repositories\DC;
use Imagick;
use Request;
use App\Models\DcFile;
use App\Services\Util;
use App\Models\DcFileTag;
use App\Repositories\BaseRepository;
use Intervention\Image\Facades\Image;
use Imagick;
class FileRepository extends BaseRepository {
private const ALLOWED_IMAGE_TYPES = [
'image/jpeg',
'image/gif',
'image/png'
];
private const ALLOWED_PDF_TYPES = [
'application/pdf'
];
public function __construct()
{
}
private const THUMB_WIDTH = 542;
private const THUMB_HEIGHT = 360;
private const BIG_WIDTH = 1600;
private const BIG_HEIGHT = 900;
public function uploadFile( $form_data )
public function uploadFile(array $form_data): DcFile
{
if (!isset($form_data['file']) || !$form_data['file']->isValid()) {
throw new \InvalidArgumentException('Invalid file provided');
}
$file = $form_data['file'];
$originalName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
@ -43,109 +55,163 @@ class FileRepository extends BaseRepository {
return $dc_file;
}
public function makeThumb($id){
public function makeThumb(int $id): bool
{
$file = DcFile::findOrFail($id);
$this->makeThumbFromFile($file);
return true;
}
public function makeThumbFromFile($file)
public function makeThumbFromFile(DcFile $file): bool
{
$path = $file->getFile(true);
$filename = $file->filename;
$mine = \File::mimeType($path);
//make thumb
$allowedMimeTypes = ['image/jpeg','image/gif','image/png'];
if (in_array($mine, $allowedMimeTypes)) {
$img = Image::make($path);
$img->resize(542, 360, function ($c) {
$c->aspectRatio();
$c->upsize();
});
\Storage::disk('public')->put('dc/thumb/'.basename($filename), (string) $img->encode());
$img = Image::make($path);
$img->resize(1600, 900, function ($c) {
$c->aspectRatio();
$c->upsize();
});
\Storage::disk('public')->put('dc/big/'.basename($filename), (string) $img->encode());
}
$allowedMimeTypes = ['application/pdf'];
if (in_array($mine, $allowedMimeTypes)) {
$imagick = new \Imagick ($path.'[0]'); // 0 specifies the first page of the pdf
$imagick->setImageBackgroundColor('#ffffff');
$imagick = $imagick->mergeImageLayers( Imagick::LAYERMETHOD_FLATTEN );
$imagick->setImageFormat('jpg'); // set the format of the output image
$imagick->setImageCompression(\Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(60);
$imagick->resizeImage(1600, 900, \Imagick::FILTER_LANCZOS, 1,1);
$filestore = \Storage::disk('public')->path('dc/big/').basename($filename).".jpg";
$imagick->writeImage($filestore);
$imagick->resizeImage(542, 360, \Imagick::FILTER_LANCZOS, 1,1);
$filestore = \Storage::disk('public')->path('dc/thumb/').basename($filename).".jpg";
$imagick->writeImage($filestore);
}
return true;
}
public function tagsUpdate($id, $tags){
$file = DcFile::findOrFail($id);
$file_tags = DcFileTag::where('file_id', $file->id)->get();
//remove Tags
foreach ($file_tags as $file_tag) {
if(is_array($tags) && ($pos = array_search($file_tag->tag_id, $tags)) !== FALSE){
unset($tags[$pos]);
}else{
$file_tag->delete();
try {
$path = $file->getFile(true);
if (!file_exists($path)) {
throw new \Exception('File not found');
}
}
//set taTagsgs
if(is_array($tags)){
foreach ($tags as $key => $tag_id) {
DcFileTag::create([
'file_id' => $file->id,
'tag_id' => $tag_id
]);
}
}
$filename = $file->filename;
$mime = \File::mimeType($path);
if (in_array($mime, self::ALLOWED_IMAGE_TYPES)) {
$this->processImage($path, $filename);
} elseif (in_array($mime, self::ALLOWED_PDF_TYPES)) {
$this->processPdf($path, $filename);
}
return true;
} catch (\Exception $e) {
\Log::error('Thumbnail creation failed: ' . $e->getMessage());
return false;
}
}
private function processImage(string $path, string $filename): void
{
// Thumbnail
$img = Image::make($path);
$img->resize(542, 360, function ($c) {
$c->aspectRatio();
$c->upsize();
});
\Storage::disk('public')->put('dc/thumb/'.basename($filename), (string) $img->encode());
// Big image
$img = Image::make($path);
$img->resize(1600, 900, function ($c) {
$c->aspectRatio();
$c->upsize();
});
\Storage::disk('public')->put('dc/big/'.basename($filename), (string) $img->encode());
}
private function processPdf(string $path, string $filename): void
{
try {
// PDF mit höherer Auflösung rendern
$imagick = new \Imagick();
$imagick->setResolution(300, 300);
$imagick->readImage($path.'[0]');
// Grundlegende Bildoptimierungen
$imagick->setImageBackgroundColor('#ffffff');
$imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$imagick->setImageFormat('jpg');
$imagick->setImageCompression(\Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality(80);
// Große Version erstellen
$bigImage = clone $imagick;
$bigImage->resizeImage(self::BIG_WIDTH, self::BIG_HEIGHT, \Imagick::FILTER_LANCZOS, 1, true);
$bigImage->writeImage(\Storage::disk('public')->path('dc/big/').basename($filename).'.jpg');
$bigImage->clear();
// Thumbnail erstellen
$imagick->resizeImage(self::THUMB_WIDTH, self::THUMB_HEIGHT, \Imagick::FILTER_LANCZOS, 1, true);
$imagick->writeImage(\Storage::disk('public')->path('dc/thumb/').basename($filename).'.jpg');
// Ressourcen freigeben
$imagick->clear();
} catch (\ImagickException $e) {
\Log::error('PDF Verarbeitung fehlgeschlagen: ' . $e->getMessage());
throw new \RuntimeException('PDF Verarbeitung fehlgeschlagen: ' . $e->getMessage());
} finally {
if (isset($bigImage)) {
$bigImage->destroy();
}
if (isset($imagick)) {
$imagick->destroy();
}
}
}
public function tagsUpdate($id, array $tags = []): bool
{
$file = DcFile::findOrFail($id);
// Get existing tags
$existingTags = DcFileTag::where('file_id', $file->id)
->pluck('tag_id')
->toArray();
// Delete removed tags
$tagsToDelete = array_diff($existingTags, $tags);
if (!empty($tagsToDelete)) {
DcFileTag::where('file_id', $file->id)
->whereIn('tag_id', $tagsToDelete)
->delete();
}
// Add new tags
$tagsToAdd = array_diff($tags, $existingTags);
$newTags = [];
foreach ($tagsToAdd as $tagId) {
$newTags[] = [
'file_id' => $file->id,
'tag_id' => $tagId
];
}
if (!empty($newTags)) {
DcFileTag::insert($newTags);
}
return true;
}
public function deleteThumb($id){
$file = DcFile::findOrFail($id);
$path_thumb = $file->getThumb(true);
if (file_exists($path_thumb)) {
unlink($path_thumb);
}
$path_big = $file->getBig(true);
if (file_exists($path_big)) {
unlink($path_big);
}
return true;
}
public function deleteFile($id){
$file = DcFile::findOrFail($id);
$path_thumb = $file->getThumb(true);
if (file_exists($path_thumb)) {
unlink($path_thumb);
}
$path_big = $file->getBig(true);
if (file_exists($path_big)) {
unlink($path_big);
}
$path = $file->getFile(true);
private function deleteFileIfExists(string $path): void
{
if (file_exists($path)) {
unlink($path);
}
$file->delete();
return true;
}
public function deleteThumb($id): bool
{
try {
$file = DcFile::findOrFail($id);
$this->deleteFileIfExists($file->getThumb(true));
$this->deleteFileIfExists($file->getBig(true));
return true;
} catch (\Exception $e) {
\Log::error('Thumbnail deletion failed: ' . $e->getMessage());
return false;
}
}
public function deleteFile(int $id): bool
{
try {
$file = DcFile::findOrFail($id);
$this->deleteFileIfExists($file->getThumb(true));
$this->deleteFileIfExists($file->getBig(true));
$this->deleteFileIfExists($file->getFile(true));
$file->delete();
return true;
} catch (\Exception $e) {
\Log::error('File deletion failed: ' . $e->getMessage());
return false;
}
}
}

View file

@ -89,47 +89,5 @@ class FileRepository extends BaseRepository {
], 200);
}
/* public function createFile(Request $request)
{
$locale = \App::getLocale();
$data = [
'step' => 2,
'locale' => $locale,
];
$rules = array(
'network_name' => 'required|max:255',
'input_file_now' => 'required|mimes:png,pdf,jpg,jpeg|max:30000'
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
return view('user.register_complete', $data)->withErrors($validator);
} else {
$user = \Auth::user();
if(!$user->account->network_name){
$file = request()->file('input_file_now');
//$ext = $file->guessClientExtension();
//$file->storeAs('user/' . $user->id .'/verification');
$data = $file->store('user/' . $user->id .'/verification');
$account = $user->account;
$account->network_name = Input::get('network_name');
$account->network_verification = basename($data);
$account->save();
$user->role_id = 2; //set as User by default!
$user->save();
}
return redirect('complete_register');
//return view('user.register_complete', $data);
}
}*/
}

View file

@ -34,12 +34,12 @@ class ProductRepository extends BaseRepository {
$data['sponsor_buying_points'] = isset($data['sponsor_buying_points']) ? 1 : 0;
$data['show_on'] = isset($data['show_on']) ? $data['show_on'] : null;
if($data['id'] === "new"){
$this->model = Product::create($data);
}
else{
$this->model = $this->getById($data['id']);
$this->model->slug = null;
$this->model->fill($data);
$this->model->save();
}