PageRenderTime 29ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/eve/apiChar.php

http://ooe.googlecode.com/
PHP | 544 lines | 471 code | 67 blank | 6 comment | 140 complexity | 68df5bd93ea5ef0377688ab18127299b MD5 | raw file
  1. <?php
  2. class eveCharacter {
  3. var $characterID = 0;
  4. var $name = '';
  5. var $race = '';
  6. var $bloodLine = '';
  7. var $gender = '';
  8. var $corporationName = '';
  9. var $corporationID = '';
  10. var $balance = 0;
  11. var $skillPoints = 0;
  12. var $attributes = array();
  13. var $skills = array();
  14. var $trainingSkill = null;
  15. var $skillQueue = null;
  16. var $skillTree = null;
  17. var $certificates = array();
  18. var $certificateTree = null;
  19. var $outpostList = null;
  20. var $faction = null;
  21. var $assets = array();
  22. var $orders = array();
  23. var $transactions = array();
  24. var $journalItems = array();
  25. var $industryJobs = array();
  26. var $mail = array();
  27. var $notifications = array();
  28. var $contactNotifications = array();
  29. var $deaths = array();
  30. var $kills = array();
  31. var $corporation = null;
  32. var $db = null;
  33. function eveCharacter($account, $characterID, $autoLoad = true) {
  34. $this->db = $account->db;
  35. $this->account = $account;
  36. $this->characterID = $characterID;
  37. if ($autoLoad)
  38. $this->loadCharacter();
  39. }
  40. function loadCharacter() {
  41. $charData = new apiRequest('char/CharacterSheet.xml.aspx', array($this->account->userId,
  42. $this->account->apiKey,
  43. $this->characterID));
  44. if (!$charData->data)
  45. return;
  46. if ($charData->data->error)
  47. apiError('char/CharacterSheet.xml.aspx', $charData->data->error);
  48. foreach (get_object_vars($charData->data->result) as $var => $val) {
  49. if (!is_array($val) && !is_object($val))
  50. $this->$var = trim($val);
  51. }
  52. foreach ($charData->data->result->rowset as $rowset) {
  53. if ($rowset['name'] == 'skills') {
  54. foreach ($rowset->row as $skill) {
  55. $this->skills[(string)$skill['typeID']] = new eveKnownSkill($this->account, $this->db, $skill);
  56. $this->skillPoints += $this->skills[(string)$skill['typeID']]->skillPoints;
  57. }
  58. } else if ($rowset['name'] == 'certificates') {
  59. foreach ($rowset->row as $certificate) {
  60. $this->certificates[(string)$certificate['certificateID']] = new eveKnownCertificate($this->account, $this->db, $certificate);
  61. }
  62. }
  63. }
  64. foreach (get_object_vars($charData->data->result->attributes) as $var => $val) {
  65. $this->attributes[$var] = new eveAttribute($this->account, $charData, $var, $this);
  66. }
  67. $trainingData = new apiRequest('char/SkillInTraining.xml.aspx', array($this->account->userId,
  68. $this->account->apiKey,
  69. $this->characterID));
  70. if ($trainingData->data) {
  71. $this->trainingSkill = new eveTrainingSkill($this->account, $this->db, $trainingData->data->result);
  72. }
  73. $factionData = new apiRequest('char/FacWarStats.xml.aspx', array($this->account->userId,
  74. $this->account->apiKey,
  75. $this->characterID), null, false);
  76. if ($factionData->data) {
  77. if ((!$factionData->data->error) && (!(int)$factionData->data->gotError))
  78. $this->faction = new eveCharacterFaction($this->account, $this->db, $factionData->data->result);
  79. }
  80. $training = $this->getSkill($this->trainingSkill->typeID);
  81. if ($training && ($training != $this->trainingSkill)) {
  82. $training->inTraining = $this->trainingSkill->inTraining;
  83. $training->toLevel = $this->trainingSkill->toLevel;
  84. }
  85. }
  86. function loadCorporation() {
  87. $corpData = new apiRequest('corp/CorporationSheet.xml.aspx', array($this->account->userId,
  88. $this->account->apiKey,
  89. $this->characterID));
  90. if ($corpData->data && !$corpData->data->error) {
  91. $this->corporation = new eveCorporation($this->account, $this, $corpData);
  92. }
  93. }
  94. function loadAssets($typeFilter = false) {
  95. if (count($this->assets) == 0) {
  96. $assetData = new apiRequest('char/AssetList.xml.aspx', array($this->account->userId,
  97. $this->account->apiKey,
  98. $this->characterID),
  99. array('version' => 2));
  100. if ($assetData->data) {
  101. if (!$assetData->data->error) {
  102. foreach ($assetData->data->result->rowset->row as $asset) {
  103. $this->assets[] = new eveAsset($this->account, $this->db, $asset, $this);
  104. }
  105. } else {
  106. apiError('char/AssetList.xml.aspx', $assetData->data->error);
  107. }
  108. }
  109. }
  110. }
  111. function loadOrders() {
  112. if (count($this->orders) == 0) {
  113. $orderData = new apiRequest('char/MarketOrders.xml.aspx', array($this->account->userId,
  114. $this->account->apiKey,
  115. $this->characterID),
  116. array('version' => 2));
  117. if ($orderData->data) {
  118. if (!$orderData->data->error) {
  119. foreach ($orderData->data->result->rowset->row as $order) {
  120. $this->orders[] = new eveMarketOrder($this->account, $this->db, $order);
  121. }
  122. } else {
  123. apiError('char/MarketOrders.xml.aspx', $orderData->data->error);
  124. }
  125. }
  126. }
  127. }
  128. function loadTransactions($fromID = 0) {
  129. $params = array();
  130. $params['rowCount'] = $GLOBALS['config']['eve']['transaction_records'];
  131. if ($fromID > 0) {
  132. $params['fromID'] = $fromID;
  133. }
  134. if ((count($this->transactions) == 0) || ($fromID > 0)) {
  135. $transData = new apiRequest('char/WalletTransactions.xml.aspx', array($this->account->userId,
  136. $this->account->apiKey,
  137. $this->characterID),
  138. $params);
  139. if ($transData->data) {
  140. if (!$transData->data->error) {
  141. $gotRows = 0;
  142. foreach ($transData->data->result->rowset->row as $transaction) {
  143. $this->transactions[] = new eveTransaction($this->account, $this->db, $transaction, $this);
  144. $gotRows ++;
  145. }
  146. // keep looping requests until we receive no more results
  147. $lowest = lowestTransactionRef($this->transactions);
  148. if (($lowest != $fromID) && ($gotRows == $params['rowCount'])) {
  149. $this->loadTransactions($lowest);
  150. } else {
  151. // if this is the last run, sort all the items we have
  152. usort($this->transactions, 'transactionsSort');
  153. }
  154. } else {
  155. apiError('char/WalletTransactions.xml.aspx', $transData->data->error);
  156. }
  157. }
  158. }
  159. }
  160. function loadJournal($fromID = 0) {
  161. $params = array();
  162. $params['rowCount'] = $GLOBALS['config']['eve']['journal_records'];
  163. if ($fromID > 0) {
  164. $params['fromID'] = $fromID;
  165. }
  166. if ((count($this->journalItems) == 0) || ($fromID > 0)) {
  167. $journalData = new apiRequest('char/WalletJournal.xml.aspx', array($this->account->userId,
  168. $this->account->apiKey,
  169. $this->characterID),
  170. $params);
  171. if ($journalData->data) {
  172. if (!$journalData->data->error) {
  173. $gotRows = 0;
  174. foreach ($journalData->data->result->rowset->row as $journalItem) {
  175. $this->journalItems[] = new eveJournalItem($this->account, $this->db, $journalItem);
  176. $gotRows ++;
  177. }
  178. // keep looping journal requests until we receive no more results
  179. $lowest = lowestJournalRef($this->journalItems);
  180. if (($lowest != $fromID) && ($gotRows == $params['rowCount'])) {
  181. $this->loadJournal($lowest);
  182. } else {
  183. // if this is the last run, sort all the items we have
  184. usort($this->journalItems, 'journalSort');
  185. }
  186. } else {
  187. apiError('char/WalletJournal.xml.aspx', $journalData->data->error);
  188. }
  189. }
  190. }
  191. }
  192. function loadIndustryJobs() {
  193. if (count($this->industryJobs) == 0) {
  194. $jobData = new apiRequest('char/IndustryJobs.xml.aspx', array($this->account->userId,
  195. $this->account->apiKey,
  196. $this->characterID),
  197. array('version' => 2));
  198. if ($jobData->data) {
  199. if (!$jobData->data->error) {
  200. foreach ($jobData->data->result->rowset->row as $job) {
  201. $this->industryJobs[] = new eveIndustryJob($this->account, $this->db, $job);
  202. }
  203. } else {
  204. apiError('char/IndustryJobs.xml.aspx', $jobData->data->error);
  205. }
  206. }
  207. }
  208. }
  209. function loadKills() {
  210. $killData = new apiRequest('char/KillLog.xml.aspx', array($this->account->userId,
  211. $this->account->apiKey,
  212. $this->characterID),
  213. array('version' => 2));
  214. if ($killData->data) {
  215. if (!$killData->data->error) {
  216. foreach ($killData->data->result->rowset->row as $kill) {
  217. if ((int)$kill->victim['characterID'] == $this->characterID)
  218. $this->deaths[] = new eveKill($this->account, $this->db, $kill);
  219. else
  220. $this->kills[] = new eveKill($this->account, $this->db, $kill);
  221. }
  222. } else {
  223. apiError('char/KillLog.xml.aspx', $killData->data->error);
  224. }
  225. }
  226. }
  227. function loadMail() {
  228. if (count($this->mail) == 0) {
  229. $mailData = new apiRequest('char/MailMessages.xml.aspx', array($this->account->userId,
  230. $this->account->apiKey,
  231. $this->characterID),
  232. array('version' => 2));
  233. if ($mailData->data) {
  234. if (!$mailData->data->error) {
  235. foreach ($mailData->data->result->rowset->row as $mail) {
  236. $this->mail[] = new eveMailMessage($this->account, $mail);
  237. }
  238. } else {
  239. apiError('char/MailMessages.xml.aspx', $mailData->data->error);
  240. }
  241. }
  242. }
  243. // get list of character and corp names for messages
  244. if (count($this->mail) > 0) {
  245. usort($this->mail, 'mailSort');
  246. $ids = array();
  247. foreach ($this->mail as $mail) {
  248. if (!empty($mail->senderID) && $mail->senderID > 0) {
  249. $ids[] = $mail->senderID;
  250. }
  251. if (!empty($mail->toCorpID) && $mail->toCorpID > 0) {
  252. $ids[] = $mail->toCorpID;
  253. }
  254. $ids = array_merge($ids, $mail->toCharacterIDs);
  255. }
  256. $ids = array_unique($ids);
  257. $names = new apiRequest('eve/CharacterName.xml.aspx', null, array('ids' => implode(',', $ids)));
  258. if ($names->data) {
  259. if (!$names->data->error) {
  260. foreach ($names->data->result->rowset->row as $name) {
  261. for ($i = 0; $i < count($this->mail); $i++) {
  262. if ($this->mail[$i]->senderID == (int)$name['characterID']) {
  263. $this->mail[$i]->senderName = (string)$name['name'];
  264. }
  265. if ($this->mail[$i]->toCorpID == (int)$name['characterID']) {
  266. $this->mail[$i]->toCorpName = (string)$name['name'];
  267. }
  268. for ($j = 0; $j < count($this->mail[$i]->toCharacterIDs); $j++) {
  269. if ($this->mail[$i]->toCharacterIDs[$j] == (int)$name['characterID']) {
  270. $this->mail[$i]->toCharacterNames[$j] = (string)$name['name'];
  271. }
  272. }
  273. }
  274. }
  275. } else {
  276. apiError('eve/CharacterName.xml.aspx', $names->data->error);
  277. }
  278. }
  279. }
  280. }
  281. function getMailMessage($message) {
  282. $result = false;
  283. $mailData = new apiRequest('char/MailBodies.xml.aspx', array($this->account->userId,
  284. $this->account->apiKey,
  285. $this->characterID),
  286. array('version' => 2,
  287. 'ids' => $message->messageID));
  288. if ($mailData->data) {
  289. if (!$mailData->data->error) {
  290. foreach ($mailData->data->result->rowset->row as $mail) {
  291. if ((int)$mail['messageID'] == $message->messageID) {
  292. $result = new eveMailMessageBody($this->account, $mail);
  293. $result->headers = $message;
  294. }
  295. }
  296. } else {
  297. apiError('char/MailBodies.xml.aspx', $mailData->data->error);
  298. }
  299. }
  300. return $result;
  301. }
  302. function loadNotifications() {
  303. if (count($this->notifications) == 0) {
  304. $notificationData = new apiRequest('char/Notifications.xml.aspx', array($this->account->userId,
  305. $this->account->apiKey,
  306. $this->characterID),
  307. array('version' => 2));
  308. if ($notificationData->data) {
  309. if (!$notificationData->data->error) {
  310. foreach ($notificationData->data->result->rowset->row as $notification) {
  311. $this->notifications[] = new eveNotification($this->account, $notification);
  312. }
  313. } else {
  314. apiError('char/Notifications.xml.aspx', $notificationData->data->error);
  315. }
  316. }
  317. $notificationData = new apiRequest('char/ContactNotifications.xml.aspx', array($this->account->userId,
  318. $this->account->apiKey,
  319. $this->characterID),
  320. array('version' => 2));
  321. if ($notificationData->data) {
  322. if (!$notificationData->data->error) {
  323. foreach ($notificationData->data->result->rowset->row as $notification) {
  324. $this->contactNotifications[] = new eveNotificationContact($this->account, $notification);
  325. }
  326. } else {
  327. apiError('char/ContactNotifications.xml.aspx', $notificationData->data->error);
  328. }
  329. }
  330. }
  331. // get list of character and corp names for messages
  332. if (count($this->notifications) > 0) {
  333. $ids = array();
  334. foreach ($this->notifications as $note) {
  335. if ((!empty($note->senderID) && $note->senderID > 0)
  336. && ($note->item->itemid == 0)) {
  337. $ids[] = $note->senderID;
  338. }
  339. }
  340. $ids = array_unique($ids);
  341. $names = new apiRequest('eve/CharacterName.xml.aspx', null, array('ids' => implode(',', $ids)));
  342. if ($names->data) {
  343. if (!$names->data->error) {
  344. foreach ($names->data->result->rowset->row as $name) {
  345. for ($i = 0; $i < count($this->notifications); $i++) {
  346. if ($this->notifications[$i]->senderID == (int)$name['characterID']) {
  347. $this->notifications[$i]->senderName = (string)$name['name'];
  348. }
  349. }
  350. }
  351. } else {
  352. apiError('eve/CharacterName.xml.aspx', $names->data->error);
  353. }
  354. }
  355. }
  356. usort($this->notifications, 'mailSort');
  357. }
  358. function getNotificationText($notification) {
  359. $result = false;
  360. $notificationData = new apiRequest('char/NotificationTexts.xml.aspx', array($this->account->userId,
  361. $this->account->apiKey,
  362. $this->characterID),
  363. array('version' => 2,
  364. 'ids' => $notification->notificationID));
  365. if ($notificationData->data) {
  366. if (!$notificationData->data->error) {
  367. foreach ($notificationData->data->result->rowset->row as $text) {
  368. if ((int)$text['notificationID'] == $notification->notificationID) {
  369. $result = new eveNotificationText($this->account, $text);
  370. $result->headers = $notification;
  371. }
  372. }
  373. } else {
  374. apiError('char/NotificationTexts.xml.aspx', $notificationData->data->error);
  375. }
  376. }
  377. return $result;
  378. }
  379. function loadSkillTree() {
  380. if ($this->skillTree == null) {
  381. $skillData = new apiRequest('eve/SkillTree.xml.aspx');
  382. if ($skillData->data) {
  383. if (!$skillData->data->error) {
  384. $this->skillTree = new eveSkillTree($this->account, $skillData->data->result);
  385. } else {
  386. apiError('eve/SkillTree.xml.aspx', $skillData->data->error);
  387. }
  388. }
  389. }
  390. }
  391. function loadSkillQueue() {
  392. if ($this->skillQueue == null) {
  393. $skillQueueData = new apiRequest('char/SkillQueue.xml.aspx', array($this->account->userId,
  394. $this->account->apiKey,
  395. $this->characterID),
  396. array('version' => 2));
  397. if ($skillQueueData->data) {
  398. if (!$skillQueueData->data->error) {
  399. $this->skillQueue = new eveSkillQueue($this->account, $this->db, $skillQueueData->data->result);
  400. } else {
  401. apiError('char/SkillQueue.xml.aspx', $skillQueueData->data->error);
  402. }
  403. }
  404. }
  405. }
  406. function loadCertificateTree() {
  407. if ($this->certificateTree == null) {
  408. $certData = new apiRequest('eve/CertificateTree.xml.aspx');
  409. if ($certData->data) {
  410. if (!$certData->data->error) {
  411. $this->certificateTree = new eveCertificateTree($this->account, $certData->data->result);
  412. } else {
  413. apiError('eve/CertificateTree.xml.aspx', $certData->data->error);
  414. }
  415. }
  416. }
  417. }
  418. function getSkill($typeID) {
  419. $result = isset($this->skills[$typeID]) ? $this->skills[$typeID] : false;
  420. if (!$result)
  421. if ($this->trainingSkill->typeID == $typeID)
  422. $result = $this->trainingSkill;
  423. return $result;
  424. }
  425. function knownSkills() {
  426. $result = array();
  427. for ($i = 0; $i < count($this->skillTree->groups); $i++) {
  428. for ($j = 0; $j < count($this->skillTree->groups[$i]->skills); $j++) {
  429. $knownSkill = $this->getSkill($this->skillTree->groups[$i]->skills[$j]->typeID);
  430. if (($knownSkill) || ($this->trainingSkill->typeID == $this->skillTree->groups[$i]->skills[$j]->typeID)) {
  431. if (!isset($result[$this->skillTree->groups[$i]->groupID])) {
  432. $theSkill = array();
  433. $theSkill['name'] = $this->skillTree->groups[$i]->groupName;
  434. $theSkill['skillpoints'] = 0;
  435. $theSkill['skills'] = array();
  436. $result[$this->skillTree->groups[$i]->groupID] = $theSkill;
  437. }
  438. $result[$this->skillTree->groups[$i]->groupID]['skillpoints'] += (int)$knownSkill->skillPoints;
  439. $result[$this->skillTree->groups[$i]->groupID]['skills'][] = array(
  440. 'typeID' => $this->skillTree->groups[$i]->skills[$j]->typeID,
  441. 'name' => $this->skillTree->groups[$i]->skills[$j]->typeName,
  442. 'description' => $this->skillTree->groups[$i]->skills[$j]->description,
  443. 'level' => (int)$knownSkill->level,
  444. 'skillpoints' => (int)$knownSkill->skillPoints,
  445. 'training' => (int)$knownSkill->inTraining,
  446. 'toLevel' => (int)$knownSkill->toLevel);
  447. }
  448. }
  449. }
  450. return $result;
  451. }
  452. function knownCertificates() {
  453. $result = array();
  454. foreach ($this->certificates as $certId => $knownCert) {
  455. $cert = $this->certificateTree->getCertificate($certId);
  456. $catId = $cert->cclass->category->categoryID;
  457. $clsId = $cert->cclass->classID;
  458. if (!isset($result[$catId])) {
  459. $result[$catId] = array();
  460. $result[$catId]['name'] = $cert->cclass->category->categoryName;
  461. $result[$catId]['classes'] = array();
  462. }
  463. if (!isset($result[$catId]['classes'][$clsId])) {
  464. $result[$catId]['classes'][$clsId] = array();
  465. $result[$catId]['classes'][$clsId]['name'] = $cert->cclass->className;
  466. $result[$catId]['classes'][$clsId]['grade'] = $cert->grade;
  467. $result[$catId]['classes'][$clsId]['icon'] = $cert->icon;
  468. }
  469. if ($cert->grade > $result[$catId]['classes'][$clsId]['grade']) {
  470. $result[$catId]['classes'][$clsId]['grade'] = $cert->grade;
  471. $result[$catId]['classes'][$clsId]['icon'] = $cert->icon;
  472. }
  473. }
  474. return $result;
  475. }
  476. }
  477. ?>