public function it_decides_alive_member_live_with_3_neighbors(\Neighborhood $neighborhood)
 {
     $member = '2,4';
     $neighborhood->isAlive($member)->willReturn(true);
     $neighborhood->countNeighbors($member)->willReturn(3);
     $this->willLive($member)->shouldBe(true);
 }
Exemple #2
0
 /**
  * Applies game of life rules for next generation
  *
  * @param  string $member
  * @return boolean
  */
 public function willLive($member)
 {
     if (!$this->neighborhood->isAlive($member)) {
         return $this->neighborhood->countNeighbors($member) == 3;
     } else {
         $neighbors = $this->neighborhood->countNeighbors($member);
         return $neighbors > 1 && $neighbors < 4;
     }
 }
Exemple #3
0
 public function it_generates_another_generation_next(\Constitution $constitution, \Neighborhood $neighborhood)
 {
     $constitution->willLive('2,3')->willReturn(true);
     $constitution->willLive('2,4')->willReturn(true);
     $constitution->willLive('3,4')->willReturn(true);
     $constitution->willLive('3,5')->willReturn(true);
     $constitution->willLive('4,3')->willReturn(true);
     $neighborhood->getMatrixSize()->willReturn(5);
     $this->nextGeneration()->shouldBe(['2,3', '2,4', '3,4', '3,5', '4,3']);
 }
Exemple #4
0
 /**
  * Defines next generation
  *
  * @return array
  */
 public function nextGeneration()
 {
     $next = [];
     for ($i = 1; $i <= $this->neighborhood->getMatrixSize(); $i++) {
         for ($j = 1; $j <= $this->neighborhood->getMatrixSize(); $j++) {
             $member = "{$i},{$j}";
             if ($this->constitution->willLive($member)) {
                 $next[] = $member;
             }
         }
     }
     return $next;
 }
 public function initialize($entity = null, $options = null)
 {
     $country = new Select('countryid', Country::find(), array('using' => array('id', 'country'), 'useEmpty' => TRUE, 'emptyText' => $this->di->get('translate')->_('Seleccione un País')));
     $country->setLabel('País');
     $this->add($country);
     if (isset($entity)) {
         if ($entity->getCountryid()) {
             $state = new Select('stateid', State::find(array("columns" => array("id,state"), "conditions" => "countryid =:countryid:", "bind" => array("countryid" => $entity->countryid))), array("useEmpty" => true, "emptyText" => $this->di->get('translate')->_('Seleccione un Estado'), 'using' => array('id', 'state')));
             $state->setLabel('Estado');
             $this->add($state);
             $city = new Select('cityid', City::find(array("columns" => array("id,city"), "conditions" => "countryid =:countryid: AND stateid =:stateid: ", "bind" => array("countryid" => $entity->countryid, "stateid" => $entity->stateid))), array("useEmpty" => true, "emptyText" => $this->di->get('translate')->_('Seleccione una ciudad'), 'using' => array('id', 'city')));
             $city->setLabel('Ciudad');
             $this->add($city);
             $township = new Select('townshipid', Township::find(array("columns" => array("id,township"), "conditions" => "cityid =:cityid:", "bind" => array("cityid" => $entity->cityid))), array("useEmpty" => true, "emptyText" => $this->di->get('translate')->_('Seleccione un Sector'), 'using' => array('id', 'township')));
             $township->setLabel('Sector');
             $this->add($township);
             $neighborhood = new Select('neighborhoodid', Neighborhood::find(array("columns" => array("id,neighborhood"), "conditions" => "cityid =:cityid:", "bind" => array("cityid" => $entity->cityid))), array("useEmpty" => true, "emptyText" => $this->di->get('translate')->_('Seleccione un Barrio'), 'using' => array('id', 'neighborhood')));
             $neighborhood->setLabel('Barrio');
             $this->add($neighborhood);
         } else {
             $this->set_empty_values();
         }
     } else {
         $this->set_empty_values();
     }
     $address = new Textarea('address', array("maxlength" => "400"));
     $address->setLabel('Dirección');
     $this->add($address);
     $description = new Textarea('description', array("maxlength" => "100"));
     $description->setLabel('Descripción');
     $this->add($description);
 }
Exemple #6
0
<?php

