2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2016-09-02 22:00:42 +01:00
|
|
|
use App\AlbumSources\IAlbumSource;
|
|
|
|
use App\AlbumSources\LocalFilesystemSource;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
|
|
|
class Album extends Model
|
|
|
|
{
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2016-09-02 21:27:50 +01:00
|
|
|
'name', 'description', 'url_alias'
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
];
|
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
public function fromRequest(Request $request)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
2016-09-01 17:31:16 +01:00
|
|
|
$this->name = $request->get('name');
|
|
|
|
$this->description = $request->get('description');
|
2016-09-02 21:27:50 +01:00
|
|
|
$this->generateAlias();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
return $this;
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
2016-09-02 21:27:50 +01:00
|
|
|
|
|
|
|
public function generateAlias()
|
|
|
|
{
|
|
|
|
$this->url_alias = ucfirst(preg_replace('/[^a-z0-9\-]/', '-', strtolower($this->name)));
|
|
|
|
}
|
|
|
|
|
2016-09-02 22:00:42 +01:00
|
|
|
/**
|
|
|
|
* @return IAlbumSource
|
|
|
|
*/
|
|
|
|
public function getAlbumSource()
|
2016-09-02 21:27:50 +01:00
|
|
|
{
|
2016-09-02 22:00:42 +01:00
|
|
|
// TODO allow albums to specify different storage locations - e.g. Amazon S3, SFTP/FTP, OpenStack
|
|
|
|
return new LocalFilesystemSource(dirname(__DIR__) . '/storage/app');
|
2016-09-02 21:27:50 +01:00
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|