public static function createAndSaveRawModelWithManyToManyRelation() { include_once __DIR__ . '/../scripts/tested_models.php'; $car = new \Car(); $car->nameCar = 'AcmeCar'; $car->noteCar = '10'; $car->idBrand = 1; $car->save(); $tags = array(); $tag1 = new \Tag(); $tag1->libTag = 'Sport'; $tag1->save(); $tag2 = new \Tag(); $tag2->libTag = 'Family'; $tag2->save(); $tag3 = new \Tag(); $tag3->libTag = 'Crossover'; $tag3->save(); $tags[] = $tag1; $tags[] = $tag2; $tags[] = $tag3; $car->setTag($tags); $car->save(); // create test $req = \PicORM\Model::getDataSource()->prepare('SELECT count(*) as nb FROM car_have_tag WHERE idCar = ?'); $req->execute(array($car->idCar)); $resultBDD = $req->fetch(\PDO::FETCH_ASSOC); return array(array($car, $tags, $resultBDD)); }
public function postCreate() { $validator = Validator::make(Input::all(), Car::$rules); if ($validator->passes()) { $car = new Car(); $car->type_id = Input::get('type_id'); $car->title = Input::get('title'); if (Input::get('description')) { $car->description = Input::get('description'); } $car->price = Input::get('price'); $car->available_at = Input::get('available_at'); $car->transmission = Input::get('transmission'); $car->aircon = Input::get('aircon'); $car->seats = Input::get('seats'); $car->doors = Input::get('doors'); $image = Input::file('image'); $filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName(); Image::make($image->getRealPath())->resize(220, 128)->save('public/img/cars/' . $filename); $car->image = 'img/cars/' . $filename; $car->save(); return Redirect::to('admin/cars/index')->with('message', 'New Car Added'); } return Redirect::to('admin/cars/index')->with('message', 'Something went wrong')->withErrors($validator)->withInput(); }
/** * Store a newly created car in storage. * * @return Response */ public function store() { $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 Redirect::back()->withErrors($validator)->withInput(); } else { $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(); } if ($result && Auth::check()) { Session::flash('successMessage', 'Thank you for saving your car'); return Redirect::action('cars.index'); } else { if ($result && !Auth::check()) { $carId = $car->id; return Response::json($carId); } else { Session::flash('errorMessage', 'Please properly input all the required fields'); Log::warning('Car failed to save: ', Input::all()); return Redirect::back()->withInput(); } } }
public function actionCreate() { $model = new Car(); $file = new File(); $model->create_at = date('Y-m-d'); if (isset($_POST['Car']) && isset($_POST['File'])) { $model->attributes = $_POST['Car']; $file->attributes = $_POST['File']; $model->validate(); if ($model->getErrors() == null) { $model->date_registration = Tools::dateToSave($model->date_registration); $file->file = CUploadedFile::getInstance($file, 'file'); if ($file->file != null) { $filename = time() . '.' . $file->file->getExtensionName(); $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename); $model->pic = $filename; } else { $model->pic = 'noimage.jpg'; } $model->save(); $this->redirect(array('view', 'id' => $model->car_id)); } } $this->render('create', array('model' => $model, 'file' => $file)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $inputs = Input::all(); $catalog = new Catalog(); $catalog->title = $inputs['title']; $catalog->description = $inputs['description']; $catalog->user_id = Auth::user()->id; $catalog->save(); $car = new Car(); $car->brand = $inputs['brand']; $car->engine = $inputs['engine']; $car->make = $inputs['make']; $car->milage = $inputs['milage']; $car->type = $inputs['type']; $car->transmission = $inputs['transmission']; $car->status = $inputs['status']; $car->location = $inputs['location']; $car->price = $inputs['price']; $car->youtube = $inputs['youtube']; $car->main_pic = 0; $car->user_id = Auth::user()->id; $car->catalog_id = $catalog->id; $car->save(); $pictures = $inputs['pictures']; Log::info(user_photo_path() . $catalog->id . '/'); if (!File::isDirectory(user_photo_path() . $catalog->id . '/')) { File::makeDirectory(user_photo_path() . $catalog->id . '/', 0777, true, true); } if (Input::hasFile('pictures[]')) { foreach ($pictures as $picture) { if ($picture != null) { $image = Image::make($picture->getRealPath()); $fileName = str_replace(' ', '_', strrolower($picture->getClientOriginalName())); $image->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . $fileName)->resize(750, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '750-' . $fileName)->resize(500, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '500-' . $fileName)->resize(250, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '250-' . $fileName); $pic = new Pictures(); $pic->url = $fileName; $pic->user_id = Auth::user()->id; $pic->catalog_id = $catalog->id; $pic->type = 'catalog'; $pic->save(); } } } return Redirect::route('admin.catalog.index')->with('success', Lang::get('messages.catalog_created')); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Car(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Car'])) { $model->attributes = $_POST['Car']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created car in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Car::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $car = new Car(); $car->reg_no = Input::get('reg_no'); $car->make = Input::get('make'); $car->driver = Input::get('driver'); $car->status = 'available'; $car->driver_contact = Input::get('driver_contact'); $car->save(); return Redirect::route('cars.index'); }
public function add($data) { $uid = intval($data['uid']); $info = Car::findFirst("uid={$uid}"); if (!$info) { $info = new Car(); $info->addtime = time(); $info->uid = $uid; } $info->uptime = time(); foreach ($data as $field => $value) { $info->{$field} = $value; } $result = $info->save(); if (!$result) { $this->outputErrors($info); return false; } return true; }
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 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]); }
//Twig Path $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //Route and Controller $app->get("/", function () use($app) { return $app['twig']->render('carsearch.html.twig'); }); //Gets the user input from add a car $app->post("/added", function () use($app) { // $car_make = $_POST['car_make']; // $car_price = $_POST['car_price']; // $car_miles = $_POST['car_miles']; // $car_image = $_POST['car_image']; //$cars = Car::getAll(); $newcar = array(); $newcar = new Car($_POST['car_make'], $_POST['car_price'], $_POST['car_miles'], $_POST['car_image']); $newcar->save(); //array_push($newcar, $cars); //$cars->save(); return $app['twig']->render('addcar.html.twig', array('addedcar' => $newcar)); }); //$_POST['car_make'], $_POST['car_price'], $_POST['car_miles'], $_POST['car_image'] // $added_car = array(); // for($i = 0; $i < 10; $i++) { // $newcar = "newcar_$i"; // $$newcar = // $added_car = array($newcar); // //$added_car->savecar(); // } // // $added_cars = Car::getAllCar(); //
/** * testAddNewRecord. * * Assert that the instantiated class is an instance of the Potato Model * * Assert that the save method adds a new [5th] record into the cars table * * For a new insert, the save method returns the ID of the inserted record */ public function testAddNewRecord() { $car = new Car(); $car->name = 'Bentley'; $car->model = 'Mulsanne Range'; $car->year = 2015; $carId = $car->save(); $this->assertTrue($car instanceof PotatoModel); $this->assertEquals(5, $carId); $this->assertTrue($carId); }
$porsche = new Car("2014 Porsche 911", "images/porsche.jpg", 114991, 7864); $ford = new Car("2011 Ford F450", "images/ford.jpg", 55995, 14241); $lexus = new Car("2013 Lexus RC 350", "images/lexus.jpg", 44700, 20000); $mercedes = new Car("Mercedes Benz CLS550", "images/mercedes.jpg", 39900); if (empty($_SESSION['da_carz'])) { $_SESSION['da_carz'] = array($porsche, $ford, $lexus, $mercedes); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('cars.html.twig'); }); $app->post("/list_car", function () use($app) { $new_car = new Car($_POST['make_model'], $_POST['picture'], $_POST['price'], $_POST['miles']); //in order to get the default value to be applied, i had to remove "$POST['miles']" entirely. so, it seems as if there's nothing to detect whether it is a value of zero or not, and what to do if that is not okay. check $new_car->save(); echo "<pre>"; print_r($new_car); echo "</pre><br>"; return $app['twig']->render('list_car.html.twig', array('list_car' => $new_car)); }); $app->get("/car_lot", function () use($app) { return $app['twig']->render('car_lot.html.twig', array('autos' => Car::getAll())); }); $app->get("/match_cars", function () use($app) { $cars = Car::getAll(); $cars_matching_search = array(); foreach ($cars as $car) { if ($car->worthBuying($_GET['max_price'], $_GET['max_miles'])) { array_push($cars_matching_search, $car); }
protected function saveChar($model) { if (!($brand = Brand::model()->find('alias=:alias', array(':alias' => $model->brand_alias)))) { $brand = new Brand(); } $brand->title = $model->brand; $brand->alias = $model->brand_alias; $brand->save(); if (!empty($brand->errors)) { d('brand ' . $brand->title); d($brand->errors); } if (!($car = Car::model()->find('alias=:alias', array(':alias' => $model->model_alias)))) { $car = new Car(); } $car->brand_id = $brand->id; $car->title = $model->model; $car->alias = $model->model_alias; $car->manufacture_start = $model->modificationManufactureStart . '0101'; $car->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null; $car->save(); if (!empty($car->errors)) { d('model ' . $car->title); d($car->errors); } if (!($mod = Modification::model()->find('alias=:alias', array(':alias' => $model->mod_alias)))) { $mod = new Modification(); } $mod->model_id = $car->id; $mod->title = $model->mod; $mod->alias = $model->mod_alias; $mod->manufacture_start = $model->modificationManufactureStart . '0101'; $mod->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null; $mod->save(); if (!empty($mod->errors)) { d('mod ' . $mod->title); d($mod->errors); } if (!($char = Characteristic::model()->find('modification_id=:mod_id', array(':mod_id' => $mod->id)))) { $char = new Characteristic(); } $char->attributes = $model->char->attributes; $char->modification_id = $mod->id; $char->save(); if (!empty($char->errors)) { d('char ' . $mod->title); d($char->errors); d($model->url); } }
require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Car.php"; session_start(); if (empty($_SESSION['list_of_cars'])) { $_SESSION['list_of_cars'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); // Home: Submit Car Form Page $app->get("/", function () use($app) { return $app['twig']->render('cars.html.twig', array('cars' => Car::getAll())); }); // Single Car Create Page $app->post("/cars", function () use($app) { $cars = new Car($_POST['image'], $_POST['make'], $_POST['price'], $_POST['miles'], $_POST['status']); $cars->save(); return $app['twig']->render('cars.html.twig', array('cars' => Car::getAll(), 'newcar' => $cars)); }); // Searching by Price $app->get("/car_matches", function () use($app) { $cars = Car::getAll(); $cars_matching_search = array(); foreach ($cars as $car) { if ($car->worthBuying($_GET["matchPrice"])) { array_push($cars_matching_search, $car); } } return $app['twig']->render('cars.html.twig', array('cars' => $cars, 'match_cars' => $cars_matching_search)); }); // Searching by Make/Model $app->get("/make_model_matches", function () use($app) {
<?php $car = new Car(); $car->doors = 3; $car->colour = 'red'; if ($car->save()) { // Car is valid } else { // Car is NOT valid foreach ($car->errorMessages() as $property => $message) { echo "Error with the {$property} field - {$message} \n"; } }
$tag3->save(); // setting car's tags $car->setTag(array($tag, $tag2, $tag3)); // getting car's tags $car->getTag(); // getting car's tags with custom parameters // parameters are same as find() method $car->getTag($where, $order, $limitStart, $limitStop); // unset relation between $car and $tag2 $car->unsetTag($tag2); // creating some cars $car = new Car(); $car->nameCar = "205 GTi"; $car->setBrand($brand); $car->save(); $car2 = new Car(); $car2->nameCar = "206"; $car2->setBrand($brand); $car2->save(); $car3 = new Car(); $car3->nameCar = "207"; $car3->setBrand($brand); $car3->save(); // affecting new cars to $tag2 $tag2->setCar(array($car, $car2, $car3)); } catch (PicORM\Exception $e) { // !!!! disable showing PicORM\Exception for production because it contains SQL query !!!! echo '<strong>' . $e->getMessage() . '</strong>'; } catch (Exception $e) { echo '<strong>' . $e->getMessage() . '</strong>'; }
public function applyAction() { if ($this->request->isPost()) { $user = $this->getAuth(); $new_car = $this->request->getPost('new_car'); if ($new_car == 0) { $car = Car::findFirst(array('conditions' => 'number = ?1', 'bind' => array(1 => $this->request->getPost('choose-car')))); } else { $car = new Car(); $car->number = $this->request->getPost('number'); $car->brand = $this->request->getPost('brand'); $car->model = $this->request->getPost('model'); $car->owner = $user['user_id']; if (!$car->save()) { message($this, "d", "Данные об автомобиле указаны неверно"); return $this->response->redirect("applyForService"); } } if ($car) { $date = $this->request->getPost('date'); $time = $this->request->getPost('time'); $apps = Application::find(array('conditions' => 'term = ?1', 'bind' => array(1 => $date))); if ($date) { if ($time) { if (count($apps) < 4 * 20) { $services = $this->request->getPost('services'); if (count($services) > 0) { $app = new Application(); $app->car = $car->number; $app->term = $date . ' ' . $time; $app->confirmed = 0; $app->manager = NULL; if ($app->save()) { foreach ($services as $service) { $as = new ApplicationService(); $as->application_id = $app->id; $as->service_id = $service; if (!$as->save()) { message($this, "d", "Ошибка при сохранении выбранной услуги"); return $this->response->redirect("applyForService"); } } //todo! Обработка поля с доп. информацией message($this, "s", "Заявка отправлена. В ближайшее время наш менеджер свяжется с Вами для ее подтверждения"); return $this->response->redirect("cabinet"); } else { message($this, "d", "Ошибка при сохранении заявки"); foreach ($app->getMessages() as $message) { message($this, "d", "Ошибка: " . $message->getMessage() . " в поле " . $message->getField() . ". Тип: " . $message->getType()); } return $this->response->redirect("applyForService"); } } else { message($this, "d", "Минимум одна услуга должна быть выбрана"); return $this->response->redirect("applyForService"); } } else { message($this, "d", "Выбранная дата занята. Пожалуйста, выберите другой день"); return $this->response->redirect("applyForService"); } } else { message($this, "d", "Время не выбрано!"); return $this->response->redirect("applyForService"); } } else { message($this, "d", "Дата не выбрана!"); return $this->response->redirect("applyForService"); } } else { message($this, "d", "Автомобиль не найден"); return $this->response->redirect("applyForService"); } } }
$app['debug'] = true; $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); session_start(); if (empty($_SESSION['list_of_cars'])) { $porsche = new Car("2014 Porsche 911", 114991, 7864, "images/porsche.jpg"); $ford = new Car("2011 Ford F450", 55995, 14241, "images/ford.jpg"); $lexus = new Car("2013 Lexus RX 350", 44700, 20000, "images/lexus.jpg"); $mercedes = new Car("Mercedes Benz CLS550", 39900, 37979, "images/mercedes.jpg"); $cars = array($porsche, $ford, $lexus, $mercedes); $_SESSION['list_of_cars'] = $cars; } $app->get("/", function () use($app) { $cars = $_SESSION['list_of_cars']; return $app['twig']->render('cars.html.twig', array('cars' => $cars)); }); $app->post("/create_cars", function () use($app) { $car = new Car($_POST['make'], $_POST['miles'], $_POST['price'], $_POST['image']); $car->save(); return $app['twig']->render('create_cars.html.twig', array('car' => $car)); }); $app->post("/search_car", function () use($app) { $cars_matching_search = array(); foreach ($_SESSION['list_of_cars'] as $car) { if ($car->worthBuying($_POST["price"], $_POST["miles"])) { array_push($cars_matching_search, $car); } } return $app['twig']->render('search_car.html.twig', array('cars_matching_search' => $cars_matching_search)); }); return $app;
$first_car = new Car("2014 Porsche 911", 7864, 114991, "img/porsche.jpg"); $second_car = new Car("2011 Ford F450", 14000, 55995, "img/ford.jpeg"); $third_car = new Car("2013 Lexus RX 350", 20000, 44700, "img/lexus.jpg"); $fourth_car = new Car("Mercedes Benz CLS550", 37979, 39900, "img/mercedes.jpg"); if (empty($_SESSION['cars'])) { $_SESSION['cars'] = array($first_car, $second_car, $third_car, $fourth_car); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('dealership_search.html.twig'); }); $app->get("/search_results", function () use($app) { $cars = Car::getAll(); $cars_matching_search = array(); foreach ($cars as $car) { if ($car->worthBuying($_GET["price"], $_GET["miles"])) { array_push($cars_matching_search, $car); } } return $app['twig']->render('search_results.html.twig', array('cars_matching_search' => $cars_matching_search)); }); $app->get("/submit_car", function () use($app) { return $app['twig']->render('submit_car.html.twig'); }); $app->post("/submission_thankyou", function () use($app) { $submitted_car = new Car($_POST['make_model'], $_POST['price'], $_POST['miles'], $_POST['picture']); $submitted_car->save(); return $app['twig']->render('submission_thankyou.html.twig'); }); return $app;