コード例 #1
0
 public function getWeighInEntryData()
 {
     $fishingCategories = array_filter((new CategoryTransformer())->transformCollection(Category::all()->toArray()));
     $fishingLocations = array_filter((new LocationTransformer())->transformCollection(Location::all()->toArray()));
     $fishingSectors = array_filter((new SectorTransformer())->transformCollection(Sector::all()->toArray()));
     $speciesList = array_filter((new SpeciesTransformer())->transformCollection(Species::with(['type', 'weights'])->get()->toArray()));
     return $this->respond(['fishingCategories' => $fishingCategories ?: null, 'fishingLocations' => $fishingLocations ?: null, 'fishingSectors' => $fishingSectors ?: null, 'speciesList' => $speciesList ?: null]);
 }
コード例 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Location::create(['name' => 'Unknown', 'description' => 'Unknown location description.']);
     Location::create(['name' => 'Charter', 'description' => 'Charter location description.']);
     Location::create(['name' => 'Dart', 'description' => 'Dart location description.']);
     Location::create(['name' => 'Exe', 'description' => 'Exe location description.']);
     Location::create(['name' => 'Local', 'description' => 'Local location description.']);
     Location::create(['name' => 'Start', 'description' => 'Start location description.']);
     Location::create(['name' => 'Teign', 'description' => 'Teign location description.']);
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param WeighInsRequest|Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(WeighInsRequest $request)
 {
     // TODO: extract this as it is also used in weigh ins request
     // Clear up the entries
     $request['entries'] = array_filter(array_map(function ($entry) {
         return array_filter($entry);
     }, $request['entries']));
     // If any exceptions are thrown any DB operations
     // will be automatically rolled back.
     DB::transaction(function () use($request) {
         $weighIn = new WeighIn();
         // Deal with boat section
         if (!empty($request['boat']) && !empty($request['boat']['name'])) {
             if (isset($request['boat']['id'])) {
                 // assign a boat to the weigh-in
                 $boat = Boat::findOrFail($request['boat']['id']);
             } else {
                 // create a new boat
                 $boat = new Boat();
                 $boat->name = $request['boat']['name'];
                 $boat->charter = isset($request['boat']['charter']) ? true : false;
                 if (!empty($request['boat']['skipper']['id'])) {
                     $boat->skipper()->associate(User::find($request['boat']['skipper']['id']));
                 }
                 $boat->save();
             }
             $weighIn->boat()->associate($boat);
         }
         // TODO: discuss with Rob if it makes sense
         //            if(!empty($request['team_id'])){
         //                $weighIn->team()->associate(Team::find($request['team_id']));
         //            }
         $weighIn->date = $request['date'];
         $weighIn->entry_ticket_number = $request['entry_ticket_number'];
         $weighIn->sheet_number = $request['sheet_number'];
         $weighIn->team_number = !empty($request['team_number']) ? $request['team_number'] : null;
         $weighIn->event()->associate(Event::find($request['event_id']));
         $weighIn->site()->associate(Site::find($request['weigh_in_site_id']));
         $weighIn->user()->associate(User::find($request['user_id']));
         $weighIn->save();
         foreach ($request['entries'] as $e) {
             $entry = new Entry();
             $entry->weight = Helpers::toDrams($e['species_weight']);
             $entry->percentage = Weight::calculatePercentage($e['species_id'], $e['sector_id'], $e['species_weight']);
             $entry->sector()->associate(Sector::find($e['sector_id']));
             $entry->location()->associate(Location::find($e['location_id']));
             $entry->event()->associate(Event::find($request['event_id']));
             $entry->species()->associate(Species::find($e['species_id']));
             $entry->user()->associate(User::find($request['user_id']));
             $entry->weighIn()->associate($weighIn);
             $entry->save();
             if (isset($e['categories'])) {
                 $categories = [];
                 foreach ($e['categories'] as $catId) {
                     $categories[$catId] = ['event_id' => (int) $request['event_id']];
                 }
                 $entry->categories()->sync($categories);
             }
         }
         //dd($request);
     });
     flash()->success('Success!', "New weigh-in has been created!");
     return redirect(route('admin.weigh-ins.create'));
 }
コード例 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $location = Location::findOrFail($id);
     $locationName = $location->name;
     $location->delete();
     flash()->success('Success!', "{$locationName} location has been created!");
     return redirect(route('admin.settings.fishing.locations.index'));
 }
コード例 #5
0
 /**
  * Returns an array of Fishing Locations
  *
  * @return array
  */
 public static function getWeighInLocations()
 {
     $locations = [];
     foreach (Location::all() as $location) {
         $locations[$location->id] = $location->name;
     }
     return $locations;
 }
コード例 #6
0
 /**
  * @return mixed
  */
 public function index()
 {
     $locations = Location::orderBy('id')->get();
     return $this->respond(['data' => $this->locationsTransformer->transformCollection($locations->all())]);
 }