/**
  * Collect stats on user login
  * @return [type] [description]
  */
 private function collectStat($user)
 {
     //collect stats on users
     Log::info('collecting');
     $stat = new Stat();
     $stat->user_id = $user->email;
     $stat->last_login = Stat::lastLoginDate($user);
     $stat->ip = $_SERVER['REMOTE_ADDR'];
     $stat->browser = $_SERVER['HTTP_USER_AGENT'];
     $stat->save();
 }
 /**
  * Get all the user stats on user login/logout
  * @param  Request $request Htttp Get
  * @return JSon response           All the stats
  */
 function getStats(Request $request)
 {
     $allowed_columns = ['last_login', 'ip'];
     $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'user_id';
     $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
     $stats = Stat::orderBy($sort, $order)->get();
     return response()->json($stats)->setCallback($request->input('callback'));
 }
 /**
  * Handle the event.
  *
  * @param  Events  $event
  * @return void
  */
 public function handle(UserLogoutEvent $event)
 {
     $user = $event->user;
     if ($stat = Stat::lastLoginStat($user)) {
         Log::log('logout duration');
         $stat->duration = $stat->created_at->diff(Carbon::now())->format('%hh:%im:%ss');
         $stat->last_login = $stat->created_at;
         $stat->save();
     }
 }
Esempio n. 4
0
 public function getAll()
 {
     return Stat::all();
     /*return DB::table('associer')
     		->join('ligne_commande', 'associer.ID_LIGNE', '=', 'ligne_commande.ID_ligne')
     		->join('composer', 'ligne_commande.ID_LIGNE', '=', 'composer.ID_ligne')
     		->join('commande', 'composer.ID_COM', '=', 'commande.ID_COM')
     		->select('associer.QTE_PRO_ART', 'MONTH(commande.DATE_COM)')
     		->groupBy('MONTH(commande.DATE_COM)');*/
 }
Esempio n. 5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = new User();
     $user->name = 'hisyam';
     $user->email = '*****@*****.**';
     //$user->photo = 'southern_miss_logo.0.0.jpeg';
     $user->password = bcrypt('admin1');
     $user->save();
     $stat = Stat::create(['user_id' => '1', 'content' => 'Lorem Ipsum', 'published_at' => Carbon\Carbon::now()]);
     $like = Like::create(['stat_id' => '1', 'count' => 45]);
     $comment = Comment::create(['stat_id' => 1, 'user_id' => 1, 'content' => 'Lorem Ipsum', 'published_at' => Carbon\Carbon::now()]);
 }
 public function store(Request $request)
 {
     $text = $request->input('text');
     $messages = ['in' => "ค่า Happy มีค่าระหว่าง 1 - 3 นะครับ", 'required' => "อย่าลืมส่งค่า Happy มาด้วยนะครับ เช่น /Happytime 3"];
     $validator = \Validator::make(['text' => $text], ['text' => 'required|in:1,2,3,list'], $messages);
     if (!$validator->fails()) {
         if ($text == 'list') {
             $response = Stat::ListSenderToday()->lists('user_name');
         } else {
             if (Stat::isTodaySend($request->input('user_id'))) {
                 $response = "วันนี้คุณส่ง happytime ไปแล้วนะครับ";
             } else {
                 Stat::create($request->all());
                 $response = 'บันทึกเรียบร้อยครับ';
             }
         }
     } else {
         $response = $validator->errors()->first();
     }
     return $response;
 }
Esempio n. 7
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     $v = \Validator::make($request->all(), ['url' => 'required|url']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors());
     } else {
         $new_url = new Url();
         $new_url->long_url = $request->url;
         while (true) {
             $generated = \Illuminate\Support\Str::random(4);
             $url_validation = \Validator::make([], [$generated => 'unique:urls']);
             if (!$url_validation->fails()) {
                 $new_url->short_url = \Illuminate\Support\Str::random(4);
                 break;
             }
         }
         $new_url->save();
         $stat = Stat::where('links_created', '>=', 0)->first();
         $stat->links_created = $stat->links_created + 1;
         $stat->save();
     }
     return redirect('/')->with('url', $new_url->short_url);
 }
Esempio n. 8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $stat = Stat::find($id);
     return view('home', compact('stat'));
 }
Esempio n. 9
0
 public function fetchAll()
 {
     return Stat::all();
 }
Esempio n. 10
0
 /**
  * http://wiki.atlauncher.com/api:stats#get_stats_downloads_zip
  *
  * @return Response
  */
 public function v1DownloadsZip()
 {
     $zip = Stat::where('key', 'downloads-zip')->value('value');
     return Response::make(json_encode(array("error" => false, "code" => 200, "message" => null, "data" => $zip), JSON_PRETTY_PRINT))->header('Content-Type', "application/json");
 }
Esempio n. 11
0
 /**
  * [lastLogin description]
  * @return [type] [description]
  */
 public static function lastLoginStat($user)
 {
     return Stat::where('user_id', $user)->latest('created_at')->first();
 }
Esempio n. 12
0
 public static function isTodaySend($user_id)
 {
     $found = Stat::where('user_id', $user_id)->whereDate('updated_at', '=', Carbon::today()->toDateString())->first();
     return isset($found);
 }
 public function translate(Request $request)
 {
     // валидация
     $paramsToValidate = array('phrase' => Input::get('phrase'));
     $validatorRules = array('phrase' => ['required']);
     $validator = Validator::make($paramsToValidate, $validatorRules);
     if ($validator->fails()) {
         return $this->response->validatorError($validator->messages());
     }
     // лог
     Stat::log('translation query');
     // форматируем фразу для дальнейшей работы
     $phraseFormatted = urldecode($request->phrase);
     $phraseFormatted = strtolower($phraseFormatted);
     // поиск в базе только в том случае, если длина фразы < @idiomMaxWordLength слов
     // в @idiomMaxWordLength слов может вписаться идиома
     $phraseWordsCount = count(explode(' ', $phraseFormatted));
     if ($phraseWordsCount < $this->idiomMaxWordLength) {
         $translation = Phrase::findByPhrase($phraseFormatted);
         if ($translation) {
             return $this->response->onSuccess(array('translation' => $translation->translate, 'meaning' => $translation->meaning));
         }
     }
     // если перевод не найден, ищем в гугле, и если гугл не находит перевод то выйдем
     $googleTranslation = GoogleApi::translate($phraseFormatted, 'enru');
     if (!$googleTranslation) {
         return $this->response->onError('no translation for:' . $request->phrase);
     }
     // поиск описания слова в vocabulary.com
     $translationVoc = false;
     if ($phraseWordsCount < $this->idiomMaxWordLength) {
         $translationVoc = VocabularyApi::translation($phraseFormatted);
     }
     // перед тем как вернуть результат, внесем его в базу
     $phraseMeaning = '';
     if ($translationVoc) {
         $phraseMeaning = "<p class=\"short\"> {$translationVoc['short']} </p><p class=\"long\"> {$translationVoc['long']} </p>";
     }
     $newPhrase = Phrase::create(array('phrase' => $phraseFormatted, 'translate' => $googleTranslation, 'meaning' => $phraseMeaning));
     // вернем результат
     return $this->response->onSuccess(array('translation' => $newPhrase->translate, 'meaning' => $newPhrase->meaning));
 }
Esempio n. 14
0
 public function getStatMensuel()
 {
     $stat = new Stat();
     $results = $stat->getStatMensuel();
     return Response()->json($results, 200);
 }
Esempio n. 15
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $stats = Stat::orderBy('published_at', 'desc')->get();
     return view('home', compact('stats'));
 }