示例#1
0
 static function find($search_id)
 {
     $found_pub = null;
     $all_pubs = Pub::getAll();
     foreach ($all_pubs as $pub) {
         if ($pub->getId() == $search_id) {
             $found_pub = $pub;
         }
     }
     return $found_pub;
 }
示例#2
0
<?php

$liste = Pub::Lister();
$nbre_pub = count($liste);
$prevRand = rand(0, $nbre_pub - 1);
$nextRand = $prevRand;
while ($nextRand == $prevRand) {
    $nextRand = rand(0, $nbre_pub - 1);
}
$nextRand2 = $prevRand;
while ($nextRand2 == $prevRand || $nextRand2 == $nextRand) {
    $nextRand2 = rand(0, $nbre_pub - 2);
}
?>
<div class='cadrePub'>
    <div class='pub_titre'>	
        PUBLICITÉ
    </div>
    <div class='pub'>	
        <img src='image/pubs/<?php 
echo $liste[$prevRand];
?>
'>
    </div>
    <div class='pub'>	
        <img src='image/pubs/<?php 
echo $liste[$nextRand];
?>
'>
    </div>
    <div class='pub'>	
示例#3
0
<?php

date_default_timezone_set('Europe/Berlin');
// set include path
ini_set("include_path", ".:../library/");
// required classes
require_once 'spoon/spoon.php';
require_once 'publicApp/publicApp.php';
$tpl = new SpoonTemplate();
$tpl->setForceCompile(true);
$tpl->setCompileDirectory('./compiled_templates');
//Content layout
$pub = new Pub(SpoonFilter::getGetValue('id', null, ''));
if (SpoonSession::exists('public_uid')) {
    //show logout
    $tpl->assign('oLogout', true);
}
if ($pub->pub_id === null) {
    SpoonHTTP::redirect('index.php');
}
$recent = CheckIn::getCheckinsByPubId($pub->pub_id);
for ($i = 0; $i < sizeof($recent); $i++) {
    $recent[$i]['timestamp'] = SpoonDate::getTimeAgo(strtotime($recent[$i]['timestamp']));
    //check if the user has a fb account authenticated
    if (!$recent[$i]['fb_uid']) {
        //else, use standard fb icon
        $recent[$i]['fb_uid'] = 1;
    }
}
if ($recent !== null) {
    $tpl->assign('oRecent', true);
示例#4
0
    $brewery = Brewery::find($beer->getBreweryId());
    return $app['twig']->render('beer.html.twig', array('beer' => $beer, 'pubs' => $pubs_on_tap, 'brewery' => $brewery));
});
//takes pub user to a page where they can add a pub
$app->get('/pub_login', function () use($app) {
    $app['twig']->addGlobal('logged_user', $_SESSION['user']);
    $all_pubs = Pub::getAll();
    return $app['twig']->render('pub.html.twig', array('pubs' => $all_pubs));
});
//posts the new pub to the pubs homepage
$app->post('/pub_login', function () use($app) {
    $app['twig']->addGlobal('logged_user', $_SESSION['user']);
    $name = $_POST['name'];
    $location = $_POST['location'];
    $link = $_POST['link'];
    $new_pub = new Pub($name, $location, $link);
    $new_pub->save();
    return $app['twig']->render('pub.html.twig', array('pubs' => Pub::getAll()));
});
//deletes all the pubs
$app->delete('/pub_login', function () use($app) {
    $app['twig']->addGlobal('logged_user', $_SESSION['user']);
    Pub::deleteAll();
    return $app['twig']->render('pub.html.twig', array('all_pubs' => Pub::getAll()));
});
//takes user to an individual's pub page
$app->get('/pub/{id}', function ($id) use($app) {
    $app['twig']->addGlobal('logged_user', $_SESSION['user']);
    $pub = Pub::find($id);
    return $app['twig']->render('pub_profile.html.twig', array('pub' => $pub, 'beers' => $pub->getBeers()));
});
示例#5
0
 function test_deleteAllBeers()
 {
     //Arrange
     $name = "Paddys";
     $location = "462 Over There Way";
     $link = "www.paddyspub.com";
     $test_pub = new Pub($name, $location, $link);
     $test_pub->save();
     $id = null;
     $name = "Lip Blaster";
     $type = "IPA";
     $abv = 4.2;
     $ibu = 10;
     $region = "Pacific Northwest";
     $brewery_id = 1;
     $test_beer = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer->save();
     $id = null;
     $name = "Hip Hops";
     $type = "Pale Ale";
     $abv = 3.2;
     $ibu = 4;
     $region = "South Central LA";
     $brewery_id = 2;
     $test_beer2 = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer2->save();
     $test_pub->addBeer($test_beer);
     $test_pub->addBeer($test_beer2);
     //Act
     $test_pub->deleteAllBeers();
     //Assert
     $result = $test_pub->getBeers();
     $this->assertEquals([], $result);
 }
示例#6
0
SpoonSession::start();
//Content layout
if (SpoonSession::exists('id') === false) {
    SpoonHTTP::redirect('index.php');
}
$lat = SpoonFilter::getGetValue('lat', null, '');
$long = SpoonFilter::getGetValue('long', null, '');
$tpl->assign('formaction', $_SERVER['PHP_SELF'] . '?lat=' . $lat . '&long=' . $long);
$msgFault = '';
$pubname = SpoonFilter::getPostValue('pubname', null, '');
if (SpoonFilter::getPostValue('btnAdd', null, '')) {
    if ($pubname === "") {
        $msgFault = "Please fill in the name of the pub.";
    } else {
        if ($lat !== "" && $long !== "") {
            $pub = new Pub('');
            $pub->name = $pubname;
            $pub->latitude = $lat;
            $pub->longitude = $long;
            $id = $pub->Add();
            SpoonHTTP::redirect('pubDetail.php?id=' . $id);
        }
    }
}
$tpl->assign('pubname', $pubname);
$tpl->assign('msgFault', $msgFault);
$tpl->assign('latitude', $lat);
$tpl->assign('longitude', $long);
// show the output
$tpl->assign('content', $tpl->getContent('templates/addPub.tpl'));
$tpl->display('templates/template.tpl');
示例#7
0
 function testGetPubs()
 {
     //Arrange
     $id = null;
     $name = "Lip Blaster";
     $type = "IPA";
     $abv = 4.2;
     $ibu = 10;
     $region = "Pacific Northwest";
     $brewery_id = 1;
     $test_beer = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id);
     $test_beer->save();
     $name = "The Outback Steakhouse";
     $location = "300NW Outback Steak Rd";
     $link = "http://www.outback.com/";
     $test_pub = new Pub($name, $location, $link);
     $test_pub->save();
     $test_pub->addBeer($test_beer);
     //Act
     $result = $test_beer->getPubs();
     //Assert
     $this->assertEquals([$test_pub], $result);
 }
示例#8
0
 /**
  * Inserts a row inte the table pubs
  *
  * @param Pub $pub
  * @throws \DataBaseException
  * @throws \Exception
  */
 public function addPub(Pub $pub)
 {
     try {
         $stmt = $this->conn->prepare("INSERT INTO " . self::$table . " VALUES(?, ?, ?, ?)");
         if (!$stmt) {
             throw new \DataBaseException($this->conn->error);
         }
         $id = $pub->getId();
         $name = $pub->getName();
         $address = $pub->getAddress();
         $webpage = $pub->getWebpageURL();
         $stmt->bind_param("ssss", $id, $name, $address, $webpage);
         $stmt->execute();
     } catch (\DataBaseException $e) {
         if (\Settings::DEBUG_MODE) {
             throw $e;
         } else {
             error_log($e->getMessage() . "\n", 3, \Settings::ERROR_LOG);
             echo "Something went wrong when connecting to the database";
             die;
         }
     }
 }
示例#9
0
$tpl->setForceCompile(true);
$tpl->setCompileDirectory('./compiled_templates');
SpoonSession::start();
//Content layout
if (SpoonSession::exists('id') === false) {
    SpoonHTTP::redirect('index.php');
}
$lat = SpoonFilter::getGetValue('lat', null, '');
$long = SpoonFilter::getGetValue('long', null, '');
$pubs = array();
if ($lat !== "" && $long !== "") {
    $tpl->assign('latitude', $lat);
    $tpl->assign('longitude', $long);
    $pubs = Pub::getPubsByLocation($lat, $long);
    for ($i = 0; $i < sizeof($pubs); $i++) {
        $pub = new Pub($pubs[$i]['pub_id']);
        $distance = $pub->calculateDistance($lat, $long, "k");
        if ($distance > 1) {
            $pubs[$i]["distance"] = round($distance, 3) . ' kilometer';
        } else {
            $pubs[$i]["distance"] = round($distance, 3) * 1000 . ' meter';
        }
    }
} else {
    $tpl->assign('latitude', "");
    $tpl->assign('longitude', "");
}
if ($pubs !== null) {
    $tpl->assign('iPubs', $pubs);
    $tpl->assign('oPubs', true);
} else {
示例#10
0
 protected function tearDown()
 {
     Brewery::deleteAll();
     Beer::deleteAll();
     Pub::deleteAll();
 }
示例#11
0
if (SpoonSession::exists('public_uid')) {
    //show logout
    $tpl->assign('oLogout', true);
}
//Content layout
$tpl->assign('oNavPubs', true);
$lat = SpoonFilter::getGetValue('lat', null, '');
$long = SpoonFilter::getGetValue('long', null, '');
$pubs = array();
if ($lat !== "" && $long !== "") {
    $tpl->assign('latitude', $lat);
    $tpl->assign('longitude', $long);
    $pubs = Pub::getPubsByLocation($lat, $long);
    $abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for ($i = 0; $i < sizeof($pubs); $i++) {
        $pub = new Pub($pubs[$i]["pub_id"]);
        $pubs[$i]["letter"] = substr($abc, $i, 1);
        $pubs[$i]["people"] = $pub->getNumberPeople();
        $pubs[$i]["checkins"] = $pub->getNumberCheckins();
    }
} else {
    $tpl->assign('latitude', '""');
    $tpl->assign('longitude', '""');
}
if ($pubs !== null) {
    $tpl->assign('iPubs', $pubs);
} else {
    $tpl->assign('iPubs', array());
}
$tpl->assign('intoHead', '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <script>