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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user