11 changed files with 235 additions and 7 deletions
@ -0,0 +1,99 @@
|
||||
<?php |
||||
|
||||
namespace App; |
||||
|
||||
use function GuzzleHttp\json_decode; |
||||
use Shikiryu\LBCReposter\Categories; |
||||
|
||||
class Deal |
||||
{ |
||||
/** @var Folder */ |
||||
protected $folder; |
||||
/** @var array */ |
||||
protected $data; |
||||
/** @var string[] */ |
||||
protected $images = []; |
||||
/** @var int */ |
||||
protected $id; |
||||
|
||||
/** |
||||
* Deal constructor. |
||||
* @param $folder |
||||
* @param int $id |
||||
*/ |
||||
public function __construct($folder, $id) |
||||
{ |
||||
$this->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']]; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,11 @@
|
||||
<?php |
||||
|
||||
namespace App; |
||||
|
||||
|
||||
class Folder |
||||
{ |
||||
const FOLDER_NEW = 'new'; |
||||
const FOLDER_BACKUP = 'backup'; |
||||
const FOLDER_CURRENT = 'list'; |
||||
} |
@ -0,0 +1,47 @@
|
||||
@extends('layouts.app') |
||||
|
||||
@section('content') |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<div class="col-md-8 col-md-offset-2"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-heading">Dashboard</div> |
||||
|
||||
<div class="panel-body"> |
||||
@if (session('status')) |
||||
<div class="alert alert-success"> |
||||
{{ session('status') }} |
||||
</div> |
||||
@endif |
||||
|
||||
<table class="table"> |
||||
<thead> |
||||
<tr> |
||||
<th>Image</th> |
||||
<th>Titre</th> |
||||
<th>Date</th> |
||||
<th>Options</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody>@foreach($deals as $deal) |
||||
<tr> |
||||
<td> |
||||
|
||||
</td> |
||||
<td> |
||||
{{$deal->getSubject()}} |
||||
</td> |
||||
<td> |
||||
{{$deal->getDateCreation()->format('d/m/Y')}} |
||||
</td> |
||||
<td> |
||||
<a href="<?php echo route('deals.view', ['type' => $type, 'id' => $deal->getId()]); ?>">Voir</a>
|
||||
</td> |
||||
</tr> |
||||
@endforeach</tbody> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
@endsection |
@ -0,0 +1,30 @@
|
||||
@extends('layouts.app') |
||||
|
||||
@section('content') |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<div class="col-md-8 col-md-offset-2"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-heading">Dashboard</div> |
||||
|
||||
<div class="panel-body"> |
||||
@if (session('status')) |
||||
<div class="alert alert-success"> |
||||
{{ session('status') }} |
||||
</div> |
||||
@endif |
||||
|
||||
<h1>{{ $deal->getSubject() }}</h1> |
||||
<h2>{{ $deal->getCategory() }}</h2> |
||||
<p>id : <strong>{{ $deal->getId() }}</strong> − proposée le <strong>{{$deal->getDateCreation()->format('d/m/Y')}}</strong> à <strong>{{ $deal->getPrice() }} €</strong></p> |
||||
<p>{{ $deal->getBody() }}</p> |
||||
<ul>@foreach($deal->getImages() as $image) |
||||
<li><img src="{{ $image }}"/></li> |
||||
@endforeach</ul> |
||||
</div> |
||||
<div class="panel-footer"><a href="<?php echo route('deals.list', ['type' => $type]); ?>">Revenir à la liste</a></div>
|
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
@endsection |
Loading…
Reference in new issue