Ejemplo n.º 1
0
 public function test_database_exists()
 {
     $thread = \DB::table('parley_threads')->insert(array('subject' => 'test thread', 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
     $threads = Thread::all();
     $this->assertEquals($threads->count(), 1);
     $this->assertEquals($threads->first()->id, 1);
 }
Ejemplo n.º 2
0
 /**
  * Get a thread by its hash value
  * @param string|int $id
  *
  * @return mixed
  */
 public function getThread($id)
 {
     return Thread::find($id);
 }
Ejemplo n.º 3
0
 /**
  * Get Threads belonging to a specific Member object
  *
  * @param $member
  *
  * @return mixed
  */
 public function getThreadsForMember($member)
 {
     // Confirm the specified member is a valid Parleyable Object
     if (!$this->confirmObjectIsParleyable($member)) {
         return new Collection();
     }
     $query = Thread::join('parley_members', 'parley_threads.id', '=', 'parley_members.parley_thread_id')->where('parley_members.parleyable_id', $member->id)->where('parley_members.parleyable_type', get_class($member))->select('parley_threads.*', 'parley_members.is_read as is_read', 'parley_members.parleyable_id as member_id', 'parley_members.parleyable_type as member_type');
     switch ($this->trashed) {
         case 'yes':
             $query = $query->withTrashed();
             break;
         case 'only':
             $query = $query->onlyTrashed();
             break;
         default:
             break;
     }
     if ($this->type == 'open') {
         $query = $query->whereNull('parley_threads.closed_at');
     }
     if ($this->type == 'closed') {
         $query = $query->whereNotNull('parley_threads.closed_at');
     }
     if ($this->status == 'read') {
         $query = $query->where('parley_members.is_read', 1);
     }
     if ($this->status == 'unread') {
         $query = $query->where('parley_members.is_read', 0);
     }
     return $query->orderBy('updated_at', 'desc')->get();
 }