191 lines
5.1 KiB
PHP
191 lines
5.1 KiB
PHP
<?php
|
|
namespace XaiCorp\AbcParser\Models\Laravel5;
|
|
|
|
use XaiCorp\AbcParser\Traits\ValidationTrait;
|
|
|
|
class CollectionAttribute extends ValidatingModel
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'collection_attributes';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $validationRules = [
|
|
'collection_id' => 'required|exists:collections,id',
|
|
'type' => 'required|string|in:Author,Composer,Discography,Rhythm,History,File,Book,Note,Source,Transcriber',
|
|
'string' => 'required|string|max:255',
|
|
'ordering' => 'required|integer'
|
|
];
|
|
|
|
/**
|
|
* supported attribute types
|
|
* @var array
|
|
*/
|
|
public static $types = [
|
|
'Author',
|
|
'Composer',
|
|
'Discography',
|
|
'Rhythm',
|
|
'History',
|
|
'File',
|
|
'Book',
|
|
'Note',
|
|
'Origin',
|
|
'Source',
|
|
'Transcriber',
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = ['collection_id', 'type', 'string', 'ordering'];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = ['collection_id', 'type', 'ordering'];
|
|
|
|
public static function getTypes()
|
|
{
|
|
return self::$types;
|
|
}
|
|
|
|
/*****************************************************************
|
|
* Scopes
|
|
*/
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeAuthors($query, $id)
|
|
{
|
|
return $query->where('type', 'Author')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeComposers($query, $id)
|
|
{
|
|
return $query->where('type', 'Composer')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeDiscographys($query, $id)
|
|
{
|
|
return $query->where('type', 'Discography')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeFiles($query, $id)
|
|
{
|
|
return $query->where('type', 'File')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeRhythms($query, $id)
|
|
{
|
|
return $query->where('type', 'Rhythm')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeHistorys($query, $id)
|
|
{
|
|
return $query->where('type', 'History')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeBooks($query, $id)
|
|
{
|
|
return $query->where('type', 'Book')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeNotes($query, $id)
|
|
{
|
|
return $query->where('type', 'Note')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeOrigins($query, $id)
|
|
{
|
|
return $query->where('type', 'Origin')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeSources($query, $id)
|
|
{
|
|
return $query->where('type', 'Source')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param integer $id
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeTranscribers($query, $id)
|
|
{
|
|
return $query->where('type', 'Transcriber')->where('collection_id', $id);
|
|
}
|
|
|
|
/**
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param string $attr
|
|
* @param mixed $value
|
|
* @param \XaiCorp\AbcParser\Models\Laravel5\Tune|null $collection
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeAttr($query, $attr, $value, Collection $collection = null)
|
|
{
|
|
if ($collection) {
|
|
$query = $query->where('collection_id', $collection->id);
|
|
}
|
|
return $query->where('type', strtolower($attr))->where('string', $value);
|
|
}
|
|
}
|