Ejemplo n.º 1
0
 public function actionNew($type)
 {
     $model = new Razz();
     $model->scenario = 'create';
     if ($type == 'any') {
         $model->type = $model::ANYONE;
     }
     if ($type == 'some') {
         $model->type = $model::SOMEONE;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->type == 1 && !$model->fb_friend) {
             $this->redirect(['/razz/vote-on-challenges', 't' => 'some']);
         }
         if ($model->fb_friend) {
             $Razz = Yii::$app->request->post('Razz', null);
             if ($Razz['fileName'] != "") {
                 $linkToImg = \common\helpers\Ziggeo::getPreview($Razz['fileName']);
             } else {
                 $linkToImg = $model->preview;
             }
             $twitter = new \common\helpers\Twitter();
             $userModel = new \frontend\models\User();
             $userName = ucfirst($userModel->getFullname(Yii::$app->user->id));
             $recipientNick = $model->screen_name;
             $linkToRazzd = Url::base(true) . "/razz/respond/" . $model->id;
             $text = "@{$recipientNick} You have been Razzd by {$userName}: '{$model->title}' {$linkToRazzd}";
             $r = $twitter->tweet($text, ['image' => $linkToImg]);
             if ($twitter->hasErrors()) {
                 // Error
             } else {
                 if (isset($r['id'])) {
                     // Success
                 }
             }
             $this->redirect(['/razz/vote-on-challenges', 't' => 'some']);
             /*
              * Facebook
             $client = Yii::$app->authClientCollection->getClient('facebook');
             $host = 'http://' . $_SERVER['HTTP_HOST'];
             $this->redirect('http://www.facebook.com/dialog/send?app_id=' . $client->clientId . '&to=' . $model->fb_friend . '&link=' . $host . '/razz/respond?hash=' . $model->hash . '&redirect_uri=' . $host . '/razz/vote-on-challenges?t=some');
             */
         }
         if ($model->type == 2) {
             $this->redirect(['/razz/vote-on-challenges', 't' => 'any']);
         }
     } else {
         //print_r($model->getErrors());
         //exit();
     }
     return $this->render('new', ['model' => $model]);
 }