+ Homparty Part 1
This commit is contained in:
parent
74923859d1
commit
9252094a04
43 changed files with 2385 additions and 66 deletions
269
app/Http/Controllers/User/HomepartyController.php
Executable file
269
app/Http/Controllers/User/HomepartyController.php
Executable file
|
|
@ -0,0 +1,269 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Homeparty;
|
||||
use App\Models\HomepartyUser;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Util;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
|
||||
class HomepartyController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('superadmin');
|
||||
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'homepartys' => Homeparty::where('auth_user_id', '=', \Auth::user()->id)->get(),
|
||||
];
|
||||
return view('user.homeparty.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id === 'new'){
|
||||
$homeparty = new Homeparty();
|
||||
}else{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
}
|
||||
if($homeparty->homeparty_host){
|
||||
$homeparty_user = $homeparty->homeparty_host;
|
||||
}else{
|
||||
$homeparty_user = new HomepartyUser();
|
||||
$homeparty_user->is_host = true;
|
||||
}
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
'homeparty_user' => $homeparty_user,
|
||||
|
||||
];
|
||||
return view('user.homeparty.detail', $data);
|
||||
}
|
||||
|
||||
public function store($id = null)
|
||||
{
|
||||
$data = Request::all();
|
||||
if($data['action'] === 'homeparty-party-store'){
|
||||
$rules = array(
|
||||
'date' => 'required',
|
||||
'name' => 'required',
|
||||
'place' => 'required'
|
||||
);
|
||||
}
|
||||
if($data['action'] === 'homeparty-user-store'){
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname' => 'required',
|
||||
'billing_lastname' => 'required',
|
||||
'billing_address' => 'required',
|
||||
'billing_zipcode' => 'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
if (!Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($data['action'] === 'homeparty-party-store'){
|
||||
if(!$id){
|
||||
//first save create and empty user/host
|
||||
$homeparty = Homeparty::create($data);
|
||||
do {
|
||||
$token = Util::uuidToken();
|
||||
} while( HomepartyUser::where('token', $token)->count() );
|
||||
$homeparty_user = HomepartyUser::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'auth_user_id' => \Auth::user()->id,
|
||||
'is_host' => true,
|
||||
'token' => $token,
|
||||
]);
|
||||
}else {
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$homeparty->fill($data)->save();
|
||||
}
|
||||
}
|
||||
|
||||
if($data['action'] === 'homeparty-user-store'){
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
$homeparty_user = $homeparty->homeparty_host;
|
||||
$homeparty_user->fill($data)->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('user_homeparty_detail', $homeparty->id));
|
||||
}
|
||||
|
||||
|
||||
public function guests($id = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
];
|
||||
return view('user.homeparty.guests', $data);
|
||||
}
|
||||
|
||||
|
||||
public function guestDetail($id = null, $gid = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
if($gid === 'new'){
|
||||
do {
|
||||
$token = Util::uuidToken();
|
||||
} while( HomepartyUser::where('token', $token)->count() );
|
||||
$homeparty_user = HomepartyUser::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'auth_user_id' => \Auth::user()->id,
|
||||
'is_host' => false,
|
||||
'token' => $token,
|
||||
]);
|
||||
}else{
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
'homeparty_user' => $homeparty_user,
|
||||
];
|
||||
return view('user.homeparty.guest_detail', $data);
|
||||
}
|
||||
|
||||
public function guestStore($id = null, $gid = null)
|
||||
{
|
||||
$data = Request::all();
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname' => 'required',
|
||||
'billing_lastname' => 'required',
|
||||
'billing_address' => 'required',
|
||||
'billing_zipcode' => 'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
if (!Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
$homeparty_user->fill($data)->save();
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('user_homeparty_guests', [$homeparty->id]));
|
||||
}
|
||||
|
||||
|
||||
public function order($id = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
abort(404);
|
||||
|
||||
/*$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->auth_user_id !== $user->id){
|
||||
abort(404);
|
||||
}
|
||||
$shopping_order->getLastShoppingPayment();
|
||||
|
||||
$data = [
|
||||
'shopping_order' => $shopping_order,
|
||||
'isAdmin' => false,
|
||||
];
|
||||
return view('user.order.detail', $data);*/
|
||||
}
|
||||
|
||||
public function delete($do, $id = null, $gid=null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
|
||||
if($do === 'hpu'){
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
$homeparty_user->token = null;
|
||||
$homeparty_user->save();
|
||||
$homeparty_user->delete();
|
||||
\Session()->flash('alert-success', "Homeparty Gast gelöscht");
|
||||
return redirect(route('user_homeparty_guests', [$homeparty->id]));
|
||||
|
||||
}
|
||||
if($do === 'hp') {
|
||||
|
||||
foreach ($homeparty->homeparty_users as $homeparty_user){
|
||||
if ($homeparty->id !== $homeparty_user->homeparty_id) {
|
||||
abort(404);
|
||||
}
|
||||
$homeparty_user->token = null;
|
||||
$homeparty_user->save();
|
||||
$homeparty_user->delete();
|
||||
}
|
||||
$homeparty->delete();
|
||||
\Session()->flash('alert-success', "Homeparty gelöscht");
|
||||
return redirect(route('user_homepartys'));
|
||||
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function getHomparty($id){
|
||||
$homeparty = Homeparty::findOrFail($id);
|
||||
if($homeparty->auth_user_id !== \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
return $homeparty;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue