public function actionSend()
 {
     if (Yii::$app->request->post("recipient_id")) {
         $recipient_id = Yii::$app->request->post("recipient_id");
         $text = Yii::$app->request->post("message");
         $sender_id = Yii::$app->request->post("sender_id");
         $recipientUser = Salamiuser::find()->where(['id' => $recipient_id])->one();
         $senderUser = Salamiuser::find()->where(['id' => $sender_id])->one();
         $message = new Messages();
         $message->sender_id = $senderUser->id;
         $message->recipient_id = $recipientUser->id;
         $message->text = $text;
         $message->state = "new";
         $saved = $message->save();
         $data = array('user_ids' => array($recipientUser->facebook_id), 'notification' => array("alert" => $text, "android" => array('payload' => array("sender" => $senderUser->facebook_id))));
         $ionicAppId = "70f2a984";
         $ionicApiSecret = "ec4839bfb9ea2daa2271b0149a0c18003a3672178f4e6485";
         $url = "https://push.ionic.io/api/v1/push";
         $content = json_encode($data);
         $curl = new curl\Curl();
         $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl->setOption(CURLOPT_POSTFIELDS, $content);
         $curl->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Ionic-Application-Id: ' . $ionicAppId, 'Content-Length: ' . strlen($content), 'Authorization: Basic ' . base64_encode($ionicApiSecret)));
         $response = $curl->post('https://push.ionic.io/api/v1/push');
         return $response;
     }
     return '{"error": "Invalid request parameters"}';
 }
 public function actionLikes()
 {
     $current_user = Salamiuser::find()->where(['id' => $_GET["user_id"]])->one();
     $query = new Query();
     $salami_ids = $query->select('salami_user.id')->from('salami_user')->join('INNER JOIN', 'likes', 'likes.user2_id = salami_user.id')->where(['likes.type' => 'like', 'likes.user1_id' => $current_user->id])->all();
     $salamiusers = Salamiuser::find()->joinWith('albums')->where(['id' => $salami_ids])->asArray()->all();
     return $salamiusers;
 }
Esempio n. 3
0
 public function getLikedusers()
 {
     return $this->hasMany(Salamiuser::className(), ['id' => 'user2_id'])->viaTable(Likes::tableName(), ['user1_id' => 'id']);
 }