Esempio n. 1
0
 /**
  * Returns general chat messages at most 1 day old
  * @return [type] [description]
  */
 public static function getGlobalMessages()
 {
     $date = Date::forge('now - 1 days');
     // Default history 1 day
     return static::where('to', '<', '0')->where('created_at', '>=', $date->format('datetime'))->get();
 }
Esempio n. 2
0
 public function messages($arguments)
 {
     $date = Date::forge('now - 3 hours');
     // Default history 3 hours
     $own_id = $this->id;
     $query = DB::table('messages')->where(function ($query) use($own_id) {
         $query->where_from($own_id);
         $query->or_where('to', '=', $own_id);
     });
     if (is_array($arguments)) {
         // TODO: various arguments
     } else {
         // If only one argument, assume it's the participant id
         $participant = $arguments;
         $query->where(function ($query) use($participant) {
             $query->where_from($participant);
             $query->or_where('to', '=', $participant);
         });
     }
     $query->where('created_at', '>=', $date->format('datetime'));
     $query->order_by('created_at', 'asc');
     return $query;
 }