Files
cachet-docker/app/Presenters/ComponentPresenter.php
Laravel Shift 2d2c1d4df3 Adopt PSR-2 coding style
The Laravel framework adopts the PSR-2 coding style in version 5.1.
Laravel apps *should* adopt this coding style as well. Read the
[PSR-2 coding style guide][1] for more details and check out [PHPCS][2]
to use as a code formatting tool.

[1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[2]: https://github.com/squizlabs/PHP_CodeSniffer
2016-10-19 07:53:09 +00:00

88 lines
2.1 KiB
PHP

<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Dates\DateFactory;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Config;
use McCool\LaravelAutoPresenter\BasePresenter;
class ComponentPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;
/**
* Returns the override class name for theming.
*
* @return string
*/
public function status_color()
{
switch ($this->wrappedObject->status) {
case 1:
return 'greens';
case 2:
return 'blues';
case 3:
return 'yellows';
case 4:
return 'reds';
}
}
/**
* Looks up the human readable version of the status.
*
* @return string
*/
public function human_status()
{
return trans('cachet.components.status.'.$this->wrappedObject->status);
}
/**
* Find all tag names for the component names.
*
* @return array
*/
public function tags()
{
return $this->wrappedObject->tags->pluck('name', 'slug');
}
/**
* Present formatted date time.
*
* @return string
*/
public function updated_at_formatted()
{
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->updated_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
}
/**
* Convert the presenter instance to an array.
*
* @return string[]
*/
public function toArray()
{
return array_merge($this->wrappedObject->toArray(), [
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
'status_name' => $this->human_status(),
'tags' => $this->tags(),
]);
}
}