Skip to content

Commit

Permalink
Create guild_rank entries, in case MySQL trigger not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
slawkens committed Jun 13, 2024
1 parent 4c0739d commit d9c1b25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 21 additions & 4 deletions system/pages/guilds/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
defined('MYAAC') or die('Direct access not allowed!');

use MyAAC\Models\GuildRank;

require __DIR__ . '/base.php';

$guild_name = isset($_REQUEST['guild']) ? urldecode($_REQUEST['guild']) : NULL;
Expand Down Expand Up @@ -124,14 +126,29 @@
$player->setRank($rank);
}
}

if ($db->hasTable('guild_ranks')) {
if (!GuildRank::where('guild_id', $new_guild->getId())->first()) {
$ranks = [
['level' => 3, 'name' => 'the Leader'],
['level' => 2, 'name' => 'a Vice-Leader'],
['level' => 1, 'name' => 'a Member'],
];

foreach ($ranks as $rank) {
GuildRank::create([
'guild_id' => $new_guild->getId(),
'name' => $rank['name'],
'level' => $rank['level'],
]);
}
}
}

$twig->display('guilds.create.success.html.twig', array(
'guild_name' => $guild_name,
'leader_name' => $player->getName()
));

/*$db->exec('INSERT INTO `guild_ranks` (`id`, `guild_id`, `name`, `level`) VALUES (null, '.$new_guild->getId().', "the Leader", 3)');
$db->exec('INSERT INTO `guild_ranks` (`id`, `guild_id`, `name`, `level`) VALUES (null, '.$new_guild->getId().', "a Vice-Leader", 2)');
$db->exec('INSERT INTO `guild_ranks` (`id`, `guild_id`, `name`, `level`) VALUES (null, '.$new_guild->getId().', "a Member", 1)');*/
}
else {
sort($array_of_player_nig);
Expand Down
2 changes: 2 additions & 0 deletions system/src/Models/GuildRank.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class GuildRank extends Model {

public $timestamps = false;

protected $fillable = ['guild_id', 'name', 'level'];

public function guild()
{
return $this->belongsTo(Guild::class);
Expand Down

0 comments on commit d9c1b25

Please sign in to comment.