Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
evsmash/files / libs / Attachment.php
Size: Mime:
<?php

namespace Evsmash\Files;

use Evsmash\Core\Database\Eloquent;

use Evsmash\Core\Database\SoftDeleting;
use Evsmash\Core\Dec\Dec;
use Evsmash\Core\Dec\Image;
use Evsmash\Core\Dec\Thumb;
use Evsmash\Core\Helpers\Str;
use Evsmash\Core\Input\Route;
use Evsmash\Core\Simpy\Params;

use Evsmash\Files\Schemas\Attachments as Schema;

class Attachment extends Eloquent {

	use SoftDeleting;

	// validate
	static public function validate() {

		return Schema::validate();

	}

	// belongs to group
	public function group() { 
		
		return $this->belongsToGroup('Evsmash\Files\Attachments');
	
	}

	// params
	public function scopeParams($query, $params = false) {

		$scope = new Params();
		$scope->scope($query, $params);
		$scope->where('ext');
		if(Route::get('type') !== 'file') {
			$scope->where('type');
		}
		$scope->search(['name', 'description']);
		$scope->order(['sort' => 'asc']);
		return $scope->query;

	}

	// extensions
	static public function extensions() {

		return Attachment::where('ext', '!=', '')->orderBy('ext', 'asc')->groupBy('ext')->pluck('ext', 'ext');

	}

	// link
	static public function link($file) {

		if($file->type == 'image') {
			return str_replace('<a', '<a data-lightbox="roadtrip"', Dec::a(Thumb::fly($file->file, '1000xauto'), Thumb::show($file->file, 'autox30')->style('max-width: 70px;'), false));
		}
		return Dec::a(cfg('protocol').cfg('domain').Route::map('evsmash/files/attachments/show').'/'.$file->id.'/'.Str::slug($file->name), Attachment::icon($file), false)->blank();

	}

	// icon
	static public function icon($file, $size = '25') {

		// thumbs
		if($file->type == 'video') { return Dec::i('file-video-o', false,  $size); }
		if($file->type == 'audio') { return Dec::i('file-audio-o', false,  $size); }
		if($file->type == 'archive') { return Dec::i('file-archive-o', false,  $size); }
		if($file->ext == 'pdf') { return Dec::i('file-pdf-o', false,  $size); }
		return Dec::i('file-o', false,  $size);

	}

}