diff --git a/app/Deal.php b/app/Deal.php new file mode 100644 index 0000000..fb1f0ab --- /dev/null +++ b/app/Deal.php @@ -0,0 +1,99 @@ +folder = $folder; + $this->id = $id; + foreach (new \DirectoryIterator(sprintf('%s/%s/%s', config('app.deals_dire'), $folder, $id)) as $file) { + if ($file->getExtension() === 'json') { + $content = file_get_contents($file->getPathname()); + $this->data = json_decode($content, true); + } elseif ($file->getExtension() === 'jpg') { + $data = file_get_contents($file->getPathname()); + $base64 = 'data:image/jpg;base64,' . base64_encode($data); + $this->images[] = $base64; + } + } + + } + + public function getDateCreation(): \DateTime + { + $date_creation = \DateTime::createFromFormat('Y-m-d H:i:s.u', $this->data['datecreation']['date']); + return $date_creation; + } + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @return \string[] + */ + public function getImages(): array + { + return $this->images; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getSubject(): string + { + return $this->data['subject']; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->data['body']; + } + + /** + * @return float + */ + public function getPrice(): float + { + return $this->data['price']; + } + + public function getCategory(): string + { + return Categories::$categories[$this->data['category']]; + } + +} \ No newline at end of file diff --git a/app/Folder.php b/app/Folder.php new file mode 100644 index 0000000..d3374c4 --- /dev/null +++ b/app/Folder.php @@ -0,0 +1,11 @@ +getPathname().'/data.json')) { + $deals[] = new Deal($folder_path, $folder->getBasename()); + } + } + } + return view('list', ['deals' => $deals, 'type' => $type]); + } + + public function view($type, $id) + { + $folder_path = sprintf('%s/%s/%s', config('app.deals_dir'), $type, $id); + if (file_exists($folder_path)) { + $deal = new Deal(sprintf('%s/%s', config('app.deals_dir'), $type), $id); + } + return view('view', ['deal' => $deal, 'type' => $type]); + } } diff --git a/config/app.php b/config/app.php index edb6f10..cbbdc78 100755 --- a/config/app.php +++ b/config/app.php @@ -15,6 +15,8 @@ return [ 'name' => env('APP_NAME', 'Laravel'), + 'deals_dir' => env('DEALS_DIR', storage_path('deals')), + /* |-------------------------------------------------------------------------- | Application Environment diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index d8437bf..b9cacf2 100755 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -15,6 +15,17 @@ @endif You are logged in! + + diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php new file mode 100755 index 0000000..c865a01 --- /dev/null +++ b/resources/views/list.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Dashboard
+ +
+ @if (session('status')) +
+ {{ session('status') }} +
+ @endif + + + + + + + + + + + @foreach($deals as $deal) + + + + + + + @endforeach + + + + + +@endsection diff --git a/resources/views/view.blade.php b/resources/views/view.blade.php new file mode 100755 index 0000000..7243741 --- /dev/null +++ b/resources/views/view.blade.php @@ -0,0 +1,30 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+
Dashboard
+ +
+ @if (session('status')) +
+ {{ session('status') }} +
+ @endif + +

{{ $deal->getSubject() }}

+

{{ $deal->getCategory() }}

+

id : {{ $deal->getId() }} − proposée le {{$deal->getDateCreation()->format('d/m/Y')}} à {{ $deal->getPrice() }} €

+

{{ $deal->getBody() }}

+
    @foreach($deal->getImages() as $image) +
  • + @endforeach
+
+ +
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index ea97194..608980c 100755 --- a/routes/web.php +++ b/routes/web.php @@ -11,14 +11,12 @@ | */ -Route::get('/', function () { - return view('welcome'); -}); +Route::redirect('/', 'home'); Auth::routes(); -Route::get('/home', 'HomeController@index')->name('home'); +Route::redirect('/', 'deals.list'); -Auth::routes(); +Route::get('/deals/list/{type}', 'HomeController@list')->name('deals.list'); -Route::get('/home', 'HomeController@index')->name('home'); +Route::get('/deals/view/{type}/{id}', 'HomeController@view')->name('deals.view'); \ No newline at end of file diff --git a/storage/deals/backup/.gitignore b/storage/deals/backup/.gitignore new file mode 100755 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/deals/backup/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/deals/list/.gitignore b/storage/deals/list/.gitignore new file mode 100755 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/deals/list/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/storage/deals/new/.gitignore b/storage/deals/new/.gitignore new file mode 100755 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/deals/new/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore
ImageTitreDateOptions
+ + + {{$deal->getSubject()}} + + {{$deal->getDateCreation()->format('d/m/Y')}} + + Voir +