|
|
@@ -0,0 +1,63 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Knockout; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
use Carbon\Carbon; |
|
|
|
|
|
|
|
class Event { |
|
|
|
|
|
|
|
public $id; |
|
|
|
public $executedBy; |
|
|
|
public $content; |
|
|
|
public $date; |
|
|
|
|
|
|
|
private static function unwrapContent($content) |
|
|
|
{ |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public static function unwrap($event) |
|
|
|
{ |
|
|
|
$s = new self(); |
|
|
|
|
|
|
|
$payload = json_decode($event->content); |
|
|
|
|
|
|
|
$s->id = $event->id; |
|
|
|
$s->executedBy = $event->executed_by; |
|
|
|
$s->date = Carbon::parse($event->created_at)->format('d/m/Y H:i'); |
|
|
|
|
|
|
|
$s->content = array_map(function($item) { |
|
|
|
return (object) [ |
|
|
|
'text' => stripslashes($item->text ?? $item), |
|
|
|
'link' => stripcslashes($item->link ?? null) |
|
|
|
]; |
|
|
|
}, $payload->content ?? []); |
|
|
|
|
|
|
|
return $s; |
|
|
|
} |
|
|
|
|
|
|
|
private static function requestAll() |
|
|
|
{ |
|
|
|
$data = (new AbstractData)->httpGet('/events'); |
|
|
|
$json = json_decode($data); |
|
|
|
return array_map(function($event) { |
|
|
|
return self::unwrap($event); |
|
|
|
}, $json); |
|
|
|
} |
|
|
|
|
|
|
|
public static function updateAll() |
|
|
|
{ |
|
|
|
$data = self::requestAll(); |
|
|
|
Cache::put('events', $data, 3600); |
|
|
|
return $data; |
|
|
|
} |
|
|
|
|
|
|
|
public static function all() |
|
|
|
{ |
|
|
|
return Cache::get('events', function() { |
|
|
|
return self::requestAll(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |