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]); }
/** * 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]); }
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); }