diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index a40a188..10c043a 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Models\Calendar\Month; +use App\Post; +use Illuminate\Support\Facades\Auth; class StatsController extends Controller { @@ -11,4 +13,22 @@ class StatsController extends Controller // TODO exit; } + + public function calendar($type, $year = null, $month = null) + { + if (null === $month) { + $month = date('m'); + } + + if (null === $year) { + $year = date('Y'); + } + + $posts = Post::getUserPostForMonth(Auth::user()->getAuthIdentifier(), $year, $month); + + if ('month' === $type) { + $month_calendar = new Month($year, $month, $posts); + return view('stats.calendar', ['month' => $month_calendar, 'type' => $type]); + } + } } diff --git a/app/Http/Middleware/GenerateMenus.php b/app/Http/Middleware/GenerateMenus.php index 56178e3..6210b59 100644 --- a/app/Http/Middleware/GenerateMenus.php +++ b/app/Http/Middleware/GenerateMenus.php @@ -29,6 +29,11 @@ class GenerateMenus $stats->prepend(' '); $stats->checkActivationStatus(); + $calendar = $menu->add('Mon calendrier', ['route' => ['calendar', 'month'], 'class' => 'nav-item'])->nickname('calendar'); + $calendar->link->attr(['class' => 'nav-link']); + $calendar->prepend(' '); + $calendar->checkActivationStatus(); + $gallery = $menu->add('Ma gallerie', ['route' => 'gallery', 'class' => 'nav-item'])->nickname('gallery'); $gallery->link->attr(['class' => 'nav-link']); $gallery->prepend(' '); diff --git a/app/Models/Calendar/Day.php b/app/Models/Calendar/Day.php new file mode 100644 index 0000000..17659c3 --- /dev/null +++ b/app/Models/Calendar/Day.php @@ -0,0 +1,41 @@ +date = $date; + $this->post = $post; + } + + /** + * @return DateTime + */ + public function getDate(): DateTime + { + return $this->date; + } + + /** + * @return Post + */ + public function getPost(): ?Post + { + return $this->post; + } +} diff --git a/app/Models/Calendar/Month.php b/app/Models/Calendar/Month.php new file mode 100644 index 0000000..1c1a0bc --- /dev/null +++ b/app/Models/Calendar/Month.php @@ -0,0 +1,138 @@ +year = $year; + $this->month = $month; + $this->fillDays($posts); + } + + /** + * @param $posts + * @throws \Exception + */ + protected function fillDays($posts) + { + $start = DateTime::createFromFormat('Y-m-d', sprintf('%s-%s-01', $this->year, str_pad($this->month, '0', 2))); + $interval = new DateInterval('P1D'); + $end = clone $start; + $end->add(new DateInterval('P1M')); + $period = new DatePeriod($start, $interval, $end); + + foreach ($period as $dt) { + $post = null; + if (count($posts) > 0 && $posts->first()->date_post->format('Ymd') === $dt->format('Ymd')) { + $post = $posts->shift(); + } + + $this->days[] = new Day($dt, $post); + } + } + + /** + * @return string + */ + public function getDate() + { + return DateTime::createFromFormat('Y-m-d', sprintf('%s-%s-01', $this->year, str_pad($this->month, '0', 2))) + ->format('F Y'); + } + + /** + * @return Day[] + */ + public function getDays(): array + { + return $this->days; + } + + /** + * @return DateTime|false + */ + public function getPrevious() + { + return DateTime::createFromFormat('Y-m-d', sprintf('%s-%s-01', $this->year, str_pad($this->month, '0', 2))) + ->modify('-1 month'); + } + + /** + * @return DateTime|false + */ + public function getNext() + { + return DateTime::createFromFormat('Y-m-d', sprintf('%s-%s-01', $this->year, str_pad($this->month, '0', 2))) + ->modify('+1 month'); + } + + /** + * @return string + */ + public function render(): string + { + $content = ''; + + return $content; + } + + /** + * @param Day $day + * @return string + */ + private function _showDay(Day $day): string + { + $currentDate = $day->getDate()->format('Ymd'); + $day_of_week = $day->getDate()->format('N'); + $day_number = $day->getDate()->format('d'); + $post = $day->getPost(); + $classes = ['day']; + if ($currentDate === date('Ymd')) { + $classes[] = 'today'; + } + if ($day_of_week % 7 === 1) { + $classes[] = 'start'; + } + if ($day_of_week % 7 === 0) { + $classes[] = 'end'; + } + if ($post instanceof Post) { + $classes[] = 'has-post'; + } + + return '
  • ' . $day_number . '
  • '; + } +} diff --git a/app/Post.php b/app/Post.php index 3657a13..03b790b 100644 --- a/app/Post.php +++ b/app/Post.php @@ -43,4 +43,13 @@ class Post extends Model $tag_to_delete->delete(); } } + + public static function getUserPostForMonth($user_id, $year, $month) + { + return self::whereMonth('date_post', $month) + ->whereYear('date_post', $year) + ->where('user_id', $user_id) + ->orderBy('date_post') + ->get(); + } } diff --git a/resources/sass/app.scss b/resources/sass/app.scss index 5c1925f..ab0c320 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -19,3 +19,6 @@ // Surcharge @import 'general'; + +// Calendar +@import "calendar"; diff --git a/resources/sass/calendar.scss b/resources/sass/calendar.scss new file mode 100644 index 0000000..54e7af2 --- /dev/null +++ b/resources/sass/calendar.scss @@ -0,0 +1,118 @@ +/*******************************Calendar Top Navigation*********************************/ +div#calendar { + margin:0 auto; + padding:0; + width: 602px; + font-family:special_eliteregular, "Times New Roman", Times, serif; +} + +div#calendar div.box { + position:relative; + top:0; + left:0; + width:100%; + height:40px; + background-color: #787878 ; +} + +div#calendar div.calendar-header { + line-height:40px; + vertical-align:middle; + position:absolute; + left:11px; + top:0; + width:582px; + height:40px; + text-align:center; +} + +div#calendar div.calendar-header a.prev,div#calendar div.calendar-header a.next { + position:absolute; + top:0; + height: 17px; + display:block; + cursor:pointer; + text-decoration:none; + color:#FFF; +} + +div#calendar div.calendar-header span.title{ + color:#FFF; + font-size:18px; +} + +div#calendar div.calendar-header a.prev{ + left:0; +} + +div#calendar div.calendar-header a.next{ + right:0; +} + +/*******************************Calendar Content Cells*********************************/ +div#calendar div.box-content{ + border:1px solid #787878 ; + border-top:none; +} + +div#calendar ul.label{ + float:left; + padding: 0; + margin: 5px 0 0 5px; +} + +div#calendar ul.label li{ + padding:0; + margin: 0 5px 0 0; + float:left; + list-style-type:none; + width:80px; + height:40px; + line-height:40px; + vertical-align:middle; + text-align:center; + color:#000; + font-size: 15px; + background-color: transparent; +} + +div#calendar ul.dates{ + float:left; + padding: 0; + margin: 0 0 5px 5px; +} + +/** overall width = width+padding-right**/ +div#calendar ul.dates li { + padding:0; + margin: 5px 5px 0 0; + line-height:80px; + vertical-align:middle; + float:left; + list-style-type:none; + width:80px; + height:80px; + font-size:25px; + color:#000; + text-align:center; + + &.day { + background-color: #DDD; + } + + &.today { + background-color: #0d8ddc; + } + + &.has-post { + background-color: #63ad27; + } +} + +:focus{ + outline:none; +} + +div.clear{ + clear:both; +} diff --git a/resources/views/stats/calendar.blade.php b/resources/views/stats/calendar.blade.php new file mode 100644 index 0000000..47d1a76 --- /dev/null +++ b/resources/views/stats/calendar.blade.php @@ -0,0 +1,57 @@ +@extends('layouts.connected') + +@section('content') +
    + +
    +
    +
    +
    +
    + @php($previous = $month->getPrevious()) + @php($next = $month->getNext()) + + {{ $month->getDate() }} + +
    +
      +
    • Mon
    • +
    • Tue
    • +
    • Wed
    • +
    • Thu
    • +
    • Fri
    • +
    • Sat
    • +
    • Sun
    • +
    +
    + {!! $month->render() !!} +
    +
    +
    +
    +
    +
    +@endsection diff --git a/routes/web.php b/routes/web.php index c996b05..c260264 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,6 +29,7 @@ Route::group(['middleware' => ['auth']], function() { // stats Route::post('stats', 'StatsController@tag')->name('stats'); // TODO make a group for stats + Route::get('/calendar/{type}/{year?}/{month?}', 'StatsController@calendar')->name('calendar'); // gallery Route::get('/display/{post_id}/{options}/{image_name}', 'ImageController@display')->name('display_image');