예제 #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $role = Auth::user()->roles;
     $admin_count = 1 << 0 & $role ? User::where('roles', '>', '0')->count() : -1;
     $problem_count = 1 << 1 & $role ? Problem::count() : -1;
     $user_count = 1 << 2 & $role ? User::count() : -1;
     $contest_count = 1 << 3 & $role ? Contest::count() : -1;
     $group_count = 1 << 4 & $role ? Group::count() : -1;
     $news_count = 1 << 5 & $role ? News::count() : -1;
     $discuss_count = 0;
     $runinfo_count = 1 << 7 & $role ? Status::count() : -1;
     return response()->json(['admin_count' => $admin_count, 'problem_count' => $problem_count, 'user_count' => $user_count, 'contest_count' => $contest_count, 'group_count' => $group_count, 'news_count' => $news_count, 'discuss_count' => $discuss_count, 'runinfo_count' => $runinfo_count]);
 }
 /**
  * Update the donner dashboard
  * fetch new requests from db
  * responds to post request on /update-donner-dashboard route
  */
 public function updateDashboard(Request $request)
 {
     $count = 0;
     $mainCount = 0;
     //first check if the cookie is set or not
     //this code will run when the count cookie is set
     if (Cookie::get('count')) {
         //fetch only difference records(new records)
         $count = Problem::count();
         //check if new rows have been added to the table then send the new reply
         //else no need to send data
         if (Cookie::get('count') != $count) {
             //if user entered a new form
             if ($count > Cookie::get('count')) {
                 $mainCount = $count - Cookie::get('count');
                 $problems = Problem::orderBy('id', 'desc')->take($mainCount)->get();
                 $response = new Response($problems);
                 $response->withCookie(cookie()->forever('count', $count));
                 return $response;
             }
             if ($count < Cookie::get('count')) {
                 $response = new Response("No New Problems");
                 return $response;
             }
             //$mainCount = max($count , Cookie::get('count')) - min($count , Cookie::get('count'));
             //setcookie("mainCount", $mainCount);
             //setcookie("1", "cookie was set but counts were not equal");
         } else {
             setcookie("2", "cookie was set so no new results");
             $response = new Response("No New Problems");
             return $response;
         }
     } else {
         //fetch all records
         //this code will run first time when count cookie is not set
         $problems = Problem::orderBy('id', 'desc')->get();
         $count = $problems->count();
         //this cookie will expire in next 5 years
         setcookie("3", "cookie was not set so I am called");
         $response = new Response($problems);
         $response->withCookie(cookie()->forever('count', $count));
         return $response;
     }
 }
/*Event::listen('illuminate.query', function($query)
{
    var_dump($query);
});*/
Route::filter('csrf', function ($route, $request) {
    if (strtoupper($request->getMethod()) === 'GET') {
        return;
        // get requests are not CSRF protected
    }
    $token = $request->ajax() ? $request->header('X-CSRF-Token') : Input::get('_token');
    if (Session::token() != $token) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
Route::get('/', function () {
    $totalProblems = Problem::count();
    $solvedProblems = Problem::where('solved', 1)->get()->count();
    $unsolvedProblems = Problem::where('solved', 0)->get()->count();
    return view('Pages.index', ['totalProblems' => $totalProblems, 'solvedProblems' => $solvedProblems, 'unsolvedProblems' => $unsolvedProblems]);
});
Route::get('donner', 'HomeController@index');
// Authentication routes...
Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
Route::get('needy', 'ProblemController@needyForm');
/*handle post request to save form data*/
Route::post('needy', 'ProblemController@save');
/*donner button routes*/
Route::post('donate-money-req/{id}', 'DonnerController@returnDonateMoneyView')->middleware('donor-auth');
Route::get('donate-money-req/{id}', function () {
    return view("Pages.donate-money");
})->middleware('donor-auth');