Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Custom Statuses #2643

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions app/Models/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
* This is the status class.
*
* @author James Brooks <[email protected]>
*/
class Status extends Model
{
/**
* The incidents type.
*
* @var string
*/
const TYPE_INCIDENTS = 'incidents';

/**
* The components type.
*
* @var string
*/
const TYPE_COMPONENTS = 'components';

/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'name' => 'string',
'slug' => 'string',
'color' => 'string',
'type' => 'string',
];

/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = [
'name',
'slug',
'color',
'type',
];

/**
* Scope the statuses by type.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $type
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeForType(Builder $query, $type)
{
return $query->where('type', '=', $type);
}
}
69 changes: 69 additions & 0 deletions database/migrations/2017_07_18_214740_CreateStatuses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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.
*/

use CachetHQ\Cachet\Models\Status;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;

class CreateStatuses extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('statuses', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug');
$table->char('color', 7)->nullable()->default(null);
$table->string('type');
$table->timestamps();
});

// Migrate the existing incident language files into the statuses table.
$incidentStatuses = Lang::get('cachet.incidents.status');

foreach ($incidentStatuses as $status) {
Status::create([
'name' => $status,
'slug' => Str::slug($status),
'type' => Status::TYPE_INCIDENTS,
]);
}

// Migrate the existing component language files into the statuses table.
$componentStatuses = Lang::get('cachet.components.status');

foreach ($componentStatuses as $status) {
Status::create([
'name' => $status,
'slug' => Str::slug($status),
'type' => Status::TYPE_COMPONENTS,
]);
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('statuses');
}
}
28 changes: 28 additions & 0 deletions tests/Models/StatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\Tests\Cachet\Models;

use CachetHQ\Cachet\Models\Status;
use CachetHQ\Tests\Cachet\AbstractTestCase;

/**
* This is the status model test class.
*
* @author James Brooks <[email protected]>
*/
class StatusTest extends AbstractTestCase
{
public function testValidation()
{
$this->assertFalse(property_exists(new Status(), 'rules'));
}
}