Pony.fm/app/models/Entities/Album.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2013-07-28 09:09:10 +02:00
<?php
namespace Entities;
use Cover;
use Whoops\Example\Exception;
class Album extends \Eloquent {
protected $softDelete = true;
public static function summary() {
2013-07-28 10:35:31 +02:00
return self::select('id', 'title', 'user_id', 'slug', 'created_at', 'cover_id');
2013-07-28 09:09:10 +02:00
}
protected $table = 'albums';
public function user() {
return $this->belongsTo('Entities\User');
}
public function cover() {
return $this->belongsTo('Entities\Image');
}
public function hasCover() {
return $this->cover_id != null;
}
public function getCoverUrl($type = Image::NORMAL) {
if (!$this->hasCover())
return $this->user->getAvatarUrl($type);
return $this->cover->getUrl($type);
}
public function getDirectory() {
$dir = (string) ( floor( $this->id / 100 ) * 100 );
return \Config::get('app.files_directory') . '/tracks/' . $dir;
}
public function getDates() {
return ['created_at', 'deleted_at', 'published_at'];
}
public function getFilenameFor($format) {
if (!isset(Track::$Formats[$format]))
throw new Exception("$format is not a valid format!");
$format = Track::$Formats[$format];
return "{$this->id}.{$format['extension']}.zip";
}
}