122 lines
2.4 KiB
PHP
122 lines
2.4 KiB
PHP
<?php
|
|
namespace XaiCorp\AbcParser\Models\Laravel5;
|
|
|
|
use Illuminate\Database\Eloquent\Model as BaseModel;
|
|
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
|
|
|
class Tune extends ValidatingModel
|
|
{
|
|
use AttributesTrait;
|
|
|
|
/**
|
|
* for AttributesTrait
|
|
* @var string
|
|
*/
|
|
protected $attributesClass = TuneAttribute::class;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'tunes';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $validationRules = [
|
|
'x_id' => 'integer|min:1',
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = ['x_id', 'X', 'T'];
|
|
|
|
protected $hidden = ['x_id', 'Title', 'Group', 'Origin', 'Rhythm', 'History'];
|
|
|
|
protected $appends = ['T', 'G', 'O', 'R', 'H'];
|
|
|
|
|
|
/**************************************************************
|
|
* mutators and accessors
|
|
*/
|
|
|
|
protected $Title;
|
|
public function getTAttribute()
|
|
{
|
|
return $this->getAttr('Title');
|
|
}
|
|
|
|
public function setTAttribute(array $values)
|
|
{
|
|
$this->setAttr('Title', $values);
|
|
}
|
|
|
|
protected $Group;
|
|
public function getGAttribute()
|
|
{
|
|
return $this->getAttr('Group');
|
|
}
|
|
public function setGAttribute(array $values)
|
|
{
|
|
$this->setAttr('Group', $values);
|
|
}
|
|
|
|
public function getOAttribute()
|
|
{
|
|
return $this->getAttr('Origin');
|
|
}
|
|
|
|
protected $Origin;
|
|
public function setOAttribute(array $values)
|
|
{
|
|
$this->setAttr('Origin', $values);
|
|
}
|
|
|
|
protected $Rhythm;
|
|
public function getRAttribute()
|
|
{
|
|
return $this->getAttr('Rhythm');
|
|
}
|
|
|
|
public function setRAttribute(array $values)
|
|
{
|
|
$this->setAttr('Rhythm', $values);
|
|
}
|
|
|
|
protected $History;
|
|
public function getHAttribute()
|
|
{
|
|
return $this->getAttr('History');
|
|
}
|
|
|
|
public function setHAttribute(array $values)
|
|
{
|
|
$this->setAttr('History', $values);
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
$arr = parent::toArray();
|
|
|
|
foreach (['A','C'] as $attr) {
|
|
if (isset($arr[$attr])) {
|
|
foreach ($arr[$attr] as $key => $person) {
|
|
$arr[$attr][$key] = $person->name;
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($arr as $key => $val) {
|
|
if (empty($val)) {
|
|
unset($arr[$key]);
|
|
}
|
|
}
|
|
|
|
return $arr;
|
|
}
|
|
}
|