First Commit

This commit is contained in:
Kevin Adametz 2018-10-29 09:15:36 +01:00
commit 0c9a118281
633 changed files with 76612 additions and 0 deletions

View file

@ -0,0 +1,68 @@
<?php
namespace App\Repositories;
abstract class BaseRepository {
/**
* The Model instance.
*
* @var Illuminate\Database\Eloquent\Model
*/
protected $model;
/**
* Get number of records.
*
* @return array
*/
public function getNumber()
{
$total = $this->model->count();
$new = $this->model->whereSeen(0)->count();
return compact('total', 'new');
}
/**
* Destroy a model.
*
* @param int $id
* @return void
*/
public function destroy($id)
{
$this->getById($id)->delete();
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getById($id)
{
return $this->model->findOrFail($id);
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getAll()
{
return $this->model->all();
}
/**
* @return Illuminate\Database\Eloquent\Model
*/
public function getModel()
{
return $this->model;
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace App\Repositories;
use App\Models\TravelClass;
use App\Models\TravelProgram;
use App\Models\TravelProgramDraft;
class TravelProgramRepository extends BaseRepository {
public function __construct(TravelProgram $model)
{
$this->model = $model;
}
public function update($data)
{
if($data['id'] == "new"){
$this->model = TravelProgram::createNew();
}
else{
$this->model = $this->getById($data['id']);
}
$this->checkDraftsWeekdays($data['weekdays']);
$data['weekdays'] = $this->model->setWeekdaysFromArray($data['weekdays']);
$this->model->fill($data);
$this->model->status = isset($data['status']) ? true : false;
$this->model->save();
return $this->model;
}
public function checkDraftsWeekdays($weekdays){
if(isset($weekdays) && is_array($weekdays) && $weekdays[0] === NULL){
$weekdays = range(0, 6);
}
foreach($this->model->travel_program_drafts as $travel_program_draft){
if($travel_program_draft->weekdays !== NULL){
$wd = [];
foreach ($travel_program_draft->weekdays as $weekday){
if(in_array($weekday, $weekdays)){
$wd[] = $weekday;
}
}
if(count($wd)){
$travel_program_draft->weekdays = $wd;
}else{
$travel_program_draft->weekdays = NULL;
}
$travel_program_draft->save();
}
}
}
public function updateClass($data)
{
if($data['id'] == "new"){
$travel_class = TravelClass::create([
'program_id' => $data['program_id'],
'name' => $data['name'],
'standard' => isset($data['standard']) ? true : false,
'description' => $data['description'],
]);
}else {
$travel_class = TravelClass::findOrFail($data['id']);
$travel_class->name = $data['name'];
$travel_class->standard = isset($data['standard']) ? true : false;
$travel_class->description = $data['description'];
$travel_class->save();
}
return $travel_class;
}
public function updateDraft($data)
{
if(isset($data['weekdays']) && count($data['weekdays']) > 1 && in_array(NULL, $data['weekdays'])){
$data['weekdays'] = array_filter($data['weekdays'], 'is_numeric');
sort($data['weekdays']);
}
if($data['id'] == "new"){
$travel_program_draft = TravelProgramDraft::create([
'travel_program_id' => $data['travel_program_id'],
'travel_class_id' => $data['travel_class_id'],
'draft_id' => $data['draft_id'],
'weekdays' => isset($data['weekdays']) ? $data['weekdays'] : null,
]);
}else{
$travel_program_draft = TravelProgramDraft::findOrFail($data['id']);
$travel_program_draft->draft_id = $data['draft_id'];
$travel_program_draft->travel_class_id = $data['travel_class_id'];
$travel_program_draft->weekdays = isset($data['weekdays']) ? $data['weekdays'] : null;
$travel_program_draft->save();
}
return $travel_program_draft;
}
}

View file

@ -0,0 +1,113 @@
<?php
namespace App\Repositories;
use App\User;
class UserRepository extends BaseRepository {
public function __construct(User $model)
{
$this->model = $model;
}
/**
* refresh.
*/
/*public function update($data)
{
if($data['user_id'] == "new"){
$this->model = User::create([
'email' => $data['email'],
'password' => env('APP_KEY'),
]);
}
else{
$this->model = $this->getById($data['user_id']);
}
if(!$this->model->account_id){
$account = new UserAccount();
}else{
$account = $this->model->account;
}
$account->company = $data['company'];
$account->company_name = $data['company_name'];
$account->company_street = $data['company_street'];
$account->company_postal_code = $data['company_postal_code'];
$account->company_city = $data['company_city'];
$account->company_country_id = isset($data['company_country_id']) ? $data['company_country_id'] : null;
$account->company_pre_phone_id = isset($data['company_pre_phone_id']) ? $data['company_pre_phone_id']: null;
$account->company_phone = $data['company_phone'];
$account->company_homepage = $data['company_homepage'];
$account->position_text = $data['position_text'];
$account->salutation = $data['salutation'];
$account->title = $data['title'];
$account->first_name = $data['first_name'];
$account->last_name = $data['last_name'];
$account->street = $data['street'];
$account->postal_code = $data['postal_code'];
$account->city = $data['city'];
$account->country_id = isset($data['country_id']) ? $data['country_id'] : null;
$account->pre_phone_id = isset($data['pre_phone_id']) ? $data['pre_phone_id']: null;
$account->phone = $data['phone'];
$account->pre_mobil_id = isset($data['pre_mobil_id']) ? $data['pre_mobil_id']: null;
$account->mobil = $data['mobil'];
$account->contactpartner = $data['contactpartner'];
//data_protection
//active_date
//active
$account->save();
if(!$this->model->account_id){
$this->model->account_id = $account->id;
$this->model->save();
}
$this->updateInterests(isset($data['interests']) ? $data['interests'] : array());
$this->updateIndustrySector(isset($data['industry_sectors']) ? $data['industry_sectors'] : array());
return;
}
*/
public function deleteUser(User $user)
{
if($user->account){
$user->account->delete();
}
$user->email = "delete".time();
$user->password = "";
$user->confirmed = 0;
$user->confirmation_code = "delete".time();
$user->confirmation_date = null;
$user->confirmation_code_to = null;
$user->confirmation_code_remider = 2;
$user->agreement = null;
$user->active = 0;
$user->token = '';
$user->active_date = null;
$user->admin = 0;
$user->save();
return true;
}
}