black list entity stuff

This commit is contained in:
2019-12-28 23:19:30 -06:00
parent 38947493a1
commit eaa7281374
5 changed files with 82 additions and 32 deletions

View File

@@ -12,7 +12,7 @@ use DB;
use App\Library\Lookups\LookupHelper;
//Models
use App\Models\Blacklist\BlacklistUser;
use App\Models\Blacklist\BlacklistEntity;
use App\Models\User\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
@@ -43,43 +43,80 @@ class BlacklistController extends Controller
//Validate the user input
$this->validate($request, [
'name' => 'required',
'type' => 'required',
'reason' => 'required',
]);
//Create the library variable
$lookup = new LookupHelper;
//Declare other necessary variables
$charId = null;
$corporationId = null;
$allianceId = null;
$entityId = null;
$entityType = null;
//See if the character is already on the list
$count = BlacklistUser::where([
//See if the entity is already on the list
$count = BlacklistEntity::where([
'name' => $request->name,
])->count();
//If the count is 0, then add the character to the blacklist
if($count === 0) {
if($request->type == 'Character') {
//Get the character id from the universe end point
$charId = $lookup->CharacterNameToId($request->name);
} else if($request->entity_type == 'corporation') {
//Get the corporation id from the universe end point
$corpId = $lookup->CorporationNameToId($request->name);
} else if($request->entity_type == 'alliance') {
//Get the alliance id from the universe end point
$allianceId = $lookup->AllianceNameToId($request->name);
} else {
//Redirect back to the view
return redirect('/blacklist/display/add')->with('error', 'Entity Type not allowed.');
}
//If all id's are null, then we couldn't find the entity
if($charId == null && $corporationId == null && $allianceId == null) {
//Redirect back to the view
return redirect('/blacklist/display/add')->with('error', 'Entity Id was not found.');
}
//Construct the entityId
if($charId != null) {
//Insert the character into the blacklist table
BlacklistUser::insert([
'character_id' => $charId,
'name' => $request->name,
$entityId = $charId;
} else if($corporationId != null) {
$entityId = $corporationId;
} else if($allianceId != null) {
$entityId = $allianceId;
} else {
$entityId = null;
}
//Construct the entity type
$entityType = $request->type;
//Store the entity in the table
BlacklistEntity::insert([
'entity_id' => $entityId,
'entity_name' => $request->name,
'entity_type' => $entityType,
'reason' => $request->reason,
'alts' => $request->alts,
'lister_id' => auth()->user()->getId(),
'lister_name' => auth()->user()->getName(),
]);
} else {
//Redirect back to the view
return redirect('/blacklist/display/add')->with('error', $request->name . ' could not be added.');
}
//Return to the view
return redirect('/blacklist/display/add')->with('success', $request->name . ' added to the blacklist.');
} else {
//Return the view
return view('blacklist.add')->with('error', 'Character is already on the black list.');
return view('blacklist.add')->with('error', 'Entity of type '. $request->entity_type . ' is already on the black list.');
}
//Return the view
return redirect('/blacklist/display/add')->with('success', $request->name . ' added to the blacklist.');
//If we get back to this point redirect to the blacklist with a general error.
return redirect('/blacklist/display/add')->with('error', 'General Error. Contact Support.');
}
public function RemoveFromBlacklist(Request $request) {
@@ -92,7 +129,7 @@ class BlacklistController extends Controller
]);
//Delete the blacklist character
BlacklistUser::where([
BlacklistEntity::where([
'name' => $request->name,
])->delete();
@@ -103,7 +140,7 @@ class BlacklistController extends Controller
public function DisplayBlacklist() {
//Get the entire blacklist
$blacklist = BlacklistUser::orderBy('name', 'asc')->paginate(50);
$blacklist = BlacklistEntity::orderBy('name', 'asc')->paginate(50);
//Return the view with the data
return view('blacklist.list')->with('blacklist', $blacklist);
@@ -117,6 +154,7 @@ class BlacklistController extends Controller
]);
$blacklist = DB::table('alliance_blacklist')->where('name', 'like', $request->parameter . "%")
->orWhere('entity_type', 'like', $request->parameter . "%")
->orWhere('alts', 'like', $request->parameter . "%")
->orWhere('reason', 'like', $request->parameter . "%")
->orderBy('name', 'asc')

View File

@@ -4,7 +4,7 @@ namespace App\Models\Blacklist;
use Illuminate\Database\Eloquent\Model;
class BlacklistUser extends Model
class BlacklistEntity extends Model
{
//Table Name
public $table = 'alliance_blacklist';
@@ -18,8 +18,9 @@ class BlacklistUser extends Model
* @var array
*/
protected $fillable = [
'character_id',
'name',
'entity_id',
'entity_name',
'entity_type',
'reason',
'alts',
'lister_id',

View File

@@ -16,8 +16,9 @@ class CreateBlacklistTable extends Migration
if(!Schema::hasTable('alliance_blacklist')) {
Schema::create('alliance_blacklist', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('character_id')->unique();
$table->string('name')->unique();
$table->string('entity_id')->unique();
$table->string('entity_name')->default('');
$table->string('entity_type')->default('None');
$table->text('reason');
$table->text('alts')->nullable();
$table->string('lister_id');

View File

@@ -8,9 +8,17 @@
<div class="card-body">
{!! Form::open(['action' => 'Blacklist\BlacklistController@AddToBlacklist', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('name', 'Character Name') }}
{{ Form::label('name', 'Entity Name') }}
{{ Form::text('name', '', ['class' => 'form-control', 'placeholder' => 'CCP Antiquarian']) }}
</div>
<div class="form-group">
{{ Form::label('type', 'Entity Type') }}
{{ Form::select('type', [
'Character' => 'Character',
'Corporation' => 'Corporation',
'Alliance' => 'Alliance',
], 'Character', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('reason', 'Reason') }}
{{ Form::textarea('reason', 'No reason given.', ['class' => 'form-control']) }}

View File

@@ -9,16 +9,18 @@
@if($blacklist != null)
<table class="table table-bordered table-striped">
<thead>
<th>Character Id</th>
<th>Character Name</th>
<th>Entity Id</th>
<th>Entity Name</th>
<th>Entity Type
<th>Reason</th>
<th>Alts</th>
</thead>
<tbody>
@foreach($blacklist as $bl)
<tr>
<td>{{ $bl->character_id }}</td>
<td>{{ $bl->name }}</td>
<td>{{ $bl->entity_id }}</td>
<td>{{ $bl->entity_name }}</td>
<td>{{ $bl->entity_type }}</td>
<td>{{ $bl->reason }}</td>
@if($bl->alts != null)
<td>{{ $bl->alts }}</td>