Improve metric threshold
This commit is contained in:
@@ -12,10 +12,12 @@
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use AltThree\Validator\ValidatingTrait;
|
||||
use AltThree\Validator\ValidationException;
|
||||
use CachetHQ\Cachet\Models\Traits\SortableTrait;
|
||||
use CachetHQ\Cachet\Presenters\MetricPresenter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use McCool\LaravelAutoPresenter\HasPresenter;
|
||||
|
||||
class Metric extends Model implements HasPresenter
|
||||
@@ -57,6 +59,13 @@ class Metric extends Model implements HasPresenter
|
||||
*/
|
||||
const VISIBLE_HIDDEN = 2;
|
||||
|
||||
/**
|
||||
* Array of acceptable threshold minutes.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
const ACCEPTABLE_THRESHOLDS = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60];
|
||||
|
||||
/**
|
||||
* The model's attributes.
|
||||
*
|
||||
@@ -200,6 +209,26 @@ class Metric extends Model implements HasPresenter
|
||||
return $this->display_chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the model before save.
|
||||
*
|
||||
* @throws \AltThree\Validator\ValidationException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$messages = [];
|
||||
|
||||
if (60 % $this->threshold === 0) {
|
||||
$messages[] = 'Threshold must be divisible by 60.';
|
||||
}
|
||||
|
||||
if ($messages) {
|
||||
throw new ValidationException(new MessageBag($messages));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the presenter class.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user