public function testMerge() { // Basic merge. $tag1 = Tag::firstOrCreate(['name' => 'Tag 1']); $tag2 = Tag::firstOrCreate(['name' => 'Tag 2']); $this->assertSame(2, Tag::count()); $tag1->merge($tag2); $this->assertSame(1, Tag::count()); $this->assertSame('Tag 1', Tag::first()->name); // Merge when the other-tag has assets attached. $tag3 = Tag::firstOrCreate(['name' => 'Tag 3']); $asset = Asset::firstOrCreate(['identifier' => 'Asset 1']); $asset->addTags('Tag 3'); $this->assertSame(2, Tag::count()); $tag1->merge($tag3); $this->assertSame(1, Tag::count()); $this->assertSame(1, $tag1->assets->count()); $this->assertSame('Tag 1', $asset->tagsAsString()); // What about when a JobList is already tagged with both tags? $type = new \App\Model\JobType(); $type->save(); $jobList = new JobList(); $jobList->name = 'JL1'; $jobList->type_id = $type->id; $jobList->save(); $jobList->addTags('Tag 1, Tag 4, Tag 5'); $tag4 = Tag::firstOrCreate(['name' => 'Tag 4']); $this->assertSame(3, Tag::count()); $tag1->merge($tag4); $this->assertSame(2, Tag::count()); $this->assertSame('Tag 1, Tag 5', $jobList->tagsAsString()); }
public function search(Request $request) { $searchTerm = $request->query('quick_s'); $searchType = $request->query('quick_t'); switch ($searchType) { case 'a': $asset = Asset::whereIdentifier($searchTerm)->first(); if (isset($asset->id)) { return redirect('assets/' . $asset->id); } else { return redirect("assets?identifier={$searchTerm}"); } break; case 'j': $job = Job::whereId($searchTerm)->first(); if (isset($job->id)) { return redirect('jobs/' . $job->id); } else { return redirect("jobs?id={$searchTerm}"); } break; case 'jl': $jobList = JobList::whereName($searchTerm)->first(); if (isset($jobList->id)) { return redirect('job-lists/' . $jobList->id); } else { return redirect("job-lists?name={$searchTerm}"); } break; default: $this->view->quick_t = $searchType; $this->view->quick_s = $searchTerm; return $this->view; } }
public function home() { $this->view->title = $this->view->site_name; $this->view->asset_count = Asset::count(); $this->view->user_count = User::count(); $this->view->crew_count = Crew::count(); $this->view->job_list_count = JobList::count(); $this->view->job_count = Job::count(); $this->view->tag_count = Tag::count(); return $this->view; }
public function createForAsset(Request $request) { // Get the Asset. $assetId = $request->input('asset_id'); $asset = Asset::find($assetId); if (!$asset) { $this->alert('error', "No Asset #{$assetId}", false); return $this->view; } // Save the Contact. $contact = new Contact(); $contact->name = $request->input('name'); $contact->phone_1 = $request->input('phone_1'); $contact->phone_2 = $request->input('phone_2'); $contact->save(); // Then connect the two. $asset->contacts()->attach($contact->id); return redirect("assets/{$asset->id}#contacts"); }
/** * When adding a comment to an Asset, if the comment is already part of the Asset's comment then the new * comment will not be added. * @test */ public function comments() { $asset = new Asset(); $asset->identifier = 'TEST123'; // Set initial comment. $asset->comments = 'Test comment.'; $asset->save(); $this->assertEquals('Test comment.', $asset->comments); // Appending the same string shouldn't modify it. $asset->appendComments('Test comment.'); $asset->save(); $this->assertEquals('Test comment.', $asset->comments); // Append a different string and it'll make sure there's a newline between them. $asset->appendComments('Blah.'); $asset->save(); $this->assertEquals("Test comment.\n\nBlah.", $asset->comments); }
public function save(Request $request) { if (!$this->user || !$this->user->isClerk()) { $this->alert('warning', 'Only Clerks are allowed to edit assets.', false); return $this->view; } $asset = Asset::firstOrNew(['id' => $request->input('id')]); $asset->identifier = $request->input('identifier'); $asset->state_id = $request->input('state_id'); $asset->suburb_id = $request->input('suburb_id'); $asset->street_address = $request->input('street_address'); $asset->location_description = $request->input('location_description'); $asset->latitude = $request->input('latitude'); $asset->longitude = $request->input('longitude'); $asset->comments = $request->input('comments'); $asset->save(); $asset->tags()->sync(Tag::getIds($request->input('tags'))); $file = File::createFromUploaded($request->file('file')); if ($file) { $asset->files()->attach($file->id); } return redirect('assets/' . $asset->id); }
protected function getAssets($request) { // Get search terms. $assetIdentifiers = preg_split('/(\\n|\\r)/', $request->input('identifiers', ''), null, PREG_SPLIT_NO_EMPTY); $identifiers = array_map('trim', $assetIdentifiers); $identifier = trim($request->input('identifier')); $tagged = $request->input('tagged'); // Build and execute query. $assets = Asset::query(); if (!empty($identifiers)) { $assets->whereIn('identifier', $identifiers); } if (!empty($identifier)) { $assets->where('identifier', 'LIKE', "%{$identifier}%"); } if ($tagged) { $assets->tagged($tagged); } return $assets->get(); }