Esempio n. 1
0
 public function create(array $params)
 {
     $form = new \Kingboard\Lib\Forms\BattleCreateForm();
     if (!$form->validate($_POST)) {
         // @todo handle invalid
         return $this->error("form is not valid");
     }
     $user = \Kingboard\Lib\Auth\Auth::getUser();
     $key = $form->apiKey;
     $scope = "char";
     // for now we default to char. Account keys are never corp keys.
     if ($key['type'] == "Character") {
         $scope = "char";
     }
     if ($key['type'] == "Corporation") {
         $scope = "corp";
     }
     $pheal = new Pheal($key['apiuserid'], $key['apikey'], $scope);
     $contacts = $pheal->ContactList(array('characterID' => $form->character));
     // reset to neutral pheal
     $pheal = new Pheal();
     $characterInfo = $pheal->eveScope->CharacterInfo(array('characterID' => $form->character));
     $positives = array();
     foreach ($contacts->corporateContactList as $contact) {
         // accumulate postive standings
         if ($contact->standing > 0) {
             $positives[$contact->contactID] = $contact->contactName;
         }
     }
     // alliance standings override corp standings
     foreach ($contacts->allianceContactList as $contact) {
         if ($contact->standing > 0) {
             $positives[$contact->contactID] = $contact->contactName;
         } else {
             // negative standings, we only need those if corp has positive, but alliance negative
             if (isset($positives[$contact->contactID])) {
                 unset($positives[$contact->contactID]);
             }
         }
     }
     $battleSetting = new \Kingboard\Model\BattleSettings();
     $battleSetting->startdate = new \MongoDate(strtotime($_POST['startdate']));
     $battleSetting->user = $user->_id;
     $battleSetting->enddate = new \MongoDate(strtotime($_POST['enddate']));
     $battleSetting->system = $_POST['system'];
     $battleSetting->key = $key;
     // lets fix some info about the creator of this report
     $battleSetting->ownerCharacter = $form->character;
     $battleSetting->ownerCharacterName = $characterInfo->characterName;
     $battleSetting->ownerCorporation = (int) $characterInfo->corporationID;
     $battleSetting->ownerCorporationName = $characterInfo->corporation;
     $battleSetting->ownerAlliance = (int) $characterInfo->allianceID;
     $battleSetting->ownerAllianceName = $characterInfo->alliance;
     $battleSetting->positives = $positives;
     $battleSetting->runs = 0;
     $battleSetting->nextRun = new \MongoDate(time());
     $battleSetting->save();
     // we are done here, lets redirect to the battle!
     $this->redirect("/battle/" . $battleSetting->_id);
 }
 public function updateMarketInformation()
 {
     if (2097152 & $this->accessMask and 67108864 & $this->accessMask) {
         $pheal = new Pheal($this->keyID, $this->vCode, 'char');
         try {
             // Wallet Journal pull
             $response = $pheal->WalletJournal(array("characterID" => $this->characterID, "rowCount" => 2560));
             $stmtJournal = $this->db->prepare('INSERT INTO user_walletjournal (character_id,journal_id,journal_date,journal_type,journal_fromname,journal_fromid,journal_toname,journal_toid,journal_specialid,journal_specialname,journal_amount,journal_balance,journal_reason) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE journal_amount=VALUES(journal_amount)');
             foreach ($response->transactions as $transaction) {
                 $stmtJournal->execute(array($this->characterID, $transaction->refID, $transaction->date, $transaction->refTypeID, $transaction->ownerName1, $transaction->ownerID1, $transaction->ownerName2, $transaction->ownerID2, $transaction->argID1, $transaction->argName1, $transaction->amount, $transaction->balance, $transaction->reason));
             }
             // Contracts pull
             $response = $pheal->Contracts(array('characterID' => $this->characterID));
             $stmtContract = $this->db->prepare('INSERT INTO user_contracts (character_id,contract_id,contract_issuerid,contract_issuercorpid,contract_assigneeid,contract_acceptorid,contract_startstationid,' . 'contract_endstationid,contract_type,contract_status,contract_title,contract_forcorp,contract_availability,contract_dateissued,contract_dateexpired,contract_dateaccepted,' . 'contract_numdays,contract_datecompleted,contract_price,contract_reward,contract_collateral,contract_buyout,contract_volume) VALUES ' . '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE contract_acceptorid=VALUES(contract_acceptorid),contract_status=VALUES(contract_status),' . 'contract_dateaccepted=VALUES(contract_dateaccepted),contract_dateexpired=VALUES(contract_dateexpired),contract_datecompleted=VALUES(contract_datecompleted)');
             foreach ($response->contractList as $contract) {
                 $stmtContract->execute(array($this->characterID, $contract->contractID, $contract->issuerID, $contract->issuerCorpID, $contract->assigneeID, $contract->acceptorID, $contract->startStationID, $contract->endStationID, $contract->type, $contract->status, $contract->title, $contract->forCorp, $contract->availability, $contract->dateIssued, $contract->dateExpired, $contract->dateAccepted, $contract->numDays, $contract->dateCompleted, $contract->price, $contract->reward, $contract->collateral, $contract->buyout, $contract->volume));
             }
             // Contact List pull
             $response = $pheal->ContactList(array("characterID" => $this->characterID));
             $stmtJournal = $this->db->prepare('INSERT INTO user_contactlist (character_id,contact_type,contact_id,contact_name,contact_inwatchlist,contact_standing) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE contact_inwatchlist=VALUES(contact_inwatchlist),contact_standing=VALUES(contact_standing)');
             foreach ($response->contactList as $contact) {
                 $stmtJournal->execute(array($this->characterID, 'personal', $contact->contactID, $contact->contactName, $contact->inWatchlist, $contact->standing));
             }
             return TRUE;
         } catch (\Pheal\Exceptions\PhealException $phealException) {
             // Putting the pheal exception through our test function to determine if it's a key failure, or an API server failure.
             $this->testAPIKeyStatus($phealException);
             return FALSE;
         }
     } else {
         return TRUE;
     }
 }