Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Device {
- private $imei;
- private $sv;
- private $dateAdded;
- private $tac;
- private $brand;
- private $model;
- private $os;
- private $dbCon;
- function __construct($dbCon){
- $this->dbCon = $dbCon;
- }
- function __autoload($classname) {
- $filename = "./". $classname .".php";
- include_once($filename);
- }
- function setDeviceFromAstellia($astelliaInfo) {
- if (!empty($astelliaInfo)) {
- $this->setImei($astelliaInfo['imei']);
- $this->setTacBy($this->getImei());
- $this->setBrand($astelliaInfo['Manufacturer']);
- $this->setDateAdded($astelliaInfo['date']);
- $this->setModel($astelliaInfo['Mobile Type']);
- $this->setSv($astelliaInfo['sv']);
- if (!$this->exists()) {
- $this->persistNewDevice(0);
- } else if ($this->getBrand() != 'UNKNOWN' && $this->getPersistedBrand() == 'UNKNOWN') {
- $this->updatePersistedDeviceDetails();
- }
- return true;
- } else {
- return false;
- }
- }
- function setDeviceBy($tac) {
- $deviceInfo = $this->dbCon->select("deviceInfo", [
- "tac",
- "brand",
- "model",
- "date_added",
- "os"
- ], [
- "tac" => $tac
- ]);
- $deviceInfo = $deviceInfo[0];
- $this->setBrand($deviceInfo['brand']);
- $this->setTac($tac);
- $this->setModel($deviceInfo['model']);
- $this->setDateAdded($deviceInfo['date_added']);
- $this->setOs($deviceInfo['os']);
- }
- function setDeviceFromImeiSv($imei, $sv) {
- if (!empty($imei)) {
- $this->setImei($imei);
- $this->setTacBy($this->getImei());
- $this->setSv($sv);
- $deviceInfo = $this->getDeviceByTac($this->getTac());
- if (!empty($deviceInfo)) {
- $this->setBrand($deviceInfo['brand']);
- $this->setModel($deviceInfo['model']);
- $this->setDateAdded($deviceInfo['date_added']);
- } else {
- $this->setBrand("UNKNOWN");
- $this->setModel("[" . $this->getTac() . "]");
- $this->setDateAdded(date('Y-m-d H:i:s', time()));
- $this->persistNewDevice(1);
- }
- return true;
- } else {
- return false;
- }
- }
- function equals($device) {
- //error_log($device->getImei() . " == " . $this->getImei());
- if ( $device->getImei() != null && $this->getImei() != null ) {
- if ($device->getImei() == $this->getImei()) {
- return true;
- } else {
- return false;//array("newDevice:" => $this->getImei(), "device:" => $device->getImei());
- }
- } else {
- return false;
- }
- }
- function persistNewDevice($source) {
- $insert = $this->dbCon->insert("deviceInfo", [
- "tac" => $this->getTac(),
- "brand" => $this->getBrand(),
- "model" => $this->getModel(),
- "date_added" => $this->getDateAdded(),
- "source" => $source
- ]);
- return $insert;
- }
- function exists() {
- $result = $this->dbCon->select("deviceInfo", [
- "tac",
- "brand",
- "model"
- ], [
- "tac" => $this->getTac()
- ]);
- //$result = $result[0];
- //error_log("result: => " . var_dump($result) . "THIS => " . print_r($this->toString()));
- if ($result == null) {
- return false;
- } else {
- return true;
- }
- }
- function getOsList() {
- $deviceInfo = $this->dbCon->select("osVersion", "os",
- ["GROUP" => "os"]);
- //error_log($this->dbCon->log());
- return $deviceInfo;
- }
- function getOsVersionList($os) {
- $deviceInfo = $this->dbCon->select("osVersion", "osVersion", ["os" => $os]);
- return $deviceInfo;
- }
- function getPersistedBrand() {
- $result = $this->dbCon->select("deviceInfo", [
- "brand"
- ], [
- "tac" => $this->getTac()
- ]);
- return $result[0]['brand'];
- }
- function getAllBrands() {
- $brands = $this->dbCon->select("deviceInfo", "brand", [
- "GROUP" => "brand"
- ]);
- return $brands;
- }
- function updatePersistedDeviceDetails() {
- $result = $this->dbCon->update("deviceInfo",[
- "brand" => $this->getBrand(),
- "model" => $this->getModel(),
- "date_added" => date('Y-m-d H:i:s', time())
- ], [
- "tac" => $this->getTac()
- ]);
- error_log("Device Updated: " . $this->getBrand() . " | " . $this->getModel());
- }
- function getDeviceByTac($tac) {
- $deviceInfo = $this->dbCon->get("deviceInfo", [
- "tac",
- "brand",
- "model",
- "date_added",
- "os"
- ], [
- "tac" => $tac
- ]);
- if (isset($deviceInfo)) {
- return $deviceInfo;
- } else {
- return "";
- }
- }
- function getDeviceByModel($model, $tac) {
- $deviceInfo = $this->dbCon->select("deviceInfo", [
- "tac",
- "brand",
- "model",
- "date_added",
- "os"
- ], [
- "AND" => [
- "model" => $model,
- "tac[!]" => $tac
- ]
- ]);
- if (isset($deviceInfo[0])) {
- return $deviceInfo;
- } else {
- return [];
- }
- }
- function setTac($tac) {
- $this->tac = $tac;
- }
- function setTacBy($imei) {
- $this->setTac(substr($imei, 0, 8));
- }
- function setImei($imei) {
- if (strlen($imei) > 14) {
- $imei = substr($imei, 0, 14);
- } else if (strlen($imei) < 14) {
- $imei = 0 . $imei;
- }
- $this->imei = $imei;
- }
- function setDateAdded($dateAdded) {
- $this->dateAdded = $dateAdded;
- }
- function setBrand($brand) {
- $this->brand = $brand;
- }
- function setModel($model) {
- $this->model = $model;
- }
- function setSv($sv) {
- $this->sv = $sv;
- }
- function getSv() {
- return $this->sv;
- }
- function getTac() {
- return $this->tac;
- }
- function getImei() {
- return $this->imei;
- }
- function getDateAdded() {
- return $this->dateAdded;
- }
- function getBrand() {
- return $this->brand;
- }
- function getModel() {
- return $this->model;
- }
- /**
- * @return mixed
- */
- public function getOs()
- {
- return $this->os;
- }
- /**
- * @param mixed $os
- */
- public function setOs($os)
- {
- $this->os = $os;
- }
- public function toString() {
- $return = get_object_vars($this);
- unset($return['dbCon']);
- //unset($return['device']['dbCon']);
- return $return;
- }
- function printMe($object, $text) {
- echo "</br><b>" . $text . "</b> :: ";
- print_r($object->toString());
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement