mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 01:34:55 +02:00
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:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use MyAAC\Models\Changelog as ModelsChangelog;
|
||||
|
||||
class Changelog
|
||||
{
|
||||
static public function verify($body,$date, &$errors)
|
||||
@@ -19,43 +21,61 @@ class Changelog
|
||||
|
||||
static public function add($body, $type, $where, $player_id, $cdate, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(!self::verify($body,$cdate, $errors))
|
||||
return false;
|
||||
|
||||
$db->insert(TABLE_PREFIX . 'changelog', array('body' => $body, 'type' => $type, 'date' => $cdate, 'where' => $where, 'player_id' => isset($player_id) ? $player_id : 0));
|
||||
self::clearCache();
|
||||
return true;
|
||||
$row = new ModelsChangelog;
|
||||
$row->body = $body;
|
||||
$row->type = $type;
|
||||
$row->date = $cdate;
|
||||
$row->where = $where;
|
||||
$row->player_id = $player_id ?? 0;
|
||||
if ($row->save()) {
|
||||
self::clearCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function get($id) {
|
||||
global $db;
|
||||
return $db->select(TABLE_PREFIX . 'changelog', array('id' => $id));
|
||||
return ModelsChangelog::find($id);
|
||||
}
|
||||
|
||||
static public function update($id, $body, $type, $where, $player_id, $date, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(!self::verify($body,$date, $errors))
|
||||
return false;
|
||||
|
||||
$db->update(TABLE_PREFIX . 'changelog', array('body' => $body, 'type' => $type, 'where' => $where, 'player_id' => isset($player_id) ? $player_id : 0, 'date' => $date), array('id' => $id));
|
||||
self::clearCache();
|
||||
return true;
|
||||
if (ModelsChangelog::where('id', '=', $id)->update([
|
||||
'body' => $body,
|
||||
'type' => $type,
|
||||
'where' => $where,
|
||||
'player_id' => $player_id ?? 0,
|
||||
'date' => $date
|
||||
])) {
|
||||
self::clearCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function delete($id, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(isset($id))
|
||||
{
|
||||
if($db->select(TABLE_PREFIX . 'changelog', array('id' => $id)) !== false)
|
||||
$db->delete(TABLE_PREFIX . 'changelog', array('id' => $id));
|
||||
else
|
||||
$row = ModelsChangelog::find($id);
|
||||
if ($row) {
|
||||
if (!$row->delete()) {
|
||||
$errors[] = 'Fail during delete Changelog.';
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Changelog with id ' . $id . ' does not exist.';
|
||||
}
|
||||
else
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Changelog id not set.';
|
||||
}
|
||||
|
||||
if(count($errors)) {
|
||||
return false;
|
||||
@@ -67,17 +87,18 @@ class Changelog
|
||||
|
||||
static public function toggleHidden($id, &$errors, &$status)
|
||||
{
|
||||
global $db;
|
||||
if(isset($id))
|
||||
{
|
||||
$query = $db->select(TABLE_PREFIX . 'changelog', array('id' => $id));
|
||||
if($query !== false)
|
||||
{
|
||||
$db->update(TABLE_PREFIX . 'changelog', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
|
||||
$status = $query['hidden'];
|
||||
}
|
||||
else
|
||||
$row = ModelsChangelog::find($id);
|
||||
if ($row) {
|
||||
$row->hidden = $row->hidden == 1 ? 0 : 1;
|
||||
if (!$row->save()) {
|
||||
$errors[] = 'Fail during toggle hidden Changelog.';
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Changelog with id ' . $id . ' does not exists.';
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
$errors[] = 'Changelog id not set.';
|
||||
|
Reference in New Issue
Block a user