public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { InventoryPlan::create([]); } }
/** * Show the form for editing the specified room. * * @param int $id * @param int $channelId * @return Response */ public function getMap($id, $channelId) { $room = Room::find($id); $channelSettings = PropertiesChannel::getSettings($channelId, Property::getLoggedId()); $channel = ChannelFactory::create($channelSettings); $result = $channel->getInventoryList(); //todo temp // file_put_contents('1.txt', serialize($result)); // $result = unserialize(file_get_contents('1.txt')); //add Inventories and Plans to DB//TODO move to another place //delete exist maps Inventory::where(['channel_id' => $channelId, 'property_id' => $channelSettings->property_id])->delete(); //delete exist plan maps InventoryPlan::where(['channel_id' => $channelId, 'property_id' => $channelSettings->property_id])->delete(); if ($result) { foreach ($result as $inventory) { Inventory::create(['code' => $inventory['code'], 'name' => $inventory['name'], 'channel_id' => $channelId, 'property_id' => $channelSettings->property_id]); if ($inventory['plans']) { foreach ($inventory['plans'] as $plan) { InventoryPlan::create(['code' => $plan['code'], 'name' => $plan['name'], 'channel_id' => $channelId, 'inventory_code' => $inventory['code'], 'property_id' => $channelSettings->property_id]); } } } } $existMapping = []; // $mapCollection = InventoryMap::where( // [ // 'channel_id' => $channelId, // 'property_id' => $channelSettings->property_id // ] // ) //// ->where('room_id', '<>', $id) // ->lists('inventory_code', 'room_id'); // if ($mapCollection) { // foreach ($mapCollection as $map) { // $existMapping[] = $map; // } // }>F $inventories = Channel::find($channelId)->inventory()->where('property_id', Property::getLoggedId()); $inventoryList = []; $inventoryPlans = []; foreach ($inventories->get() as $inventory) { // if (in_array($inventory->code, $existMapping)) { // continue; // } $inventoryList[$inventory->code] = $inventory->name; $plans = $inventory->plans()->get(['name', 'code']); for ($i = 0; $i < count($plans); $i++) { //TODO rewrite to ONE query $plans[$i]->selected = InventoryMap::getByKeys($channelId, $channelSettings->property_id, $id, $plans[$i]['code'])->first() ? true : false; } $inventoryPlans[$inventory->code] = $plans; } $inventoryPlans = json_encode($inventoryPlans); $mapping = InventoryMap::getByKeys($channelId, $channelSettings->property_id, $id)->first(); return View::make('rooms.map', compact('room', 'channel', 'inventoryList', 'inventoryPlans', 'channelId', 'mapping')); }