public function buyCar(Car $car) { if ($this->getMoney() >= $car->getPrice()) { $this->setMoney($this->getMoney() - $car->getPrice()); $this->setCar($car); } }
function wordpress_setup() { $car = new Car(); add_action('init',function() use ($car){ register_taxonomy('car',array('fill'), $car->taxonomy()); }); add_action('template_include',function($template){ global $wp,$wp_query; if($wp_query->query_vars['taxonomy']=='car' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest' ){ $new_template = locate_template( array( 'taxonomy-car_ajax.php' ) ); if ( '' != $new_template ) { return $new_template ; } } elseif ($wp->request == 'car') { $new_template = locate_template( array( 'archive-car.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; }); return $this; }
public function testBridge() { $expect = "SssuuuuZzzuuuuKkiiiii"; $car = new Car(new EngineSuzuki()); $sound = $car->rase(); $this->assertEquals($sound, $expect); }
protected function isStreetLegal(Car $car) { if ($car->getMaximumSpeed() < $this->speedLimit) { return true; } else { return false; } }
public function copy() { $car = new Car(); $car->setBody($this->getBody()); $car->setWheel($this->getWheel()); $car->setEngine($this->getEngine()); return $car; }
public function testCarPartsFactoryCreateEngineCalled() { $hybridEngine = new HybridEngine(); $factoryStub = $this->getMock('HybridCarPartsFactory'); $factoryStub->expects($this->once())->method('createEngine')->will($this->returnValue($hybridEngine)); $car = new Car($factoryStub); $car->start(); }
public function testName() { // Create new Car and pass in a name $car = new Car("Murcielago"); // Get the car name $result = $car->name(); // Assert that the name has been set correctly $this->assertEquals("Murcielago", $result); }
public function testMaxSpeed() { $car = new Car(); for ($i = 0; $i < 10; $i++) { $car->accelerate(); } $this->assertEquals(100, $car->getSpeed()); $car->accelerate(); $this->assertEquals(100, $car->getSpeed()); }
public static function withPriceandMaxspeed($model, $isSportsCar, $color, $price, $maxSpeed) { $car = new Car(); $car->model = $model; $car->isSportscar = $isSportsCar; $car->color = $color; $car->setPrice($price); $car->setMaxspeed($maxSpeed); return $car; }
public function buyCar(Car $car) { if ($this->money >= $car->getPrice()) { $this->money -= $car->getPrice(); echo ' Purchase successful!', PHP_EOL; $this->car = $car; $car->changeOwner($this); return $this->money; } else { echo ' You need more money! '; } }
public function buyCar($car) { $car = new Car(); $carPrice = $car->getPrice(); //return $car->getModel; if ($this->money > $carPrice) { $this->ownedCar = $car; return $carPrice; //$this->money -= $carPrice; } else { return $this->money; } }
/** * @test */ public function shouldBeAbleToPopulateByJSON() { // given $car = new Car(1); $this->assertEquals(1, $car->getId()); $json = $car; $array = json_decode($json, true); // when $array['brand'] = 'BMW'; $car->setValues($array); $car->commit(); $newCar = new Car(1); // then $this->assertEquals('BMW', $newCar->getBrand()); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Car::create([]); } }
public function run() { $faker = Faker::create(); $parking_lot = ParkingLot::all()->random(); $car = Car::all()->random(); $order = new Order(); $order->parking_lot_id = $parking_lot->id; $order->car_id = $car->id; $order->stripe_customer_id = $faker->swiftBicNumber; $order->save(); $parking_lot = ParkingLot::all()->random(); $car = Car::all()->random(); $order2 = new Order(); $order2->parking_lot_id = $parking_lot->id; $order2->car_id = $car->id; $order2->stripe_customer_id = $faker->swiftBicNumber; $order2->save(); $parking_lot = ParkingLot::all()->random(); $car = Car::all()->random(); $order3 = new Order(); $order3->parking_lot_id = $parking_lot->id; $order3->car_id = $car->id; $order3->stripe_customer_id = $faker->swiftBicNumber; $order3->save(); }
public function getAsArray($redundantly = false) { if (isset($this->id) && (int) $this->id > 0) { $content = array(); if (!is_null($this->text)) { $content['text'] = $this->text; } else { if (!is_null($this->image_id)) { $domain = 'http' . (Request::server('HTTPS') ? '' : 's') . '://' . Request::server('HTTP_HOST'); $attachment = MessageAttachment::find($this->image_id); $content['image'] = array('id' => (int) $attachment->id, 'thumb' => $domain . '/api/messages/attach/thumb/' . $attachment->id, 'origin' => $domain . '/api/messages/attach/gallery/' . $attachment->id, 'width' => $attachment->width, 'height' => $attachment->height); } else { if (!is_null($this->car_id)) { $car = Car::withTrashed()->find($this->car_id); $content['car'] = array('id' => (int) $car->id, 'mark' => (int) $car->mark, 'model' => (int) $car->model, 'year' => (int) $car->year, 'color' => (int) $car->color, 'vehicle_type' => (int) $car->vehicle_type, 'body_type' => (int) $car->body_type); if (!is_null($this->car_number)) { $content['car']['number'] = $this->car_number; } } else { if (!is_null($this->lat)) { $content['geo'] = array('lat' => (double) $this->lat, 'long' => (double) $this->lng, 'location' => $this->location); } } } } if ($redundantly) { $user = User::find($this->user_id); return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user' => array('id' => (int) $user->id, 'name' => $user->name, 'img' => array('middle' => $user->img_middle)), 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at); } else { return array('message_id' => (int) $this->id, 'chat_id' => (int) $this->chat_id, 'user_id' => (int) $this->user_id, 'content' => $content, 'timestamp' => $this->getTimestamp(), 'delivered_at' => $this->delivered_at, 'viewed_at' => $this->viewed_at); } } return array(); }
function updateCars() { $carsId = implode(',', $this->curShowCarsId); Car::update_all(array('conditions' => 'id in(' . $carsId . ')', 'set' => 'count_visit = count_visit+1')); $this->lastCars->cars_id = $carsId; $this->lastCars->save(); }
protected function loadModel($id) { $model = Car::model()->findByPk($id); if (empty($model)) { throw new CHttpException(404, 'ผิดพลาดการดึงข้อมูลรถ ลองใหม่อีกครั้ง'); } return $model; }
public function run() { $faker = Faker::create(); Car::truncate(); foreach (range(1, 11) as $index) { Car::create(['user_id' => $index, 'mark' => $faker->word, 'model' => $faker->word, 'year' => $faker->hexcolor, 'color' => $faker->colorName, 'transmission' => $faker->word, 'body' => $faker->word, 'number' => $faker->word]); } }
public function getBookCar() { $car = Car::find(Input::get('id')); if ($car) { return View::make('store.booking')->with('car', Car::find(Input::get('id'))); } return Redirect::to('/')->with('message', 'invalid car id, please try again'); }
public static function hasDone($uid) { $car = Car::findFirst("uid={$uid}"); if (!$car) { return false; } $advises = Advise::getAdvisesByUid($uid, Advise::STATUS_UNDO, 'car'); return $advises ? false : true; }
public function move($distance) { // $this->money = 0 + 10*0.65 = 6.5 $result = parent::move($distance); if ($result == true) { $this->money = $this->money + $distance * $this->price_per_km; } else { echo "Nema nafta"; } }
public function indexAction() { $cars = Car::findAll(); foreach ($cars as $car) { echo $car->brand . '<br>'; foreach ($car->Users as $u) { echo $u->name . '<br>'; } } }
function updateCar($id) { $request = Slim\Slim::getInstance()->request(); $car = Car::find($id); $car_getbody = json_decode($request->getBody()); $car->modelC = $car_getbody->modelC; $car->brandC = $car_getbody->brandC; $car->registrationC = $car_getbody->registrationC; $car->save(); echo $car; }
public function setUpCarsAndDrivers() { Doctrine::createTablesFromArray(array('Car', 'Driver')); $bmw = new Car(); $bmw->make = 'BMW'; $bmw->save(); $this->cars['bmw'] = $bmw; $audi = new Car(); $audi->make = 'Audi'; $audi->save(); $this->cars['audi'] = $audi; $kiro = new Driver(); $kiro->name = 'Kiril Zyapkov'; $kiro->save(); $this->drivers['kiro'] = $kiro; $emo = new Driver(); $emo->name = 'Emil Ivanov'; $emo->save(); $this->drivers['emo'] = $emo; }
public function afterDelete() { # Проверка и очистка связей $models = Car::model()->findAll('brand_id=:brand_id', array(':brand_id' => $this->id)); if (count($models) > 0) { foreach ($models as $model) { $model->delete(); } } $this->deleteImage('logo_delete', $this->logo_sizes); return parent::afterDelete(); }
public function viewAction($id = null) { if (!is_null($id) and is_numeric($id)) { $car = Car::findFirst("id = " . $id); if (!$car) { return $this->dispatcher->forward(["controller" => "index", "action" => "index"]); } $this->view->car = $car; } else { return $this->dispatcher->forward(["controller" => "index", "action" => "index"]); } }
public function run() { $user = User::firstOrFail(); $car = new Car(); $car->make = 'Toyota'; $car->model = 'Prius'; $car->license_plate_number = '4AQJ668'; $car->color = 'Red'; $car->user_id = $user->id; $car->save(); $car2 = new Car(); $car2->make = 'Hyundai'; $car2->model = 'Genesis'; $car2->license_plate_number = '6GDG486'; $car2->color = 'Blue'; $car2->user_id = $user->id; $car2->save(); $car3 = new Car(); $car3->make = 'BMW'; $car3->model = 'X6'; $car3->license_plate_number = 'G742594'; $car3->color = 'White'; $car3->user_id = $user->id; $car3->save(); $car4 = new Car(); $car4->make = 'Kia'; $car4->model = 'Soul'; $car4->license_plate_number = '2CJC569'; $car4->color = 'Black'; $car4->user_id = $user->id; $car4->save(); $car5 = new Car(); $car5->make = 'Ferrari'; $car5->model = 'Testa Rossa'; $car5->license_plate_number = 'BB1B001'; $car5->color = 'Gray'; $car5->user_id = $user->id; $car5->save(); }
public function storeCar() { $messages = array('make.required' => 'Make field cannot be left empty.', 'make.max' => 'You must enter a value with a maximum of 255 characters.', 'model.required' => 'Model field cannot be left empty.', 'model.max' => 'You must enter a value with a maximum of 255 characters.', 'license_plate_number.required' => 'License Plate Number field cannot be left empty.', 'license_plate_number.max' => 'You must enter a value with a maximum of 255 characters.', 'color.required' => 'Color field cannot be left empty.', 'color.max' => 'You must enter a value with a maximum of 255 characters.'); $validator = Validator::make($data = Input::all(), Car::$rules, $messages); if ($validator->fails()) { return Response::json($validator->messages()); } $car = new Car(); $car->make = Input::get('make'); $car->model = Input::get('model'); $car->license_plate_number = Input::get('license_plate_number'); $car->color = Input::get('color'); if (Auth::check()) { $car->user_id = Auth::user()->id; } $result = $car->save(); $order = new Order(); $order->car_id = $car->id; $order->parking_lot_id = Input::get('hiddenParkingLot'); $order->save(); return Response::json(['success' => true]); }
public function actionIndex() { echo "<h1>All cars</h1>"; $cars = Car::model()->findAll(); foreach ($cars as $car) { // Each car can be of class Car, SportCar or FamilyCar echo get_class($car) . ' ' . $car->name . "<br />"; } echo "<h1>Sport cars only</h1>"; $sportCars = SportCar::model()->findAll(); foreach ($sportCars as $car) { // Each car should be SportCar echo get_class($car) . ' ' . $car->name . "<br />"; } }
public function run() { Yii::import($this->import); $id = Yii::app()->request->getParam('id', 0); if ($id <= 0) { echo '{}'; } else { $models = Car::model()->findAll(array('condition' => 'brand_id=' . $id, 'order' => 'title')); $data = array(''); foreach ($models as $m) { $data[$m->id] = $m->title . ' ' . EString::getYear($m->manufacture_start) . (empty($m->manufacture_end) ? '...' : ' - ' . EString::getYear($m->manufacture_end)); } echo CJavaScript::jsonEncode($data); } }