/**
  * BelongsToMany relationship with ModelSection.
  *
  * @return \Illuminate\Support\Collection
  */
 public function sections()
 {
     return Section::where('class_name', get_class($this))->where('team_id', $this->current_team_id)->get();
 }
Example #2
0
 /**
  * Return list of all Sections.
  *
  * @param null $class
  * @param null $team_id
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function getSections($class = null, $team_id = null)
 {
     return Section::where('team_id', $team_id)->when($class, function ($query) use($class) {
         return $query->where('class_name', $class);
     })->get()->sortBy('order')->values();
 }
 /** @test */
 public function can_search_for_specific_question_fuzzy_match()
 {
     $interrogator = new Interrogator();
     $section = $interrogator->createSection('Section 1', [], 'MetricLoop\\Interrogator\\User', 1);
     $section2 = $interrogator->createSection('Section 2', [], 'MetricLoop\\Interrogator\\Client', 1);
     $group = $interrogator->createGroup('Group 1', $section, [], 1);
     $group2 = $interrogator->createGroup('Group 2', $section2, [], 1);
     $interrogator->createQuestion('Question 1', 1, $group, [], [], 1);
     $interrogator->createQuestion('Question 2', 2, $group, [], [], 1);
     $interrogator->createQuestion('Question 3', 3, $group, [], [], 1);
     $interrogator->createQuestion('Question 4', 4, $group, [], [], 1);
     $interrogator->createQuestion('Question 5', 5, $group, [], [], 1);
     $interrogator->createQuestion('Question 6', 6, $group, [], [], 1);
     $interrogator->createQuestion('Question 1', 1, $group2, [], [], 1);
     $interrogator->createQuestion('Question 2', 2, $group2, [], [], 1);
     $interrogator->createQuestion('Question 3', 3, $group2, [], [], 1);
     $interrogator->createQuestion('Question 4', 4, $group2, [], [], 1);
     $interrogator->createQuestion('Question 5', 5, $group2, [], [], 1);
     $interrogator->createQuestion('Question 6', 6, $group2, [], [], 1);
     $user = User::create(['name' => 'Ulysses User', 'email' => '*****@*****.**', 'current_team_id' => 1]);
     $client = Client::create(['name' => 'Carly Client', 'email' => '*****@*****.**', 'current_team_id' => 1]);
     $section = Section::where('class_name', get_class($user))->first();
     foreach ($section->groups as $group) {
         foreach ($group->questions as $question) {
             $user->answerQuestion($question, 'Test Answer');
         }
     }
     $section = Section::where('class_name', get_class($client))->first();
     foreach ($section->groups as $group) {
         foreach ($group->questions as $question) {
             $client->answerQuestion($question, 'Test Answer');
         }
     }
     $term = 'est Answe';
     $question = Question::first();
     $results = $interrogator->searchQuestion($term, get_class($user), $question, 1);
     $this->assertCount(1, $results);
 }
 /** @test */
 public function can_delete_and_cascade_sections_groups_and_questions()
 {
     $interrogator = new Interrogator();
     $section = $interrogator->createSection('Section 1', [], 'MetricLoop\\Interrogator\\User');
     $section2 = $interrogator->createSection('Section 2', [], 'MetricLoop\\Interrogator\\Client');
     $group = $interrogator->createGroup('Group 1', $section);
     $group2 = $interrogator->createGroup('Group 2', $section2);
     $group3 = $interrogator->createGroup('Group 2', $section2);
     $question = $interrogator->createQuestion('Question 1', 1, $group);
     $interrogator->createQuestion('Question 2', 2, $group);
     $interrogator->createQuestion('Question 3', 3, $group);
     $interrogator->createQuestion('Question 4', 4, $group);
     $interrogator->createQuestion('Question 5', 5, $group);
     $interrogator->createQuestion('Question 6', 6, $group);
     $interrogator->createQuestion('Question 1', 1, $group2);
     $interrogator->createQuestion('Question 2', 2, $group2);
     $interrogator->createQuestion('Question 3', 3, $group2);
     $interrogator->createQuestion('Question 4', 4, $group2);
     $interrogator->createQuestion('Question 5', 5, $group2);
     $interrogator->createQuestion('Question 6', 6, $group2);
     $interrogator->createQuestion('Question 1', 1, $group3);
     $interrogator->createQuestion('Question 2', 2, $group3);
     $interrogator->createQuestion('Question 3', 3, $group3);
     $interrogator->createQuestion('Question 4', 4, $group3);
     $interrogator->createQuestion('Question 5', 5, $group3);
     $interrogator->createQuestion('Question 6', 6, $group3);
     $user = User::create(['name' => 'Ulysses User', 'email' => '*****@*****.**']);
     $client = Client::create(['name' => 'Carly Client', 'email' => '*****@*****.**']);
     $section = Section::where('class_name', get_class($user))->first();
     foreach ($section->groups as $group) {
         foreach ($group->questions as $question) {
             $user->answerQuestion($question, 'Test Answer');
         }
     }
     $section = Section::where('class_name', get_class($client))->first();
     foreach ($section->groups as $group) {
         foreach ($group->questions as $question) {
             $client->answerQuestion($question, 'Test Answer');
         }
     }
     $questions = Question::all();
     $groups = Group::all();
     $sections = Section::all();
     $answers = Answer::all();
     $this->assertCount(18, $questions);
     $this->assertCount(18, $answers);
     $this->assertCount(3, $groups);
     $this->assertCount(2, $sections);
     $interrogator->deleteQuestion($question);
     $questions = Question::all();
     $groups = Group::all();
     $sections = Section::all();
     $answers = Answer::all();
     $this->assertCount(17, $questions);
     $this->assertCount(17, $answers);
     $this->assertCount(3, $groups);
     $this->assertCount(2, $sections);
     $interrogator->deleteGroup($group2);
     $questions = Question::all();
     $groups = Group::all();
     $sections = Section::all();
     $answers = Answer::all();
     $this->assertCount(11, $questions);
     $this->assertCount(11, $answers);
     $this->assertCount(2, $groups);
     $this->assertCount(2, $sections);
     $interrogator->deleteSection($section);
     $questions = Question::all();
     $groups = Group::all();
     $sections = Section::all();
     $answers = Answer::all();
     $this->assertCount(6, $questions);
     $this->assertCount(6, $answers);
     $this->assertCount(1, $groups);
     $this->assertCount(1, $sections);
 }