RSM-8 Add team files page and ability to download files
This commit is contained in:
67
app/Console/Commands/MakeFile.php
Normal file
67
app/Console/Commands/MakeFile.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Faker\Factory;
|
||||
use Faker\Generator;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MakeFile extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'files:make {count : How many test files to generate}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates test files for the TeamFile model. Use in conjunction with it\'s factory.';
|
||||
|
||||
|
||||
/**
|
||||
* The faker instance used to obtain dummy text.
|
||||
*
|
||||
* @var Generator
|
||||
*/
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->faker = Factory::create();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$count = $this->argument('count');
|
||||
$this->info('Creating ' . $this->argument('count') . ' files!');
|
||||
|
||||
for ($max = 1; $max < $count; $max++)
|
||||
{
|
||||
Storage::disk('local')->put('factory_files/testfile_' . rand(0, 5000) . '.txt', $this->faker->paragraphs(40, true));
|
||||
|
||||
}
|
||||
|
||||
$this->info('Finished creating files! They will be randomly picked by the factory.');
|
||||
return 0;
|
||||
}
|
||||
}
|
111
app/Http/Controllers/TeamFileController.php
Normal file
111
app/Http/Controllers/TeamFileController.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\TeamFile;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\FileNotFoundException;
|
||||
|
||||
class TeamFileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (is_null(Auth::user()->currentTeam))
|
||||
{
|
||||
$request->session()->flash('error', 'Please choose a team before viewing it\'s files.');
|
||||
return redirect()->to(route('teams.index'));
|
||||
}
|
||||
|
||||
return view('dashboard.teams.team-files')
|
||||
->with('files', TeamFile::with('team', 'uploader')->paginate(20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function download(Request $request, TeamFile $teamFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Storage::download('uploads/' . $teamFile->name);
|
||||
}
|
||||
catch (FileNotFoundException $ex)
|
||||
{
|
||||
$request->session()->flash('error', 'Sorry, but the requested file could not be found in storage. Sometimes, files may be physically deleted by admins, but not from the app\'s database.');
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\TeamFile $teamFile
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(TeamFile $teamFile)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@@ -36,4 +36,10 @@ class Team extends TeamworkTeam
|
||||
{
|
||||
return $this->belongsToMany('App\Vacancy', 'team_has_vacancy');
|
||||
}
|
||||
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->hasMany('App\TeamFile', 'team_id');
|
||||
}
|
||||
}
|
||||
|
31
app/TeamFile.php
Normal file
31
app/TeamFile.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Mpociot\Teamwork\Traits\UsedByTeams;
|
||||
|
||||
class TeamFile extends Model
|
||||
{
|
||||
use HasFactory, UsedByTeams;
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'uploaded_by',
|
||||
'team_id',
|
||||
'name',
|
||||
'fs_location',
|
||||
'extension'
|
||||
];
|
||||
|
||||
public function uploader()
|
||||
{
|
||||
return $this->belongsTo('App\User', 'uploaded_by', 'id');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo('App\Team');
|
||||
}
|
||||
}
|
10
app/User.php
10
app/User.php
@@ -60,7 +60,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
//
|
||||
// RELATIONSHIPS
|
||||
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasMany('App\Application', 'applicantUserID', 'id');
|
||||
@@ -86,6 +87,13 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->hasMany('App\Comment', 'authorID', 'id');
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->hasMany('App\TeamFile', 'uploaded_by');
|
||||
}
|
||||
|
||||
// UTILITY LOGIC
|
||||
|
||||
public function isBanned()
|
||||
{
|
||||
return ! $this->bans()->get()->isEmpty();
|
||||
|
Reference in New Issue
Block a user