public function setUpData() { $user = new User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->fb_id = '123456'; $user->save(); $this->_user_id = User::where('email', '*****@*****.**')->first()->user_id; $login = new Login(); $login->id = 1; $login->user_id = $this->_user_id; $login->session_id = '3f9a362bb40714f77cadfd9f5b9d801b'; $login->expired_at = '2019-07-30'; $login->save(); $this->_session = '3f9a362bb40714f77cadfd9f5b9d801b'; $this->_user_id = Login::where('session_id', $this->_session)->first()->user_id; $winery = new Winery(); $winery->id = 1; $winery->brand_name = 'Winery 1'; $winery->country_id = '1'; $winery->region = 'Abkhazia'; $winery->save(); $wine = new Wine(); $wine->wine_id = 1; $wine->name = 'Wine_1'; $wine->rakuten_id = 'rakuten_drinkshop_10508227'; $wine->original_name = "this is wine_1"; $wine->original_name_2 = "wine_1"; $wine->winery_id = 1; $wine->year = '2009'; $wine->wine_unique_id = '1_2009'; $wine->average_price = "2200.00"; $wine->average_rate = "3.5"; $wine->rate_count = "3"; $wine->save(); $this->session(array('user_id' => $this->_user_id)); }
public static function createNewWine($input) { $wine = new Wine(); $error_code = ApiResponse::OK; if (!empty($input['name']) && !empty($input['year']) && !empty($input['winery_id'])) { $wine->name = $input['name']; $wine->year = $input['year']; $wine->winery_id = $input['winery_id']; if (!empty($input['image_url'])) { $wine->image_url = $input['image_url']; } if (!empty($input['average_price'])) { $wine->average_price = $input['average_price']; } if (!empty($input['average_rate'])) { $wine->average_rate = $input['average_rate']; } if (!empty($input['wine_type'])) { $wine->wine_type = $input['wine_type']; } // Validation and Filtering is sorely needed!! // Seriously, I'm a bad person for leaving that out. if (Winery::where('id', $wine->winery_id)->first()) { $wine->save(); $wine->wine_unique_id = $wine->wine_id . '_' . $wine->year; $wine->save(); $data = $wine; } else { $error_code = ApiResponse::UNAVAILABLE_WINERY; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINERY); } } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } return array("code" => $error_code, "data" => $data); }
<?php require "../config/config.php"; require "../library/DataBase.php"; require "../model/wine.php"; $w = new Wine(); $mensaje = ""; if (isset($_POST["btnGuardar"])) { $w->__SET("name", $_POST["txtName"]); $w->__SET("year", $_POST["txtYear"]); $w->__SET("grapes", $_POST["txtGrapes"]); $w->__SET("description", $_POST["txtDescription"]); if ($w->save()) { $mensaje = "alert('guardo')"; } else { $mensaje = "alert('no guardo')"; } } $datos = $w->read(); include "../view/index.php";