本文整理汇总了PHP中CachetHQ\Cachet\Models\Component::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Component::find方法的具体用法?PHP Component::find怎么用?PHP Component::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CachetHQ\Cachet\Models\Component
的用法示例。
在下文中一共展示了Component::find方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
$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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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';
}
示例6: handle
/**
* Handle the report incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(ReportIncidentCommand $command)
{
$incident = Incident::create(['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible, 'component' => $command->component_id]);
// 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;
}
示例7: 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());
}
示例8: handle
/**
* Handle the update incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(UpdateIncidentCommand $command)
{
$incident = $command->incident;
$incident->update($this->filterIncidentData($command));
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
$incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
}
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update(['status' => $command->component_status]);
}
event(new IncidentWasUpdatedEvent($incident));
return $incident;
}
示例9: handle
/**
* Handle the update incident command.
*
* @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
*
* @return \CachetHQ\Cachet\Models\Incident
*/
public function handle(UpdateIncidentCommand $command)
{
$incident = $command->incident;
$incident->update($this->filterIncidentData($command));
// 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'));
$incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
}
// Update the component.
if ($command->component_id) {
Component::find($command->component_id)->update(['status' => $command->component_status]);
}
// Notify subscribers.
event(new IncidentWasUpdatedEvent($incident));
return $incident;
}
示例10: createIncidentAction
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incidentData = Binput::get('incident');
$componentStatus = array_pull($incidentData, 'component_status');
if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentData['created_at'] = $incidentDate;
$incidentData['updated_at'] = $incidentDate;
} else {
unset($incidentData['created_at']);
}
try {
$incident = Incident::create($incidentData);
} catch (ValidationException $e) {
return Redirect::route('dashboard.incidents.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->withErrors($e->getMessageBag());
}
// Update the component.
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
Component::find($incidentData['component_id'])->update(['status' => $componentStatus]);
}
if (array_get($incidentData, 'notify') && subscribers_enabled()) {
event(new IncidentHasReportedEvent($incident));
}
return Redirect::route('dashboard.incidents.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
}
示例11: createIncidentAction
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incidentData = Binput::get('incident');
$componentStatus = array_pull($incidentData, 'component_status');
if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentData['created_at'] = $incidentDate;
$incidentData['updated_at'] = $incidentDate;
} else {
unset($incidentData['created_at']);
}
$incident = Incident::create($incidentData);
if (!$incident->isValid()) {
segment_track('Dashboard', ['event' => 'Created Incident', 'success' => false]);
return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->with('errors', $incident->getErrors());
}
// Update the component.
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
Component::find($incidentData['component_id'])->update(['status' => $componentStatus]);
}
segment_track('Dashboard', ['event' => 'Created Incident', 'success' => true]);
$successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success'));
$isEnabled = (bool) Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
if (array_get($incidentData, 'notify') && $subscribersEnabled) {
event(new IncidentHasReportedEvent($incident));
}
return Redirect::back()->with('success', $successMsg);
}