Cachet/app/Models/ComponentGroup.php

99 lines
2.1 KiB
PHP
Raw Normal View History

2015-01-04 20:56:10 +00:00
<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-01-04 20:56:10 +00:00
namespace CachetHQ\Cachet\Models;
use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Presenters\ComponentGroupPresenter;
2015-01-04 20:56:10 +00:00
use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter;
2015-01-04 20:56:10 +00:00
class ComponentGroup extends Model implements HasPresenter
2015-01-04 20:56:10 +00:00
{
2015-03-26 15:07:16 -06:00
use ValidatingTrait;
2015-01-04 20:56:10 +00:00
/**
* The attributes that should be casted to native types.
2015-01-04 20:56:10 +00:00
*
* @var string[]
*/
protected $casts = [
'name' => 'string',
'order' => 'int',
'collapsed' => 'bool',
2015-01-04 20:56:10 +00:00
];
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = ['name', 'order', 'collapsed'];
2015-01-04 20:56:10 +00:00
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'order' => 'int',
'collapsed' => 'bool',
];
/**
* The relations to eager load on every query.
*
* @var string[]
*/
2016-01-03 12:26:27 +00:00
protected $with = ['enabled_components', 'enabled_components_lowest'];
2015-01-04 20:56:10 +00:00
/**
* A group can have many components.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function components()
{
2015-06-16 09:46:29 +01:00
return $this->hasMany(Component::class, 'group_id', 'id');
2015-01-04 20:56:10 +00:00
}
/**
* Return all of the enabled components.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function enabled_components()
{
return $this->components()->enabled();
}
2016-01-03 12:26:27 +00:00
/**
* Return all of the enabled components ordered by status.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function enabled_components_lowest()
{
return $this->components()->enabled()->orderBy('status', 'desc');
}
/**
* Get the presenter class.
*
* @return string
*/
public function getPresenterClass()
{
return ComponentGroupPresenter::class;
}
2015-01-04 20:56:10 +00:00
}