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

@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Gallery as ModelsGallery;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Gallery';
@@ -164,22 +167,19 @@ class Gallery
}
static public function get($id) {
global $db;
return $db->select(TABLE_PREFIX . 'gallery', array('id' => $id));
return ModelsGallery::find($id)->toArray();
}
static public function update($id, $comment, $image, $author) {
global $db;
$pathinfo = pathinfo($image);
$extension = strtolower($pathinfo['extension']);
$filename = GALLERY_DIR . $pathinfo['filename'] . '.' . $extension;
if($db->update(TABLE_PREFIX . 'gallery', array(
if(ModelsGallery::where('id', $id)->update([
'comment' => $comment,
'image' => $filename, 'author' => $author),
array('id' => $id)
)) {
'image' => $filename,
'author' => $author
])) {
if(self::generateThumb($id, $image, $errors))
self::resize($image, 650, 500, $filename, $errors);
}
@@ -187,11 +187,13 @@ class Gallery
static public function delete($id, &$errors)
{
global $db;
if(isset($id))
{
if(self::get($id) !== false)
$db->delete(TABLE_PREFIX . 'gallery', array('id' => $id));
$row = ModelsGallery::find($id);
if($row)
if (!$row->delete()) {
$errors[] = 'Fail during delete Gallery';
}
else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
@@ -203,13 +205,15 @@ class Gallery
static public function toggleHidden($id, &$errors)
{
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'gallery', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
else
$row = ModelsGallery::find($id);
if($row) {
$row->hidden = $row->hidden == 1 ? 0 : 1;
if (!$row->save()) {
$errors[] = 'Fail during toggle hidden Gallery';
}
} else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
else
@@ -226,10 +230,15 @@ class Gallery
{
$ordering = $query['ordering'] + $i;
$old_record = $db->select(TABLE_PREFIX . 'gallery', array('ordering' => $ordering));
if($old_record !== false)
$db->update(TABLE_PREFIX . 'gallery', array('ordering' => $query['ordering']), array('ordering' => $ordering));
if($old_record !== false) {
ModelsGallery::where('ordering', $ordering)->update([
'ordering' => $query['ordering'],
]);
}
$db->update(TABLE_PREFIX . 'gallery', array('ordering' => $ordering), array('id' => $id));
ModelsGallery::where('id', $id)->update([
'ordering' => $ordering,
]);
}
else
$errors[] = 'Image with id ' . $id . ' does not exists.';
@@ -297,13 +306,13 @@ class Gallery
if(!self::resize($file, 170, 110, $thumb_filename, $errors))
return false;
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'gallery', array('thumb' => $thumb_filename), array('id' => $id));
else
$row = ModelsGallery::find($id);
if($row) {
$row->thumb = $thumb_filename;
$row->save();
} else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
else