public function myListings($app) { if (!$app->user->isLoggedIn()) { $app->output->redirect('/account/login'); } $app->output->addBreadcrumb('', 'CSGOShop'); $app->output->addBreadcrumb('account/listings', 'My Listings'); $listings = Listing::all(array('conditions' => array('user_id = ? AND ISNULL(parent_listing_id)', $app->user->id), 'order' => 'updated_at DESC', 'include' => array('description'))); $request = $app->router->flight->request(); $page = $request->query->p ?: 0; $offset = $page * self::MAX_LISTINGS_SHOWN; $total = ceil(count($listings) / self::MAX_LISTINGS_SHOWN); if ($offset < 0 || $page > $total) { $app->output->redirect('/account/listings'); } $listings = array_slice($listings, $offset, self::MAX_LISTINGS_SHOWN); if (isset($app->router->flight->request()->query->new)) { $app->output->alert('You have successfully requested a new listing.', 'success'); } if (isset($app->router->flight->request()->query->cancel)) { $app->output->alert('Your request to cancel a listing has been sent.', 'success'); } if (empty($listings)) { $app->output->alert('You do not have any listings open.', 'warning'); } $app->output->setTitle('My Listings'); $app->output->setActiveTab('account'); $app->output->render('account.listings', ['listings' => $listings, 'page_num' => $page, 'total' => $total]); }
/** * Revert the changes to the database. * * @return void */ public function down() { // $listings = Listing::all(); foreach ($listings as $listing) { $listing->delete(); } }
/** * Make changes to the database. * * @return void */ public function up() { // $listings = Listing::all(); foreach ($listings as $l) { for ($i = 0; $i < 5; $i++) { $image = new Image(); $image->description = "PIC DESCRIPTIOIN"; $image->listing_id = $l->id; $image->save(); } } }
public function inventory($app) { try { $id = $app->user->id; $inventory = $app->steam->getInventory($id); // Filter out items already in listings $listings = Listing::all(array('conditions' => array('user_id = ? AND stage != ?', $id, Listing::STAGE_DELETE))); foreach ($listings as $idx => $listing) { unset($inventory[$listing->item_id]); } $inventory_json = array(); foreach ($inventory as $item_id => $item) { print_r($item); array_push($inventory_json, array('id' => $item->id, 'market_name' => $item->desc->market_name, 'stackable' => $item->desc->stackable, 'price_preset' => $item->desc->price_preset, 'icon' => $item->desc->icon_url_large ?: $item->desc->icon_url)); } $app->output->json(array('error' => false, 'items' => $inventory_json)); } catch (SteamAPIException $e) { $app->logger->log('Inventory fetch failed (SteamAPIException)', 'ERROR', array('pathway' => 'inventory'), 'user'); $app->output->json(array('error' => true, 'message' => 'Steam API could not be reached.'), 503); } catch (User_InventoryError $e) { $app->logger->log('Inventory fetch failed (User_InventoryError)', 'ERROR', array('pathway' => 'inventory'), 'user'); $app->output->json(array('error' => true, 'message' => 'Your inventory could not be fetched.'), 500); } }