2018-09-25 13:30:50 +02:00
|
|
|
<?php namespace BookStack\Uploads;
|
|
|
|
|
|
|
|
use BookStack\Entities\Page;
|
|
|
|
use BookStack\Ownable;
|
2016-10-09 19:58:22 +02:00
|
|
|
|
2016-11-12 15:12:26 +01:00
|
|
|
class Attachment extends Ownable
|
2016-10-09 19:58:22 +02:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'order'];
|
|
|
|
|
2016-10-23 14:36:45 +02:00
|
|
|
/**
|
|
|
|
* Get the downloadable file name for this upload.
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
2018-01-28 17:58:52 +01:00
|
|
|
if (str_contains($this->name, '.')) {
|
|
|
|
return $this->name;
|
|
|
|
}
|
2016-10-23 14:36:45 +02:00
|
|
|
return $this->name . '.' . $this->extension;
|
|
|
|
}
|
|
|
|
|
2016-10-09 19:58:22 +02:00
|
|
|
/**
|
|
|
|
* Get the page this file was uploaded to.
|
2016-10-10 21:30:27 +02:00
|
|
|
* @return Page
|
2016-10-09 19:58:22 +02:00
|
|
|
*/
|
|
|
|
public function page()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Page::class, 'uploaded_to');
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:30:27 +02:00
|
|
|
/**
|
|
|
|
* Get the url of this file.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
2018-05-20 12:06:10 +02:00
|
|
|
if ($this->external && strpos($this->path, 'http') !== 0) {
|
|
|
|
return $this->path;
|
|
|
|
}
|
2016-11-12 15:12:26 +01:00
|
|
|
return baseUrl('/attachments/' . $this->id);
|
2016-10-10 21:30:27 +02:00
|
|
|
}
|
2016-10-09 19:58:22 +02:00
|
|
|
}
|