public function loadFromRow(\stdClass $row) { $this->setId($row->id)->setTypeId($row->type_id)->setVin($row->vin)->setMakeId($row->make_id)->setModelId($row->model_id)->setInventoryNumber($row->inventory_number)->setYear($row->year)->setOdometerReading($row->odometer_reading)->setDescription($row->description)->setPrice($row->price)->setPricePostfix($row->price_postfix)->setIsVisible($row->is_visible)->setIsFeatured($row->is_featured)->setExterior($row->exterior)->setInterior($row->interior)->setCreatedAt($row->created_at)->setImportedAt($row->imported_at)->setUpdatedAt($row->updated_at); if (isset($row->make)) { $this->make = new Make(); $this->make->setId($row->make_id)->setTitle($row->make); } if (isset($row->model)) { $this->model = new Model(); $this->model->setId($row->model_id)->setTitle($row->model); } if (isset($row->type)) { $this->type = new AutoType(); $this->type->setId($row->type_id)->setTitle($row->type); } $features = json_decode($row->features, TRUE); if (!empty($features)) { foreach ($features as $f) { $feature = new AutoFeature(); $feature->setId($f['id'])->setFeatureId($f['feature_id'])->setFeatureTitle($f['feature_title'])->setValue($f['value'])->setCreatedAt($f['created_at'])->setUpdatedAt($f['updated_at']); $this->addFeature($feature); } } }
public function editInventory() { 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($_REQUEST['id']); $auto->setPrice($_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'])->setDescription($_REQUEST['description'])->setIsVisible($_REQUEST['is_visible'])->setIsFeatured($_REQUEST['is_featured'])->setInterior($_REQUEST['interior'])->setExterior($_REQUEST['exterior'])->setOdometerReading($_REQUEST['odometer_reading']); /* Features */ $auto->setFeatures(NULL); $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->update(); $images = json_decode(stripslashes($_REQUEST['images']), TRUE); /** Remove deleted images */ if ($auto->getImageCount() > 0) { foreach ($auto->getImages() as $image) { $delete_me = TRUE; foreach ($images as $i) { if ($image->getId() == $i['id']) { $delete_me = FALSE; break; } } if ($delete_me) { $auto->deleteImage($image->getId()); } } } foreach ($images as $i) { /** Add new images */ if ($i['id'] == 0) { $image = new Image(); $image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->create(); $auto->addImage($image); } else { $image = new Image($i['id']); $image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->update(); $auto->setImage($i['id'], $image); } } return $auto->getId(); }