Cachet/app/Http/Controllers/RssController.php
2015-03-20 18:30:45 -06:00

47 lines
1.3 KiB
PHP

<?php
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Response;
use Roumen\Feed\Facades\Feed;
class RssController extends Controller
{
/**
* Generates an RSS feed of all incidents.
*
* @return \Illuminate\Http\Response
*/
public function feedAction()
{
$feed = Feed::make();
$feed->title = Setting::get('app_name');
$feed->description = trans('cachet.feed');
$feed->link = Setting::get('app_domain');
$feed->setDateFormat('datetime');
Incident::all()->map(function ($incident) use ($feed) {
if ($incident->component) {
$componentName = $incident->component->name;
} else {
$componentName = null;
}
$feed->add(
$incident->name,
Setting::get('app_name'),
Setting::get('app_domain'),
$incident->created_at,
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
$incident->message
);
});
return $feed->render('rss');
}
}