$rank = new OTS_GuildRank(); $rank->load($rank_to_delete); if (!$rank->isLoaded()) { $guild_errors2[] = 'Rank with ID ' . $rank_to_delete . ' doesn\'t exist.'; } else { if ($rank->getGuild()->getId() != $guild->getId()) { $guild_errors2[] = 'Rank with ID ' . $rank_to_delete . ' isn\'t from your guild.'; } else { if (count($rank_list) < 2) { $guild_errors2[] = 'You have only 1 rank in your guild. You can\'t delete this rank.'; } else { $players_with_rank = $rank->getPlayersList(); $players_with_rank_number = count($players_with_rank); if ($players_with_rank_number > 0) { foreach ($rank_list as $checkrank) { if ($checkrank->getId() != $rank->getId()) { if ($checkrank->getLevel() <= $rank->getLevel()) { $new_rank = $checkrank; } } } if (empty($new_rank)) { $new_rank = new OTS_GuildRank(); $new_rank->setGuild($guild); $new_rank->setLevel($rank->getLevel()); $new_rank->setName('New Rank level ' . $rank->getLevel()); $new_rank->save(); } foreach ($players_with_rank as $player_in_guild) { $player_in_guild->setRank($new_rank); $player_in_guild->save();
/** * @version 0.0.5 * @param OTS_GuildRank $guildRank Rank to be deleted. * @deprecated 0.0.5 Use OTS_GuildRank->delete(). */ public function deleteGuildRank(OTS_GuildRank $guildRank) { $this->db->query('DELETE FROM ' . $this->db->tableName('guild_ranks') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $guildRank->getId()); }
/** * Assigns guild rank. * * <p> * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database. * </p> * * @param OTS_GuildRank|null Guild rank (null to clear assign). * @throws E_OTS_NotLoaded If passed <var>$guildRank</var> parameter is not loaded. */ public function setRank(OTS_GuildRank $guildRank = null) { if (isset($guildRank)) { $this->data['rank_id'] = $guildRank->getId(); } else { $this->data['rank_id'] = 0; } }