Cachet/app/Http/Controllers/RssController.php

47 lines
1.3 KiB
PHP
Raw Normal View History

2015-01-02 14:27:51 +00:00
<?php
namespace CachetHQ\Cachet\Http\Controllers;
2015-01-14 17:19:41 -06:00
use CachetHQ\Cachet\Facades\Setting;
2015-01-02 14:27:51 +00:00
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Response;
use Roumen\Feed\Facades\Feed;
2015-03-20 18:30:45 -06:00
class RssController extends Controller
2015-01-02 14:27:51 +00:00
{
/**
2015-03-20 18:30:45 -06:00
* Generates an RSS feed of all incidents.
2015-01-02 14:27:51 +00:00
*
* @return \Illuminate\Http\Response
*/
public function feedAction()
{
$feed = Feed::make();
$feed->title = Setting::get('app_name');
$feed->description = trans('cachet.feed');
2015-01-02 14:27:51 +00:00
$feed->link = Setting::get('app_domain');
$feed->setDateFormat('datetime');
2015-03-20 18:30:45 -06:00
Incident::all()->map(function ($incident) use ($feed) {
2015-01-02 14:27:51 +00:00
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,
2015-01-04 12:24:11 +00:00
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
2015-01-02 14:27:51 +00:00
$incident->message
);
});
2015-03-20 18:30:45 -06:00
return $feed->render('rss');
2015-01-02 14:27:51 +00:00
}
}