%PDF- %PDF-
Direktori : /www/old2/_music/diplomka/diplomka/src/API/app/model/ |
Current File : /www/old2/_music/diplomka/diplomka/src/API/app/model/Inventory.php |
<?php /** * Created by JetBrains PhpStorm. * User: E581905 * Date: 9/18/13 * Time: 6:11 PM * To change this template use File | Settings | File Templates. */ class Inventory { protected $collection; public function __construct() { $m = new MongoClient(); $db = $m->selectDB("ingress"); $this->collection = $db->selectCollection("inventory"); } public function getInventoryIds($playerName) { $query = array('owner' => $playerName); $fields = array('_id' => true, 'owner' => true, 'time' => true); $res = $this->collection->find($query, $fields); $data = array(); foreach($res as $r) { $obj = new stdClass(); $obj->id = (string)$r['_id']; $obj->owner = $r['owner']; $obj->time = $r['time']; $data[] = $obj; } return $data; } public function getInventoryShapshot($snapshotId) { // Try to create an MongoId object try { $id = new MongoId($snapshotId); } catch(Exception $e) { // If fails, return error object $obj = new stdClass(); $obj->error = "Invalid inventory snapshot ID"; return $obj; } $res = $this->collection->findOne(array('_id' => $id)); return $res; } public function getKeys($playerName) { $query = array('owner' => $playerName); $fields = array('keys' => true, 'owner' => true); $res = $this->collection->find($query, $fields); $res = $res->sort(array('_id' => -1)); $res = $res->limit(1); if($res->hasNext()) $res->next(); $data = $res->current(); $out = new stdClass(); $out->nickname = $data['owner']; $out->portalKeys = array(); foreach($data['keys'] as $key) { $out->portalKeys[$key['portalGuid']] = $key['amount']; } return $out; } }