public function get_click($id) { //Are we even working with a number? if (!is_numeric($id)) { //Yikes let's get the hell out of here App::abort(404, 'Invalid click link'); } //Now to pull our VA record or fail $va = User::find($id); if (empty($va)) { return Redirect::to('/')->with('topmessage', 'Sorry, that VA URL could not be located. Please try again and open a ticket if you continue experiencing the same issue.'); } //Great a VA exists, let's make sure to add one to their clicks if this IP hasn't added a click within the last minute. $existingClick = Click::where('ip', '=', Request::getClientIp())->orderBy('created_at', 'DESC')->first(); if (!empty($existingClick)) { $lastClickByIp = strtotime($existingClick->created_at); if (time() - $lastClickByIp > 60) { //No click found by the same IP in the last 60 seconds thus we should add this one $click = new Click(); $click->vid = $id; $click->ip = Request::getClientIp(); $click->save(); } } else { //No click found by that same IP at all. Let's insert into the DB $click = new Click(); $click->vid = $id; $click->ip = Request::getClientIp(); $click->save(); } //Finally redirect the user to the VA URL return Redirect::to($va->url); }
public function get_va() { //Pull our users VA data $record = User::where('cid', '=', Auth::user()->get()->cid)->first(); // //Figure out what the last 4 months are and append -1 for the first day of the month // $month = date('Y-m'); // $month .= '-1'; // $month1before = date('Y-m', strtotime('-1 month')); // $month1before .= '-1'; // $month2before = date('Y-m', strtotime('-2 month')); // $month2before .= '-1'; // $month3before = date('Y-m', strtotime('-3 month')); // $month3before .= '-1'; // //Convert to unix time stamps to compare with the DB // $month = strtotime($month); // $month1before = strtotime($month1before); // $month2before = strtotime($month2before); // $month3before = strtotime($month3before); // // //Now let's store our month names in an array // $clicks = array(); // $clicks['month_name'] = date("F", $month); // $clicks['month1before_name'] = date("F", $month1before); // $clicks['month2before_name'] = date("F", $month2before); // $clicks['month3before_name'] = date("F", $month3before); // // // //Count the data in the DB // //Where data is greater than the first of this month and is associated with our logged in user. // $month = Click::where('created_at', '>=', $month)->where('vid', '=', Auth::user()->get()->cid)->count(); // //Where data is greater than the first of last month, but less than the first of this month and is associated with our logged in user. // $month1before = Click::where('created_at', '>=', $month1before)->where('created_at', '<', $month)->where('vid', '=', Auth::user()->get()->cid)->count(); // //You get the point :) // $month2before = Click::where('created_at', '>=', $month2before)->where('created_at', '<', $month1before)->where('vid', '=', Auth::user()->get()->cid)->count(); // $month3before = Click::where('created_at', '>=', $month3before)->where('created_at', '<', $month2before)->where('vid', '=', Auth::user()->get()->cid)->count(); // //Add to our clicks array. // $clicks['month'] = $month; // $clicks['month1before'] = $month1before; // $clicks['month2before'] = $month2before; // $clicks['month3before'] = $month3before; //Let's just keep it simple for now and get the total number of clicks $clicks = Click::where('vid', '=', Auth::user()->get()->cid)->count(); //Pull our ticket information $opentickets = Ticket::where('vid', '=', Auth::user()->get()->cid)->where('status', '=', '1')->orderBy('created_at', 'DESC')->get(); $openticketscount = count($opentickets); $closedtickets = Ticket::where('vid', '=', Auth::user()->get()->cid)->where('status', '=', '0')->orderBy('created_at', 'DESC')->get(); $closedticketscount = count($closedtickets); //Create our array $tickets = array(); $tickets['opentickets'] = $opentickets; $tickets['opentickets_count'] = $openticketscount; $tickets['closedtickets'] = $closedtickets; $tickets['closedtickets_count'] = $closedticketscount; //Pull our replies $tickets_request = Ticket::where('vid', '=', Auth::user()->get()->cid)->get(); $tids = array(); foreach ($tickets_request as $ticket_request) { $tid = $ticket_request->id; $tids[$tid] = $tid; } if (!empty($tids)) { $replies = TicketReply::whereIn('tid', $tids)->orderBy('created_at', 'ASC')->get(); } else { $replies = ''; } $tickets['replies'] = $replies; //Pull our Category data $categories = Category::where('hidden', '!=', 1)->get(); //Check to see if there is a banner if so provide the source for it if ($record->banner) { $banner = User::getBannerUrl(Auth::user()->get()->cid); } else { //No banner we will set this as false so the views no not to try and display it. $banner = FALSE; } //Get our news $news = News::orderBy("updated_at", "DESC")->get(); //Create our view with the VA, clicks, categories and tickets data. return View::make('va')->with(array('news' => $news, 'record' => $record, 'clicks' => $clicks, 'tickets' => $tickets, 'categories' => $categories, 'banner' => $banner)); }
public function savexi() { $data = Input::all(); $data['openid'] = Session::get('openid') ? Session::get('openid') : null; $save = array('openid' => $data['openid'], 'score' => $data['sub'], 'time' => $data['score']); if ($data['openid'] != null) { $num = Click::where('openid', '=', $data['openid'])->count(); if ($num != 0) { $info = Click::where('openid', '=', $data['openid'])->first(); if ($save['score'] > $info['score']) { Click::where('openid', '=', $data['openid'])->update($save); $id = Click::where('openid', '=', $data['openid'])->first(); } elseif ($save['score'] == $info['score'] && $save['time'] < $info['time']) { Click::where('openid', '=', $data['openid'])->update($save); $id = Click::where('openid', '=', $data['openid'])->first(); } else { $id = Click::create($save); $uid = $id['id']; $paiming = DB::select("SELECT rowno as list FROM (SELECT id,score,time,(@rowno:=@rowno+1) as rowno FROM `click`, (SELECT (@rowno:=0)) a ORDER BY score DESC, time ASC )b WHERE id = {$uid} limit 1"); Click::destroy($uid); return $paiming; } } else { $id = Click::create($save); } } else { $id = Click::create($save); } $uid = $id['id']; $paiming = DB::select("SELECT rowno as list FROM (SELECT id,score,time,(@rowno:=@rowno+1) as rowno FROM `click`, (SELECT (@rowno:=0)) a ORDER BY score DESC, time ASC )b WHERE id = {$uid} limit 1"); return $paiming; }