update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
89
dev/app-bak/Repositories/AboRepository.php
Normal file
89
dev/app-bak/Repositories/AboRepository.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue