/** * 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(); }
/** @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); }
public function test_can_restore_deleted_question() { $interrogator = new Interrogator(); $this->createTestQuestion($interrogator); $interrogator->deleteQuestion(1); $this->assertFalse(Section::first()->trashed()); $this->assertFalse(Group::first()->trashed()); $this->assertTrue(Question::withTrashed()->first()->trashed()); $interrogator->restoreQuestion(1); $this->assertFalse(Section::first()->trashed()); $this->assertFalse(Group::first()->trashed()); $this->assertFalse(Question::first()->trashed()); }
/** * Returns a single Section. * * @param null $section * @return bool|null */ public function getSection($section = null) { return Section::resolveSelf($section); }
/** * Resolves Section object regardless of given identifier. * * @param $section * @param bool $withTrashed * @return null * @throws SectionNotFoundException */ public static function resolveSelf($section, $withTrashed = false) { if (is_null($section)) { return null; } if (!$section instanceof Section) { if (is_numeric($section)) { try { if ($withTrashed) { $section = Section::withTrashed()->findOrFail($section); } else { $section = Section::findOrFail($section); } } catch (ModelNotFoundException $e) { throw new SectionNotFoundException('Section not found with the given ID.'); } } else { try { if ($withTrashed) { $section = Section::withTrashed()->whereSlug($section)->firstOrFail(); } else { $section = Section::whereSlug($section)->firstOrFail(); } } catch (ModelNotFoundException $e) { throw new SectionNotFoundException('Section not found with the given slug.'); } } } return $section; }