Restyled by php-cs-fixer
This commit is contained in:
parent
ba9fa0f12a
commit
711ac93cb9
17 changed files with 74 additions and 47 deletions
|
@ -8,7 +8,8 @@
|
|||
|
||||
class AdminBookmarksController extends Controller
|
||||
{
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
$categories = BookmarkCategory::with('sites')->get();
|
||||
return view('admin.bookmarks', compact('categories'));
|
||||
}
|
||||
|
|
|
@ -9,16 +9,19 @@
|
|||
|
||||
class AdminGuestbookController extends Controller
|
||||
{
|
||||
function getGuestbookUniqueAddr(): int {
|
||||
public function getGuestbookUniqueAddr(): int
|
||||
{
|
||||
$uniqueIpsCount = DB::table('guestbook__entries')->distinct()->count('ip');
|
||||
return $uniqueIpsCount;
|
||||
}
|
||||
|
||||
function getGuestbookEntriesCount(): int {
|
||||
public function getGuestbookEntriesCount(): int
|
||||
{
|
||||
$entryCount = DB::table('guestbook__entries')->count();
|
||||
return $entryCount;
|
||||
}
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
$guestbook_unique_addr = $this->getGuestbookUniqueAddr();
|
||||
$guestbook_entry_count = $this->getGuestbookEntriesCount();
|
||||
$entries = GuestbookEntry::selectEntries();
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
|
||||
class AdminImportController extends Controller
|
||||
{
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
return view('admin.import');
|
||||
}
|
||||
|
||||
|
@ -26,7 +27,9 @@ public function submit(Request $request)
|
|||
$data = json_decode($jsonContent, true);
|
||||
$tables = [];
|
||||
foreach($data as $item) {
|
||||
if ($item['type'] !== "table") continue;
|
||||
if ($item['type'] !== "table") {
|
||||
continue;
|
||||
}
|
||||
$tables[$item['name']] = [
|
||||
'data' => $item['data'],
|
||||
'count' => count($item['data'])
|
||||
|
@ -48,7 +51,8 @@ public function submit(Request $request)
|
|||
* @return void
|
||||
* @throws Exception Invalid table specified, to be replaced with custom exception
|
||||
*/
|
||||
public function import(array $data, string $table_name): void {
|
||||
public function import(array $data, string $table_name): void
|
||||
{
|
||||
switch ($table_name) {
|
||||
case 'guestbook__entries':
|
||||
GuestbookEntry::importGuestbookEntry($data);
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
class BookmarksController extends Controller
|
||||
{
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
$categories = BookmarkCategory::with('sites')->get();
|
||||
return view('bookmarks', compact('categories'));
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
class CalculatorsController extends Controller
|
||||
{
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
return view('calculators');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
class ComputersController extends Controller
|
||||
{
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
return view('computers');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
use Illuminate\Validation\ValidationException;
|
||||
use UAParser\Parser;
|
||||
|
||||
class GuestbookController extends Controller {
|
||||
public function show(): View {
|
||||
class GuestbookController extends Controller
|
||||
{
|
||||
public function show(): View
|
||||
{
|
||||
$entries = GuestbookEntry::selectEntries();
|
||||
$parser = Parser::create();
|
||||
|
||||
|
@ -26,7 +28,8 @@ public function show(): View {
|
|||
* @return RedirectResponse
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function addEntry(Request $request): RedirectResponse {
|
||||
public function addEntry(Request $request): RedirectResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'name' => 'required',
|
||||
'message' => 'required'
|
||||
|
@ -37,7 +40,8 @@ public function addEntry(Request $request): RedirectResponse {
|
|||
return back()->with('success', 'Entry submitted successfully!');
|
||||
}
|
||||
|
||||
public function banIP(string $addr) {
|
||||
public function banIP(string $addr)
|
||||
{
|
||||
// TODO: Add banning system
|
||||
// $matching_bans = DB::select('SELECT reason FROM guestbook__bans WHERE ip_address = ?', array($request->ip()));
|
||||
// if (!empty($matching_bans)) {
|
||||
|
|
|
@ -11,7 +11,7 @@ class HomeController extends Controller
|
|||
* Returns age based on birthday date and current date (GMT)
|
||||
* @return int
|
||||
*/
|
||||
function returnAge(): int
|
||||
public function returnAge(): int
|
||||
{
|
||||
date_default_timezone_set('Europe/London');
|
||||
$birthday = new DateTime("2005-06-07");
|
||||
|
@ -24,7 +24,8 @@ function returnAge(): int
|
|||
* Shows home page
|
||||
* @return View
|
||||
*/
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
return view('home', [
|
||||
'age' => $this->returnAge()
|
||||
]);
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
|
||||
class MusicController extends Controller
|
||||
{
|
||||
public function getCurrentTrack() {
|
||||
public function getCurrentTrack()
|
||||
{
|
||||
// If it's already cached just return that
|
||||
if (Cache::has('current_track')) {
|
||||
return Cache::get('current_track');
|
||||
|
@ -34,7 +35,8 @@ public function getCurrentTrack() {
|
|||
return $current_track;
|
||||
}
|
||||
|
||||
public function getTopTracks() {
|
||||
public function getTopTracks()
|
||||
{
|
||||
// If it's already cached just return that
|
||||
if (Cache::has('top_tracks')) {
|
||||
return Cache::get('top_tracks');
|
||||
|
@ -61,7 +63,8 @@ public function getTopTracks() {
|
|||
Cache::put('top_tracks', $topTracks, now()->addSeconds(15));
|
||||
return $topTracks;
|
||||
}
|
||||
public function show() : View {
|
||||
public function show(): View
|
||||
{
|
||||
return view('music')
|
||||
->with('current_track', $this->getCurrentTrack())
|
||||
->with('top_tracks', $this->getTopTracks());
|
||||
|
|
|
@ -11,23 +11,27 @@ class BookmarkCategory extends Model
|
|||
protected $table = "bookmark__categories";
|
||||
protected $fillable = ['name'];
|
||||
|
||||
public function sites() {
|
||||
public function sites()
|
||||
{
|
||||
return $this->hasMany(BookmarkSite::class, 'category');
|
||||
}
|
||||
|
||||
public static function insertBookmarkCategory(string $name) {
|
||||
$newBookmarkCategory = new BookmarkCategory;
|
||||
public static function insertBookmarkCategory(string $name)
|
||||
{
|
||||
$newBookmarkCategory = new BookmarkCategory();
|
||||
$newBookmarkCategory->name = $name;
|
||||
$newBookmarkCategory->save();
|
||||
}
|
||||
public static function selectBookmarks(int $id) {
|
||||
public static function selectBookmarks(int $id)
|
||||
{
|
||||
$bookmarks = BookmarkSite::where('category', '=', $id)->firstOrFail();
|
||||
return $bookmarks;
|
||||
}
|
||||
|
||||
public static function importBookmarkCategory(array $data) {
|
||||
public static function importBookmarkCategory(array $data)
|
||||
{
|
||||
foreach ($data as $category) {
|
||||
$newBookmarkCategory = new BookmarkCategory;
|
||||
$newBookmarkCategory = new BookmarkCategory();
|
||||
$newBookmarkCategory->name = $category['name'];
|
||||
$newBookmarkCategory->priority = intval($category['priority']);
|
||||
$newBookmarkCategory->save();
|
||||
|
|
|
@ -5,26 +5,30 @@
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BookmarkSite extends Model {
|
||||
class BookmarkSite extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = "bookmark__sites";
|
||||
protected $fillable = ['name', 'description', 'url', 'category'];
|
||||
|
||||
public function category() {
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(BookmarkCategory::class, 'category');
|
||||
}
|
||||
public static function insertBookmark(string $name, string $url, int $category) {
|
||||
public static function insertBookmark(string $name, string $url, int $category)
|
||||
{
|
||||
$category = BookmarkCategory::where('id', $category)->firstOrFail();
|
||||
$newBookmark = new BookmarkSite;
|
||||
$newBookmark = new BookmarkSite();
|
||||
$newBookmark->name = $name;
|
||||
$newBookmark->url = $url;
|
||||
$newBookmark->category = $category->id;
|
||||
$newBookmark->save();
|
||||
}
|
||||
|
||||
public static function importBookmark(array $data) {
|
||||
public static function importBookmark(array $data)
|
||||
{
|
||||
foreach ($data as $site) {
|
||||
$newBookmark = new BookmarkSite;
|
||||
$newBookmark = new BookmarkSite();
|
||||
$newBookmark->name = $site['name'];
|
||||
$newBookmark->description = $site['description'];
|
||||
$newBookmark->url = $site['url'];
|
||||
|
|
|
@ -18,8 +18,9 @@ class GuestbookEntry extends Model
|
|||
* @param Request $request The HTTP POST request
|
||||
* @return void
|
||||
*/
|
||||
public static function insertGuestbookEntry(Request $request) {
|
||||
$newEntry = new GuestbookEntry;
|
||||
public static function insertGuestbookEntry(Request $request)
|
||||
{
|
||||
$newEntry = new GuestbookEntry();
|
||||
$newEntry->name = htmlspecialchars($request->get('name'));
|
||||
$newEntry->message = htmlspecialchars($request->get('message'));
|
||||
$newEntry->ip = $request->ip();
|
||||
|
@ -28,15 +29,17 @@ public static function insertGuestbookEntry(Request $request) {
|
|||
$newEntry->save();
|
||||
}
|
||||
|
||||
public static function selectEntries() {
|
||||
public static function selectEntries()
|
||||
{
|
||||
$entries = GuestbookEntry::orderBy('created_at', 'desc')->get();
|
||||
return $entries;
|
||||
}
|
||||
|
||||
public static function importGuestbookEntry(array $data) {
|
||||
public static function importGuestbookEntry(array $data)
|
||||
{
|
||||
foreach ($data as $entry) {
|
||||
$dt = new \DateTime('@' . $entry['timestamp']);
|
||||
$newEntry = new GuestbookEntry;
|
||||
$newEntry = new GuestbookEntry();
|
||||
$newEntry->name = $entry['name'];
|
||||
$newEntry->ip = $entry['ip_address'];
|
||||
$newEntry->agent = $entry['agent'];
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
|
|
|
@ -11,10 +11,11 @@ class BookmarkCategoriesTableSeeder extends Seeder
|
|||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void {
|
||||
// BookmarkCategory::factory()->count(5)->create()->each(function ($category) {
|
||||
// $category->sites()->saveMany(BookmarkSite::factory()->count(3)->make());
|
||||
// });
|
||||
public function run(): void
|
||||
{
|
||||
// BookmarkCategory::factory()->count(5)->create()->each(function ($category) {
|
||||
// $category->sites()->saveMany(BookmarkSite::factory()->count(3)->make());
|
||||
// });
|
||||
$category = new BookmarkCategory([
|
||||
'name' => 'cool people',
|
||||
]);
|
||||
|
|
|
@ -41,4 +41,3 @@
|
|||
Route::post('/admin/import', [AdminImportController::class, 'submit'])
|
||||
->name('admin.import.submit')
|
||||
->middleware('auth');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue