Guest User

Untitled

a guest
Jan 9th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1.          $standingsRes = $client->get($endpoint, $standings_headers);
  2.            $standingsResp = json_decode($standingsRes->getBody());
  3.            if(count($standingsResp > 0)) {
  4.               $factionStandings = array();
  5.               $corpStandings = array();
  6.               foreach($standingsResp as $st) {
  7.                  if($st->from_type == 'faction') {      
  8.                    $ret = Faction::where('faction_id', $st->from_id)->first();
  9.                    array_push($factionStandings, array('from_id' => $st->from_id, 'from_type' => $st->from_type, 'faction_name' => $ret->faction_name, 'standing' => $st->standing));
  10.                  } elseif($st->from_type == 'npc_corp') {
  11.                    $retC = NpcCorp::where('corp_id', $st->from_id)->first();
  12.                    if(!isset($retC->corp_name)) {
  13.                        $endpoint = "https://esi.tech.ccp.is/latest/corporations/$st->from_id";
  14.                        $corp_headers = [
  15.                            'headers' => [
  16.                                'User-Agent' => env('USERAGENT'),
  17.                            ],
  18.                            'query' => [
  19.                                 'datasource' => 'tranquility',
  20.                            ]
  21.                        ];
  22.                        $corpRes = $client->get($endpoint, $corp_headers);
  23.                        $corpResp = json_decode($corpRes->getBody());
  24.                        $newCorp = new NpcCorp;
  25.                        $newCorp->corp_id = $st->from_id;
  26.                        $newCorp->corp_name = $corpResp->name;
  27.                        $newCorp->save();
  28.                        
  29.                        array_push($corpStandings, array('from_type' => $st->from_type, 'standing' => $st->standing, 'from_id' => $st->from_id, 'name' => $corpResp->name));
  30.                    } else {
  31.                        array_push($corpStandings, array('from_type' => $st->from_type, 'standing' => $st->standing, 'from_id' => $st->from_id, 'name' => $retC->corp_name));
  32.                    }
  33.                    } else {
  34.                      //Don't care about Agents for now
  35.                      continue;
  36.                    }
  37.                    
  38.                  }
  39.               }
  40.               $resp->{'factionStandings'} = $factionStandings;
  41.               $resp->{'corpStandings'} = $corpStandings;
  42.            }
Advertisement
Add Comment
Please, Sign In to add comment