public function getOrCreate($serial, $user_id, $mac) { $device = $this->getByMac($mac); $result = parse_uagent($_SERVER['HTTP_USER_AGENT']); if (isset($device->id)) { return $device; } else { $gateway = $this->getGateway($serial); $id = $this->insert(array('owner_id' => $user_id, 'gateway_id' => $gateway->id, 'mac' => $mac, 'browser' => $result->ua->family, 'browser_version' => $result->ua->toVersion(), 'os' => $result->os->family, 'os_version' => $result->os->toVersion(), 'uagent' => $result->originalUserAgent)); return $this->load($id); } }
public function createDevice($mac, $uid = null) { if ($mac) { // TODO Validate the mac address $ua = parse_uagent($this->input->server('HTTP_USER_AGENT')); $arr = array('mac' => $mac, 'os' => $ua->os->family, 'os_version' => $ua->os->toVersion(), 'uagent' => $ua->originalUserAgent); if ($uid) { $arr['uid'] = $uid; } return $this->insert($arr); } return null; }
public function testUAParser() { $this->helper('uagent'); $agent = fake_uagent(); $result = parse_uagent($agent); $this->assertNotNull($result->os); $this->assertNotNull($result->device); $this->assertNotNull($result->ua); print_r($result); }