public function getShoeRunAPI($shoe_id, $run_id) { $user_id = Auth::user()->id; $shoe = Shoe::find($shoe_id); if ($shoe->user_id == $user_id) { $run = Run::find($run_id); return Response::json($runs); } else { return Redirect::route('home'); } }
public function run() { DB::table('shoes')->delete(); Shoe::create(array('name' => 'Nike Foos', 'purpose' => 'Running', 'miles_cap' => 250, 'show' => true, 'shoe_image_url' => 'http://placehold.it/300x300', 'purchase_url' => 'http://example.com', 'user_id' => 7)); Shoe::create(array('name' => 'Reebok Foos', 'purpose' => 'Running', 'miles_cap' => 350, 'show' => true, 'shoe_image_url' => 'http://placehold.it/300x300', 'purchase_url' => 'http://example.com', 'user_id' => 8)); }
/** * Add equipment */ protected function addEquipment() { $id = $this->Context->activity()->shoeID(); if ($id) { $Shoe = new Shoe($id); if (!$Shoe->isDefaultId()) { $RunningShoe = new BoxedValue($Shoe->getSearchLink(), '', __('Running shoe')); $RunningShoe->defineAsFloatingBlock('w100 flexible-height'); $this->BoxedValues[] = $RunningShoe; } } }
$Frontend = new Frontend(); if (Request::param('delete') == 'true') { DB::getInstance()->deleteByID('shoe', (int) Request::sendId()); DB::getInstance()->query('UPDATE `' . PREFIX . 'training` SET `shoeid`=0 WHERE `shoeid`=' . (int) Request::sendId() . ' AND accountid = ' . SessionAccountHandler::getId()); Cache::delete(ShoeFactory::CACHE_KEY); header('Location: window.schuhe.table.php?reload=true'); exit; } if (Request::sendId() === false) { $Header = __('Add new shoe'); $Mode = StandardFormular::$SUBMIT_MODE_CREATE; $Shoe = new Shoe(DataObject::$DEFAULT_ID); } else { $Header = __('Edit shoe'); $Mode = StandardFormular::$SUBMIT_MODE_EDIT; $Shoe = new Shoe(Request::sendId()); } $Formular = new StandardFormular($Shoe, $Mode); if ($Formular->submitSucceeded()) { header('Location: window.schuhe.table.php'); ShoeFactory::clearCache(); exit; } if (Request::sendId() > 0) { $DeleteText = '<strong>' . __('Delete shoe') . ' »</strong>'; $DeleteUrl = $_SERVER['SCRIPT_NAME'] . '?delete=true&id=' . $Shoe->id(); $DeleteLink = Ajax::link($DeleteText, 'ajax', $DeleteUrl); if ($Shoe->getKm() != $Shoe->getAdditionalKm()) { $DeleteLink = __('The shoe cannot be deleted as long it is used for some activity.'); } $DeleteFieldset = new FormularFieldset(__('Delete shoe'));
/** * Display table */ public function displayTable() { if (is_null($this->schuhe)) { $this->initTableData(); } echo '<table id="list-of-all-shoes" class="fullwidth zebra-style"> <thead> <tr> <th class="{sorter: \'x\'} small">' . __('x-times') . '</th> <th class="{sorter: false}"></th> <th>' . __('Name') . '</th> <th class="{sorter: \'germandate\'} small">' . __('since') . '</th> <th class="{sorter: \'distance\'}">Ø km</th> <th>Ø ' . __('Pace') . '</th> <th class="{sorter: \'distance\'} small"><small>' . __('max.') . '</small> km</th> <th class="small"><small>' . __('min.') . '</small> ' . __('Pace') . '</th> <th class="{sorter: \'resulttime\'}">' . __('Time') . '</th> <th class="{sorter: \'distance\'}">' . __('Distance') . '</th> <th>' . __('Weight') . '</th> </tr> </thead> <tbody>'; if (!empty($this->schuhe)) { foreach ($this->schuhe as $schuh) { $Shoe = new Shoe($schuh); $in_use = $Shoe->isInUse() ? '' : ' unimportant'; $Pace = new Pace($Shoe->getTime(), $Shoe->getKmInDatabase()); $MaxPace = new Pace($schuh['pace_in_s'], 1); echo '<tr class="' . $in_use . ' r" style="position: relative"> <td class="small">' . $schuh['num'] . 'x</td> <td>' . $this->editLinkFor($schuh['id']) . '</td> <td class="b l">' . ShoeFactory::getSearchLink($schuh['id']) . '</td> <td class="small">' . $Shoe->getSince() . '</td> <td>' . ($schuh['num'] != 0 ? Distance::format($Shoe->getKmInDatabase() / $schuh['num']) : '-') . '</td> <td>' . ($schuh['num'] != 0 ? $Pace->asMinPerKm() . '/km' : '-') . '</td> <td class="small">' . Distance::format($schuh['dist']) . '</td> <td class="small">' . $MaxPace->asMinPerKm() . '/km' . '</td> <td>' . $Shoe->getTimeString() . '</td> <td>' . $Shoe->getKmString() . '</td> <td class="small">' . $Shoe->getWeightString() . '</td> </tr>'; } } else { echo '<tr><td colspan="9">' . __('You don\'t have any shoes') . '</td></tr>'; } echo '</tbody>'; echo '</table>'; Ajax::createTablesorterFor("#list-of-all-shoes", true); }
//delete shoe page $app->get("/shoes/{id}/delete", function ($id) use($app) { $shoe = Shoe::find($id); $shoe->deleteOne(); return $app['twig']->render('shoes.html.twig', array('shoes' => Shoe::getAll())); }); //delete all shoes page $app->post("/delete_shoes", function () use($app) { Shoe::deleteAll(); return $app['twig']->render('index.html.twig'); }); //delete all stores page $app->post("/delete_stores", function () use($app) { Store::deleteAll(); return $app['twig']->render('index.html.twig'); }); //add shoes page $app->post("/add_shoes", function () use($app) { $store = Store::find($_POST['store_id']); $shoe = Shoe::find($_POST['shoe_id']); $store->addShoe($shoe); return $app['twig']->render('store.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'shoes' => $store->getShoes(), 'all_shoes' => Shoe::getAll())); }); //add stores page $app->post("/add_stores", function () use($app) { $store = Store::find($_POST['store_id']); $shoe = Shoe::find($_POST['shoe_id']); $shoe->addStore($store); return $app['twig']->render('shoe.html.twig', array('shoe' => $shoe, 'shoes' => Shoe::getAll(), 'stores' => $shoe->getStores(), 'all_stores' => Store::getAll())); }); return $app;
public function testResetShoe() { $this->assertNull($this->shoe->resetShoe()); }
/** * Gather all relevant data for passing into the All Shoes View * @return array of all relevant data */ public function prepareUserShoeData($name, $include_hidden = false) { /** * Get All of a User's Relevant Data */ $shoe_array = array(); $user = User::where('name', '=', $name)->first(); // Sort so that newest shoes show up first $shoes = Shoe::where('user_id', '=', $user->id)->orderBy('created_at', 'DESC')->get(); /** * Now Map It All */ $array = array('username' => $user->name, 'email' => $user->email); /** * Loops through all shoes and matches all runs to the appropriate shoe * Also totals up the number of miles based off of the runs * And calculates miles remianing * Ignores shoes that are hidden unless $include_hidden is set to 'true' */ foreach ($shoes as $shoe) { if ($shoe->show || $include_hidden) { $shoe->runs = Run::where('shoe_id', '=', $shoe->id)->orderBy('run_date', 'DESC')->get(); $shoe->miles_run = 0; foreach ($shoe->runs as $run) { $shoe->miles_run += $run->miles; $run->run_date = date("M d, Y", strtotime($run->run_date)); // Only one decimal for miles $run->miles = number_format_clean($run->miles, 1); // Add a string version for printing if ($run->miles == 1) { $run->miles_string = "1 Mile"; } else { $run->miles_string = $run->miles . " Miles"; } } // Don't let @var miles_remaining this value go below zero $shoe->miles_remaining = $shoe->miles_cap - $shoe->miles_run; if ($shoe->miles_remaining < 0) { $shoe->miles_remaining = 0; } $shoe->percent_remaining = $shoe->miles_run / $shoe->miles_cap * 100; array_push($shoe_array, $shoe); } } $array['shoes'] = $shoe_array; return $array; }
function testDelete() { //Arrange $store_name = "New Balance"; $id = 1; $test_store = new Store($store_name, $id); $test_store->save(); $shoe_name = "Nike"; $id2 = 2; $test_shoe = new Shoe($shoe_name, $id2); $test_shoe->save(); //Act $test_shoe->addStore($test_store); $test_shoe->deleteOne(); //Assert $this->assertEquals([], $test_store->getShoes()); }