diff --git a/api/app/Http/Controllers/TaxonomyController.php b/api/app/Http/Controllers/TaxonomyController.php index 6556c9b8f2..5ea02d3481 100644 --- a/api/app/Http/Controllers/TaxonomyController.php +++ b/api/app/Http/Controllers/TaxonomyController.php @@ -55,7 +55,7 @@ public function showAllTaxa(Request $request){ $offset = $request->input('offset',0); $fullCnt = Taxonomy::count(); - $result = Taxonomy::skip($offset)->take($limit)->get(); + $result = Taxonomy::with('taxonCodes')->skip($offset)->take($limit)->get(); $eor = false; $retObj = [ @@ -134,32 +134,26 @@ public function showAllTaxaSearch(Request $request){ $type = $request->input('type', 'EXACT'); - $fullCnt = 0; - $result = []; + $taxaModel = Taxonomy::with('taxonCodes'); if($type == 'START'){ - $fullCnt = Taxonomy::where('sciname', 'like', $request->taxon . '%')->count(); - $result = Taxonomy::where('sciname', 'like', $request->taxon . '%')->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', 'like', $request->taxon . '%'); } elseif($type == 'WILD'){ - $fullCnt = Taxonomy::where('sciname', 'like', '%' . $request->taxon . '%')->count(); - $result = Taxonomy::where('sciname', 'like', '%' . $request->taxon . '%')->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', 'like', '%' . $request->taxon . '%'); } elseif($type == 'WHOLEWORD'){ - $fullCnt = Taxonomy::where('unitname1', $request->taxon) + $taxaModel->where('unitname1', $request->taxon) ->orWhere('unitname2', $request->taxon) - ->orWhere('unitname3', $request->taxon) - ->count(); - $result = Taxonomy::where('unitname1', $request->taxon) - ->orWhere('unitname2', $request->taxon) - ->orWhere('unitname3', $request->taxon) - ->skip($offset)->take($limit)->get(); + ->orWhere('unitname3', $request->taxon); } else{ //Exact match - $fullCnt = Taxonomy::where('sciname', $request->taxon)->count(); - $result = Taxonomy::where('sciname', $request->taxon)->skip($offset)->take($limit)->get(); + $taxaModel->where('sciname', $request->taxon); } + $fullCnt = $taxaModel->count(); + $result = $taxaModel->skip($offset)->take($limit)->get(); + $eor = false; $retObj = [ 'offset' => (int)$offset, @@ -228,6 +222,8 @@ public function showOneTaxon($id, Request $request){ $parStatusResult = $parStatus->get(); $taxonObj->classification = $parStatusResult; + $taxonObj->taxonCodes; + if(!$taxonObj->count()) $taxonObj = ['status' =>false, 'error' => 'Unable to locate inventory based on identifier']; return response()->json($taxonObj); } diff --git a/api/app/Models/NeonTaxonomy.php b/api/app/Models/NeonTaxonomy.php new file mode 100644 index 0000000000..188871e97c --- /dev/null +++ b/api/app/Models/NeonTaxonomy.php @@ -0,0 +1,27 @@ +belongsTo(Taxonomy::class, 'tid', 'tid'); + } +} diff --git a/api/app/Models/Taxonomy.php b/api/app/Models/Taxonomy.php index f743e6d7d2..8ee7857d88 100644 --- a/api/app/Models/Taxonomy.php +++ b/api/app/Models/Taxonomy.php @@ -23,4 +23,8 @@ public function descriptions(){ public function media(){ return $this->hasMany(media::class, 'tid', 'tid'); } + + public function taxonCodes(){ + return $this->hasMany(NeonTaxonomy::class, 'tid', 'tid'); + } }