Exemplo n.º 1
0
 /**
  *
  */
 public function testFillFromDatabase()
 {
     $test = array('id_vendor' => '5', 'name_vendor' => 'burger truck', 'postcode' => 'NW85695', 'max_cover' => '20');
     $this->vendor = Vendor::fillFromDatabase($test);
     $this->assertInstanceOf('Citypantry\\Models\\Entities\\Vendor', $this->vendor);
     $this->assertEquals($this->vendor->getId(), $test['id_vendor']);
     $this->assertEquals($this->vendor->getNameVendor(), $test['name_vendor']);
     $this->assertEquals($this->vendor->getPostCode(), $test['postcode']);
     $this->assertEquals($this->vendor->getMaxCover(), $test['max_cover']);
 }
Exemplo n.º 2
0
 /**
  * @param $location
  * @param $date
  * @param $covers
  * @return array
  */
 public function findPackages($location, $date, $covers)
 {
     $pattern = '/^([a-zA-Z]+)[a-zA-Z0-9]+/';
     preg_match($pattern, $location, $matches);
     $locationToFind = $matches[1] . '%';
     $stmt = $this->prepare('SELECT * FROM vendors v ' . 'LEFT JOIN packages p ON v.id = p.id_vendor ' . 'WHERE v.postcode LIKE :location ' . 'AND datetime(:dateProvide) < datetime("now", "+"|| p.advance||" hours") ' . 'AND :covers <= v.max_cover ');
     $stmt->bindValue(':location', $locationToFind, SQLITE3_TEXT);
     $stmt->bindValue(':dateProvide', $date->format('Y-m-d H:i:s'));
     $stmt->bindValue(':covers', $covers, SQLITE3_INTEGER);
     $result = $stmt->execute();
     $vendors = array();
     while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
         if (!isset($vendors[$row['id_vendor']])) {
             $vendors[$row['id_vendor']] = Vendor::fillFromDatabase($row);
         }
         $vendors[$row['id_vendor']]->addPackage(Package::fillFromDatabase($row));
     }
     return $vendors;
 }