public function status($statusType) { if (1 == $statusType) { $buildingNumber = Building::count(); $roomNumber = Room::count(); $buildingRet = ['buildingNumber' => $buildingNumber, 'roomNumber' => $roomNumber]; return $buildingRet; } else { if (2 == $statusType) { $roomNumber = Room::count(); $rentedRoomNumber = Contract::count(); $emptyRoomNumber = $roomNumber - $rentedRoomNumber; $rentRet = ['roomNumber' => $roomNumber, 'rentedNumber' => $rentedRoomNumber, 'emptyNumber' => $emptyRoomNumber]; return $rentRet; } else { if (3 == $statusType) { $feePlanItem = DB::select('SELECT COUNT(DISTINCT feemeta_id) as counts FROM fee_plans WHERE status=0 AND deleted_at IS NULL'); $feePlanRentNumber = DB::select('SELECT COUNT(DISTINCT rent_id) as counts FROM fee_plans WHERE status=0 AND deleted_at IS NULL'); $feeRet = ['feePlanNumber' => $feePlanItem[0]->counts, 'feePlanRentNumber' => $feePlanRentNumber[0]->counts]; return $feeRet; } else { if (4 == $statusType) { $userNumber = User::count(); $userRet = ['userCount' => $userNumber]; return $userRet; } } } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($id, Request $request) { //a user can add a unit to a building $building = Building::findOrFail($id); $unit = $building->units()->create($request->all()); return redirect(url('/home')); }
/** * @param City $city * @param Building $building * @param Request $request * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ private function setWorkers(City $city, Building $building, Request $request) { $workers = $request->input('workers'); // validate the request's number if ($workers > $building->level * 10 || $workers < 0) { return redirect($request->url())->withErrors(["no_more_worker" => "Az épületben nem dolgozhat ennyi munkás"]); } // check if the user want to add or remove workers. $diff = $workers - $building->workers; if ($city->hasEnoughHumanResources(['workers' => $diff])) { $city->human_resources->subtract(['workers' => $diff]); $building->workers = $workers; $building->save(); return redirect()->back(); } return redirect()->back()->withErrors(['not_enough_worker' => "Nincs elég munkás"]); }
public function getBuilding($id) { $building = \App\Building::where('street_id', $id)->orderBy('number')->orderBy('housing')->get(); $data = []; foreach ($building as $item) { $n = strval($item->number); if ($item->housing) { $n .= '/' . $item->housing; } array_push($data, ['id' => $item->id, 'title' => $n]); } return json_encode($data); }
public function healWall(Request $request, $city_id) { $city = City::where('id', $city_id)->first(); if (!$this->validateOwner($city)) { return redirect('/home')->withErrors('Nem a te városod'); } $wall = $city->building_slot->wall; $wall = Building::find($wall); $this->validate($request, ['health' => 'required|integer|max:100']); $health = $request->input('health'); $price = ['iron' => $health, 'food' => $health, 'stone' => $health, 'lumber' => $health]; $time = $health; $this->heal($city, $wall, $price, $time, $health); return redirect("/city/{$city_id}/wall"); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $building = Building::find($this->buildings); switch ($this->method()) { case 'GET': case 'DELETE': return []; case 'POST': return ['code' => 'required|unique:buildings|max:20', 'name' => 'required|max:254']; case 'PUT': case 'PATCH': return ['code' => "required|unique:buildings,code,{$building->id}|max:20", 'name' => 'required|max:254']; default: break; } }
/** * creates a city and the belonging models (BuildingSlot, Resource, HumanResource) * saves the city in the map * * @param User $user The user to whom the city belongs * @param bool $capital Is the city a capital * @param int $hex_id the id of the hex on which the city is located * @param string $name the name of the city */ public static function create(array $attributes) { /** @var City $city */ $city = parent::create($attributes); /** @var BuildingSlot $slot */ $slot = BuildingSlot::create(['city_id' => $city->id]); Resource::create(['city_id' => $city->id]); HumanResource::create(['city_id' => $city->id]); $city->building_slot = $slot->id; $city->save(); /** @var Building $wall */ $wall = Building::create(['city_id' => $city->id, 'slot' => $slot->id, 'nation' => $attributes['nation'], 'type' => 9, 'finished_at' => Carbon::now()]); $slot->wall = $wall->id; $slot->save(); /** @var Grid $hex */ $hex = Grid::find($hex_id); $hex->update(['owner_id' => $attributes['owner'], 'city_id' => $city->id]); $hex->setNeighborsOwner($attributes['owner']); }
/** * Generate an address for a location * @param $location * @return string */ private function generateAddress($location) { $locationName = $location->locationKeyCode; $locationId = $location->id; $location = $this->location->findOrFail($locationId); $levelId = $location->level_id; $level = $this->level_building->findOrFail($levelId); $levelName = $level->levelName; $building_id = $level->building_id; $building = $this->building->findOrFail($building_id); $buildingName = $building->buildingKeyCode; $street_id = $building->street_id; $street = $this->street->findOrFail($street_id); $streetName = $street->streetKeyCode; $agent_id = $street->agent_id; $this->agent_id = $agent_id; //$agent = $this->agent->findOrFail($agent_id); $agentName = \App\Agent::where('user_id', '=', $agent_id)->first()->agentName; return $buildingName . $levelName . $locationName . "-" . $streetName . " ( " . $agentName . " ) "; }
public function remove(Building $building) { $building->delete(); }
/** * Persist a building level to the database * @param $request * @param $id */ public function persist($request, $id) { $building = $this->building->findOrFail($id); $building->levels()->create(['building_id' => $id, 'level_id' => $request->levelName, 'levelName' => $this->level->where('id', '=', $request->levelName)->first()->levelName]); $this->updateLevels($building); }
<?php require_once 'vendor/autoload.php'; use App\Building; use App\FordAssemblyLine; $building = new Building(new FordAssemblyLine()); $building->createTrucks(); $inventory = $building->getInventory(); dump($inventory);
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $building = Building::findOrFail($id); $building->delete(); return redirect()->route('buildings.index')->with('message', 'Item deleted successfully.'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $buildings = Building::all(); $classroom = Classroom::findOrFail($id); return view('classrooms.edit', compact('classroom', 'buildings')); }
/** * Get the number of levels that a building has * @param $id * @return mixed */ public function getLevelsCount($id) { return $this->building->where('id', '=', $id)->first()->levelsCount; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { return Building::find($id); }
public function getBuildingsForCity($id) { $city = City::find($id); $buildings = \App\Building::all(); $modifiedPrices = ResourceController::getPricesForBuildings($buildings, $city); return $modifiedPrices; for ($i = 0; $i < count($buildings); $i++) { $buildings[$i]->resource = $modifiedPrices[$i]; } return $buildings; }
public static function buildingWearing(Building $building) { $now = Carbon::now(); $workers = $building->workers; if ($workers == 0) { $workers = 0.5; } $time = $building->updated_at->diffInSeconds($now); $wearing = $time / 3600 * ($workers * 0.1); $building->health -= $wearing; $building->save(); }
public function index() { return Building::all(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $buildings = Building::with('resource')->get(); return $buildings; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { return Building::destroy($id); }
/** * Store a csv created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function import(Request $request) { if ($request->file('csv-file')->isValid()) { $csv_file = $request->file('csv-file'); if ("text/csv" == $csv_file->getClientMimeType()) { $dest_path = storage_path('temp'); $file_name = time() . '_' . str_replace(" ", "_", $csv_file->getClientOriginalName()); $csv_file->move($dest_path, $file_name); $fname = $dest_path . '/' . $file_name; $file = fopen($fname, "r"); $flash_message = []; $flash_error = 0; while (!feof($file)) { $tmp_data = fgetcsv($file); $item['building_id'] = !empty($tmp_data[0]) ? $tmp_data[0] : ''; $building = Building::where('code', '=', $item['building_id'])->first(); if ($building) { $item['building_id'] = $building->id; } $item['code'] = !empty($tmp_data[1]) ? $tmp_data[1] : ''; $item['name'] = !empty($tmp_data[2]) ? $tmp_data[2] : ''; $item['capacity'] = !empty($tmp_data[3]) ? $tmp_data[3] : '0'; $item['feature_id'] = !empty($tmp_data[4]) ? $tmp_data[4] : '1'; $v = Validator::make($item, ['building_id' => 'required|integer', 'code' => 'required|unique:rooms|max:20', 'name' => 'required|max:254', 'capacity' => 'integer|min:5', 'feature_id' => 'integer|min:1']); if (!$v->fails()) { Room::create($item); $flash_message['success'][] = '[' . $item['code'] . '] ' . $item['name']; } else { $flash_error++; $flash_message['error'] = $flash_error; } } \Session::flash('flash_message', $flash_message); fclose($file); chmod($fname, 0777); unlink($fname); } } return redirect('/rooms'); }