Ejemplo n.º 1
0
 public function actionLike()
 {
     if (!\Yii::$app->getRequest()->getIsPost()) {
         return 'try agaen';
     }
     if (\Yii::$app->getRequest()->getHeaders()->get('x-like') !== 'True') {
         return 'try agaen';
     }
     $pictureId = \Yii::$app->getRequest()->post('p');
     $hash = \Yii::$app->getRequest()->post('h');
     $picture = Picture::find()->where(['id' => $pictureId])->one();
     /* @var Picture $picture */
     if ($picture == null) {
         return 'try agaen';
     }
     if ($picture->getLikeHash() !== $hash) {
         return 'try agaen';
     }
     $like = Like::find()->where(['ip' => \Yii::$app->getRequest()->getUserIP(), 'pictureId' => $picture->getPrimaryKey()])->count();
     if ($like > 0) {
         return 'pls stap';
     }
     $like = new Like();
     $like->ip = \Yii::$app->getRequest()->getUserIP();
     $like->pictureId = $picture->getPrimaryKey();
     $like->save();
     $picture->likeCount += 1;
     $picture->save();
     return '+' . $picture->likeCount;
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Like model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Like();
     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.º 3
0
 /**
  * Добавить лайк к сообщению
  * @return mixed
  */
 public function actionNewLike()
 {
     $msg = Yii::$app->request->post();
     $user_set_like = (int) Like::find()->where(['message_id' => $msg['message_id'], 'user_name' => $this->current_user])->count();
     if ($user_set_like === 0) {
         $like = new Like();
         $like->message_id = $msg['message_id'];
         $like->user_name = $msg['user_name'];
         $like->save();
         return Like::find()->where(['message_id' => $msg['message_id']])->count();
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 public function actionLike($id)
 {
     $apartment = $this->findModel($id);
     if ($apartment) {
         //            $apartment->setlike();
         //            $apartment->save();
         //            if($apartment->like == 1){
         $like = new Like();
         $like->url = $apartment->url;
         $like->title = $apartment->title;
         $like->save();
         $like->link('apartment', $apartment);
         //            }else{
         //                $like = Like::findOne(['id'=>$apartment]);
         //                $like->unlink('apartment', $apartment);
         //            }
         return 'ok';
     }
     return 'error';
 }