Beispiel #1
0
 public static function getRazzdUserVoted()
 {
     if (Yii::$app->user->isGuest) {
         return null;
     }
     $razz = new Razz();
     return $razz->getRazzdByUserVoted(Yii::$app->user->id);
 }
Beispiel #2
0
 /**
  * @param User $user
  * @param $accounts
  */
 public static function assignRazz(User $user, $accounts)
 {
     if (!empty($user->id) && !empty($user->email)) {
         Razz::updateAll(['responder_uid' => $user->id], 'responder_uid IS NULL AND email = :email', [':email' => $user->email]);
     }
     if (!empty($accounts)) {
         foreach ($accounts as $provider => $account) {
             if ($provider == 'facebook' && !empty($account->user_id)) {
                 Razz::updateAll(['responder_uid' => $account->user_id], 'responder_uid IS NULL AND facebook_id = :facebook', [':facebook' => $account->client_id]);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * @param $id
  * @param $stream
  * @param $stream_preview
  * @param bool|false $isRespond
  * @param string $class
  * @param bool $showPlayer - выводить Ziggeo player
  * @return string
  */
 static function getImage($id, $stream, $stream_preview, $isRespond = false, $class = "video-preview", $showPlayer = false)
 {
     $image = "<img class=\"no-image\" src=\"" . Url::base(true) . "" . \common\helpers\Html::noImage() . "\" >";
     ///$default_ext = ".mp4";
     if (is_null($stream)) {
         return $image;
     }
     $ziggeo_video_url = Yii::$app->params['ziggeo']['video_url'] . "/" . Yii::$app->params['ziggeo']['api_version'] . "/applications/" . Yii::$app->params['ziggeo']['application_token'] . "/videos/:token/video.mp4";
     $scheme = "";
     // Stream is an Image
     if (preg_match('/^http(s)?:\\/\\/([\\w\\d-\\.]*)(.)*\\.(png|jpg|jpeg|gif|wav|mp3|mp4)$/i', $stream) and is_null($stream_preview)) {
         return $image;
     }
     if (preg_match('/^http(s)?:\\/\\/([\\w\\d-\\.]*)(.)*\\.(png|jpg|jpeg|gif|wav|mp3|mp4)$/i', $stream_preview)) {
         // Stream is pure Url
         $image = "<img class=\"{$class}\"  data-video=\"{$stream}\" src=\"{$stream_preview}\">";
     } elseif (preg_match('/(http(s)?:\\/\\/){0,1}[a-z\\.]*ziggeo(.)*/i', $stream_preview)) {
         // Preview is Ziggeo url
         if ($showPlayer === true) {
             $image = self::getPlayer($stream);
         } else {
             if (!preg_match('/http/i', $stream_preview)) {
                 $scheme = "http://";
             }
             $src = str_replace(':token', $stream, $ziggeo_video_url);
             $image = "<img class=\"{$class}\"  data-video=\"{$src}\" src=\"{$scheme}{$stream_preview}\">";
         }
     } else {
         if (preg_match('/([\\w\\d])*/i', $stream) and !preg_match('/(http)/i', $stream) or is_null($stream_preview)) {
             // It seems like Stream is a Ziggeo Token
             if (is_null($stream_preview)) {
                 // Запросить урл имаджа через апи и положить его в базу
                 try {
                     $video = self::getInstance()->videos()->get($stream);
                     if (is_object($video)) {
                         ///$default_ext = $video->default_stream->video_type;
                         if (isset($video->embed_image_url)) {
                             $src = str_replace(':token', $stream, $ziggeo_video_url);
                             $image = "<img class=\"{$class}\" data-video=\"{$src}\" src=\"http://{$video->embed_image_url}\">";
                             $razz = Razz::findOne($id);
                             $razz->pureUpdate = true;
                             if ($isRespond) {
                                 $razz->responder_stream_preview = $video->embed_image_url;
                             } else {
                                 $razz->stream_preview = $video->embed_image_url;
                             }
                             $razz->fb_friend = $razz->facebook_id;
                             if (!$razz->save()) {
                                 self::addError(serialize($razz->getErrors()));
                                 $logger = Yii::$app->getLog()->getLogger();
                                 $logger->log('ZiggeoHelper error', \yii\log\Logger::LEVEL_INFO);
                                 $logger->log($razz->getErrors(), \yii\log\Logger::LEVEL_ERROR);
                             }
                         }
                     }
                 } catch (ZiggeoException $e) {
                     self::addError($e->getMessage());
                 }
             } else {
                 // Только сгенерить имадж
                 // FIXME - Сюда заходит, когда в базе битый урл
                 $razz = Razz::findOne($id);
                 $video_src = str_replace(':token', $stream, $ziggeo_video_url);
                 if ($isRespond) {
                     $preview = $razz->responder_stream_preview;
                 } else {
                     $preview = $razz->stream_preview;
                 }
                 if (!preg_match('/http/i', $preview)) {
                     $preview = "http://" . $preview;
                 }
                 $image = "<img class=\"{$class}\" data-video=\"{$video_src}\" src=\"{$preview}\">";
             }
             if ($showPlayer === true) {
                 $image = self::getPlayer($stream);
             }
         }
     }
     return $image;
 }
Beispiel #4
0
 /**
  * Get the particular razzd; output on individual screen
  * @param $id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionView($id)
 {
     $razzModel = new Razz();
     $razzSearch = new RazzSearch();
     $razzModel->toch($id);
     $object = $razzModel->getRazz($id);
     if (!$object || !$object['responder_uid']) {
         throw new NotFoundHttpException('Razzd not found');
     }
     $razzModel->end($object);
     $commentModel = new Comments();
     $commentModel->eid = $id;
     if ($commentModel->load(Yii::$app->request->post()) && $commentModel->save()) {
         if (Yii::$app->request->isAjax) {
             return $this->renderPartial('comments', ['model' => $commentModel]);
         }
         return $this->redirect(['/razz/' . $id]);
     }
     return $this->render('view', ['commentModel' => $commentModel, 'razzModel' => $razzModel, 'razzSearch' => $razzSearch, 'object' => $object]);
 }
Beispiel #5
0
 private function total_views()
 {
     $razzModel = new Razz();
     $total = $razzModel->getViewsTotalByUserRazzd($this->user->id);
     if (isset($total['views'])) {
         return $total['views'];
     }
     return null;
 }
Beispiel #6
0
 public function actionIndex()
 {
     $razzModel = new Razz();
     $razzSearch = new RazzSearch();
     // FIXME [?] if needed
     $razzSearch->freshOnly = true;
     $object = false;
     $i = 0;
     while (!$object) {
         $id = $razzModel->getRazzRandom($fresh = true);
         $object = $razzModel->getRazz($id, $fresh);
         $i++;
         if ($i > 50) {
             break;
         }
     }
     if (!$object || !$object['responder_uid']) {
         return $this->render('/razz/view', []);
         //throw new NotFoundHttpException('Razzd not found');
     }
     $razzModel->toch($id);
     $commentModel = new Comments();
     $commentModel->eid = $id;
     return $this->render('/razz/view', ['commentModel' => $commentModel, 'razzModel' => $razzModel, 'razzSearch' => $razzSearch, 'object' => $object]);
 }
Beispiel #7
0
 public function actionRazzVote()
 {
     $request = Yii::$app->request;
     $token = Token::checkToken($request->get('token'));
     if (!is_array($token)) {
         throw new HttpException(401, $token);
     }
     $model = new Razz();
     $razz = $model->getRazz($request->get('id'));
     if (!$razz) {
         throw new HttpException(404, 'Razzd not found.');
     }
     if (!$razz['responder_stream']) {
         throw new HttpException(422, 'Razzd is not started.');
     }
     if ($razz['created_at'] + Razz::DAYS < time()) {
         throw new HttpException(422, 'Razzd is ended.');
     }
     $ratingModel = Yii::createObject(['class' => \frontend\widgets\rating\models\Rating::className(), 'nid' => $request->get('id'), 'model' => 'Razz', 'vote' => $request->get('vote') == 'my' ? ['my' => 1] : ['responder' => 1], 'uid' => $token['user_id']]);
     if ($ratingModel->save()) {
         return RestApi::response($ratingModel->return);
     }
     return RestApi::response($ratingModel->return);
 }