Skip to content

Commit

Permalink
Merge pull request #39 from pbbg/develop
Browse files Browse the repository at this point in the history
v1.0.1 bug fixes
  • Loading branch information
1e4 authored Oct 11, 2019
2 parents 8f123aa + 36225d3 commit cb57dbd
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 147 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Topsite Application

[![Build Status](https://travis-ci.org/1e4/topsite.svg?branch=develop)](https://travis-ci.org/1e4/topsite) [![Maintainability](https://api.codeclimate.com/v1/badges/84627b35523d6894e261/maintainability)](https://codeclimate.com/github/1e4/topsite/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/84627b35523d6894e261/test_coverage)](https://codeclimate.com/github/1e4/topsite/test_coverage)
[![Build Status](https://travis-ci.org/1e4/topsite.svg?branch=develop)](https://travis-ci.org/1e4/topsite) [![Maintainability](https://api.codeclimate.com/v1/badges/8be22f945708dda410b6/maintainability)](https://codeclimate.com/github/pbbg/topsite/maintainability)[![Test Coverage](https://api.codeclimate.com/v1/badges/8be22f945708dda410b6/test_coverage)](https://codeclimate.com/github/pbbg/topsite/test_coverage)

There are many different topsite applications out there, but none that are open source that have a range of features, we aim to address this, so whether it's a PBBG topsite, Minecraft topsite or any other topsite we aim to be to go solution

Expand Down
6 changes: 6 additions & 0 deletions app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Category extends Model

protected $fillable = ['name'];


public function scopeFindBySlug($query, $slug): Category
{
return $query->whereSlug($slug)->firstOrFail();
}

public function sluggable(): array
{
return [
Expand Down
18 changes: 12 additions & 6 deletions app/Http/Controllers/Administration/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function datatables(): JsonResponse
public function create(): View
{
$categories = [];
$categories[] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name')->toArray());
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('administration.game.create', compact('categories'));
}
Expand All @@ -68,11 +68,14 @@ public function create(): View
*/
public function store(CreateGameRequest $request): RedirectResponse
{
$category = Category::findBySlug($request->input('category_id'));

$game = new Game();
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->fill($request->all('name', 'url', 'description', 'callback_url'));
$game->is_pending = $request->has('is_pending') ? false : true;
$game->is_premium = $request->has('is_premium');
$game->uuid = \Str::uuid();
$game->category_id = $category->id;
$game->save();

flash('Game has been created')->success();
Expand Down Expand Up @@ -101,8 +104,8 @@ public function show(Game $game): View
public function edit(Game $game): View
{
$categories = [];
$categories[] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name')->toArray());
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('administration.game.edit', compact('game', 'categories'));
}
Expand All @@ -116,8 +119,11 @@ public function edit(Game $game): View
*/
public function update(CreateGameRequest $request, Game $game): RedirectResponse
{
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$category = Category::findBySlug($request->input('category_id'));

$game->fill($request->all('name', 'url', 'description', 'callback_url'));
$game->is_premium = $request->has('is_premium');
$game->category_id = $category->id;
$game->slug = null;
$game->save();

Expand Down
45 changes: 25 additions & 20 deletions app/Http/Controllers/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@

class GameController extends Controller
{
public function index(): View {
public function index(): View
{

$games = Game::where('created_by', auth()->user()->id)
->get();

return view('games.index', compact('games'));
}

public function create(): View {
public function create(): View
{
$categories = [];
$categories[] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name')->toArray());
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

return view('games.create', compact('categories'));
}
Expand All @@ -37,14 +39,16 @@ public function show($slug): RedirectResponse
public function store(CreateGameRequest $request): RedirectResponse
{

$category = Category::findBySlug($request->input('category_id'));

$game = new Game();
$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->is_pending = true;
$game->is_premium = false;
$game->category_id = $category->id;
$game->uuid = \Str::uuid();

if($request->has('banner_image'))
{
if ($request->has('banner_image')) {
$banner = $request->file('banner_image');
$imageName = md5($banner->getClientOriginalName() . time()) . '.' . $banner->getClientOriginalExtension();
$banner->move(public_path('images/uploads'), $imageName);
Expand All @@ -54,9 +58,8 @@ public function store(CreateGameRequest $request): RedirectResponse

$game->save();

if($request->has('images'))
{
ImageUpload::whereIn('filename', $request->input('images'))->each(function($image) use($game) {
if ($request->has('images')) {
ImageUpload::whereIn('filename', $request->input('images'))->each(function ($image) use ($game) {
$image->game_id = $game->id;
$image->save();
});
Expand All @@ -68,17 +71,18 @@ public function store(CreateGameRequest $request): RedirectResponse
->route('front.game.index');
}

public function edit(Game $game): View {
public function edit(Game $game): View
{

$categories = [];
$categories[] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name')->toArray());
$categories["none__"] = "-- Select Category --";
$categories = array_merge($categories, Category::all()->pluck('name', 'slug')->toArray());

$images = ImageUpload::where('game_id', $game->id)->get();

$imageCache = [];

foreach($images as $image)
{
foreach ($images as $image) {
$img['name'] = $image->filename; //get the filename in array
$img['size'] = filesize(public_path('images/uploads/' . $image->filename)); //get the flesize in array
$imageCache[] = $img; // copy it to another array
Expand All @@ -91,14 +95,16 @@ public function edit(Game $game): View {

public function update(CreateGameRequest $request, Game $game): RedirectResponse
{
$category = Category::findBySlug($request->input('category_id'));

$game->fill($request->all('name', 'url', 'description', 'category_id', 'callback_url'));
$game->is_pending = true;
$game->is_premium = false;
$game->slug = null;
$game->category_id = $category->id;

if($request->has('banner_image'))
{
if($game->banner_image !== null) {
if ($request->has('banner_image')) {
if ($game->banner_image !== null) {
// Remove old banner image
$path = public_path() . '/images/uploads/' . $game->banner_image;

Expand All @@ -116,9 +122,8 @@ public function update(CreateGameRequest $request, Game $game): RedirectResponse

$game->save();

if($request->has('images'))
{
ImageUpload::whereIn('filename', $request->input('images'))->each(function($image) use($game) {
if ($request->has('images')) {
ImageUpload::whereIn('filename', $request->input('images'))->each(function ($image) use ($game) {
$image->game_id = $game->id;
$image->save();
});
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/CreateGameRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function rules()
],
'category_id' => [
'required',
'exists:categories,id'
'exists:categories,slug'
],
'callback_url' => [
'nullable',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/VoteIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
// 'g-recaptcha-response' => 'required|captcha'
'g-recaptcha-response' => 'required|captcha'
];
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"php": "^7.2",
"anhskohbo/no-captcha": "^3.1",
"ccaglayan/discord-webhooks-php": "^0.1.0",
"clarification/sparkpost-laravel-driver": "^1.2",
"cviebrock/eloquent-sluggable": "^6.0",
"fideloper/proxy": "^4.0",
"laracasts/flash": "^3.0",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"netojose/laravel-bootstrap-4-forms": "^2.0",
"netojose/laravel-bootstrap-4-forms": "^3.0",
"yajra/laravel-datatables-oracle": "~9.0"
},
"require-dev": {
Expand Down
Loading

0 comments on commit cb57dbd

Please sign in to comment.