public function run()
 {
     $count = Wine::where('group_id', 0)->count();
     echo "Operating wines number : {$count} wines" . PHP_EOL;
     Wine::where('group_id', 0)->chunk(100, function ($wines) {
         foreach ($wines as $wine) {
             echo "Handling: {$wine->rakuten_id}";
             $start = time();
             $request = curl_init('http://54.64.177.240:8888/api/match');
             curl_setopt($request, CURLOPT_POST, true);
             curl_setopt($request, CURLOPT_POSTFIELDS, array('img' => "@" . $wine->local_path));
             curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
             $result = json_decode(curl_exec($request));
             $matched_wines = $result->matches;
             $matched_rakuten_ids = array();
             foreach ($matched_wines as $matched_wine) {
                 $matched_id = $matched_wine->id;
                 $num_of_match = $matched_wine->numMatches;
                 if ($num_of_match < 10) {
                     continue;
                 }
                 $rakuten_paths = explode('_', $matched_id);
                 if (count($rakuten_paths) < 2) {
                     continue;
                 }
                 $matched_rakuten_ids[] = join('_', array('rakuten', $rakuten_paths[0], $rakuten_paths[1]));
             }
             if (count($matched_rakuten_ids) == 0) {
                 echo "No Matched Wines to group" . PHP_EOL;
                 continue;
             }
             echo "Num of matched wines : " . count($matched_rakuten_ids) . ". Now updating group" . PHP_EOL;
             $group_wines = Wine::where('rakuten_id', $matched_rakuten_ids)->get();
             $group_id = 0;
             foreach ($group_wines as $group_wine) {
                 if ($group_wine->group_id > 0) {
                     $group_id = $group_wine->group_id;
                     break;
                 }
             }
             if ($group_id == 0) {
                 $group_id = $wine->wine_id;
             }
             $wine->group_id = $group_id;
             $wine->save();
             foreach ($group_wines as $group_wine) {
                 $group_wine->group_id = $group_id;
                 $group_wine->save();
             }
             echo "Grouping Done. Group id is {$group_id}" . PHP_EOL;
             echo "Cost : " . (time() - $start) . " seconds." . PHP_EOL;
             curl_close($request);
         }
     });
 }
示例#2
0
 public function testGetTimelineSuccess()
 {
     $this->setUpRating();
     $this->setUpCountry();
     $this->setUpWineNote();
     $this->setUpProfile();
     $_params = $this->_params;
     $_params['user_id'] = "user_id";
     $response = $this->_getAuth($_params);
     $error_code = ApiResponse::OK;
     $user_timeline = array();
     $user_timeline[] = $this->_user_id;
     $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get();
     if (isset($user_follow)) {
         foreach ($user_follow as $user) {
             $user_timeline[] = $user->to_id;
         }
     }
     $pagination = ApiResponse::pagination();
     $page = $pagination['page'];
     $limit = $pagination['limit'];
     $wine = Wine::with('winery')->forPage($page, $limit)->get();
     $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get();
     foreach ($ratings as $rating) {
         $winery = Winery::where('id', $rating->wine->winery_id)->first();
         $rating->winery = $winery;
         $country = Country::where('id', $rating->winery->country_id)->first();
         $rating->winery->country_name = $country->country_name;
         $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first();
         if ($like) {
             $rating->liked = true;
         } else {
             $rating->liked = false;
         }
         $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first();
         if ($wishlist) {
             $rating->wishlist = true;
         } else {
             $rating->wishlist = false;
         }
         if ($rating->wine->image_url != null) {
             $rating->wine->image_url = URL::asset($rating->wine->image_url);
         }
         if ($rating->wine->wine_flag != null) {
             $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag);
         }
         if ($rating->profile->image != null) {
             $rating->profile->image = URL::asset($rating->profile->image);
         }
         $rating->winery = $rating->winery->toArray();
     }
     $data = $ratings;
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true));
 }
 public function run()
 {
     DB::table('wine_notes')->delete();
     $user_id = User::where('email', '*****@*****.**')->first()->user_id;
     $user_1 = User::where('email', '*****@*****.**')->first()->user_id;
     $user_2 = User::where('email', '*****@*****.**')->first()->user_id;
     $wine_1 = Wine::where('wine_id', 1)->first()->wine_unique_id;
     $wine_2 = Wine::where('wine_id', 2)->first()->wine_unique_id;
     $wine_3 = Wine::where('wine_id', 3)->first()->wine_unique_id;
     Winenote::create($data = array('id' => 1, 'wine_unique_id' => $wine_1, 'user_id' => $user_id, 'note' => 'This is note 1'));
     Winenote::create($data = array('id' => 2, 'wine_unique_id' => $wine_2, 'user_id' => $user_1, 'note' => 'This is note 2'));
     Winenote::create($data = array('id' => 3, 'wine_unique_id' => $wine_3, 'user_id' => $user_2, 'note' => 'This is note 3'));
 }
 public function run()
 {
     DB::table('ratings')->delete();
     $user_id = User::where('email', '*****@*****.**')->first()->user_id;
     $user_1 = User::where('email', '*****@*****.**')->first()->user_id;
     $user_2 = User::where('email', '*****@*****.**')->first()->user_id;
     $wine_1 = Wine::where('wine_id', 1)->first()->wine_unique_id;
     $wine_2 = Wine::where('wine_id', 2)->first()->wine_unique_id;
     $wine_3 = Wine::where('wine_id', 3)->first()->wine_unique_id;
     Rating::create(array('id' => '1', 'user_id' => $user_id, 'wine_unique_id' => $wine_1, 'rate' => '0.5', 'content' => 'this is rating 1', 'like_count' => '5', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '2', 'user_id' => $user_id, 'wine_unique_id' => $wine_2, 'rate' => '1.5', 'content' => 'this is rating 2', 'like_count' => '5', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '3', 'user_id' => $user_id, 'wine_unique_id' => $wine_3, 'rate' => '4.5', 'content' => 'this is rating 3', 'like_count' => '8', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '4', 'user_id' => $user_1, 'wine_unique_id' => $wine_1, 'rate' => '5', 'content' => 'this is rating 7', 'like_count' => '6', 'comment_count' => '15', 'is_my_wine' => '1'));
     Rating::create(array('id' => '5', 'user_id' => $user_2, 'wine_unique_id' => $wine_2, 'rate' => '5', 'content' => 'this is rating 8', 'like_count' => '14', 'comment_count' => '8', 'is_my_wine' => '1'));
 }
 public function run()
 {
     DB::table('wishlists')->delete();
     $user_id = User::where('email', '*****@*****.**')->first()->user_id;
     $user_1 = User::where('email', '*****@*****.**')->first()->user_id;
     $user_2 = User::where('email', '*****@*****.**')->first()->user_id;
     $wine_1 = Wine::where('wine_id', 1)->first()->wine_unique_id;
     $wine_2 = Wine::where('wine_id', 2)->first()->wine_unique_id;
     $wine_3 = Wine::where('wine_id', 3)->first()->wine_unique_id;
     Wishlist::create(array('id' => '1', 'wine_unique_id' => $wine_1, 'user_id' => $user_id));
     Wishlist::create(array('id' => '2', 'wine_unique_id' => $wine_2, 'user_id' => $user_id));
     Wishlist::create(array('id' => '3', 'wine_unique_id' => $wine_3, 'user_id' => $user_id));
     Wishlist::create(array('id' => '4', 'wine_unique_id' => $wine_1, 'user_id' => $user_1));
     Wishlist::create(array('id' => '5', 'wine_unique_id' => $wine_3, 'user_id' => $user_1));
     Wishlist::create(array('id' => '6', 'wine_unique_id' => $wine_1, 'user_id' => $user_2));
     Wishlist::create(array('id' => '7', 'wine_unique_id' => $wine_3, 'user_id' => $user_2));
 }
示例#6
0
 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 function run()
 {
     DB::table('wines')->truncate();
     DB::table('wineries')->truncate();
     DB::connection()->disableQueryLog();
     set_time_limit(3600);
     $c = 0;
     $i = 1;
     $count = 1;
     $winery_id = 1;
     try {
         $file = app_path() . '/rakuten_wine_data_20140905.csv';
         //$file = app_path() . '/testcsv.csv';
         $i = 1;
         $country_name_on_wines = Wine::take(300)->get(array('country_name'));
         $country_name_ja_list = Country::get(array('country_name_ja'));
         foreach ($country_name_ja_list as $country_name) {
             if ($country_name->country_name_ja != null) {
                 if ($i == 1) {
                     $re = $country_name->country_name_ja;
                     $i++;
                 } else {
                     $re = $re . "|" . $country_name->country_name_ja;
                 }
             }
         }
         $re_country_name = "'/" . $re . "/'";
         $parser = \KzykHys\CsvParser\CsvParser::fromFile($file, array("encoding" => "UTF-8"));
         foreach ($parser as $column_wine) {
             echo $c++ . "\n";
             if (count($column_wine) == 33) {
                 $validator = Validator::make(array('rakuten_id' => $column_wine[0]), array('rakuten_id' => 'exists:wines2,rakuten_id'));
                 if ($validator->passes()) {
                     if ($column_wine[13] == 'NA' && $column_wine[14] !== 'NA') {
                         $column_wine[13] = $column_wine[14];
                     }
                     if ($column_wine[9] == 'NA' && $column_wine[10] !== 'NA') {
                         $column_wine[9] = $column_wine[10];
                     }
                     for ($j = 0; $j < 33; $j++) {
                         if ($column_wine[$j] == 'NA') {
                             $column_wine[$j] = '';
                         }
                     }
                     if ($column_wine[3] == '') {
                         $column_wine[3] = $column_wine[1];
                     }
                     if ($column_wine[9] != null) {
                         $in_string = preg_match($re_country_name, $column_wine[9], $matches);
                         if ($in_string == true) {
                             //$country = explode('・', $country_name->country_name, -1);
                             $country = Country::where('country_name_ja', $matches[0])->first();
                             if ($country) {
                                 $flag = $country->flag_url;
                             } else {
                                 $flag = null;
                             }
                         }
                     }
                     $winery = Winery::where('brand_name', $column_wine[16])->first();
                     if ($winery == null) {
                         $winery_data = array('id' => $winery_id, 'brand_name' => $column_wine[16], 'country_id' => '', 'country_name' => $column_wine[10], 'year' => $column_wine[14], 'winery_url' => $column_wine[18], 'region' => $column_wine[11], 'description' => '');
                         Winery::create($winery_data);
                         $winery = $winery_id;
                         $winery_id++;
                     } else {
                         $winery = $winery->id;
                     }
                     $wine = array('name' => $column_wine[3], 'name_en' => $column_wine[4], 'sub_name' => $column_wine[5], 'sub_name_en' => $column_wine[6], 'year' => $column_wine[13], 'winery_id' => $winery, 'rakuten_id' => $column_wine[0], 'original_name' => $column_wine[1], 'original_name_2' => $column_wine[2], 'country_name' => $column_wine[9], 'image_url' => $column_wine[27], 'wine_flag' => $flag, 'imformation_image' => $column_wine[21] . ',' . $column_wine[22] . ',' . $column_wine[23] . ',' . $column_wine[24] . ',' . $column_wine[25] . ',' . $column_wine[26], 'rakuten_url' => $column_wine[17], 'wine_unique_id' => $i . '_' . $column_wine[13], 'color' => $column_wine[12], 'average_price' => $column_wine[15], 'average_rate' => 0, 'rate_count' => 0, 'wine_type' => $column_wine[7], 'folder_code' => $column_wine[20]);
                     if ($wine['year'] == '' || $wine['year'] == 0) {
                         $wine['wine_unique_id'] = $i . '_' . $i;
                     }
                     Wine::create($wine);
                     $i++;
                 }
             } else {
                 $error = implode(",", $column_wine);
                 $file_error = app_path() . "/error.txt";
                 file_put_contents($file_error, $error . "\n", FILE_APPEND | LOCK_EX);
             }
         }
     } catch (Exception $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
     }
 }
 public function upload_image_wine_scan($wine_unique_id)
 {
     $result = Wine::uploadImageWineScan($wine_unique_id);
     return Response::json($result);
 }
示例#9
0
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
	<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
	<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>	
	<script src="/js/javascript.js"></script>
<body>
<div id="message"></div>
	<div class="container_12">
			<div id="nav">
				<?php 
showMenu();
?>
				<div style="float:right;margin-top:12px; margin-right:15px"><label for="quickSummary">Quick Summary By UPC:</label><input type="number" id="quickSummary" name="quickSummary"><input type="button" value="Go" onClick="window.location.assign('/upcsummary/'+$('#quickSummary').val())"></div>
			</div>
		<div id="content">
			<?php 
$wine = new Wine($dbh);
$wine->fetchWineByUPC($_GET['upc']);
?>
			<div id="edit" style="display:none">
			<h2>Edit: <span id="editUPC"><?php 
echo $_GET['upc'];
?>
</span></h2>
			<form id="form" name="form">
			<input type="hidden" id="function" name="function" value="updateWine">
			<input type="hidden" id="wine_id" name="wine_id" value="<?php 
echo $wine->getID();
?>
">
			<label for="name">UPC/EAN:</label><input type="text" style="width:400px" id="upc" name="upc" value="<?php 
echo $wine->getUPC();
function login()
{
    if (isset($_REQUEST['username']) & isset($_REQUEST['password'])) {
        include_once '../models/wine.php';
        $obj = new Wine();
        $username = stripslashes($_REQUEST['username']);
        $password = stripslashes($_REQUEST['password']);
        $username = $obj->real_escape_string($username);
        $password = $obj->real_escape_string($password);
        $result = $obj->login($username, $password);
        $row = $result->fetch_assoc();
        if (!$row) {
            echo '{"result":0, "message":"Failed to login"}';
        } else {
            echo '{"result":1, "user_name":"' . $row['user_name'] . '"}';
        }
        $result->close();
    }
}
示例#11
0
<?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";
示例#12
0
	<link rel="stylesheet" href="/css/style.css">
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
	<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
	<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>	
	<script src="/js/javascript.js"></script>
<body>
	<div class="container_12">
			<div id="nav">
				<?php 
showMenu();
?>
				<div style="float:right;margin-top:12px; margin-right:15px"><label for="quickSummary">Quick Summary By UPC:</label><input type="number" id="quickSummary" name="quickSummary"><input type="button" value="Go" onClick="window.location.assign('/upcsummary/'+$('#quickSummary').val())"></div>
			</div>
		<div id="content">
			<?php 
$wine = new Wine($dbh);
$json = $wine->getInventoryRecord($_GET['id']);
$arr = json_decode($json, true);
?>
			<?php 
/*<div id="edit" style="display:none">
		<h2>Edit: <span id="editUPC"><?php echo $_GET['id'];?></span></h2>
		<form id="form" name="form">
		<input type="hidden" id="function" name="function" value="updateWine">
		<input type="hidden" id="wine_id" name="wine_id" value="<? echo $wine->getID();?>">
		<label for="name">UPC/EAN:</label><input type="text" style="width:400px" id="upc" name="upc" value="<?echo $wine->getUPC();?>"><br>
		<label for="name">Type:</label><select id="type" name="type">
		<option value="Chardonnay" <? echo (strtoupper($wine->getType()) == 'CHARDONNAY'?'selected':''); ?>>Chardonnay</option>
		<option value="Fume/Sauvignon Blanc" <? echo (strtoupper($wine->getType()) == 'FUME/SAUVIGNON BLANC'?'selected':''); ?>>Fume/Sauvignon Blanc</option>
		<option value="Pinot Grigio" <? echo (strtoupper($wine->getType()) == 'PINOT GRIGIO'?'selected':''); ?>>Pinot Grigio</option>
		<option value="White Zinfandel/Rose" <? echo (strtoupper($wine->getType()) == 'WHITE ZINFANDEL/ROSE'?'selected':''); ?>>White Zinfandel/Rose</option>
示例#13
0
 public static function deleteWinenote($wine_unique_id)
 {
     $user_id = Session::get('user_id');
     $winenote = Winenote::where('user_id', $user_id)->where('wine_unique_id', $wine_unique_id)->first();
     $error_code = ApiResponse::OK;
     if (Wine::where('wine_unique_id', $wine_unique_id)->first()) {
         if ($winenote) {
             $winenote->delete();
             $data = 'Wine note is deleted';
         } else {
             $error_code = ApiResponse::UNAVAILABLE_WINE_NOTE;
             $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE_NOTE);
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_WINE;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#14
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'inc/init.php';
require_once 'inc/class.wine.php';
$wine = new Wine($dbh);
$wine->fetchWineByUPC($_GET['upc']);
?>
<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" href="/css/960/reset.css">
	<link rel="stylesheet" href="/css/960/960_12_col.css">
	<!--<link rel="stylesheet" href="/css/960/text.css">-->
	<link rel="stylesheet" href="/css/style.css">
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
	<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
	<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
	<script src="/js/javascript.js"></script>	
	<script type="text/javascript">
	$( document ).ready(function() {
		changePagination(0,'first','inventory');
	});
	</script>
<body>
	<div class="container_12">
			<div id="nav">
				<?php 
showMenu();
?>
/**
 * Function to search for a task
 */
function searchWine()
{
    if (isset($_REQUEST['searchWord'])) {
        include_once '../models/wine.php';
        $wine = new Wine();
        $searchWord = $_REQUEST['searchWord'];
        if ($result = $wine->searchWine($searchWord)) {
            $row = $result->fetch_assoc();
            echo '{"result":1, "wines": [';
            while ($row) {
                echo '{"wine_id": "' . $row["wine_id"] . '", "wine_name": "' . $row["wine_name"] . '",
            "winery_name": "' . $row["winery_name"] . '", "cost": "' . $row["cost"] . '",
            "wine_type": "' . $row["wine_type"] . '", "year": "' . $row["year"] . '"}';
                if ($row = $result->fetch_assoc()) {
                    echo ',';
                }
            }
            echo ']}';
        } else {
            echo '{"result":0,"status": "An error occurred for select product."}';
        }
    }
}
示例#16
0
 public function run()
 {
     DB::table('wines')->delete();
     Wine::create(array('wine_id' => '1', 'name' => 'Gnarly Head Authentic White', 'year' => '2011', 'winery_id' => '1', 'image_url' => 'wines/1.jpg', 'wine_unique_id' => '1_2011', 'average_price' => '1200', 'average_rate' => '3.0', 'wine_type' => '2'));
     Wine::create(array('wine_id' => '2', 'name' => 'Trimbach Riesling', 'year' => '2010', 'winery_id' => '2', 'image_url' => 'wines/2.png', 'wine_unique_id' => '2_2010', 'average_price' => '1700', 'average_rate' => '4.0', 'wine_type' => '2'));
     Wine::create(array('wine_id' => '3', 'name' => 'Gruner Love Featuring the Stadlmann Gruner Veltliner ', 'year' => '2011', 'winery_id' => '3', 'image_url' => 'wines/3.png', 'wine_unique_id' => '3_2011', 'average_price' => '1600', 'average_rate' => '2.5', 'wine_type' => '1'));
     Wine::create(array('wine_id' => '4', 'name' => 'Pine Ridge Chenin Blanc + Viognier ', 'year' => '2013', 'winery_id' => '4', 'image_url' => 'wines/4.png', 'wine_unique_id' => '4_2013', 'average_price' => '1200', 'average_rate' => '2.0', 'wine_type' => '3'));
     Wine::create(array('wine_id' => '5', 'name' => 'Frescobaldi Nipozzano Chianti Rufina Riserva', 'year' => '2009', 'winery_id' => '5', 'image_url' => 'wines/5.png', 'wine_unique_id' => '5_2009', 'average_price' => '2200', 'average_rate' => '4.5', 'wine_type' => '1'));
     for ($i = 6; $i < 11; $i++) {
         $data = array('wine_id' => "{$i}", 'name' => "Wine_{$i}", 'year' => '2009', 'winery_id' => "1", 'wine_flag' => '', 'image_url' => 'wines/' . $i . '.png', 'wine_unique_id' => $i . "_2009", 'average_price' => '2200', 'average_rate' => '4.5', 'wine_type' => '1', 'rate_count' => '3');
         $winery_id = $data['winery_id'];
         $winery = Winery::where('id', $winery_id)->with('country')->first();
         if ($winery) {
             $data['wine_flag'] = $winery->country->flag_url;
         } else {
             $data['wine_flag'] = '';
         }
         Wine::create($data);
     }
     //        Wine::create(array(
     //        	'name' => 'カベルネ・ソーヴィニヨン',s
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/1',
     //            'wine_unique_id' => '1_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '赤',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'メルロー ',
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/2',
     //            'wine_unique_id' => '2_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '赤',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'カルメネール',
     //            'year' => '1993',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/3',
     //            'wine_unique_id' => '3_1993',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '赤',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'シラー',
     //            'year' => '1993',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/4',
     //            'wine_unique_id' => '4_1993',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '赤',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'ピノ・ノワール',
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/5',
     //            'wine_unique_id' => '5_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '赤',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'ピノノワール・ロゼ ',
     //            'year' => '1993',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/6',
     //            'wine_unique_id' => '6_1993',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => 'ロゼ',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'シャルドネ',
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/7',
     //            'wine_unique_id' => '7_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '白',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'ゲヴュルツトラミネール ',
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/8',
     //            'wine_unique_id' => '8_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '白',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'リースリング ',
     //            'year' => '1990',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/9',
     //            'wine_unique_id' => '9_1990',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '白',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'ソーヴィニヨン・ブラン ',
     //            'year' => '1993',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/10',
     //            'wine_unique_id' => '10_1993',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '白',
     //        ));
     //        Wine::create(array(
     //        	'name' => 'ヴィオニエ',
     //            'year' => '1993',
     //            'winery_id' => '1',
     //            'image_url' => public_path() . '/images/11',
     //            'wine_unique_id' => '11_1993',
     //            'average_price' => '0.0',
     //            'average_rate' => '0.0',
     //            'wine_type' => '白',
     //        ));
 }
示例#17
0
<?php

require_once 'inc/init.php';
require_once 'inc/class.wine.php';
echo 'Hello Wine Enthusiasts.<br>';
$dbh->query("DELETE FROM wine");
$dbh->query("DELETE FROM inventory");
$newWine = new Wine($dbh);
$newWine->setUPC('1541948561658');
$newWine->setName('Pinot Grigio');
$newWine->setVintage('1954');
$newWine->setSellPrice('150.00');
$id = $newWine->writeWineToTable();
echo $id . '<br>';
$newWine->setID($id);
$id = $newWine->addInventory(10, 15.5, 'Bought From Bob');
echo $id . '<br>';
$id = $newWine->removeInventory(5, 45.5, 'Sold To James');
echo $id;
示例#18
0
文件: test.php 项目: seanhess/redbean
function testsperengine()
{
    global $tests;
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "perform generic bean manipulation";
    $ok = 1;
    $bean = RedBean_OODB::dispense("note");
    $bean->message = "hai";
    $bean->color = 3;
    $bean->date = time();
    $bean->special = 'n';
    $bean->state = 90;
    RedBean_OODB::set($bean);
    $bean2 = RedBean_OODB::getById("note", 1);
    if ($bean2->state != 90 || $bean2->special != 'n' || $bean2->message != 'hai') {
        $ok = 0;
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bean->message = "lorem ipsum";
    RedBean_OODB::set($bean);
    $bean->message = 1;
    $bean->color = "green";
    $bean->date = str_repeat("BLABLA", 100);
    RedBean_OODB::set($bean);
    $note = $bean;
    SmartTest::instance()->progress();
    $person = RedBean_OODB::dispense("person");
    $person->age = 50;
    $person->name = "Bob";
    $person->gender = "m";
    RedBean_OODB::set($person);
    RedBean_OODB::associate($person, $note);
    $memo = RedBean_OODB::getById("note", 1);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) !== 1) {
        SmartTest::failedTest();
    }
    RedBean_OODB::trash($authors[1]);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) > 0) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    //unit tests
    //drop the note table
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "dispense an RedBean_OODB Bean";
    $oBean = RedBean_OODB::dispense();
    if (!$oBean instanceof OODBBean) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "put a bean in the database";
    $person = RedBean_OODB::dispense("person");
    $person->name = "John";
    $person->age = 35;
    $person->gender = "m";
    $person->hasJob = true;
    $id = RedBean_OODB::set($person);
    $johnid = $id;
    $person2 = RedBean_OODB::getById("person", $id);
    if ($person2->age != $person->age) {
        SmartTest::failedTest();
    }
    $person2->anotherprop = 2;
    RedBean_OODB::set($person2);
    $person = RedBean_OODB::dispense("person");
    $person->name = "Bob";
    $person->age = 50;
    $person->gender = "m";
    $person->hasJob = false;
    $bobid = RedBean_OODB::set($person);
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "find records on basis of similarity";
    $ids = RedBean_OODB::getBySQL("`gender`={gender} order by `name` asc", array("gender" => "m"), "person");
    if (count($ids) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $ids = RedBean_OODB::getBySQL("`gender`={gender} OR `color`={clr} ", array("gender" => "m", "clr" => "red"), "person");
    if (count($ids) != 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $ids = RedBean_OODB::getBySQL("`gender`={gender} AND `color`={clr} ", array("gender" => "m", "clr" => "red"), "person");
    if (count($ids) != 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    R::gen("Person");
    $dummy = new Person();
    $dummy->age = 40;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 1);
    $dummy->age = 20;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 2);
    $dummy->age = 100;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => ">"))), 0);
    $dummy->age = 100;
    SmartTest::instance()->test(count(Person::find($dummy, array("age" => "<="))), 2);
    $dummy->name = "ob";
    SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 1);
    $dummy->name = "o";
    SmartTest::instance()->test(count(Person::find($dummy, array("name" => "LIKE"))), 2);
    $dummy->gender = "m";
    SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 2);
    $dummy->gender = "f";
    SmartTest::instance()->test(count(Person::find($dummy, array("gender" => "="))), 0);
    SmartTest::instance()->test(count(Person::listAll()), 2);
    SmartTest::instance()->test(count(Person::listAll(0, 1)), 1);
    SmartTest::instance()->test(count(Person::listAll(1)), 1);
    $can = Person::where("`gender`={gender} order by `name`  asc", array("gender" => "m"), "person");
    //test array access
    foreach ($can as $item) {
        if ($item->getName() == "Bob" || $item->getName() == "John") {
            SmartTest::instance()->progress();
        } else {
            SmartTest::failedTest();
        }
    }
    //test array access
    $bean = $can[0];
    if ($bean->name == "Bob") {
        SmartTest::instance()->progress();
    } else {
        SmartTest::failedTest();
    }
    if ($can->count() != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $can->rewind();
    SmartTest::instance()->test($can->key(), 0);
    SmartTest::instance()->test($can->valid(), true);
    SmartTest::instance()->test($can->current()->getName(), "Bob");
    $can->next();
    SmartTest::instance()->test($can->key(), 1);
    SmartTest::instance()->test($can->valid(), false);
    SmartTest::instance()->test($can->current()->getName(), "John");
    $can->seek(0);
    SmartTest::instance()->test($can->key(), 0);
    $beans = $can->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //test slicing
    $can->slice(0, 1);
    $can->rewind();
    SmartTest::instance()->test($can->current()->getName(), "Bob");
    SmartTest::instance()->test($can->count(), 1);
    $b1 = array_shift($beans);
    if ($b1->name != "Bob") {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //basic functionality where()
    $beans = Person::where("`gender`={gender} order by `name` asc", array("gender" => "m"), "person")->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //without backticks should still work
    $beans = Person::where("gender={person} order by `name` asc", array("person" => "m"), "person")->getBeans();
    if (count($beans) != 2) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    //like comparing should still work
    $beans = Person::where("gender={gender} and `name` LIKE {name} order by `name` asc", array("gender" => "m", "name" => "B%"), "person")->getBeans();
    if (count($beans) != 1) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->gender = "m";
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "associate beans with eachother?";
    $app = RedBean_OODB::dispense("appointment");
    $app->kind = "dentist";
    RedBean_OODB::set($app);
    RedBean_OODB::associate($person2, $app);
    $appforbob = array_shift(RedBean_OODB::getAssoc($person2, "appointment"));
    if (!$appforbob || $appforbob->kind != "dentist") {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "delete a bean?";
    $person = RedBean_OODB::getById("person", $bobid);
    RedBean_OODB::trash($person);
    try {
        $person = RedBean_OODB::getById("person", $bobid);
        $ok = 0;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = true;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "unassociate two beans?";
    $john = RedBean_OODB::getById("person", $johnid);
    //hmmmmmm gaat mis bij innodb
    $app = RedBean_OODB::getById("appointment", 1);
    RedBean_OODB::unassociate($john, $app);
    $john2 = RedBean_OODB::getById("person", $johnid);
    $appsforjohn = RedBean_OODB::getAssoc($john2, "appointment");
    if (count($appsforjohn) > 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "unassociate by deleting a bean?";
    $anotherdrink = RedBean_OODB::dispense("whisky");
    $anotherdrink->name = "bowmore";
    $anotherdrink->age = 18;
    $anotherdrink->singlemalt = 'y';
    RedBean_OODB::set($anotherdrink);
    RedBean_OODB::associate($anotherdrink, $john);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 1) {
        SmartTest::failedTest();
    }
    RedBean_OODB::trash($anotherdrink);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 0) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "create parent child relationships?";
    $pete = RedBean_OODB::dispense("person");
    $pete->age = 48;
    $pete->gender = "m";
    $pete->name = "Pete";
    $peteid = RedBean_OODB::set($pete);
    $rob = RedBean_OODB::dispense("person");
    $rob->age = 19;
    $rob->name = "Rob";
    $rob->gender = "m";
    $saskia = RedBean_OODB::dispense("person");
    $saskia->age = 20;
    $saskia->name = "Saskia";
    $saskia->gender = "f";
    RedBean_OODB::set($saskia);
    RedBean_OODB::set($rob);
    RedBean_OODB::addChild($pete, $rob);
    RedBean_OODB::addChild($pete, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $names = 0;
    if (is_array($children) && count($children) === 2) {
        foreach ($children as $child) {
            if ($child->name === "Rob") {
                $names++;
            }
            if ($child->name === "Saskia") {
                $names++;
            }
        }
    }
    if (!$names) {
        SmartTest::failedTest();
    }
    $daddies = RedBean_OODB::getParent($saskia);
    $daddy = array_pop($daddies);
    if ($daddy->name === "Pete") {
        $ok = 1;
    } else {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "remove a child from a parent-child tree?";
    RedBean_OODB::removeChild($daddy, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $ok = 0;
    if (count($children) === 1) {
        $only = array_pop($children);
        if ($only->name === "Rob") {
            $ok = 1;
        }
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "save on the fly while associating?";
    $food = RedBean_OODB::dispense("dish");
    $food->name = "pizza";
    RedBean_OODB::associate($food, $pete);
    $petesfood = RedBean_OODB::getAssoc($pete, "food");
    if (is_array($petesfood) && count($petesfood) === 1) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    //some extra tests... quick without further notice.
    $food = RedBean_OODB::dispense("dish");
    $food->name = "spaghetti";
    RedBean_OODB::trash($food);
    //test aggregation functions
    //insert stat table
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 1;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 2;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 3;
    RedBean_OODB::set($s);
    SmartTest::instance()->testPack = "can we use aggr functions using Redbean?";
    if (RedBean_OODB::numberof("stattest") != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::maxof("stattest", "amount") != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::minof("stattest", "amount") != 1) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::avgof("stattest", "amount") != 2) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::sumof("stattest", "amount") != 6) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::distinct("stattest", "amount")) != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    RedBean_OODB::setLocking(true);
    $i = 3;
    SmartTest::instance()->testPack = "generate only valid classes?";
    try {
        $i += RedBean_OODB::gen("");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //nothing
    try {
        $i += RedBean_OODB::gen(".");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen(",");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen("null");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //keywords
    try {
        $i += RedBean_OODB::gen("Exception");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //reserved
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "generate classes using Redbean?";
    if (!class_exists("Bug")) {
        $i += RedBean_OODB::gen("Bug");
        if ($i !== 4) {
            SmartTest::failedTest();
        }
    } else {
        if ($i !== 3) {
            SmartTest::failedTest();
        }
    }
    if (!class_exists("Bug")) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "use getters and setters";
    $bug = new Bug();
    $bug->setSomething(sha1("abc"));
    if ($bug->getSomething() != sha1("abc")) {
        SmartTest::failedTest();
    }
    //can we use non existing props? --triggers fatal..
    $bug->getHappy();
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "Use boolean values and retrieve them with is()?";
    if ($bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bug->setHappy(true);
    $bug->save();
    $bug = new Bug(1);
    if (!$bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bug->setHappy(false);
    if ($bug->isHappy()) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "avoid race-conditions by locking?";
    RedBean_OODB::gen("Cheese,Wine");
    $cheese = new Cheese();
    $cheese->setName('Brie');
    $cheese->save();
    $cheese = new Cheese(1);
    //try to mess with the locking system...
    $oldkey = RedBean_OODB::$pkey;
    RedBean_OODB::$pkey = 1234;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    $bordeaux = new Wine();
    $bordeaux->setRegion("Bordeaux");
    try {
        $bordeaux->add($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->attach($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->add(new Wine());
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    RedBean_OODB::$pkey = $oldkey;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        SmartTest::failedTest();
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::$pkey = 999;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    try {
        RedBean_OODB::$pkey = 123;
        RedBean_OODB::setLockingTime(100);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar2");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::failedTest();
    } catch (Exception $e) {
        SmartTest::instance()->progress();
    }
    try {
        RedBean_OODB::$pkey = 42;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar3");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        SmartTest::failedTest();
    }
    //test value ranges
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(-1);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(1.5);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime("aaa");
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->testPack = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(null);
        SmartTest::failedTest();
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    //test convenient tree functions
    SmartTest::instance()->testPack = "convient tree functions";
    if (!class_exists("Person")) {
        RedBean_OODB::gen("person");
    }
    $donald = new Person();
    $donald->setName("Donald");
    $donald->save();
    $kwik = new Person();
    $kwik->setName("Kwik");
    $kwik->save();
    $kwek = new Person();
    $kwek->setName("Kwek");
    $kwek->save();
    $kwak = new Person();
    $kwak->setName("Kwak");
    $kwak->save();
    $donald->attach($kwik);
    $donald->attach($kwek);
    $donald->attach($kwak);
    if (count($donald->children()) != 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if (count($kwik->siblings()) != 2) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //todo
    if ($kwik->hasParent($donald) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasParent($kwak) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($kwak) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($donald) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasChild($kwik) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwek) != true) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwak) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($donald) != false) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //copy
    SmartTest::instance()->testPack = "copy functions";
    $kwak2 = $kwak->copy();
    $id = $kwak2->save();
    $kwak2 = new Person($id);
    if ($kwak->getName() != $kwak2->getName()) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "countRelated";
    R::gen("Blog,Comment");
    $blog = new Blog();
    $blog2 = new Blog();
    $blog->setTitle("blog1");
    $blog2->setTitle("blog2");
    for ($i = 0; $i < 5; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog->add($comment);
    }
    for ($i = 0; $i < 3; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog2->add($comment);
    }
    if ($blog->numofComment() !== 5) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($blog2->numofComment() !== 3) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "associate tables of the same name";
    $blog = new Blog();
    $blogb = new Blog();
    $blog->title = 'blog a';
    $blogb->title = 'blog b';
    $blog->add($blogb);
    $b = $blog->getRelatedBlog();
    if (count($b) !== 1) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $b = array_pop($b);
    if ($b->title != 'blog b') {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "inferTypeII patch";
    $blog->rating = 4294967295.0;
    $blog->save();
    $id = $blog->getID();
    $blog2->rating = -1;
    $blog2->save();
    $blog = new Blog($id);
    if ($blog->getRating() != 4294967295.0) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "Longtext column type";
    $blog->message = str_repeat("x", 65535);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65535) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "text") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $blog->message = str_repeat("x", 65536);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65536) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "longtext") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    Redbean_OODB::clean();
    SmartTest::instance()->testPack = "Export";
    RedBean_OODB::gen("justabean");
    $oBean = new JustABean();
    $oBean->setA("a");
    $oOtherBean = new OODBBean();
    $oOtherBean->a = "b";
    $oBean2 = new OODBBean();
    $oBean->exportTo($oBean2);
    if ($oBean2->a !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $oBean2 = $oBean->exportTo($oBean2);
    if ($oBean2->a !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $oBean->exportTo($oBean2, $oOtherBean);
    if ($oBean2->a !== "b") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = array();
    $oBean->exportTo($arr);
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = array();
    $arr = $oBean->exportTo($arr);
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    $arr = $oBean->exportTo($arr, $oOtherBean);
    if ($arr["a"] !== "b") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->testPack = "Export Array";
    $oBean->a = "a";
    $oInnerBean = new JustABean();
    $oInnerBean->setID(123);
    $oBean->innerbean = $oInnerBean;
    $arr = $oBean->exportAsArr();
    if (!is_array($arr)) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($arr["innerbean"] !== 123) {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    if ($arr["a"] !== "a") {
        SmartTest::failedTest();
    } else {
        SmartTest::instance()->progress();
    }
    //test 1-to-n
    SmartTest::instance()->testPack = "1-to-n relations";
    R::gen("Track,Disc");
    $cd1 = new Disc();
    $cd1->name = 'first';
    $cd1->save();
    $cd2 = new Disc();
    $cd2->name = 'second';
    $cd2->save();
    $track = new Track();
    $track->title = "song 1";
    $track->belongsTo($cd1);
    $discs = $track->getRelatedDisc();
    SmartTest::instance()->test(count($discs), 1);
    $track->belongsTo($cd2);
    $discs = $track->getRelatedDisc();
    SmartTest::instance()->test(count($discs), 1);
    $track2 = new Track();
    $track2->title = "song 2";
    $cd1->exclusiveAdd($track2);
    SmartTest::instance()->test(count($track->getRelatedDisc()), 1);
    $cd2->exclusiveAdd($track2);
    SmartTest::instance()->test(count($track->getRelatedDisc()), 1);
}
示例#19
0
 public function testSearchWineSuccess()
 {
     $data = array();
     $_params = $this->_params;
     $response = $this->action('POST', 'WineController@search', array(), array('data' => json_encode($_params)));
     $user_id = $this->_user_id;
     $wine = Wine::where('name', 'LIKE', '%wi%')->with('winery')->get();
     if ($wine) {
         foreach ($wine as $wines) {
             if ($wines->image_url != null) {
                 $wines->image_url = URL::asset($wines->image_url);
             }
             if ($wines->wine_flag != null) {
                 $wines->wine_flag = URL::asset($wines->wine_flag);
             }
             $ratings = Rating::where('user_id', $user_id)->where('wine_unique_id', $wines->wine_unique_id)->where('is_my_wine', 1)->first();
             if ($ratings) {
                 $data[] = $wines;
             } else {
                 $wishlist = Wishlist::where('user_id', $user_id)->where('wine_unique_id', $wines->wine_unique_id)->first();
                 if ($wishlist) {
                     $data[] = $wines;
                 }
             }
         }
     }
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true));
 }
示例#20
0
 public static function deleteRating($id)
 {
     $rating = Rating::where('id', $id)->first();
     $error_code = ApiResponse::OK;
     if ($rating) {
         $rating_profile = Profile::where('user_id', $rating->user_id)->first();
         if ($rating_profile != null) {
             $rating_profile->rate_count = $rating_profile->rate_count - 1;
             $rating_profile->save();
         }
         $rating_wine = Wine::where('wine_unique_id', $rating->wine_unique_id)->first();
         if ($rating_wine != null) {
             $rating_rate = $rating_wine->average_rate * $rating_wine->rate_count;
             $rating_wine->rate_count = $rating_wine->rate_count - 1;
             if ($rating_wine->rate_count > 0) {
                 $rating_wine->average_rate = ($rating_rate - $rating->rate) / $rating_wine->rate_count;
             } else {
                 $rating_wine->average_rate = 0;
             }
             $rating_wine->save();
         }
         $rating->delete();
         $data = 'Rating Deleted';
     } else {
         $error_code = ApiResponse::UNAVAILABLE_RATING;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING);
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#21
0
 public static function uploadImageWineScan($wine_unique_id)
 {
     $error_code = ApiResponse::OK;
     $user_id = Session::get('user_id');
     $wine = Wine::where('wine_unique_id', $wine_unique_id)->first();
     if ($wine) {
         if (Input::hasFile('file')) {
             $file = Input::file('file');
             $destinationPath = public_path() . '/images/' . $user_id . '/wine/' . $wine->wine_unique_id;
             $filename = date('YmdHis') . '_' . $file->getClientOriginalName();
             $extension = $file->getClientOriginalExtension();
             if (!File::isDirectory($destinationPath)) {
                 File::makeDirectory($destinationPath, $mode = 0777, true, true);
             } else {
                 File::cleanDirectory($destinationPath);
             }
             $upload_success = $file->move($destinationPath, $filename);
             $data = URL::asset('images/' . $user_id . '/wine/' . $wine_unique_id . '/' . $filename);
         } else {
             $error_code = ApiResponse::MISSING_PARAMS;
             $data = null;
         }
     } else {
         $error_code = ApiResponse::UNAVAILABLE_WINE;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE);
     }
     return array("code" => $error_code, "data" => $data);
 }
示例#22
0
function exportCSV($arr, $dbh)
{
    if (isset($arr['reportType']) && $arr['reportType'] == 'summaryByUPC') {
        $wine = new Wine($dbh);
        $wine->fetchWineByUPC($arr['upc']);
        if (isset($arr['toDate']) && $arr['toDate'] != null) {
            $to = $arr['toDate'];
        } else {
            $to = null;
        }
        if (isset($arr['fromDate']) && $arr['fromDate'] != null) {
            $from = $arr['fromDate'];
        } else {
            $from = null;
        }
        $json = $wine->getInventorySummary($from, $to);
        //Generate HTML and echo it out;
        $data = json_decode($json, true);
        if (!isset($data[0])) {
            die('No data was found matching your criteria.');
        }
        $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/tmp/summaryByUPC.csv', 'w');
        $header = 'UPC,Name,Cost,SellingPrice,Quantity,DateTime,Location';
        fwrite($fp, $header);
        fwrite($fp, PHP_EOL);
        foreach ($data as $row) {
            fputcsv($fp, $row);
        }
        fclose($fp);
        header('Location: /tmp/summaryByUPC.csv');
    } else {
        if (isset($arr['reportType']) && $arr['reportType'] == 'completeInventory') {
            $wine = new Wine($dbh);
            if (isset($arr['toDate']) && $arr['toDate'] != null) {
                $to = $arr['toDate'];
            } else {
                $to = null;
            }
            $args = array('date' => $to);
            $wines = $wine->fetchAllWines();
            $data = json_decode($wines, true);
            $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/tmp/completeInventory.csv', 'w');
            $header = 'UPC,Name,Qty,Cost/Bottle,Total Cost,Selling Price,Cost/Selling Price';
            fwrite($fp, $header);
            fwrite($fp, PHP_EOL);
            foreach ($data as $row) {
                $curWine = new Wine($dbh);
                $curWine->fetchWineByUPC($row['upc']);
                $args = array('date' => $to);
                $inv = $curWine->getCurrentInventory($args);
                //cur is json summary of inventory
                $row = '' . $curWine->getUPC() . ',' . $curWine->getName() . ',' . $curWine->getCurrentInventory($args) . ',' . number_format($curWine->getCost(), 2, '.', '') . ',' . number_format($curWine->getCurrentInventory($args) * $curWine->getCost(), 2, '.', '') . ',' . number_format($curWine->getSellPrice(), 2, '.', '') . ',' . $curWine->getCost() / $curWine->getSellPrice();
                fwrite($fp, $row);
                fwrite($fp, PHP_EOL);
            }
            fclose($fp);
            header('Location: /tmp/completeInventory.csv');
        } else {
            die('Invalid Report Type');
        }
    }
}
示例#23
0
 //try to mess with the locking system...
 $oldkey = RedBean_OODB::$pkey;
 RedBean_OODB::$pkey = 1234;
 $cheese = new Cheese(1);
 $cheese->setName("Camembert");
 $ok = 0;
 try {
     $cheese->save();
 } catch (ExceptionFailedAccessBean $e) {
     $ok = 1;
 }
 if (!$ok) {
     die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
 }
 SmartTest::instance()->progress();
 $bordeaux = new Wine();
 $bordeaux->setRegion("Bordeaux");
 try {
     $bordeaux->add($cheese);
 } catch (ExceptionFailedAccessBean $e) {
     $ok = 1;
 }
 if (!$ok) {
     die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
 }
 SmartTest::instance()->progress();
 try {
     $bordeaux->attach($cheese);
 } catch (ExceptionFailedAccessBean $e) {
     $ok = 1;
 }