Guest User

Armory Model

a guest
Apr 23rd, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.75 KB | None | 0 0
  1. <?php
  2.  
  3. class Armory_model extends CI_Model
  4. {
  5. public $realm;
  6. private $connection;
  7. private $id;
  8. private $realmId;
  9. private $storedData;
  10. private $EmulatorSimpleString = '';
  11.  
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. /**
  17. * Assign the character ID to the model
  18. */
  19. public function setId($id)
  20. {
  21. $this->id = $id;
  22. }
  23.  
  24. /**
  25. * Assign the realm object to the model
  26. */
  27. public function setRealm($id)
  28. {
  29. $this->realmId = $id;
  30. $this->realm = $this->realms->getRealm($id);
  31. $this->EmulatorSimpleString = str_replace(array('_ra', '_soap', '_rbac'), '', $this->realm->getConfig('emulator'));
  32. }
  33.  
  34. private function getEmulatorString()
  35. {
  36. return $this->EmulatorSimpleString;
  37. }
  38.  
  39. /**
  40. * Connect to the character database
  41. */
  42. public function connect()
  43. {
  44. $this->realm->getCharacters()->connect();
  45. $this->connection = $this->realm->getCharacters()->getConnection();
  46. }
  47.  
  48. /**
  49. * Check if the current character exists
  50. */
  51. public function characterExists()
  52. {
  53. $this->connect();
  54.  
  55. $query = $this->connection->query("SELECT COUNT(*) AS total FROM ".table("characters", $this->realmId)." WHERE ".column("characters", "guid", false, $this->realmId)."= ?", array($this->id));
  56. $row = $query->result_array();
  57.  
  58. if($row[0]['total'] > 0)
  59. {
  60. return true;
  61. }
  62. else
  63. {
  64. return false;
  65. }
  66. }
  67.  
  68. /**
  69. * Get the character data that belongs to the character
  70. */
  71. public function getCharacter()
  72. {
  73. $this->connect();
  74.  
  75. $query = $this->connection->query(query('get_character', $this->realmId), array($this->id));
  76.  
  77. if($query && $query->num_rows() > 0)
  78. {
  79. $row = $query->result_array();
  80.  
  81. return $row[0];
  82. }
  83. else
  84. {
  85. return array(
  86. "account" => "",
  87. "name" => "",
  88. "race" => "",
  89. "class" => "",
  90. "gender" => "",
  91. "level" => ""
  92. );
  93. }
  94. }
  95.  
  96. /**
  97. * Get the character stats that belongs to the character
  98. */
  99. public function getStats()
  100. {
  101. $this->connect();
  102.  
  103. $query = $this->connection->query("SELECT ".allColumns("character_stats", $this->realmId)." FROM ".table("character_stats", $this->realmId)." WHERE ".column("character_stats", "guid", false, $this->realmId)."= ?", array($this->id));
  104.  
  105. if($this->connection->_error_message())
  106. {
  107. die("function getStats() returned SQL error: " . $this->connection->_error_message());
  108. }
  109.  
  110. if($query && $query->num_rows() > 0)
  111. {
  112. $row = $query->result_array();
  113.  
  114. return $row[0];
  115. }
  116. else
  117. {
  118. return false;
  119. }
  120. }
  121.  
  122. public function getPVPPoints()
  123. {
  124. $this->connect();
  125.  
  126. switch ($this->getEmulatorString())
  127. {
  128. case 'trinity_cata':
  129. $statement = "SELECT * FROM `character_currency` WHERE `guid` = ? AND `currency` IN(390, 392);";
  130. break;
  131. case 'skyfire':
  132. case 'arkcore':
  133. $statement = "SELECT `currency`, `count` AS total_count FROM `character_currency` WHERE `guid` = ? AND `currency` IN(390, 392);";
  134. break;
  135. }
  136.  
  137. $query = $this->connection->query($statement, array($this->id));
  138.  
  139. if ($query && $query->num_rows() > 0)
  140. {
  141. $result = $query->result_array();
  142.  
  143. $temp = array(
  144. 'totalHonorPoints' => 0,
  145. 'arenaPoints' => 0
  146. );
  147.  
  148. foreach ($result as $row)
  149. {
  150. switch ((int)$row['currency'])
  151. {
  152. case 390:
  153. $temp['arenaPoints'] = ($row['total_count'] / 100);
  154. break;
  155. case 392:
  156. $temp['totalHonorPoints'] = ($row['total_count'] / 100);
  157. break;
  158. }
  159. }
  160.  
  161. return $temp;
  162. }
  163. else
  164. {
  165. return false;
  166. }
  167. }
  168.  
  169. /**
  170. * Load items that belong to the character
  171. */
  172. public function getItems()
  173. {
  174. $this->connect();
  175.  
  176. //handle the extended method with gems and enchants
  177. switch ($this->getEmulatorString())
  178. {
  179. case 'skyfire':
  180. case 'trinity':
  181. case 'trinity_cata':
  182. case 'arkcore':
  183. $query = $this->connection->query(" SELECT
  184. `character_inventory`.`slot`,
  185. `character_inventory`.`item`,
  186. `item_instance`.`itemEntry`,
  187. `item_instance`.`enchantments`
  188. FROM `character_inventory`, `item_instance`
  189. WHERE `character_inventory`.`item` = `item_instance`.`guid` AND `character_inventory`.`slot` >= 0 AND `character_inventory`.`slot` <= 18 AND `character_inventory`.`guid` = ? AND `character_inventory`.`bag` = 0;",
  190. array($this->id));
  191. break;
  192. case 'mangos':
  193. case 'mangosr2':
  194. $query = $this->connection->query(" SELECT
  195. `character_inventory`.`slot`,
  196. `character_inventory`.`item`,
  197. `character_inventory`.`item_template` AS itemEntry,
  198. `item_instance`.`data` AS enchantments
  199. FROM `character_inventory`
  200. LEFT JOIN `item_instance` ON `character_inventory`.`item` = `item_instance`.`guid`
  201. WHERE `character_inventory`.`slot` >= 0 AND `character_inventory`.`slot` <= 18 AND `character_inventory`.`guid` = ? AND `character_inventory`.`bag` = 0;",
  202. array($this->id));
  203. break;
  204. case 'arcemu':
  205. $query = $this->connection->query(" SELECT
  206. slot,
  207. guid AS item,
  208. entry AS itemEntry,
  209. enchantments
  210. FROM playeritems
  211. WHERE slot >= 0 AND slot <= 18 AND ownerguid = ?;",
  212. array($this->id));
  213. break;
  214. default:
  215. $query = $this->connection->query(query("get_inventory_item", $this->realmId), array($this->id));
  216. break;
  217. }
  218.  
  219. if($query && $query->num_rows() > 0)
  220. {
  221. $row = $query->result_array();
  222.  
  223. return $row;
  224. }
  225. else
  226. {
  227. return false;
  228. }
  229. }
  230.  
  231. public function getGuild($guid = false)
  232. {
  233. if (!$guid)
  234. $guid = $this->id;
  235.  
  236. $this->connect();
  237.  
  238. $query = $this->connection->query("SELECT ".column("guild_member", "guildid", true, $this->realmId)." FROM ".table("guild_member", $this->realmId)." WHERE ".column("guild_member", "guid", false, $this->realmId)."= ?", array($this->id));
  239.  
  240. if($this->connection->_error_message())
  241. {
  242. die($this->connection->_error_message());
  243. }
  244.  
  245. if($query && $query->num_rows() > 0)
  246. {
  247. $row = $query->result_array();
  248.  
  249. return $row[0]['guildid'];
  250. }
  251. else
  252. {
  253. $query2 = $this->connection->query("SELECT ".column("guild", "guildid", true, $this->realmId)." FROM ".table("guild", $this->realmId)." WHERE ".column("guild", "leaderguid", false, $this->realmId)."= ?", array($this->id));
  254.  
  255. if($this->connection->_error_message())
  256. {
  257. die($this->connection->_error_message());
  258. }
  259.  
  260. if($query2 && $query2->num_rows() > 0)
  261. {
  262.  
  263. $row2 = $query2->result_array();
  264.  
  265. return $row2[0]['guildid'];
  266. }
  267. else
  268. {
  269. return false;
  270. }
  271. }
  272. }
  273.  
  274. public function getGuildName($id)
  275. {
  276. if(!$id)
  277. {
  278. return '';
  279. }
  280. else
  281. {
  282. $this->connect();
  283.  
  284. $query = $this->connection->query("SELECT ".column("guild", "name", true, $this->realmId)." FROM ".table("guild", $this->realmId)." WHERE ".column("guild", "guildid", false, $this->realmId)."= ?", array($id));
  285.  
  286. if($query && $query->num_rows() > 0)
  287. {
  288. $row = $query->result_array();
  289.  
  290. return $row[0]['name'];
  291. }
  292. else
  293. {
  294. return false;
  295. }
  296. }
  297. }
  298.  
  299. public function getTalents($spec)
  300. {
  301. $this->connect();
  302.  
  303. //Handle arcemu
  304. if ($this->getEmulatorString() == 'arcemu')
  305. {
  306. $this->getArcemuCharacterDataIfNeeded();
  307.  
  308. if ($this->storedData)
  309. {
  310. //increase spec number
  311. $spec = $spec + 1;
  312. //get the talents string
  313. $talentList = $this->storedData['talents'.$spec];
  314. //check for empty talent list
  315. if ($talentList != '')
  316. {
  317. //strip the last ,
  318. $talentList = rtrim($talentList, ',');
  319. //convert to array
  320. $talents = explode(',', $talentList);
  321. //each second record in the array is the rank of the previous record, we need to merge them
  322. $new = array();
  323. foreach ($talents as $key => $value)
  324. {
  325. if (($key % 2) == 0) //push the talent id
  326. $new[] = array('talent_id' => $value);
  327. else //push the rank
  328. $new[count($new) - 1]['current_rank'] = $value;
  329. }
  330. unset($talents, $talentList);
  331.  
  332. return $new;
  333. }
  334. else
  335. return false;
  336. }
  337. else
  338. return false;
  339. }
  340.  
  341. $statements['trinity'] =
  342. $statements['trinity_cata'] =
  343. $statements['arkcore'] =
  344. $statements['skyfire'] = "SELECT `spell` FROM `character_talent` WHERE `guid` = ? AND `spec` = ? ORDER BY `spell` DESC;";
  345.  
  346. $statements['mangos'] =
  347. $statements['mangosr2'] = "SELECT `talent_id`, `current_rank` FROM `character_talent` WHERE `guid` = ? AND `spec` = ? ORDER BY `talent_id` DESC;";
  348.  
  349. $query = $this->connection->query($statements[$this->getEmulatorString()], array($this->id, $spec));
  350.  
  351. if($query && $query->num_rows() > 0)
  352. {
  353. $array = $query->result_array();
  354.  
  355. //put the talents into a single array
  356. $temp = array();
  357. foreach ($array as $key => $row)
  358. {
  359. if (isset($row['spell']))
  360. $temp[] = $row['spell'];
  361. else
  362. $temp[] = $row;
  363. }
  364. unset($array);
  365.  
  366. return $temp;
  367. }
  368.  
  369. unset($query);
  370.  
  371. return false;
  372. }
  373.  
  374. public function getGlyphs($spec)
  375. {
  376. $this->connect();
  377.  
  378. //Handle arcemu
  379. if ($this->getEmulatorString() == 'arcemu')
  380. {
  381. $this->getArcemuCharacterDataIfNeeded();
  382.  
  383. if ($this->storedData)
  384. {
  385. //increase spec number
  386. $spec = $spec + 1;
  387. //get the talents string
  388. $glyphList = $this->storedData['glyphs'.$spec];
  389. //strip the last ,
  390. $glyphList = rtrim($glyphList, ',');
  391. //convert to array
  392. $glyphs = explode(',', $glyphList);
  393. //make it suitable to use the mangos function
  394. foreach ($glyphs as $key => $id)
  395. {
  396. $glyphs[$key] = array('glyph' => $id);
  397. }
  398. unset($glyphList, $key, $id);
  399.  
  400. return $glyphs;
  401. }
  402. else
  403. return false;
  404. }
  405.  
  406. $statements['trinity'] =
  407. $statements['trinity_cata'] =
  408. $statements['arkcore'] =
  409. $statements['skyfire'] = "SELECT * FROM `character_glyphs` WHERE `guid` = ? AND `spec` = ? LIMIT 1;";
  410.  
  411. $statements['mangos'] =
  412. $statements['mangosr2'] = "SELECT `slot`, `glyph` FROM `character_glyphs` WHERE `guid` = ? AND `spec` = ?;";
  413.  
  414. $query = $this->connection->query($statements[$this->getEmulatorString()], array($this->id, $spec));
  415.  
  416. if($query && $query->num_rows() > 0)
  417. {
  418. $array = $query->result_array();
  419.  
  420. return $array;
  421. }
  422.  
  423. unset($query);
  424.  
  425. return false;
  426. }
  427.  
  428. public function getTalentSpecsInfo()
  429. {
  430. $this->connect();
  431.  
  432. //Handle arcemu
  433. if ($this->getEmulatorString() == 'arcemu')
  434. {
  435. $this->getArcemuCharacterDataIfNeeded();
  436.  
  437. if ($this->storedData)
  438. {
  439. return array('speccount' => $this->storedData['speccount'], 'activespec' => $this->storedData['activespec']);
  440. }
  441. else
  442. return false;
  443. }
  444.  
  445. $statements['trinity'] =
  446. $statements['trinity_cata'] =
  447. $statements['arkcore'] =
  448. $statements['skyfire'] = "SELECT `speccount`, `activespec` FROM `characters` WHERE `guid` = ? LIMIT 1;";
  449.  
  450. $statements['mangos'] =
  451. $statements['mangosr2'] = "SELECT `specCount` AS speccount, `activeSpec` AS activespec FROM `characters` WHERE `guid` = ? LIMIT 1;";
  452.  
  453. $query = $this->connection->query($statements[$this->getEmulatorString()], array($this->id));
  454.  
  455. if($query && $query->num_rows() > 0)
  456. {
  457. $result = $query->result_array();
  458.  
  459. return $result[0];
  460. }
  461.  
  462. unset($query);
  463.  
  464. return false;
  465. }
  466.  
  467. private function getArcemuCharacterDataIfNeeded()
  468. {
  469. if (!isset($this->storedData) || !is_array($this->storedData))
  470. {
  471. $query = $this->connection->query("SELECT `glyphs1`, `glyphs2`, `talents1`, `talents2`, `numspecs` AS speccount, `currentspec` AS activespec, `skills` FROM `characters` WHERE `guid` = ? LIMIT 1;", array($this->id));
  472.  
  473. if($query && $query->num_rows() > 0)
  474. {
  475. $array = $query->result_array();
  476.  
  477. $this->storedData = $array[0];
  478.  
  479. unset($array);
  480. }
  481. else
  482. {
  483. $this->storedData = false;
  484. }
  485. unset($query);
  486. }
  487. }
  488.  
  489. /***************************************
  490. * TOP ARENA FUNCTIONS
  491. ***************************************/
  492.  
  493. public function getTeam($type = 2)
  494. {
  495. //Switch the type number for arcemu
  496. if ($this->getEmulatorString() == 'arcemu')
  497. {
  498. switch ($type)
  499. {
  500. case 2: $type = 0; break;
  501. case 3: $type = 1; break;
  502. case 5: $type = 2; break;
  503. }
  504. }
  505.  
  506. $this->connect();
  507.  
  508. //First get the arena team member record for this character
  509. $statements['trinity'] =
  510. $statements['trinity_cata'] =
  511. $statements['arkcore'] =
  512. $statements['skyfire'] = " SELECT
  513. `arena_team_member`.`arenaTeamId` AS arenateamid,
  514. `arena_team`.`name` AS teamName,
  515. `arena_team`.`rating` AS teamRating,
  516. `arena_team`.`rank` AS teamRank
  517. FROM `arena_team_member`, `arena_team`
  518. WHERE `arena_team_member`.`guid` = ? AND `arena_team`.`arenaTeamId` = `arena_team_member`.`arenaTeamId` AND `arena_team`.`type` = ?
  519. LIMIT 1;";
  520.  
  521. //Mangos and MangosR2
  522. $statements['mangos'] =
  523. $statements['mangosr2'] = " SELECT
  524. `arena_team_member`.`arenateamid`,
  525. `arena_team`.`name` AS teamName,
  526. `arena_team_stats`.`rating` AS teamRating,
  527. `arena_team_stats`.`rank` AS teamRank
  528. FROM `arena_team_member`, `arena_team`, `arena_team_stats`
  529. WHERE `arena_team_member`.`guid` = ? AND `arena_team`.`arenateamid` = `arena_team_member`.`arenateamid` AND `arena_team`.`arenateamid` = `arena_team_stats`.`arenateamid` AND `arena_team`.`type` = ?
  530. LIMIT 1;";
  531.  
  532. $statements['arcemu'] = " SELECT
  533. `id` AS arenateamid,
  534. `rating` AS teamRating,
  535. `ranking` AS teamRank,
  536. `name` AS teamName
  537. FROM `arenateams`
  538. WHERE
  539. (`type` = @type AND LOCATE(@guid, player_data1) = 1) OR
  540. (`type` = @type AND LOCATE(@guid, player_data2) = 1) OR
  541. (`type` = @type AND LOCATE(@guid, player_data3) = 1) OR
  542. (`type` = @type AND LOCATE(@guid, player_data4) = 1) OR
  543. (`type` = @type AND LOCATE(@guid, player_data5) = 1) OR
  544. (`type` = @type AND LOCATE(@guid, player_data6) = 1) OR
  545. (`type` = @type AND LOCATE(@guid, player_data7) = 1) OR
  546. (`type` = @type AND LOCATE(@guid, player_data8) = 1) OR
  547. (`type` = @type AND LOCATE(@guid, player_data9) = 1) OR
  548. (`type` = @type AND LOCATE(@guid, player_data10) = 1)
  549. LIMIT 1;";
  550.  
  551. //set sql variables for arcemu
  552. if ($this->getEmulatorString() == 'arcemu')
  553. {
  554. $this->connection->query("SET @guid=?;", array($this->id));
  555. $this->connection->query("SET @type=?;", array($type));
  556. }
  557.  
  558. $result = $this->connection->query($statements[$this->getEmulatorString()], array($this->id, $type));
  559.  
  560. if($result && $result->num_rows() > 0)
  561. {
  562. $array = $result->result_array();
  563. //re-variable
  564. $team = $array[0];
  565.  
  566. unset($array);
  567.  
  568. // Get the team members
  569. $team['members'] = $this->getTeamMembers((int)$team['arenateamid']);
  570. //Find the player and remove him from the members array
  571. foreach ($team['members'] as $key => $member)
  572. {
  573. if ($member['guid'] == $this->id)
  574. {
  575. //store with new assoc key
  576. $team['player'] = $member;
  577. //remove from members
  578. unset($team['members'][$key]);
  579. }
  580. }
  581.  
  582. return $team;
  583. }
  584.  
  585. unset($result);
  586.  
  587. return false;
  588. }
  589.  
  590. private function getTeamMembers($teamId)
  591. {
  592. // Different handling for arcemu
  593. if ($this->getEmulatorString() == 'arcemu')
  594. {
  595. return $this->getTeamMembersArcemu($teamId);
  596. }
  597.  
  598. $this->connect();
  599.  
  600. //Trinity and Skyfire is the same
  601. $statements['trinity'] =
  602. $statements['trinity_cata'] =
  603. $statements['arkcore'] =
  604. $statements['skyfire'] = " SELECT
  605. `arena_team_member`.`guid`,
  606. `arena_team_member`.`personalRating` AS rating,
  607. `arena_team_member`.`seasonGames` AS games,
  608. `arena_team_member`.`seasonWins` AS wins,
  609. `characters`.`name`,
  610. `characters`.`class`,
  611. `characters`.`race`,
  612. `characters`.`level`
  613. FROM `arena_team_member`
  614. RIGHT JOIN `characters` ON `characters`.`guid` = `arena_team_member`.`guid`
  615. WHERE `arena_team_member`.`arenateamid` = ? ORDER BY guid ASC;";
  616.  
  617. //Mangos and MangosR2
  618. $statements['mangos'] =
  619. $statements['mangosr2'] = " SELECT
  620. `arena_team_member`.`guid`,
  621. `arena_team_member`.`personal_rating` AS rating,
  622. `arena_team_member`.`played_season` AS games,
  623. `arena_team_member`.`wons_season` AS wins,
  624. `characters`.`name`,
  625. `characters`.`class`,
  626. `characters`.`race`,
  627. `characters`.`level`
  628. FROM `arena_team_member`
  629. RIGHT JOIN `characters` ON `characters`.`guid` = `arena_team_member`.`guid`
  630. WHERE `arena_team_member`.`arenateamid` = ? ORDER BY guid ASC;";
  631.  
  632. $result = $this->connection->query($statements[$this->getEmulatorString()], array($teamId));
  633.  
  634. if($result && $result->num_rows() > 0)
  635. {
  636. $array = $result->result_array();
  637.  
  638. //get some more info
  639. foreach ($array as $key => $row)
  640. {
  641. $array[$key]['className'] = $this->realms->getClass($row['class']);
  642.  
  643. if (in_array($row['race'], array(4, 10)))
  644. {
  645. if ($row['race'] == 4)
  646. $row['raceName'] = "Night elf";
  647. else
  648. $row['raceName'] = "Blood elf";
  649. }
  650. else
  651. $row['raceName'] = $this->realms->getRace($row['race']);
  652.  
  653. $array[$key]['raceName'] = $row['raceName'];
  654.  
  655. //Try getting the player guild
  656. if ($guildid = $this->getGuild($row['guid']))
  657. {
  658. $row['guildName'] = $this->getGuildName($guildid);
  659. }
  660. unset($guildid);
  661.  
  662. $array[$key]['guildName'] = (isset($row['guildName']) ? $row['guildName'] : false);
  663. $array[$key]['faction'] = $this->getFactionName($row['race']);
  664. }
  665.  
  666. return $array;
  667. }
  668.  
  669. unset($result);
  670.  
  671. return false;
  672. }
  673.  
  674. public function getTeamMembersArcemu($team)
  675. {
  676. $this->connect();
  677.  
  678. $result = $this->connection->query("SELECT `player_data1`, `player_data2`, `player_data3`, `player_data4`, `player_data5`, `player_data6`, `player_data7`, `player_data8`, `player_data9`, `player_data10` FROM `arenateams` WHERE `id` = ? LIMIT 1;", array($team));
  679.  
  680. if($result && $result->num_rows() > 0)
  681. {
  682. $members = array();
  683. $row = $result->result_array();
  684. $row = $row[0];
  685.  
  686. // Get the team members
  687. for ($i = 1; $i <= 10; $i++)
  688. {
  689. if ($row['player_data'.$i] == '')
  690. continue;
  691.  
  692. list($guid, $weekGames, $weekWins, $seasonGames, $seasonWins, $rating) = explode(' ', $row['player_data'.$i]);
  693.  
  694. settype($guid, "integer");
  695.  
  696. // Check if there is a player at this pos
  697. if ($guid == 0)
  698. continue;
  699.  
  700. //Get some character data
  701. $result2 = $this->connection->query("SELECT `guid`, `name`, `class`, `race`, `level` FROM `characters` WHERE `guid` = ? LIMIT 1;", array($guid));
  702.  
  703. if($result2 && $result2->num_rows() > 0)
  704. {
  705. $char = $result2->result_array();
  706. $char = $char[0];
  707.  
  708. if (in_array($char['race'], array(4, 10)))
  709. {
  710. if ($char['race'] == 4)
  711. $char['raceName'] = "Night elf";
  712. else
  713. $char['raceName'] = "Blood elf";
  714. }
  715. else
  716. $char['raceName'] = $this->realms->getRace($char['race']);
  717.  
  718. //Try getting the player guild
  719. if ($guildid = $this->getGuild($guid))
  720. {
  721. $char['guildName'] = $this->getGuildName($guildid);
  722. }
  723. unset($guildid);
  724.  
  725. array_push($members, array(
  726. 'guid' => $guid,
  727. 'rating' => $rating,
  728. 'games' => $seasonGames,
  729. 'wins' => $seasonWins,
  730. 'name' => $char['name'],
  731. 'class' => $char['class'],
  732. 'className' => $this->realms->getClass($char['class']),
  733. 'race' => $char['race'],
  734. 'raceName' => $char['raceName'],
  735. 'level' => $char['level'],
  736. 'guildName' => (isset($char['guildName']) ? $char['guildName'] : false),
  737. 'faction' => $this->getFactionName($char['race'])
  738. ));
  739.  
  740. unset($char);
  741. }
  742. unset($result2, $guid, $weekGames, $weekWins, $seasonGames, $seasonWins, $rating);
  743. }
  744. unset($row);
  745.  
  746. //check if the team has any players
  747. if (count($members) > 0)
  748. {
  749. return $members;
  750. }
  751. }
  752.  
  753. unset($result);
  754.  
  755. return false;
  756. }
  757.  
  758. private function getFactionName($id)
  759. {
  760. switch($id)
  761. {
  762. case 1: return 'alliance';
  763. case 2: return 'horde';
  764. case 3: return 'alliance';
  765. case 4: return 'alliance';
  766. case 5: return 'horde';
  767. case 6: return 'horde';
  768. case 7: return 'alliance';
  769. case 8: return 'horde';
  770. case 9: return 'horde';
  771. case 10: return 'horde';
  772. case 11: return 'alliance';
  773. case 22: return 'alliance';
  774. }
  775.  
  776. return false;
  777. }
  778.  
  779. public function getRecentAchievements($count = 5)
  780. {
  781. $this->connect();
  782.  
  783. $statements['trinity'] =
  784. $statements['trinity_cata'] =
  785. $statements['arkcore'] =
  786. $statements['arcemu'] =
  787. $statements['mangos'] =
  788. $statements['skyfire'] = "SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid` = ? ORDER BY date DESC LIMIT ?;";
  789.  
  790. $statements['mangosr2'] = "";
  791.  
  792. $query = $this->connection->query($statements[$this->getEmulatorString()], array($this->id, $count));
  793.  
  794. if ($query && $query->num_rows() > 0)
  795. {
  796. $result = $query->result_array();
  797.  
  798. return $result;
  799. }
  800.  
  801. unset($query);
  802.  
  803. return false;
  804. }
  805.  
  806. #####################################################
  807. ########### PROFESSIONS #############################
  808.  
  809. public function getProfessions()
  810. {
  811. //Define the professions (skill ids) we need
  812. $professionsString = "164,165,171,182,186,197,202,333,393,755,773,129,185,356,794";
  813.  
  814. //Handle arcemu
  815. if ($this->getEmulatorString() == 'arcemu')
  816. {
  817. $result = $this->getArcemuProfessions();
  818. }
  819. else
  820. {
  821. $this->connect();
  822.  
  823. $statements['trinity'] =
  824. $statements['trinity_cata'] =
  825. $statements['arkcore'] =
  826. $statements['mangos'] =
  827. $statements['skyfire'] = "SELECT `skill`, `value`, `max` FROM `character_skills` WHERE `guid` = ? AND `skill` IN(".$professionsString.");";
  828.  
  829. $statements['mangosr2'] = "";
  830.  
  831. $query = $this->connection->query($statements[$this->getEmulatorString()], array($this->id));
  832.  
  833. if ($query && $query->num_rows() > 0)
  834. {
  835. $result = $query->result_array();
  836. }
  837. else
  838. {
  839. $result = false;
  840. }
  841.  
  842. unset($query);
  843. }
  844.  
  845. if ($result)
  846. {
  847. //loop trough the records and get some more info
  848. foreach ($result as $key => $row)
  849. {
  850. if ($info = $this->getProfessionInfo((int)$row['skill']))
  851. {
  852. $result[$key] = array(
  853. 'skill' => $row['skill'],
  854. 'value' => $row['value'],
  855. 'max' => $row['max'],
  856. 'name' => $info['name'],
  857. 'icon' => $info['icon'],
  858. 'category' => $info['category']
  859. );
  860. }
  861. }
  862.  
  863. return $result;
  864. }
  865.  
  866. return false;
  867. }
  868.  
  869. private function getArcemuProfessions()
  870. {
  871. //Define the professions (skill ids) we need
  872. $professions = array(164,165,171,182,186,197,202,333,393,755,773,129,185,356,794);
  873.  
  874. $this->getArcemuCharacterDataIfNeeded();
  875.  
  876. if ($this->storedData)
  877. {
  878. //get the skills string
  879. $Skills = $this->storedData['skills'];
  880. //strip the last ,
  881. $SkillList = rtrim($Skills, ';');
  882. //convert to array
  883. $SkillList = explode(';', $SkillList);
  884.  
  885. $SkillArr = array();
  886. //Loop trought the skills and covert them to a nice array
  887. for ($i = 0; $i < (count($SkillList) / 3); $i++)
  888. {
  889. $SkillArr[] = array(
  890. 'skill' => (int)$SkillList[$i * 3],
  891. 'value' => (int)$SkillList[$i * 3 + 1],
  892. 'max' => (int)$SkillList[$i * 3 + 2]
  893. );
  894. }
  895.  
  896. //Filter the skills
  897. $temp = array();
  898. foreach ($SkillArr as $row)
  899. {
  900. if (in_array($row['skill'], $professions))
  901. {
  902. $temp[] = $row;
  903. }
  904. }
  905. //override the old SkillArr
  906. $SkillArr = $temp;
  907. unset($temp);
  908.  
  909. return $SkillArr;
  910. }
  911.  
  912. return false;
  913. }
  914.  
  915. //We can store the information about professions in array
  916. private function getProfessionInfo($id)
  917. {
  918. $data = array(
  919. //Primary
  920. 164 => array('name' => 'Blacksmithing', 'icon' => 'Trade_BlackSmithing', 'category' => 0),
  921. 165 => array('name' => 'Leatherworking', 'icon' => 'Trade_LeatherWorking', 'category' => 0),
  922. 171 => array('name' => 'Alchemy', 'icon' => 'Trade_Alchemy', 'category' => 0),
  923. 182 => array('name' => 'Herbalism', 'icon' => 'Trade_Herbalism', 'category' => 0),
  924. 186 => array('name' => 'Mining', 'icon' => 'Trade_Mining', 'category' => 0),
  925. 197 => array('name' => 'Tailoring', 'icon' => 'Trade_Tailoring', 'category' => 0),
  926. 202 => array('name' => 'Engineering', 'icon' => 'Trade_Engineering', 'category' => 0),
  927. 333 => array('name' => 'Enchanting', 'icon' => 'Trade_Engraving', 'category' => 0),
  928. 393 => array('name' => 'Skinning', 'icon' => 'INV_Misc_Pelt_Wolf_01', 'category' => 0),
  929. 755 => array('name' => 'Jewelcrafting', 'icon' => 'INV_Misc_Gem_01', 'category' => 0),
  930. 773 => array('name' => 'Inscription', 'icon' => 'INV_Inscription_Tradeskill01', 'category' => 0),
  931. //Secondery
  932. 129 => array('name' => 'First Aid', 'icon' => 'Spell_Holy_SealOfSacrifice', 'category' => 1),
  933. 185 => array('name' => 'Cooking', 'icon' => 'INV_Misc_Food_15', 'category' => 1),
  934. 356 => array('name' => 'Fishing', 'icon' => 'Trade_Fishing', 'category' => 1),
  935. 794 => array('name' => 'Archaeology', 'icon' => 'trade_archaeology', 'category' => 1),
  936. );
  937.  
  938. if (isset($data[(int)$id]))
  939. {
  940. return $data[(int)$id];
  941. }
  942.  
  943. return false;
  944. }
  945. }
Add Comment
Please, Sign In to add comment