forked from eatvio/eatvio-infra
init commit
This commit is contained in:
137
app/Http/Controllers/CalendarController.php
Normal file
137
app/Http/Controllers/CalendarController.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Calendar;
|
||||
use App\Models\Diary;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\{Carbon, CarbonPeriod};
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class CalendarController extends Controller
|
||||
{
|
||||
public $weekStartsAt;
|
||||
public $weekEndsAt;
|
||||
public $startsAt;
|
||||
public $endsAt;
|
||||
public $gridStartsAt;
|
||||
public $gridEndsAt;
|
||||
|
||||
public function __construct($initialYear = null, $initialMonth = null, $weekStartsAt = null)
|
||||
{
|
||||
$this->weekStartsAt = $weekStartsAt ?? Carbon::MONDAY;
|
||||
$this->weekEndsAt = $this->weekStartsAt == Carbon::MONDAY
|
||||
? Carbon::SUNDAY
|
||||
: collect([0,1,2,3,4,5,6])->get($this->weekStartsAt + 6 - 7)
|
||||
;
|
||||
|
||||
$initialYear = $initialYear ?? Carbon::today()->year;
|
||||
$initialMonth = $initialMonth ?? Carbon::today()->month;
|
||||
|
||||
$this->startsAt = Carbon::createFromDate($initialYear, $initialMonth, 1)->startOfDay();
|
||||
$this->endsAt = $this->startsAt->clone()->endOfMonth()->startOfDay();
|
||||
$this->calculateGridStartsEnds();
|
||||
|
||||
}
|
||||
|
||||
public function calculateGridStartsEnds()
|
||||
{
|
||||
$this->gridStartsAt = $this->startsAt->clone()->startOfWeek($this->weekStartsAt);
|
||||
$this->gridEndsAt = $this->endsAt->clone()->endOfWeek($this->weekEndsAt);
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$curUser = Auth::user();
|
||||
$fullGridPeriod = CarbonPeriod::create(
|
||||
$this->gridStartsAt,
|
||||
'1 day',
|
||||
$this->gridEndsAt
|
||||
);
|
||||
$filledDays = Diary::where('user_id', $curUser->id)
|
||||
->whereMonth('date', now()->month)
|
||||
->get()
|
||||
->keyBy('date');
|
||||
return view(
|
||||
'calendar.index',
|
||||
[
|
||||
'fullGridPeriod' => $fullGridPeriod,
|
||||
'currentLocale' => LaravelLocalization::getCurrentLocale(),
|
||||
'filledDays' => $filledDays,
|
||||
'curUser' => $curUser,
|
||||
]
|
||||
);
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Calendar $calendar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Calendar $calendar)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Calendar $calendar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Calendar $calendar)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Calendar $calendar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Calendar $calendar)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Calendar $calendar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Calendar $calendar)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Normal file
13
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
133
app/Http/Controllers/DiaryController.php
Normal file
133
app/Http/Controllers/DiaryController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Diary;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DiaryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/* return view('diary.index'); */
|
||||
$curDiary = $this->getCurrentDiary();
|
||||
/* dd($curDiary); */
|
||||
return redirect()->route('diary.edit', $curDiary);
|
||||
}
|
||||
|
||||
private function getCurrentDiary()
|
||||
{
|
||||
$curUserId = Auth::id();
|
||||
$curDiary = Diary::userToDayItem($curUserId)->first();
|
||||
|
||||
if (!is_null($curDiary)) {
|
||||
return $curDiary;
|
||||
}
|
||||
return $this->newDiary($curUserId);
|
||||
}
|
||||
|
||||
private function newDiary($curUserId)
|
||||
{
|
||||
$curDiary = new Diary();
|
||||
$curDiary->date = now()->setTimezone('3')->format('Y-m-d');
|
||||
$curDiary->wakeup = '06:30';
|
||||
$curDiary->retire = '22:30';
|
||||
$curDiary->user_id = $curUserId;
|
||||
$curDiary->closed = false;
|
||||
$curDiary->save();
|
||||
|
||||
return $curDiary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
dd($request);
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Diary $diary)
|
||||
{
|
||||
/* $curDiary = Diary::find($id); */
|
||||
$daysCount = Diary::where('user_id', auth()->id())->count();
|
||||
return view('diary.show', ['curDiary' => $diary, 'daysCount' => $daysCount]);
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$curDiary = Diary::find($id);
|
||||
$daysCount = Diary::where('user_id', auth()->id())->count();
|
||||
return view(
|
||||
'diary.index',
|
||||
[
|
||||
'diaryId' => $id,
|
||||
'curDiary' => $curDiary,
|
||||
'daysCount' => $daysCount
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
|
||||
/* dd($request, $id, $request->input()); */
|
||||
$curDiary = Diary::find($id);
|
||||
$curDiary->wakeup = $request->input('wakeup');
|
||||
$curDiary->retire = $request->input('retire');
|
||||
$curDiary->closed = true;
|
||||
$curDiary->save();
|
||||
return redirect()->route('diary.show', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
86
app/Http/Controllers/UserController.php
Normal file
86
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UserDetailz;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(User $user)
|
||||
{
|
||||
return view('user.show', ['user' => $user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(UserDetailz $userDetailz)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, UserDetailz $userDetailz)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(UserDetailz $userDetailz)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
184
app/Http/Controllers/UserDetailzController.php
Normal file
184
app/Http/Controllers/UserDetailzController.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UserDetailz;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserDetailzController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(UserDetailz $userDetailz)
|
||||
{
|
||||
$regFormKeys = [
|
||||
'first_name' => __('reg_form.first_name'),
|
||||
'last_name' => __('reg_form.last_name'),
|
||||
'birthdate' => __('reg_form.date_of_birth'),
|
||||
'gender' => __('reg_form.gender'),
|
||||
'country' => __('reg_form.country'),
|
||||
'city' => __('reg_form.city'),
|
||||
'lang' => __('reg_form.talk_lang'),
|
||||
'weight' => __('reg_form.your_weight'),
|
||||
'chest_circumference' => __('reg_form.chest_circumference'),
|
||||
'waist_circumference' => __('reg_form.waist_circumference'),
|
||||
'hip_circumference' => __('reg_form.hip_circumference'),
|
||||
'blood_pressure_up' => __('reg_form.pressure_up'),
|
||||
'blood_pressure_down' => __('reg_form.pressure_down'),
|
||||
'has_hypo' => __('reg_form.tendency_to_be_hypo'),
|
||||
'has_hyper' => __('reg_form.prone_to_hypertension'),
|
||||
'about_alergy' => __('reg_form.has_alergy'),
|
||||
'about_taking_pils' => __('reg_form.take_pils'),
|
||||
'about_sport_hobbies' => __('reg_form.sport_hobbies'),
|
||||
'favorite_foods' => __('reg_form.favorite_foods'),
|
||||
'unfavorite_foods' => __('reg_form.unfavorite_foods'),
|
||||
'additional_info' => __('reg_form.optional_info')
|
||||
];
|
||||
|
||||
$userAttributes = json_decode(json_encode($userDetailz->user), true);
|
||||
$userDetailzAttributes = json_decode(json_encode($userDetailz), true);
|
||||
|
||||
return view(
|
||||
'profile.detailz_show',
|
||||
[
|
||||
'user' => $userDetailz->user,
|
||||
'userDetailz' => $userDetailz,
|
||||
'regFormKeys' => $regFormKeys,
|
||||
'userAttributes' => $userAttributes,
|
||||
'userDetailzAttributes' => $userDetailzAttributes
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(UserDetailz $userDetailz)
|
||||
{
|
||||
$regFormKeys = [
|
||||
'first_name' => __('reg_form.first_name'),
|
||||
'last_name' => __('reg_form.last_name'),
|
||||
'birthdate' => __('reg_form.date_of_birth'),
|
||||
'gender' => __('reg_form.gender'),
|
||||
'country' => __('reg_form.country'),
|
||||
'city' => __('reg_form.city'),
|
||||
'lang' => __('reg_form.talk_lang'),
|
||||
'weight' => __('reg_form.your_weight'),
|
||||
'chest_circumference' => __('reg_form.chest_circumference'),
|
||||
'waist_circumference' => __('reg_form.waist_circumference'),
|
||||
'hip_circumference' => __('reg_form.hip_circumference'),
|
||||
'blood_pressure_up' => __('reg_form.pressure_up'),
|
||||
'blood_pressure_down' => __('reg_form.pressure_down'),
|
||||
'has_hypo' => __('reg_form.tendency_to_be_hypo'),
|
||||
'has_hyper' => __('reg_form.prone_to_hypertension'),
|
||||
'about_alergy' => __('reg_form.has_alergy'),
|
||||
'about_taking_pils' => __('reg_form.take_pils'),
|
||||
'about_sport_hobbies' => __('reg_form.sport_hobbies'),
|
||||
'favorite_foods' => __('reg_form.favorite_foods'),
|
||||
'unfavorite_foods' => __('reg_form.unfavorite_foods'),
|
||||
'additional_info' => __('reg_form.optional_info')
|
||||
];
|
||||
|
||||
$regFormTypes = [
|
||||
'first_name' => 'text',
|
||||
'last_name' => 'text',
|
||||
'birthdate' => 'date',
|
||||
'gender' => 'text',
|
||||
'country' => 'text',
|
||||
'city' => 'text',
|
||||
'lang' => 'text',
|
||||
'weight' => 'number',
|
||||
'chest_circumference' => 'number',
|
||||
'waist_circumference' => 'number',
|
||||
'hip_circumference' => 'number',
|
||||
'blood_pressure_up' => 'number',
|
||||
'blood_pressure_down' => 'number',
|
||||
'has_hypo' => 'text',
|
||||
'has_hyper' => 'text',
|
||||
'about_alergy' => 'text',
|
||||
'about_taking_pils' => 'text',
|
||||
'about_sport_hobbies' => 'text',
|
||||
'favorite_foods' => 'text',
|
||||
'unfavorite_foods' => 'text',
|
||||
'additional_info' => 'text',
|
||||
];
|
||||
|
||||
$userAttributes = json_decode(json_encode($userDetailz->user), true);
|
||||
$userDetailzAttributes = json_decode(json_encode($userDetailz), true);
|
||||
|
||||
return view(
|
||||
'profile.detailz_edit',
|
||||
[
|
||||
'user' => $userDetailz->user,
|
||||
'userDetailz' => $userDetailz,
|
||||
'regFormKeys' => $regFormKeys,
|
||||
'userAttributes' => $userAttributes,
|
||||
'userDetailzAttributes' => $userDetailzAttributes,
|
||||
'regFormTypes' => $regFormTypes,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, UserDetailz $userDetailz)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\UserDetailz $userDetailz
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(UserDetailz $userDetailz)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user