public function getLeaderBoardData()
    {
        $input = Input::all();
        $userTaskObj = new UserTask();
        // DEFINE JSON STRING
        // create new LeaderBoard Object
        $leaderBoardObj = new stdClass();
        //		$input['keycodes'] = '{"teams": [
        //		  {"keycode": "dev001"},
        //		  {"keycode": "mim001"}
        //		]}';
        // decode json string
        $teamArray = $input['keycodes'];
        $teamArray = $teamArray['teams'];
        $returnArray = array();
        $teamCounter = 0;
        foreach ($teamArray as $key => $value) {
            # code...
            $group = DB::table('groups')->where('keycode', $value['keycode'])->get();
            $totalPlayers = DB::table('users')->where('keycode', $value['keycode'])->count();
            // check the group existence
            if (count($group) > 0) {
                // run the logic code to get the number of days passed
                $groupDetails = $group[0];
                $timeStartDate = new DateTime(date("Y-m-d", $groupDetails->timestart));
                $dayPassed = daysDiff($timeStartDate, new DateTime('now')) + 1;
                $returnArray[$teamCounter]['teamid'] = $groupDetails->id;
                $returnArray[$teamCounter]['teamname'] = $groupDetails->name;
                $returnArray[$teamCounter]['teamPIC'] = SITE_URL . base64_decode($groupDetails->thumbnail);
                $returnArray[$teamCounter]['daypassed'] = $dayPassed;
                $returnArray[$teamCounter]['totalPlayers'] = $totalPlayers;
                /*
                // DEFINE VARIABLE
                //
                */
                $totalNumTeamMissions = 0;
                $totalNumCompletedMissions = 0;
                $totalNumLikes = 0;
                $totalNumComments = 0;
                $totalNumPosts = 0;
                $day = array();
                // loop thru days
                for ($i = 1; $i <= $dayPassed; $i++) {
                    # code...
                    $date = $timeStartDate->format('Y-m-d');
                    $returnArray[$teamCounter]['day'][$i]['date'] = $date;
                    // get the number of completed mission on that day
                    $completedTasks = DB::table('user_tasks')->where('group_id', $groupDetails->id)->where('complete', 1)->where('created_at', 'LIKE', $date . '%')->get();
                    $totalNumCompletedMissions = $totalNumCompletedMissions + count($completedTasks);
                    $day[$i]['completedTasks'] = count($completedTasks);
                    // get the total posts based on groupID
                    $totalPosts = DB::table('posts')->where('group_id', $groupDetails->id)->where('created_at', 'LIKE', $date . '%')->count();
                    $totalNumPosts = $totalPosts + $totalNumPosts;
                    $day[$i]['totalPosts'] = $totalPosts;
                    // get the total likes , comments each day JOIN 2 tables into one SQL statement
                    $totalLikesArray = DB::select('select l.id 
					FROM likes as l, posts as p 
					WHERE p.group_id = ? AND l.post_id = p.id AND l.created_at LIKE ?
					', array($groupDetails->id, $date . '%'));
                    $totalLikes = count($totalLikesArray);
                    $totalNumLikes = $totalLikes + $totalNumLikes;
                    $day[$i]['totalLikes'] = $totalLikes;
                    // get total comment
                    $totalCommentsArray = DB::select('select l.id 
					FROM comments as l, posts as p 
					WHERE p.group_id = ? AND l.post_id = p.id AND l.created_at LIKE ?
					', array($groupDetails->id, $date . '%'));
                    $totalComments = count($totalCommentsArray);
                    $totalNumComments = $totalComments + $totalNumComments;
                    $day[$i]['totalComments'] = $totalComments;
                    $timeStartDate->modify('+1 day');
                }
                $returnArray[$teamCounter]['totalNumTeamMissions'] = $userTaskObj->totalTasks($groupDetails->id);
                $returnArray[$teamCounter]['totalNumCompletedMissions'] = $totalNumCompletedMissions;
                $returnArray[$teamCounter]['totalNumLikes'] = $totalNumLikes;
                $returnArray[$teamCounter]['totalNumComments'] = $totalNumComments;
                $returnArray[$teamCounter]['totalNumPosts'] = $totalNumPosts;
                $returnArray[$teamCounter]['totalPoints'] = $totalNumComments + $totalNumLikes + $totalNumPosts + $totalNumCompletedMissions * 6;
                $returnArray[$teamCounter]['score'] = round($returnArray[$teamCounter]['totalPoints'] / $returnArray[$teamCounter]['totalPlayers'] / $returnArray[$teamCounter]['daypassed'], 1);
                $dayCollection = array($day);
                $returnArray[$teamCounter]['day'] = $dayCollection[0];
            }
            $teamCounter++;
        }
        function compare($a, $b)
        {
            $result = null;
            if ($a['score'] == $b['score']) {
                if ($a['totalPoints'] = $b['totalPoints']) {
                    $result = 0;
                } else {
                    $result = $a['totalPoints'] > $b['totalPoints'] ? -1 : 1;
                }
            } else {
                $result = $a['score'] > $b['score'] ? -1 : 1;
            }
            return $result;
        }
        usort($returnArray, "compare");
        $leaderBoardObj->teams = $returnArray;
        // return json data
        return $_GET['callback'] . '(' . json_encode($leaderBoardObj) . ')';
        //		return json_encode($leaderBoardObj);
    }
 /**
  * Suspend user after 
  * @return number of user affected
  */
 public function accountSuspentionNotificationCron()
 {
     $userObj = new stdClass();
     // read user data from the database
     $users = DB::table('users')->where('suspend_after', 1)->get(array('id', 'created_at'));
     if (sizeof($users) < 1) {
         print_r('no users found<br/>');
     }
     // loop thru all the users with email_notification enable
     foreach ($users as $user) {
         // init role assignment to check wether the user is admin or normal user
         $role_assignments = DB::table('role_assignments')->where('user_id', $user->id)->where('role_id', 1)->get();
         // get the current group id
         $groupid = DB::table('group_users')->where('user_id', $user->id)->pluck('group_id');
         if (count($role_assignments) > 0) {
             continue;
         }
         $userObj->id = $user->id;
         $userObj->created_at = $user->created_at;
         // get total tasks
         $userTaskObj = new UserTask();
         $totaltasks = $userTaskObj->totalTasks($groupid);
         // calculating suspended date 86400 = 1 day ; 432000 = 5 days
         $totalDaysBeforeSuspention = $totaltasks + 5;
         $userCreatedTime = new DateTime($user->created_at);
         $actualDays = $userCreatedTime->modify('+ ' . $totalDaysBeforeSuspention . ' days');
         $currentDate = new DateTime();
         $interval = daysDiff($actualDays, $currentDate);
         if ($interval == 0) {
             $user = User::find($user->id);
             $user->suspended = 1;
             $user->save();
         }
     }
     return "OK - Task Done";
 }