Ejemplo n.º 1
0
 public function import($devices)
 {
     $subscriptionCount = 0;
     foreach ($devices as $device) {
         if (isset($device['type']) && isset($device['address'])) {
             if (!($deviceModel = Device::find()->where(array('type' => $device['type'], 'address' => $device['address']))->one())) {
                 $deviceModel = new Device();
             }
         }
         $deviceModel->setAttributes($device);
         $identity = Yii::$app->user->identity;
         $deviceModel->user = $identity->id;
         //return $identity->id;
         if ($deviceModel->save()) {
             $deviceIndex = $deviceModel->getPrimaryKey();
             //return $deviceIndex;
             if (isset($device['services'])) {
                 //die(print_r($device['services'],true));
                 $subscriptionCount += Service::import($device['services'], $deviceIndex);
             }
         }
         /*else {
               return $deviceModel->getErrors();
           }*/
         return $subscriptionCount;
     }
 }
Ejemplo n.º 2
0
 /**
  * Store device to our db
  *
  */
 public function store($userId, $device = null)
 {
     if ($device == null) {
         $device = new Device(['device_uuid' => \Request::get('device_uuid'), 'model' => \Request::get('model'), 'manufacturer' => \Request::get('manufacturer'), 'user_id' => $userId]);
     }
     $device->save();
     return $device;
 }
 /**
  * Creates a new Device model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Device();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 public static function newDevice($userId, $deviceName, $deviceToken)
 {
     $device = new Device();
     $device->user_id = $userId;
     $device->device_name = $deviceName;
     $device->device_token = $deviceToken;
     $device->created_at = Carbon::now()->toDateTimeString();
     $device->save();
     return $device;
 }
Ejemplo n.º 5
0
 static function createIfNew($domain, $node, $lat, $lng, $address = null)
 {
     $dev = self::find()->where(['domain' => $domain, 'node' => $node])->one();
     if (!$dev) {
         $dev = new Device();
         $dev->domain = $domain;
         $dev->node = $node;
         $dev->lat = $lat;
         $dev->lng = $lng;
         $dev->address = $address;
         $dev->save();
     }
 }
 /**
  * Creates a new Device model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Device();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = time();
         $model->update_at = time();
         $model->add_username = Yii::$app->user->identity->username;
         $model->update_username = Yii::$app->user->identity->username;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id, 'sys_n' => $model->sys_n]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 7
0
 /**
  * Link new device to a user
  *
  * @param String $platform
  * @param Request $request
  * @return Response
  */
 public function putDevice($platform, Request $request)
 {
     if (!$this->appKeyAvailable($request)) {
         return $this->notAuthorized($request);
     }
     if ($this->isSessionEmpty($request)) {
         $this->setResultError("Session token is missing", 401);
     } elseif (!$request->get('token') || !$request->get('udid')) {
         $this->setResultError("Token and UDID are both required.", 400);
     } elseif (strtolower($platform) != 'android' && strtolower($platform) != 'ios') {
         $this->setResultError("Only iOS & Android are currently supported.", 400);
     } elseif ($this->setSessionUser($request)) {
         $device = new Device();
         Device::updateOrCreate(['platform' => strtolower($platform), 'udid' => $request->get('udid'), 'environment' => getenv(strtoupper($platform) . '_PUSH_ENVIRONMENT'), 'user_id' => $this->user->id], ['token' => $request->get('token')]);
         $device->save();
         $this->setResultOk();
     } else {
         $this->setResultError("Mismatched session token", 401);
     }
     return $this->setResponse();
 }