feat: replace POT Query Builder to Eloquent ORM (#230)

* wip

* wip

* wip

* wip

* wip

* fix: reusing pdo connection from pot

* wip

* wip

* wip

* wip

* move files

In future, all classes will be in src/ folder

* Replace namespace name, for future

* Remove duplicated exception

* Fix towns from db

* Fix spells page

* Add default FAQ question + FAQ model

* feat: reset colors in menus

* Add confirm + save button at the top (menus)

* Do not insert duplicated FAQ on install

* Refactor install menus

* Fix changelogs showing

* Fix menu update, only with specified template name

* Fix account create -> missing compat

* Fix bans_per_page

* banned_by is player_id. type = 2 is namelock in tfs 0.3

* Add getPlayerNameById, fix getPlayerNameByAccount

* Change link name

* Order by lastlogin

* fix: query optimize

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Refactor notepad.php, class was useless

* This is showing error, if the updated rows = 0

* Fix success & error class (bootstrap)

* Uncomment require migrate.php

* Some distro have owner_id

* Update Player.php

---------

Co-authored-by: slawkens <slawkens@gmail.com>
This commit is contained in:
Gabriel Pedro
2023-08-21 04:16:58 -04:00
committed by GitHub
parent b72e7a3d96
commit a692607c5e
95 changed files with 1809 additions and 933 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Account extends Model {
protected $table = 'accounts';
public $timestamps = false;
protected $casts = [
'lastday' => 'integer',
'premdays' => 'integer',
'premend' => 'integer',
'premium_ends_at' => 'integer',
];
public function players()
{
return $this->hasMany(Player::class);
}
public function viplist()
{
return $this->hasMany(AccountVipList::class);
}
public function getPremiumDaysAttribute()
{
if(isset($this->premium_ends_at) || isset($this->premend)) {
$col = isset($this->premium_ends_at) ? 'premium_ends_at' : 'premend';
$ret = ceil(($this->{$col}- time()) / (24 * 60 * 60));
return $ret > 0 ? $ret : 0;
}
if($this->premdays == 0) {
return 0;
}
global $config;
if(isset($config['lua']['freePremium']) && getBoolean($config['lua']['freePremium'])) return -1;
if($this->premdays == 65535){
return 65535;
}
$ret = ceil($this->premdays - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $this->lastday))) - date("z", $this->lastday)));
return $ret > 0 ? $ret : 0;
}
public function getIsPremiumAttribute()
{
global $config;
if(isset($config['lua']['freePremium']) && getBoolean($config['lua']['freePremium'])) return true;
if(isset($this->premium_ends_at)) {
return $this->premium_ends_at > time();
}
if(isset($this->premend)) {
return $this->premend > time();
}
return ($this->premdays - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $this->lastday))) - date("z", $this->lastday)) > 0);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class AccountVipList extends Model {
protected $table = 'account_viplist';
public $timestamps = false;
public function account()
{
return $this->belongsTo(Account::class);
}
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class BoostedCreature extends Model {
protected $table = 'boosted_creature';
protected $casts = [
'raceid' => 'integer',
];
public $timestamps = false;
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class BugTracker extends Model {
protected $table = TABLE_PREFIX . 'bugtracker';
public $timestamps = false;
protected $fillable = ['account', 'type', 'status', 'text', 'id', 'subject', 'reply', 'who', 'uid', 'tag'];
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Changelog extends Model {
protected $table = TABLE_PREFIX . 'changelog';
public $timestamps = false;
public function scopeIsPublic($query) {
$query->where('hidden', '!=', 1);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Config extends Model {
protected $table = TABLE_PREFIX . 'config';
public $timestamps = false;
protected $fillable = ['name', 'value'];
}

14
system/src/Models/FAQ.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class FAQ extends Model {
protected $table = TABLE_PREFIX . 'faq';
public $timestamps = false;
protected $fillable = ['question', 'answer', 'ordering', 'hidden'];
}

View File

@@ -0,0 +1,13 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Gallery extends Model {
protected $table = TABLE_PREFIX . 'gallery';
public $timestamps = false;
}

View File

@@ -0,0 +1,33 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Guild extends Model {
protected $table = 'guilds';
public $timestamps = false;
public function owner()
{
global $db;
$column = 'ownerid';
if($db->hasColumn('guilds', 'owner_id')) {
$column = 'owner_id';
}
return $this->belongsTo(Player::class, $column);
}
public function members()
{
return $this->belongsToMany(Player::class, 'guild_membership')->withPivot('rank_id', 'nick');
}
public function invites()
{
return $this->belongsToMany(Player::class, 'guild_invites');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class GuildInvites extends Model {
protected $table = 'guild_invites';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
public function guild()
{
return $this->belongsTo(Guild::class);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class GuildMembership extends Model {
protected $table = 'guild_membership';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
public function guild()
{
return $this->belongsTo(Guild::class);
}
public function rank()
{
return $this->belongsTo(GuildRank::class, 'rank_id');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class GuildRank extends Model {
protected $table = 'guild_ranks';
public $timestamps = false;
public function guild()
{
return $this->belongsTo(Guild::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class House extends Model {
protected $table = 'houses';
public $timestamps = false;
public function owner()
{
return $this->belongsTo(Player::class, 'owner');
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Menu extends Model {
protected $table = TABLE_PREFIX . 'menu';
public $timestamps = false;
protected $fillable = ['template', 'name', 'link', 'blank', 'color', 'category', 'ordering', 'enabled'];
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Monster extends Model {
protected $table = TABLE_PREFIX . 'monsters';
public $timestamps = false;
protected $guarded = ['id']; // lazy dev
}

View File

@@ -0,0 +1,22 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class News extends Model {
protected $table = TABLE_PREFIX . 'news';
public $timestamps = false;
protected $fillable = [
'title', 'body', 'type', 'date', 'category', 'player_id',
'last_modified_by', 'last_modified_date', 'comments', 'article_text',
'article_image', 'hidden'
];
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Notepad extends Model {
protected $table = TABLE_PREFIX . 'notepad';
public $timestamps = false;
protected $fillable = [
'account_id', 'content'
];
public function account()
{
return $this->belongsTo(Account::class);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Pages extends Model {
protected $table = TABLE_PREFIX . 'pages';
public $timestamps = false;
protected $fillable = ['name', 'title', 'body', 'date', 'player_id', 'php', 'enable_tinymce', 'access', 'hidden'];
protected $casts = [
'player_id' => 'integer',
'enable_tinymce' => 'integer',
'access' => 'integer',
'hidden' => 'integer',
];
public function player()
{
return $this->belongsTo(Player::class);
}
public function scopeIsPublic($query) {
$query->where('hidden', '!=', 1);
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Player extends Model {
protected $table = 'players';
public $timestamps = false;
protected $casts = [
'worldid' => 'integer',
'sex' => 'integer',
'level' => 'integer',
'vocation' => 'integer',
'promotion' => 'integer',
'looktype' => 'integer',
'lookhead' => 'integer',
'lookbody' => 'integer',
'looklegs' => 'integer',
'lookfeet' => 'integer',
'lookaddons' => 'integer',
'isreward' => 'integer',
];
public function scopeOrderBySkill($query, $value)
{
global $db;
$query->when($db->hasColumn('players', 'skill_fist'), function ($query) {
});
}
public function getVocationNameAttribute()
{
$vocation = $this->vocation;
if (isset($this->promotion)) {
$vocation *= $this->promotion;
}
return config('vocations')[$vocation] ?? 'Unknown';
}
public function getIsDeletedAttribute()
{
if (isset($this->deleted)) {
return $this->deleted !== 0;
}
if (isset($this->deletion)) {
return $this->deletion !== 0;
}
return false;
}
public function scopeNotDeleted($query) {
global $db;
$column = 'deleted';
if($db->hasColumn('players', 'deletion')) {
$column = 'deletion';
}
$query->where($column, 0);
}
public function scopeWithOnlineStatus($query) {
global $db;
$query->when($db->hasTable('players_online'), function ($query) {
$query->with('onlineTable');
});
}
public function getOnlineStatusAttribute()
{
global $db;
if ($db->hasColumn('players', 'online')) {
return $this->online;
}
if ($db->hasTable('players_online')) {
return $this->onlineTable != null;
}
return false;
}
public function onlineTable()
{
return $this->belongsTo(PlayerOnline::class);
}
public function account()
{
return $this->belongsTo(Account::class);
}
public function storages()
{
return $this->hasMany(PlayerStorage::class);
}
public function items()
{
return $this->hasMany(PlayerItem::class);
}
public function kills()
{
return $this->hasMany(PlayerKillers::class);
}
public function deaths()
{
return $this->hasMany(PlayerDeath::class);
}
public function houses()
{
return $this->hasMany(House::class, 'owner');
}
public function skills()
{
return $this->hasMany(PlayerSkill::class);
}
public function viplist()
{
return $this->hasMany(PlayerVipList::class);
}
public function scopeOnline($query) {
$query->where('online', '>', 0);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerDeath extends Model {
protected $table = 'player_deaths';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
public function killer()
{
return $this->belongsTo(Player::class, 'killed_by');
}
public function scopeUnjustified($query) {
$query->where('unjustified', 1);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerDepotItem extends Model {
protected $table = 'player_depotitems';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerKillers extends Model {
protected $table = 'players_killers';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerOnline extends Model {
protected $table = 'players_online';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerSkill extends Model {
protected $table = 'player_skills';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerSpell extends Model {
protected $table = 'player_spells';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerStorage extends Model {
protected $table = 'player_storage';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerVipList extends Model {
protected $table = 'player_viplist';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
public function vip()
{
return $this->belongsTo(Player::class, 'vip_id');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class PlayerItem extends Model {
protected $table = 'player_items';
public $timestamps = false;
public function player()
{
return $this->belongsTo(Player::class);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class ServerConfig extends Model {
protected $table = 'server_config';
public $timestamps = false;
protected $fillable = ['config', 'value'];
}

View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class ServerRecord extends Model {
protected $table = 'server_record';
public $timestamps = false;
protected $fillable = ['record', 'timestamp'];
}

View File

@@ -0,0 +1,14 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Settings extends Model {
protected $table = TABLE_PREFIX . 'settings';
public $timestamps = false;
protected $fillable = ['name', 'key', 'value'];
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Spell extends Model {
protected $table = TABLE_PREFIX . 'spells';
public $timestamps = false;
protected $guarded = ['id']; // lazy dev
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Town extends Model {
protected $table = 'towns';
public $timestamps = false;
protected $fillable = ['id', 'name', 'posx', 'posy', 'posz'];
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Visitor extends Model {
protected $table = TABLE_PREFIX . 'visitors';
public $timestamps = false;
protected $fillable = ['ip', 'lastivist', 'page', 'user_agent'];
}

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class Weapon extends Model {
protected $table = TABLE_PREFIX . 'weapons';
public $timestamps = false;
protected $fillable = ['id', 'level', 'maglevel', 'vocations'];
}