Example #1
0
 public function getChildrenOfTaxaGroup(Request $request)
 {
     $taxaGroupIDs = $request->input('taxaGroupIDs');
     //        $specimenSegregationTaxaGroups = TaxaGroup::where('parentTaxaGroupID', '=', $taxaGroupIDs)->where('taxaThumbnailFilePath', '=', '')->get();
     //
     //        foreach ($specimenSegregationTaxaGroups as $taxaGroup) {
     //            $taxaGroup->childrenSpecimens->toArray();
     //        }
     $hierachy = [];
     $parentTaxaGroupID = $taxaGroupIDs;
     while (TaxaGroup::find($parentTaxaGroupID)->tier > 1) {
         $taxaGroupName = TaxaGroup::find($parentTaxaGroupID)->TaxaGroupName;
         array_unshift($hierachy, ['taxaGroupID' => $parentTaxaGroupID, 'TaxaGroupName' => $taxaGroupName]);
         $parentTaxaGroupID = TaxaGroup::find($parentTaxaGroupID)->parentTaxaGroupID;
     }
     //        $speciesDirectlyUnderTaxaGroup = TaxaGroup::find($taxaGroupIDs)->childrenSpecimens;
     $childrenTaxaGroups = TaxaGroup::find($taxaGroupIDs)->childrenTaxaGroups()->where('taxaThumbnailFilePath', '!=', '')->where('uploadToWeb', '=', 1)->get();
     $speciesDirectlyUnderTaxaGroup = [];
     $specimenSegregationTaxaGroups = [];
     HomeController::recursivelyGetSpecies(TaxaGroup::find($taxaGroupIDs), $specimenSegregationTaxaGroups, $speciesDirectlyUnderTaxaGroup);
     return response()->json(['TaxaGroupName' => TaxaGroup::find($taxaGroupIDs)->TaxaGroupName, 'childrenSpecies' => $speciesDirectlyUnderTaxaGroup, 'taxaGroupIDs' => $hierachy, 'specimenSegregationTaxaGroups' => $specimenSegregationTaxaGroups, 'childrenTaxaGroups' => $childrenTaxaGroups]);
 }