public function addToInventory() { if (strlen($_REQUEST['new_make']) > 0 && strlen($_REQUEST['new_model']) > 0) { $make = new Make(); $make->setTitle($_REQUEST['new_make'])->create(); $model = new Model(); $model->setTitle($_REQUEST['new_model'])->setMake($make)->create(); } else { $model = new Model($_REQUEST['model_id']); $model->loadMake(); } $auto = new Auto(); $auto->setPrice(preg_replace('/[^0-9\\.]/', '', $_REQUEST['price']))->setPricePostfix($_REQUEST['price_postfix'])->setTypeId($_REQUEST['type_id'])->setInventoryNumber($_REQUEST['inventory_number'])->setVin($_REQUEST['vin'])->setMakeId($model->getMakeId())->setModelId($model->getId())->setYear($_REQUEST['year'])->setOdometerReading(preg_replace('/\\D/', '', $_REQUEST['odometer_reading']))->setDescription($_REQUEST['description'])->setIsVisible($_REQUEST['is_visible'])->setIsFeatured($_REQUEST['is_featured'])->setExterior($_REQUEST['exterior'])->setInterior($_REQUEST['interior']); /* Features */ $features = json_decode(stripslashes($_REQUEST['features']), TRUE); foreach ($features as $f) { if ($f['remove'] == 0) { $feature = new AutoFeature(); $feature->setId(uniqid())->setFeatureId($f['feature_id'])->setFeatureTitle($f['title'])->setValue($f['value'])->setCreatedAt(time())->setUpdatedAt(time()); $auto->addFeature($feature); } } $auto->create(); /* Photos */ $images = json_decode(stripslashes($_REQUEST['images']), TRUE); foreach ($images as $i) { $image = new Image(); $image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->create(); $auto->addImage($image); } return $auto->getId(); }