本文整理汇总了PHP中CachetHQ\Cachet\Models\Component类的典型用法代码示例。如果您正苦于以下问题:PHP Component类的具体用法?PHP Component怎么用?PHP Component使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the report incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(ReportIncidentCommand $command)
{
if ($command->template) {
$command->message = $this->parseIncidentTemplate($command->template, $command->template_vars);
}
$data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
// Link with the component.
if ($command->component_id) {
$data['component_id'] = $command->component_id;
}
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
$data['created_at'] = $incidentDate;
$data['updated_at'] = $incidentDate;
}
// Create the incident
$incident = Incident::create($data);
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update(['status' => $command->component_status]);
}
$incident->notify = (bool) $command->notify;
event(new IncidentWasReportedEvent($incident));
return $incident;
}
示例2: handle
/**
* Handle the report incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(ReportIncidentCommand $command)
{
$data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
// Link with the component.
if ($command->component_id) {
$data['component_id'] = $command->component_id;
}
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
$data['created_at'] = $incidentDate;
$data['updated_at'] = $incidentDate;
}
// Create the incident
$incident = Incident::create($data);
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update(['status' => $command->component_status]);
}
// Notify subscribers.
if ($command->notify) {
event(new IncidentWasReportedEvent($incident));
}
return $incident;
}
示例3: showDashboard
/**
* Shows the dashboard view.
*
* @return \Illuminate\View\View
*/
public function showDashboard()
{
$components = Component::orderBy('order')->get();
$incidents = $this->getIncidents();
$subscribers = $this->getSubscribers();
return View::make('dashboard.index')->withComponents($components)->withIncidents($incidents)->withSubscribers($subscribers);
}
示例4: compose
/**
* Bind data to the view.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$view->withIncidentCount(Incident::notScheduled()->count());
$view->withIncidentTemplateCount(IncidentTemplate::count());
$view->withComponentCount(Component::all()->count());
$view->withSubscriberCount(Subscriber::isVerified()->count());
}
示例5: compose
/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$totalComponents = Component::enabled()->count();
$majorOutages = Component::enabled()->status(4)->count();
$isMajorOutage = $majorOutages / $totalComponents >= 0.5;
// Default data
$withData = ['system_status' => 'info', 'system_message' => trans_choice('cachet.service.bad', $totalComponents), 'favicon' => 'favicon-high-alert'];
if ($isMajorOutage) {
$withData = ['system_status' => 'danger', 'system_message' => trans_choice('cachet.service.major', $totalComponents), 'favicon' => 'favicon-high-alert'];
} elseif (Component::enabled()->notStatus(1)->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
$incidentCount = $incidents->count();
if ($incidentCount === 0 || $incidentCount >= 1 && (int) $incidents->first()->status === 4) {
$withData = ['system_status' => 'success', 'system_message' => trans_choice('cachet.service.good', $totalComponents), 'favicon' => 'favicon'];
}
} else {
if (Component::enabled()->whereIn('status', [2, 3])->count() > 0) {
$withData['favicon'] = 'favicon-medium-alert';
}
}
// Scheduled maintenance code.
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
// Component & Component Group lists.
$usedComponentGroups = Component::enabled()->where('group_id', '>', 0)->groupBy('group_id')->pluck('group_id');
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
$view->with($withData)->withComponentGroups($componentGroups)->withUngroupedComponents($ungroupedComponents)->withScheduledMaintenance($scheduledMaintenance);
}
示例6: putComponent
/**
* Update an existing component.
*
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return \Illuminate\Http\JsonResponse
*/
public function putComponent(Component $component)
{
try {
$component->update(Binput::except('tags'));
} catch (Exception $e) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use($component) {
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
}
return $this->item($component);
}
示例7: seedComponents
/**
* Seed the components table.
*
* @return void
*/
protected function seedComponents()
{
$defaultComponents = [['name' => 'API', 'description' => 'Used by third-parties to connect to us', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => ''], ['name' => 'Documentation', 'description' => 'Kindly powered by Readme.io', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://docs.cachethq.io'], ['name' => 'Website', 'description' => '', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://cachethq.io'], ['name' => 'Blog', 'description' => 'The Cachet Blog.', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://blog.cachethq.io']];
Component::truncate();
foreach ($defaultComponents as $component) {
Component::create($component);
}
}
示例8: handle
/**
* Handle the add component command.
*
* @param \CachetHQ\Cachet\Commands\Component\AddComponentCommand $command
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function handle(AddComponentCommand $command)
{
$componentData = array_filter(['name' => $command->name, 'description' => $command->description, 'link' => $command->link, 'status' => $command->status, 'order' => $command->order, 'group_id' => $command->group_id]);
$componentData['enabled'] = $command->enabled;
$component = Component::create($componentData);
event(new ComponentWasAddedEvent($component));
return $component;
}
示例9: run
/**
* Run the database seeding.
*
* @return void
*/
public function run()
{
Model::unguard();
$defaultComponents = [["name" => "API", "description" => "Used by third-parties to connect to us", "status" => 1, "user_id" => 1], ["name" => "Payments", "description" => "Backed by Stripe", "status" => 1, "user_id" => 1], ["name" => "Website", "status" => 1, "user_id" => 1]];
Component::truncate();
foreach ($defaultComponents as $component) {
Component::create($component);
}
}
示例10: updateComponentAction
/**
* Updates a component.
*
* @param \CachetHQ\Cachet\Models\Component $component
*
* @return \Illuminate\Http\RedirectResponse
*/
public function updateComponentAction(Component $component)
{
$_component = Binput::get('component');
$tags = array_pull($_component, 'tags');
try {
$component->update($_component);
} catch (ValidationException $e) {
return Redirect::route('dashboard.components.edit', ['id' => $component->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure')))->withErrors($e->getMessageBag());
}
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', $tags);
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use($component) {
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
return Redirect::route('dashboard.components.edit', ['id' => $component->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
}
示例11: postUpdateComponentOrder
/**
* Updates a components ordering.
*
* @return array
*/
public function postUpdateComponentOrder()
{
$componentData = Binput::get('ids');
foreach ($componentData as $order => $componentId) {
// Ordering should be 1-based, data comes in 0-based
Component::find($componentId)->update(['order' => $order + 1]);
}
return $componentData;
}
示例12: postUpdateComponentOrder
/**
* Updates a components ordering.
*
* @return array
*/
public function postUpdateComponentOrder()
{
$componentData = Binput::all();
unset($componentData['component'][0]);
// Remove random 0 index.
foreach ($componentData['component'] as $componentId => $order) {
$component = Component::find($componentId);
$component->update(['order' => $order]);
}
return $componentData;
}
示例13: showIndex
/**
* Returns the rendered Blade templates.
*
* @return \Illuminate\View\View
*/
public function showIndex()
{
$components = Component::orderBy('order')->orderBy('created_at')->get();
$allIncidents = [];
$incidentDays = Setting::get('app_incident_days') ?: 7;
foreach (range(0, $incidentDays) as $i) {
$date = Carbon::now()->subDays($i);
$incidents = Incident::whereBetween('created_at', [$date->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get();
$allIncidents[] = ['date' => $date->format('jS F Y'), 'incidents' => $incidents];
}
return View::make('index', ['components' => $components, 'allIncidents' => $allIncidents, 'pageTitle' => Setting::get('app_name'), 'aboutApp' => Markdown::render(Setting::get('app_about'))]);
}
示例14: getComponentStatus
/**
* Find the status on a component.
*
* @param string $componentId
*
* @return string
*/
protected function getComponentStatus($componentId = '')
{
if ('' == $componentId) {
return 'n/a';
}
$statuses = trans('cachet.components.status');
$component = Component::find($componentId);
if ($component instanceof Component) {
return $component->name . ': *' . $statuses[$component->status] . '*';
}
return 'n/a';
}
示例15: postUpdateComponentOrder
/**
* Updates a components ordering.
*
* @return array
*/
public function postUpdateComponentOrder()
{
$componentData = Binput::get('ids');
foreach ($componentData as $order => $componentId) {
try {
$component = Component::find($componentId);
dispatch(new UpdateComponentCommand($component, $component->name, $component->description, $component->status, $component->link, $order + 1, $component->group_id, $component->enabled));
} catch (QueryException $e) {
throw new BadRequestHttpException();
}
}
return $this->collection(Component::query()->orderBy('order')->get());
}