/** * Store a newly created resource in storage. * * @return Response */ public function getRate($question_id, $user_rate) { /*check for user_id if has rated we don't accept else continue other soloution is: on route we use auth filter but this is just for beta using. */ if (Auth::check() == 1) { $count = DB::table('rates')->where('question_id', $question_id)->where('user_id', Auth::id())->count(); if ($count == 0) { $newRate = new Rate(); $newRate->question_id = $question_id; $newRate->user_id = Auth::id(); $newRate->user_rate = $user_rate; $newRate->save(); return Redirect::back(); } else { return "already Voted!"; } } else { return "Only member can vote to audiopedias"; } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Rate(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Rate'])) { $model->attributes = $_POST['Rate']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionAdd() { $model = new Rate; if(isset($_POST['Rate'])){ $model->name = $_POST['Rate']['name']; $model->symbol = $_POST['Rate']['symbol']; $model->code = $_POST['Rate']['code']; $model->rate = $_POST['Rate']['rate']; $model->status = $_POST['Rate']['status']; if($model->save()){ Yii::app()->user->setFlash('success','添加成功!'); $this->redirect(array('list')); }else{ Yii::app()->user->setFlash('error','添加失败!'); } } $this->render('add',array( 'model'=>$model, )); }
/** * * */ public function actionCreateRate($id) { $model = $this->loadModel($id); $Rate = new Rate(); $Rate->attributes = $_POST['Rate']; $Rate->userId = Yii::app()->user->id; $Rate->rateableEntityId = $model->entityId; $Rate->addTime = $Rate->upTime = time(); if (!isset($_POST['Rate']['score'])) { // Case: 没有打分 $rateDataProvider = $model->getRateDataProvider(array('criteria' => array('order' => 'addTime DESC'))); $html = $this->renderPartial('_viewRate_panel_rate', array('rateDataProvider' => $rateDataProvider), true); $html .= '<script>alert("请给课程打分,再一起发表评价");</script>'; echo json_encode(array('html' => $html, 'error' => 1)); } else { // Case: 有打分 if ($Rate->save()) { $rateDataProvider = $model->getRateDataProvider(array('criteria' => array('order' => 'addTime DESC'))); $html = $this->renderPartial('_viewRate_panel_rate', array('rateDataProvider' => $rateDataProvider), true); echo json_encode(array('html' => $html, 'error' => 0)); } } }
private static function refreshRatePrices(Rate $rate) { $where['RateId'] = $rate->getId(); $where['Done'] = 0; $where['Type'] = OrderType::BUY; $buyDeals = Deal::findBy($where); $where['Type'] = OrderType::SELL; $sellDeals = Deal::findBy($where); $getOnlyPrices = function ($deals) { return $deals['Price']; }; $isUpdated = false; if (!empty($buyDeals)) { $buyPrices = array_map($getOnlyPrices, $buyDeals); $bid = max($buyPrices); if ($rate->getBid() != $bid) { $rate->setBid($bid); $rate->save(); $isUpdated = true; } } if (!empty($sellDeals)) { $sellPrices = array_map($getOnlyPrices, $sellDeals); $ask = min($sellPrices); if ($rate->getAsk() != $ask) { $rate->setAsk($ask); $rate->save(); $isUpdated = true; } } return $isUpdated; }