include "classes.php";
if (isset($_POST['location']) && isset($_POST['group'])) {
    $location = $_POST['location'];
    $group = $_POST['group'];
    $hood = new Neighborhood($location);
    $hood->get_recommended_venues();
    $restaurants = array();
    if ($group == "no filter") {
        $restaurants = $hood->recommended_venues;
    } else {
        $restaurants = $hood->filter_by_group($group);
    }
    echo '
        <!doctype html>
            <html>
            	<head>
            		<title> hungry? </title>
            		<link rel="stylesheet" type="text/css" href="css/style.css">
            	</head>
            	<body>

            	<h1> Starving. </h1>
            	<div class="back">  </div><h2><a href="/"> <img src="images/prev_button.png" width="20" height="auto"></a> Restaurant recommendations for ' . $location . ' </h2>
            	<div class="thick"><hr></div>
    ';
    $i = 0;
    foreach ($restaurants as $restaurant) {
        if (empty($hood->venue_ids)) {
            $id = $restaurant->id;
 public function showAddressPage()
 {
     if (strlen($this->data) == 0) {
         return $this->showAddressForm();
     } else {
         $this->getLatLon();
         if (strlen($this->error) > 0) {
             $this->return .= '<p class="wbb-alert wbb-alert-danger">' . $this->error . '</p>';
             return $this->showAddressForm();
         } else {
             $data = Neighborhood::getNeighborhoodFromLatLng($this->lat, $this->lng);
             if ($data['id'] == 0) {
                 if (strlen($data['expires_at']) > 0 && strtotime($data['expires_at']) < strtotime(date('Y-m-d'))) {
                     $this->return .= "\n\t\t\t\t\t\t\t<script>\n\n\t\t\t\t\t\t\t\tvar wbb_popup_width = 450;\n\t\t\t\t\t\t\t\tvar wbb_popup_height = 300;\n\t\t\t\t\t\t\t\tvar wbb_popup_html = 'We are sorry, but registration has ended for the " . $data['title'] . " neighborhood.<br><br>\\\n\t\t\t\t\t\t\t\tSign up for the Walk Bike Bus<br>newsletter to stay informed.<br><br>\\\n\t\t\t\t\t\t\t\tEmail Address:\\\n\t\t\t\t\t\t\t\t<form id=\"wbb-newsletter-form\">\\\n\t\t\t\t\t\t\t\t<input name=\"email\"><br>\\\n\t\t\t\t\t\t\t\t<button class=\"submit\">Submit</button>\\\n\t\t\t\t\t\t\t\t</form>';\n\n\t\t\t\t\t\t\t</script>\n\t\t\t\t\t\t";
                 } else {
                     $this->return .= "\n\t\t\t\t\t\t\t<script>\n\n\t\t\t\t\t\t\t\tvar wbb_popup_width = 450;\n\t\t\t\t\t\t\t\tvar wbb_popup_height = 300;\n\t\t\t\t\t\t\t\tvar wbb_popup_html = '<img src=\"" . plugin_dir_url(dirname(__FILE__)) . "/images/sorry.png\"><br><br>\\\n\t\t\t\t\t\t\t\tSign up for the Walk Bike Bus<br>newsletter to stay informed.<br><br>\\\n\t\t\t\t\t\t\t\tEmail Address:\\\n\t\t\t\t\t\t\t\t<form id=\"wbb-newsletter-form\">\\\n\t\t\t\t\t\t\t\t<input name=\"email\"><br>\\\n\t\t\t\t\t\t\t\t<button class=\"submit\">Submit</button>\\\n\t\t\t\t\t\t\t\t</form>';\n\n\t\t\t\t\t\t\t</script>\n\t\t\t\t\t\t";
                 }
                 //$this->return .= '<p class="wbb-alert wbb-alert-danger">The address you entered does not lie within one of our approved areas.</p>';
                 return $this->showAddressForm();
             } else {
                 $this->return .= "\n\t\t\t\t\t\t<script>\n\n\t\t\t\t\t\t\tvar wbb_popup_width = 450;\n\t\t\t\t\t\t\tvar wbb_popup_height = 200;\n\t\t\t\t\t\t\tvar wbb_popup_html = '<img src=\"" . plugin_dir_url(dirname(__FILE__)) . "/images/congrats.png\"><br><br>\\\n\t\t\t\t\t\t\tYou are part of a very small number of people in " . $data['title'] . " that are eligible to participate in our Walk Bike Bus pilot program!';\n\n\t\t\t\t\t\t</script>\n\t\t\t\t\t";
                 //$this->return .= '<p class="wbb-alert wbb-alert-success">Congrats! You are eligible to register for the ' . $data['title'] . ' neighborhood!</p>';
                 $_SESSION['wbb_register_neighborhood_id'] = $data['id'];
                 $_SESSION['wbb_register_neighborhood_title'] = $data['title'];
                 return $this->showRegisterForm();
             }
         }
     }
 }
 /**
  * @Route("/get_neighborhood_data/{cityid}/{townshipid}", methods={"POST"}, name="get_neighborhood_data")
  */
 public function get_neighborhood_dataAction($cityid, $townshipid)
 {
     $this->view->disable();
     $neighborhood_data = Neighborhood::find(array("columns" => array("id,neighborhood"), "conditions" => "cityid = :cityid: AND townshipid =:townshipid:", "bind" => array("cityid" => $cityid, "townshipid" => $townshipid)))->toArray();
     echo json_encode($neighborhood_data);
 }