Update code to match master

This commit is contained in:
Joseph Cohen
2015-03-26 15:07:16 -06:00
parent eb22ac6d8a
commit 37e20bf2bf
15 changed files with 192 additions and 105 deletions

View File

@@ -12,9 +12,11 @@ class AtomController extends AbstractController
/**
* Generates an Atom feed of all incidents.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup|null $group
*
* @return \Illuminate\Http\Response
*/
public function feedAction()
public function feedAction(ComponentGroup $group = null)
{
$feed = Feed::make();
$feed->title = Setting::get('app_name');
@@ -23,23 +25,37 @@ class AtomController extends AbstractController
$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
);
});
if ($group) {
$group->components->map(function ($component) use ($feed) {
$component->incidents->orderBy('created_at', 'desc')->map(function ($incident) use ($feed) {
$this->feedAddItem($feed, $incident);
});
});
} else {
Incident::orderBy('created_at', 'desc')->get()->map(function ($incident) use ($feed) {
$this->feedAddItem($feed, $incident);
});
}
return $feed->render('atom');
}
/**
* Adds an item to the feed.
*
* @param \Thujohn\Rss\Rss $feed
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return void
*/
private function feedAddItem(& $feed, $incident)
{
$feed->add(
$incident->name,
Setting::get('app_name'),
Setting::get('app_domain'),
$incident->created_at->toAtomString(),
$incident->message
);
}
}