예제 #1
0
 /**
  * Processes a vote toggle request (like/favorite etc).
  *
  * @param VoteForm $form
  * @return array
  * @throws \Exception
  * @throws \yii\base\InvalidConfigException
  */
 protected function processToggle(VoteForm $form)
 {
     /* @var $vote Vote */
     $module = $this->getModule();
     $vote = Vote::findOne(['entity' => $module->encodeEntity($form->entity), 'target_id' => $form->targetId, 'user_id' => Yii::$app->user->id]);
     if ($vote == null) {
         $response = $this->createVote($module->encodeEntity($form->entity), $form->targetId, $form->getValue());
         $response['toggleValue'] = 1;
     } else {
         $vote->delete();
         $response = ['success' => true, 'toggleValue' => 0];
     }
     return $response;
 }