Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Created September 25, 2017 21:50
Show Gist options
  • Save necenzurat/2e1ec4515f87c47012c9f76c4737b587 to your computer and use it in GitHub Desktop.
Save necenzurat/2e1ec4515f87c47012c9f76c4737b587 to your computer and use it in GitHub Desktop.
code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Friend;
use \App\Presence;
use \DB;
use \Carbon;
class ViewController extends Controller
{
public function index(Request $request)
{
//echo "<body bgcolor='#000'>";
$dhit = ''.$request->input('date').' 00:00:00';
$dnow= ''.$request->input('date').' 23:59:59';
$begin = new \DateTime( $dhit );
$end = new \DateTime( $dnow );
$interval = \DateInterval::createFromDateString( '1 second' );
$period = new \DatePeriod($begin, $interval, $end);
$data = [];
$x = collect(DB::select("SELECT * FROM `presence` WHERE `facebook_id` = '".$request->input('facebook_id')."' AND `created_at` like '%".$request->input('date')."%'"));
$dateStatus = $x->mapWithKeys(function ($item) {
return [$item->created_at => $item->status];
});
$swich = 0;
$i = 0;
foreach ( $period as $dt ) {
$now = $dt->format('Y-m-d H:i:s');
if (isset($dateStatus[$now])){
$swich = $dateStatus[$now];
}
if ($swich == 0){//<abbr title='$now'><abbr title='$now'>
$status = "<span style='font-color:red;'>😫</span>";
} elseif ($swich == 2) {//<abbr title='$now'><abbr title='$now'>
$status = "<span style='font-color:green;'>💩</span>";
}
if ($i % 3600 == 0){
echo "<h1> $now </h1>";
echo "<br />";
}
if ($i % 60 == 0){
echo "<br /> $now $status ";
} else {
echo "$status";
}
$i++;
}
return view('presence2', compact('data', 'date'));
//dd($data);
//$friend = Presence::where('facebook_id', 609076870)->with('friend')->get();
//$presences = Friend::where('userId', 609076870)->with('presences')->first();
// $data = Presence::where('facebook_id', 609076870)
// ->get()
// ->groupBy(function($item){
// return $item->created_at->format('Y-m-d');
// });
//
//
// return view('presence', compact('data'));
}
public function json(Request $request)
{
$date = $request->input('date');
//$friend = Presence::where('facebook_id', 609076870)->with('friend')->get();
//$presences = Friend::where('userId', 609076870)->with('presences')->first();
$data = Presence::where('facebook_id', 100000504751624)
->where('created_at', 'like', '%'.$date.'%')
->orderBy('created_at')
->get();
/* ->groupBy(function($item){
return $item->created_at->format('Y-m-d');
}); */
$ret = [];
foreach ($data as $chart){
$ret[substr($chart['timestamp'], 0, -3)] = $chart['status'] ;
}
return($ret);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment