2015-05-16 13:57:32 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-05-16 13:57:32 -05:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace CachetHQ\Cachet\Presenters;
|
|
|
|
|
2015-05-20 12:57:22 -05:00
|
|
|
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
|
2016-01-29 22:49:06 +00:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
use McCool\LaravelAutoPresenter\BasePresenter;
|
2015-05-16 13:57:32 -05:00
|
|
|
|
2016-01-29 22:49:06 +00:00
|
|
|
class MetricPresenter extends BasePresenter implements Arrayable
|
2015-05-16 13:57:32 -05:00
|
|
|
{
|
2015-05-20 12:57:22 -05:00
|
|
|
use TimestampsTrait;
|
2015-05-16 13:57:32 -05:00
|
|
|
|
2015-12-26 16:43:22 +00:00
|
|
|
/**
|
|
|
|
* Determines the metric view filter name.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-26 11:43:33 -05:00
|
|
|
public function view_name()
|
|
|
|
{
|
2015-12-26 16:43:22 +00:00
|
|
|
switch ($this->wrappedObject->default_view) {
|
2016-06-09 14:38:13 +01:00
|
|
|
case 0: return 'last_hour';
|
|
|
|
case 1: return 'today';
|
|
|
|
case 2: return 'week';
|
|
|
|
case 3: return 'month';
|
2015-12-26 16:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:50:14 +01:00
|
|
|
/**
|
|
|
|
* Determines the metric view filter name, used in the API.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function default_view_name()
|
|
|
|
{
|
|
|
|
return trans('cachet.metrics.filter.'.$this->trans_string_name());
|
|
|
|
}
|
|
|
|
|
2015-12-26 16:43:22 +00:00
|
|
|
/**
|
|
|
|
* Determines the metric translation view filter name.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-12-26 11:43:33 -05:00
|
|
|
public function trans_string_name()
|
|
|
|
{
|
2015-12-26 16:43:22 +00:00
|
|
|
switch ($this->wrappedObject->default_view) {
|
2016-06-09 14:38:13 +01:00
|
|
|
case 0: return 'last_hour';
|
|
|
|
case 1: return 'hourly';
|
|
|
|
case 2: return 'weekly';
|
|
|
|
case 3: return 'monthly';
|
2015-12-26 16:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-16 13:57:32 -05:00
|
|
|
/**
|
|
|
|
* Convert the presenter instance to an array.
|
|
|
|
*
|
2015-05-20 12:57:22 -05:00
|
|
|
* @return string[]
|
2015-05-16 13:57:32 -05:00
|
|
|
*/
|
|
|
|
public function toArray()
|
|
|
|
{
|
|
|
|
return array_merge($this->wrappedObject->toArray(), [
|
2016-04-22 15:50:14 +01:00
|
|
|
'created_at' => $this->created_at(),
|
|
|
|
'updated_at' => $this->updated_at(),
|
|
|
|
'default_view_name' => $this->default_view_name(),
|
2015-05-16 13:57:32 -05:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|