public function create(Request $request) { if ($request->isMethod('get')) { $this->data['items'] = Event::orderBy('created_at', 'desc')->get(); $this->data['questions'] = Question::get(); // return var_dump($this->data['questions']); return view('pages.event.create', $this->data); } elseif ($request->isMethod('post')) { $data = $request->all(); $event = Event::create($request->all()); $user = User::where('positionid', 1)->get(); foreach ($user as $lala) { $item = new Score(); $item->eventid = $event->id; $item->score = 0; $item->userid = $lala->id; $item->save(); } if ($event) { if (array_key_exists('questions', $data)) { $event->question()->sync($data['questions']); $event->update(['enabled' => 1]); } return redirect('event'); } else { return redirect('event'); } } }
public function store(Request $request) { $this->validate($request, ['title' => 'required', 'topic' => 'required|exists:topics,title', 'content' => 'required']); $post = Post::create($request->all()); Score::create(['user_id' => Auth::user()->id, 'reference' => 'post', 'score' => 50]); return redirect()->to('posts/' . $post->slug); }
public static function boot() { parent::boot(); static::saved(function ($model) { $targetKerja = TargetKerja::find($model->attributes['target_kerja_id']); // hitung nilai $nilais = []; if ($targetKerja->kuantitas) { // 1. Kuantitas = Realisasi Output / Target Output * 100 $nilais[] = $kuantitas = $model->attributes['kuantitas'] / $targetKerja->kuantitas * 100; } if ($targetKerja->kualitas) { // 2. Kualitas = Realisasi Output / Target Output * 100 $nilais[] = $kualitas = $model->attributes['kualitas'] / $targetKerja->kualitas * 100; } if ($targetKerja->waktu) { // 3. Waktu = (1.76 * Target Waktu - Realisasi Waktu) / Target Waktu * 100 $nilais[] = $waktu = (1.76 * $targetKerja->waktu - $model->attributes['waktu']) / $targetKerja->waktu * 100; } if ($targetKerja->biaya) { // 4. Biaya = (1.76 * Target Biaya - Realisasi Biaya) / Target Biaya * 100 $nilais[] = $biaya = (1.76 * $targetKerja->biaya - $model->attributes['biaya']) / $targetKerja->biaya * 100; } $total_nilai = collect($nilais)->sum(); $score = Score::firstOrNew(['target_kerja_id' => $targetKerja->id]); $score->fill(compact('kuantitas', 'kualitas', 'waktu', 'biaya', 'total_nilai')); $targetKerja->score()->save($score); $nilai = collect($nilais)->average(); $targetKerja->update(compact('nilai')); }); }
public function store(Request $request, Post $post) { $comment = Comment::create($request->all()); $post->comments()->save($comment); Score::create(['user_id' => Auth::user()->id, 'reference' => 'comment', 'score' => 2]); Auth::user()->increment('scores', 2); return redirect()->to('posts/' . $post->slug); }
/** * Save a new or existing topic * if the given topic is new, we add score to user * * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { $this->validate($request, ['title' => 'required|unique:topics,title', 'description' => 'required']); $topic = Topic::create($request->except('image')); $this->uploadImage($request, $topic); Score::create(['user_id' => Auth::user()->id, 'reference' => 'topic', 'score' => 5]); return redirect()->to('topics/' . $topic->slug); }
public function set($productId, $numberCommand) { $score = $this->score->where('product_id', '=', $productId)->get(); if (count($score) > 0) { $score->number_command += $numberCommand; } else { Score::create(['number_command' => $numberCommand, 'product_id' => $productId]); } }
public function handle(ScoreEvent $event) { $score = Product::find($event->productId)->score; if (!is_null($score)) { $score->number_command += $event->quantity; $score->score++; $score->save(); } else { Score::create(['product_id' => $event->id, 'score' => 1, 'number_command' => $event->quantity]); } }
public function get() { $instance = new Socialworth($this->post->url); $results = $instance->all(); // {'total': totalscore, 'facebook': facebookscore , 'twitter': twitterscore} // for calculating virality, create totalshares that gives more weight to twitter $totalShares = round(($results->facebook + 2 * $results->twitter) / 3 * 2); if ($this->post->score()->get()->count() > 0) { $score = $this->post->score; } else { $score = new Score(); } $score->twitter = $results->twitter; $score->facebook = $results->facebook; $score->total = $results->facebook + $results->twitter; $score->virality = $totalShares > 1 ? round(8 * log($totalShares)) : 2; // save the score $score->save(); // associate to $this->post->score()->save($score); }
public function get() { $instance = new Socialworth($this->post->url); $results = $instance->all(); // {'total': totalscore, 'facebook': facebookscore , 'twitter': twitterscore} // for calculating virality, create totalshares that gives more weight to twitter $totalShares = round(($results->facebook + 2 * $results->twitter) / 3 * 2); $score = Score::create(['twitter' => $results->twitter, 'facebook' => $results->facebook, 'total' => $results->facebook + $results->twitter, 'virality' => $totalShares > 1 ? round(8 * log($totalShares)) : 2]); // save the score $score->save(); // associate to $this->post->scores()->save($score); }
/** * Bootstrap any application services.customers * * @return void */ public function boot() { History::creating(function ($history) { $score = Score::find($history->product_id); if (!is_null($score)) { $score->score++; $score->number_command += $history->quantity; $score->save(); } else { Score::create(['score' => 1, 'number_command' => $history->quantity]); } }); }
/** * Add game to db * * @return \Illuminate\Http\RedirectResponse */ public function add() { $data = \Input::all(); if ($data) { $users = explode(',', $data['users']); $scores = $data['score']; $game = new Game(); $game->save(); $game_id = $game->id; foreach ($scores as $score_id => $score) { foreach ($users as $user_id) { $t_user_id = intval($user_id, 10); $t_score = intval($score[$t_user_id], 10); Score::create(['game_id' => $game_id, 'player_id' => $t_user_id, 'party_id' => $score_id, 'score' => $t_score]); } } return \Redirect::route('meet', $game->id); } return \Redirect::route('meets'); }
public function dept() { if (Auth::user()->position->id == 1) { $this->data['items'] = Score::where('userid', Auth::id())->get(); return view('pages.viewmark.staff', $this->data); } else { if (Request::isMethod('get')) { $this->data['events'] = Event::get(); $this->data['staffs'] = null; return view('pages.viewmark.yes', $this->data); } else { // dd(Input::all()); $this->data['events'] = Event::get(); $user = Score::where('eventid', Input::get('event'))->get(); foreach ($user as $key => $value) { if ($value->user->deptid != Auth::user()->deptid) { unset($user[$key]); } } $this->data['staffs'] = $user; return view('pages.viewmark.yes', $this->data); } } }
public function getRank(Request $request) { $data = $request->all(); $score = Score::orderBy('score', 'desc')->where('category_id', $data['category_id'])->get(); return response()->json(['RetCode' => '1', 'Content' => $score]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $data = Score::findOrFail($id); $data->delete(); Session::flash("flash_message", "User has been deleted"); return $this->goHome(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($groupId, $id) { $score = Score::findOrFail($id); // //if (Gate::denies('destroy-group', $group)) { // abort(403); //} // $group->delete(); return response()->json("ok"); }
public function load(Request $request) { $data = $request; $obj = Score::all(); return view('pages/users')->with(['data' => $obj]); }
public function getLockRepaired() { $rent = $this->user->rent()->lastRent()->first(); // 密码还原 $lastRent = $rent->bike->rent()->lastRent()->where('id', '!=', $rent->id)->first(); $rent->password = $lastRent->password; $rent->save(); // 上次还车导致损坏 $lastReturn = $rent->bike->rent()->lastReturn()->first(); $lastReturn->broken_type = 'lock'; $lastReturn->broken_desp = '未改密码'; $lastReturn->save(); // 上次用户惩罚 $score = new Score(); $score->user_id = $lastReturn->user->id; $score->reason = '忘改密码'; $score->score = -5; $score->save(); $lastReturn->user->score -= 5; $lastReturn->user->save(); }
public function create($data) { return Score::create($data); }
public function yes($id, $userid) { if (Request::isMethod('get')) { //cek event aktif, anaknya bukan, udah pernah ngisi belum, kadept bukan if (Auth::user()->positionid != 1) { $user = User::find($userid); // dd($user->deptid); if ($user->deptid != Auth::user()->deptid) { return redirect('/'); } $data = Event::where('enabled', 1)->find($id); if (!$data) { return redirect('/'); } if (!$data->enabled) { return redirect('/'); } $cek = Flag::where('eventid', $id)->where('from', '!=', $userid)->where('to', $userid)->first(); if ($cek != null) { return redirect('/'); } $this->data['event'] = $data; $this->data['questions'] = Pivot::where('eventid', $id)->get(); return view('pages.submit.yes', $this->data); } else { return redirect('/'); } } else { $input = Input::get('score'); $data = Event::where('enabled', 1)->find($id); if (!$data) { return redirect('/'); } if (!$data->enabled) { return redirect('/'); } // dd($input); //set ke mark foreach ($input as $key => $value) { $mark = new Mark(); $mark->userid = $userid; $mark->questionid = $key; $mark->string = $value; $mark->save(); } //set ke score $score = Score::where('eventid', $id)->where('userid', $userid)->first(); if ($score) { foreach ($input as $key => $value) { $question = Question::find($key); if ($question->type == 1) { $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first(); $score->score += $value * $pivot->score / 100; $score->save(); } } } else { $score = new Score(); $score->eventid = $id; $score->userid = $userid; $score->score = 0; foreach ($input as $key => $value) { $question = Question::find($key); // dd($input); if ($question->type == 1) { $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first(); $score->score += $value * $pivot->score / 100; $score->save(); } } } //set ke flag $flag = new Flag(); $flag->from = Auth::id(); $flag->to = $userid; $flag->eventid = $id; $flag->save(); return redirect('submit/' . $id); } }
public function unregister($id) { Score::where('event_id', $id)->where('player_id', Auth::user()->id)->delete(); return redirect('/'); }
| It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use App\Score; use Illuminate\Http\Request; // use DB; // $users = DB::table('users')->get(); Route::get('/', function () { return view('welcome'); }); Route::get('/data', function () { return DB::table('scores')->orderBy('score', 'desc')->take(4)->get(); }); Route::post('/highscore', function (Request $r) { $score = new Score(); $score->name = $r->input('name'); $score->score = $r->input('score'); $score->save(); }); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route | it contains. The "web" middleware group is defined in your HTTP | kernel and includes session state, CSRF protection, and more. | */ Route::group(['middleware' => ['web']], function () {
public function saveScore($userId, $genre, $points, $friendsList) { $score = Score::create(['user_id' => $userId, 'genre' => $genre, 'points' => $points]); return $this->getUserPosition($genre, $userId, $friendsList)->position; }
public function uploadResult(Request $request) { $data = $request->all(); $questionResult = $data['question']; $result = explode(',', $questionResult); for ($i = 0; $i < count($result); $i++) { $saveResult = explode('-', $result[$i]); Result::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0], 'answer' => $saveResult[1], 'second' => $saveResult[2]]); if ($saveResult[3] == '1') { $FavoriteRecord = Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->first(); if ($FavoriteRecord == null || $FavoriteRecord == 'null') { Favorite::create(['user_id' => $data['user_id'], 'question_id' => $saveResult[0]]); } } else { if ($saveResult[3] == '0') { Favorite::where('user_id', $data['user_id'])->where('question_id', $saveResult[0])->delete(); } } } $UserRecord = UserRecord::where('user_id', $data['user_id'])->get(); $StageRecord = $UserRecord->where('stages_id', $data['stages_id'])->first(); $CrementRecord = UserRecord::where('user_id', $data['user_id'])->where('stages_id', $data['stages_id'])->max('stage_score'); $Crement = $data['score'] - $CrementRecord; $User = User::where('id', $data['user_id'])->first(); if (count($UserRecord) == 0 || $StageRecord == 'null' || $StageRecord == null) { $User->increment('score', $data['score']); } else { if ($Crement > 0) { $User->increment('score', $Crement); } } $UserSrcoreRecord = Score::where('user_id', $data['user_id'])->where('category_id', floor($data['stages_id'] / 100)); if (count($UserSrcoreRecord->get()) == 0) { Score::create(['user_id' => $data['user_id'], 'user_name' => $User['name'], 'category_id' => floor($data['stages_id'] / 100), 'score' => $data['score']]); } else { if ($Crement > 0) { $UserSrcoreRecord->first()->increment('score', $Crement); } } UserRecord::create(['user_id' => $data['user_id'], 'stages_id' => $data['stages_id'], 'accuracy' => $data['accuracy'], 'accuracy_detail' => $data['accuracy_detail'], 'status' => $data['status'], 'status_detail' => $data['status_detail'], 'stage_score' => $data['score']]); return response()->json(['RetCode' => '1']); }
public function leaderboard($event_id) { $event = Event::where('event_name', $event_id)->first(); if ($event == null) { return "event null"; return redirect(redirect_home); } if (OpController::is_live($event_id) == 1) { return View::make('waiting_area', ['event' => $event, 'action' => 'waiting']); } if (OpController::is_live($event_id) == 3) { return View::make('winners', ['event' => $event, 'action' => 'event_end']); } $performers = Score::where('event_id', $event->id)->orderBy('level', 'desc')->orderBy('updated_at')->take(10)->get()->toArray(); $leaders = []; foreach ($performers as $someone) { $user = User::where('id', $someone['user_id'])->first(); array_push($leaders, ['user' => $user, 'score' => $someone]); } // dd($leaders); return View::make('leaderboard', ['leaders' => $leaders, 'event' => $event, 'action' => 'leaderboard', 'rank' => OpController::rank($event_id)]); }
/** * Show player page by id. * * @param int $id * @return Response */ public function show($id) { if (is_numeric($id)) { $this->tpl['player'] = Player::find($id)->first(); } else { $this->tpl['player'] = Player::where('nick', '=', $id)->first(); } if ($this->tpl['player'] === NULL) { $this->tpl['title'] = 'Not found'; $this->tpl['error']['message'] = 'User not found'; $this->tpl['error']['description'] = 'Sorry, but your user is not found.'; return \Response::view('errors.404', $this->tpl); } $scores = Score::where('player_id', '=', $this->tpl['player']->id)->with('game')->get(); $games = []; if ($scores !== NULL) { foreach ($scores as $score) { if (!isset($games[$score->game_id])) { $games[$score->game_id] = Game::find($score->game_id); } } } $this->tpl['games'] = $games; return view('player.show', $this->tpl); }
public function fetch_ques($event_id, $level) { // dd($event_id, $level); $user = Auth::user(); $event = Event::where('event_name', $event_id)->first(); $user_level = Score::where('user_id', $user->id)->where('event_id', $event->id)->first()['level']; if ($event->type == 1) { $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first(); if ($user_level == $level - 1) { return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)]; } } if ($event->type == 2) { $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first(); if ($user_level >= $level - 1) { return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)]; } } if ($event->type == 3) { $question_tuple = Question::where('level', $level)->where('event_id', $event->id)->first(); return ['status' => 1, 'question' => $question_tuple, 'rank' => self::rank($event_id)]; } return ['status' => 0]; }