public function createGuild($name, $character) { $ots = POT::getInstance(); $ots->connect(POT::DB_MYSQL, connection()); $player = new OTS_Player(); $player->load($character); $new_guild = new OTS_Guild(); $new_guild->setCreationData(time()); $new_guild->setName($name); $new_guild->setOwner($player); $new_guild->save(); $new_guild->setCustomField('motd', 'New guild. Leader must edit this text :)'); $new_guild->setCustomField('creationdata', time()); $new_guild->setCustomField('world_id', $player->getWorld()); $ranks = $new_guild->getGuildRanksList(); $ranks->orderBy('level', POT::ORDER_DESC); foreach ($ranks as $rank) { if ($rank->getLevel() == 3) { $player->setRank($rank); $player->save(); } } $ide = new IDE(); $ide->redirect(WEBSITE . "/index.php/guilds/view/" . $new_guild->getId()); success("{$name} has been created."); }
/** * Checks highest access level of account in given guild. * * @param OTS_Guild $guild Guild in which access should be checked. * @return int Access level (highest access level of all characters). * @throws PDOException On PDO operation error. */ public function getGuildAccess(OTS_Guild $guild) { // by default $access = 0; // finds ranks of all characters foreach ($this->getPlayersList() as $player) { $rank = $player->getRank(); // checks if rank's access level is higher then previouls found highest if (isset($rank) && $rank->getGuild()->getId() == $guild->getId() && $rank->getLevel() > $access) { $access = $rank->getLevel(); } } return $access; }
} if ($config['site']['guild_need_pacc'] && !$account_logged->isPremium()) { $guild_errors[] = 'Character <b>' . $name . '</b> is on FREE account. To create guild you need PREMIUM account.'; } } } if (!empty($guild_errors)) { $main_content .= '<div class="SmallBox" > <div class="MessageContainer" > <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeLeftTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeRightTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="ErrorMessage" > <div class="BoxFrameVerticalLeft" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="BoxFrameVerticalRight" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="AttentionSign" style="background-image:url(' . $layout_name . '/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>'; foreach ($guild_errors as $guild_error) { $main_content .= '<li>' . $guild_error; } $main_content .= '</div> <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeRightBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeLeftBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> </div></div><br>'; unset($todo); } if ($todo == 'save') { $new_guild = new OTS_Guild(); $new_guild->setCreationData($time); $new_guild->setName($guild_name); $new_guild->setOwner($player); $new_guild->save(); $new_guild->setCustomField('description', 'New guild. Leader must edit this text :)'); $new_guild->setCustomField('creationdata', time()); $new_guild->setCustomField('world_id', $player->getWorld()); $ranks = $new_guild->getGuildRanksList(); $ranks->orderBy('level', POT::ORDER_DESC); foreach ($ranks as $rank) { if ($rank->getLevel() == 3) { $player->setRank($rank); $player->save(); } }
function delete_guild($id) { $guild = new OTS_Guild(); $guild->load($id); if ($guild->isLoaded()) { $rank_list = $guild->getGuildRanksList(); if (count($rank_list) > 0) { $rank_list->orderBy('level'); foreach ($rank_list as $rank_in_guild) { $players_with_rank = $rank_in_guild->getPlayersList(); if (count($players_with_rank) > 0) { foreach ($players_with_rank as $player_in_guild) { $player_in_guild->setRank(); $player_in_guild->save(); } } $rank_in_guild->delete(); } } $guild->delete(); return TRUE; } else { return FALSE; } }
<?php // to not repeat all that stuff include 'quickstart.php'; // loads guild with ID 1 $guild = new OTS_Guild(1); $color = '#FFFFCC'; echo '<h1>Members of ', htmlspecialchars($guild->getName()), '</h1>'; ?> <table> <thead> <tr> <th>Rank</th> <th>Members</th> </tr> </thead> <tbody> <?php // lists members of all ranks foreach ($guild as $guildRank) { // display rank in first row $first = true; // switches rank rows color $color = $color == '#FFFFCC' ? '#FFCCFF' : '#FFFFCC'; // list members of this rank foreach ($guildRank as $player) { echo '<tr style="background-color: ', $color, '"> <td>', $first ? htmlspecialchars($guildRank->getName()) : '', '</td> <td>', $player->getName(), '</td> </tr>'; $first = false;
} if ($config['site']['guild_need_pacc'] && !$account_logged->isPremium()) { $guild_errors[] = 'A sua conta não é premium account. Para criar uma guild você deve comprar uma premium account dentro do jogo.'; } } } if (!empty($guild_errors)) { $main_content .= '<div class="SmallBox" > <div class="MessageContainer" > <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeLeftTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeRightTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="ErrorMessage" > <div class="BoxFrameVerticalLeft" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="BoxFrameVerticalRight" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="AttentionSign" style="background-image:url(' . $layout_name . '/images/content/attentionsign.gif);" /></div><b>O seguinte erro ocorreu:</b><br />'; foreach ($guild_errors as $guild_error) { $main_content .= '<li>' . $guild_error; } $main_content .= '</div> <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeRightBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeLeftBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> </div></div><br />'; unset($todo); } if ($todo == 'save') { $new_guild = new OTS_Guild(); $new_guild->setCreationData($time); $new_guild->setName($guild_name); $new_guild->setOwner($player); $new_guild->setCustomField('description', 'Nova guild. O líder deve editar esse texto!'); $new_guild->setCustomField('creationdata', time()); $new_guild->setCustomField('world_id', $player->getWorld()); $new_guild->save(); $ranks = $new_guild->getGuildRanksList(); $ranks->orderBy('level', POT::ORDER_DESC); foreach ($ranks as $rank) { if ($rank->getLevel() == 3) { $player->setRank($rank); $player->save(); } }
} if ($config['site']['guild_need_pacc'] == 'yes' && $account_logged->getCustomField("premdays") == 0) { $guild_errors[] = 'Character <b>' . $name . '</b> is on FREE account. To create guild you need PREMIUM account.'; } } } if (!empty($guild_errors)) { $main_content .= '<div class="SmallBox" > <div class="MessageContainer" > <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeLeftTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeRightTop" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="ErrorMessage" > <div class="BoxFrameVerticalLeft" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="BoxFrameVerticalRight" style="background-image:url(' . $layout_name . '/images/content/box-frame-vertical.gif);" /></div> <div class="AttentionSign" style="background-image:url(' . $layout_name . '/images/content/attentionsign.gif);" /></div><b>The Following Errors Have Occurred:</b><br/>'; foreach ($guild_errors as $guild_error) { $main_content .= '<li>' . $guild_error; } $main_content .= '</div> <div class="BoxFrameHorizontal" style="background-image:url(' . $layout_name . '/images/content/box-frame-horizontal.gif);" /></div> <div class="BoxFrameEdgeRightBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> <div class="BoxFrameEdgeLeftBottom" style="background-image:url(' . $layout_name . '/images/content/box-frame-edge.gif);" /></div> </div></div><br>'; unset($todo); } if ($todo == 'save') { $new_guild = new OTS_Guild(); $new_guild->setCreationData($time); $new_guild->setName($guild_name); $new_guild->setOwner($player); $new_guild->save(); $new_guild->setCustomField('description', 'New guild. Leader must edit this text :)'); $new_guild->setCustomField('creationdata', time()); $new_guild->setCustomField('world_id', $player->getWorld()); $ranks = $new_guild->getGuildRanksList(); $ranks->orderBy('level', POT::ORDER_DESC); foreach ($ranks as $rank) { if ($rank->getLevel() == 3) { $player->setRank($rank); $player->save(); } }
/** * Assigns rank to guild. * * <p> * This method only updates object state. To save changes in database you need to use {@link OTS_GuildRank::save() save() method} to flush changed to database. * </p> * * @param OTS_Guild $guild Owning guild. * @throws E_OTS_NotLoaded If given <var>$guild</var> object is not loaded. */ public function setGuild(OTS_Guild $guild) { $this->data['guild_id'] = $guild->getId(); }
} // commits invitation public function submitRequest(OTS_Player $player) { $rank = null; // finds normal member rank foreach ($this->guild->getGuildRanks() as $guildRank) { if ($guildRank->getLevel() == 1) { $rank = $guildRank; break; } } $player->setRank($rank); $player->save(); // clears invitation $this->deleteRequest($player); } } /* Parts of this class driver has been taken from OTSCMS (http://otscms.com/) project source code. */ // loads player wiht ID 1 $player = new OTS_Player(); $player->load(1); // loads guild with ID 1 $guild = new OTS_Guild(); $guild->load(1); // creates invitation logic driver for your implementation for current guild new InvitesDriver($guild); // note that you call guild method! $guild->invite($player);