2014-12-30 13:57:38 +00:00
|
|
|
<?php
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Component;
|
2015-01-01 16:18:24 +00:00
|
|
|
use Exception;
|
2015-01-02 12:05:50 +00:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Illuminate\Routing\Controller;
|
|
|
|
|
2014-12-30 13:57:38 +00:00
|
|
|
class DashAPIController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Updates a component with the entered info.
|
2014-12-30 18:19:22 +00:00
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @param \CachetHQ\Cachet\Models\Component $component
|
2014-12-30 18:19:22 +00:00
|
|
|
*
|
2015-01-01 15:45:04 +00:00
|
|
|
* @throws \Exception
|
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @return \CachetHQ\Cachet\Models\Component
|
2014-12-30 13:57:38 +00:00
|
|
|
*/
|
|
|
|
public function postUpdateComponent(Component $component)
|
|
|
|
{
|
2015-01-02 12:05:50 +00:00
|
|
|
if (!$component->update(Binput::except(['_token']))) {
|
2015-01-13 11:55:26 +00:00
|
|
|
throw new Exception(trans('dashboard.components.edit.failure'));
|
2014-12-30 13:57:38 +00:00
|
|
|
}
|
2015-01-01 15:45:04 +00:00
|
|
|
|
|
|
|
return $component;
|
2014-12-30 13:57:38 +00:00
|
|
|
}
|
2015-01-01 13:37:47 +00:00
|
|
|
|
2015-01-01 13:40:02 +00:00
|
|
|
/**
|
|
|
|
* Updates a components ordering.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-01-01 13:37:47 +00:00
|
|
|
public function postUpdateComponentOrder()
|
|
|
|
{
|
2015-01-02 12:05:50 +00:00
|
|
|
$componentData = Binput::all();
|
2015-01-01 13:37:47 +00:00
|
|
|
unset($componentData['component'][0]); // Remove random 0 index.
|
|
|
|
|
|
|
|
foreach ($componentData['component'] as $componentId => $order) {
|
|
|
|
$component = Component::find($componentId);
|
2015-01-01 15:45:04 +00:00
|
|
|
$component->update(['order' => $order]);
|
2015-01-01 13:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $componentData;
|
|
|
|
}
|
2014-12-30 13:57:38 +00:00
|
|
|
}
|