/** * Creates a new alliance * * @param string name * @param string tag * @param int owner id * @param string name of the leader rank * @return AllianceEditor */ public static function create($allianceName, $allianceTag, $userID, $leaderRankName = 'Leader') { if (Alliance::getByUserID($userID) !== null) { return null; } // create $sql = "INSERT INTO ugml_alliance\n\t\t\t\t(ally_register_time, ally_ranks, ally_owner, ally_owner_range)\n\t\t\t\tVALUES\n\t\t\t\t(" . TIME_NOW . ", 'a:0:{}', " . $userID . ", '" . escapeString($leaderRankName) . "')"; WCF::getDB()->sendQuery($sql); $insertID = WCF::getDB()->getInsertID(); $editor = new AllianceEditor($insertID); $editor->setName($allianceName, $allianceTag); // add the first user $editor->addUser($userID); return $editor; }
/** * @see Form::save() */ public function save() { parent::save(); AllianceEditor::create($this->allianceName, $this->allianceTag, WCF::getUser()->userID); WCF::getSession()->setUpdate(true); header('Location: index.php?page=Alliance'); exit; }
/** * @see Action::execute() */ public function execute() { parent::execute(); // check user if (!WCF::getUser()->userID) { require_once WCF_DIR . 'lib/system/exception/PermissionDeniedException.class.php'; throw new PermissionDeniedException(); } // update users $sql = "DELETE FROM wcf" . WCF_N . "_session\r\n\t\t\t\tWHERE userID IN(SELECT id\r\n\t\t\t\t\t\t\t \tFROM ugml_users\r\n\t\t\t\t\t\t\t \tWHERE ally_id = " . $this->allianceID . "\r\n\t\t\t\t\t\t\t \t\tAND ally_rank_id = " . ($this->rankID + 1) . ")"; WCF::getDB()->sendQuery($sql); $sql = "UPDATE ugml_users\r\n\t\t\t\tSET ally_rank_id = 0\r\n\t\t\t\tWHERE ally_id = " . $this->allianceID . "\r\n\t\t\t\t\tAND ally_rank_id = " . ($this->rankID + 1); WCF::getDB()->sendQuery($sql); // update alliance $alliance = new AllianceEditor($this->allianceID); $ranks = $alliance->getRank(); $ranks[$this->rankID] = false; $alliance->setRank($ranks); $this->executed(); header('Location: index.php?form=AllianceRankList&allianceID=' . $this->allianceID); exit; }