static function getInstance() { if (CouponsDAO::$instance == null) { CouponsDAO::$instance = new CouponsDAO(); } return CouponsDAO::$instance; }
public function getNearestCoupons() { $couponsArray = CouponsDAO::getInstance()->getCoupons(); $minDistance = 1000000; foreach ($couponsArray as $couponInfo) { $businessInfo = CouponsDAO::getInstance()->getBusinessInfo($couponInfo->getBusinessID()); $distance = sqrt(pow($businessInfo->getLatitude() - LocationData::$userLatitude, 2) + pow($businessInfo->getLongtitude() - LocationData::$userLongtitude, 2)); if ($distance < $minDistance) { $minDistance = $distance; $nearestBusiness = $businessInfo; } } return $nearestBusiness; }
<?php include_once 'Entities.php'; include_once 'DBHandle.php'; use Entities\Category; $dao = new CouponsDAO(); $categoriesArray = $dao->getCategories(); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html"> <head> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" /> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script> <script> $('#ul-categories li').live('click', function() { }); </script> </head> <body> <!-- Start of first page --> <div data-role="page" id="page-categories"> <div data-role="header" data-theme="b">
<?php /** * Created by ron. * User: admin * Date: 8/7/13 * Time: 5:31 PM */ include_once 'Entities.php'; include_once 'DBHandle.php'; use Entities\Coupon; use Entities\Business; $dao = new CouponsDAO(); if (!empty($_GET['q'])) { $coupons = $dao->getBusinessCoupons($_GET['q']); $couponsSelection = ""; foreach ($coupons as $couponInfo) { echo '<option value="' . $couponInfo->getID() . '">' . $couponInfo->getName() . '</option>'; } } else { if (!empty($_GET['couponID'])) { $dao->deleteCoupon($_GET['couponID']); echo $_GET['couponID']; } else { $businesses = $dao->getBusinesses(); $busSelection = ""; $coupons = $dao->getBusinessCoupons($businesses[0]->getID()); $couponsSelection = ""; foreach ($businesses as $businessInfo) { $busSelection .= "<option value={$businessInfo->getID()}>{$businessInfo->getName()}</option>"; }
$target_path = getcwd() . "/uploads/"; $target_path .= basename($_FILES['coupon_image_upload']['name']); if (move_uploaded_file($_FILES['coupon_image_upload']['tmp_name'], $target_path)) { $dao = new CouponsDAO(); try { $dao->addCoupon($couponObj); } catch (Exception $e) { echo "failed adding coupon to database"; } echo "<h3>Coupon was successfully uploaded!</h3><br /><a href='http://localhost:10088/Coupons/'>Back to form</a>"; } else { echo "There was an error uploading the file, please try again!"; } } } else { $dao = new CouponsDAO(); $businesses = $dao->getBusinesses(); foreach ($businesses as $businessInfo) { $busSelection .= "<option value={$businessInfo->getID()}>{$businessInfo->getName()}</option>"; } $categories = $dao->getCategories(); foreach ($categories as $categoryInfo) { $categoriesSelection .= "<option value={$categoryInfo->getID()}>{$categoryInfo->getName()}</option>"; } echo '<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<?php /** * Created by ron. * User: admin * Date: 7/29/13 * Time: 7:11 PM */ include_once 'Entities.php'; include_once 'DBHandle.php'; include_once 'distance.php'; use Entities\Business; $businessesArray = CouponsDAO::getInstance()->getBusinesses(); $latitude = $businessesArray[0]->getLatitude(); $longtitude = $businessesArray[0]->getLongtitude(); $name = $businessesArray[0]->getName(); ?> <!DOCTYPE html> <html> <head> <title>Businesses Map</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Bootstrap --> <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="css/signin.css" rel="stylesheet"> <style type="text/css"> html { height: 100%;width: 50% } body { height: 100%; margin: 0; padding: 0 } #map-canvas { height: 70% }
<?php include_once 'Entities.php'; include_once 'DBHandle.php'; use Entities\Category; if (!empty($_GET['category_id'])) { $categoryID = $_GET['category_id']; $_SESSION['category_id'] = $categoryID; $dao = new CouponsDAO(); $couponsArray = $dao->getCouponsByCategory($categoryID); } ?> <!DOCTYPE html> <html> <head> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" /> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script> </head> <body> <!-- Start of first page --> <div data-role="page" id="page-coupons"> <div data-role="header" data-theme="b"> <h1>Nearest Coupons</h1> </div><!-- /header -->
include_once 'DBHandle.php'; $request_method = strtolower($_SERVER['REQUEST_METHOD']); if ($request_method == 'get') { Header('Content-type: text/xml'); $xml = new DOMDocument("1.0"); $xml->formatOutput = true; if (isset($_GET['couponid'])) { try { $couponsArray = array(CouponsDAO::getInstance()->getCoupon($_GET['couponid'])); } catch (Exception $e) { //empty array echo "no coupons were found with provided id"; } } else { $couponsArray = CouponsDAO::getInstance()->getCoupons(); } $root = $xml->createElement("coupons"); $root = $xml->appendChild($root); foreach ($couponsArray as $couponInfo) { $couponRoot = $xml->createElement("coupon"); $couponRoot = $root->appendChild($couponRoot); $idElem = $xml->createElement("id", $couponInfo->getID()); $nameElem = $xml->createElement("name", $couponInfo->getName()); $catagoryElem = $xml->createElement("categoryid", $couponInfo->getCatagoryID()); $businessElem = $xml->createElement("businessid", $couponInfo->getBusinessID()); $descElem = $xml->createElement("description", $couponInfo->getDescription()); $imgElem = $xml->createElement("imagefilename", $couponInfo->getImageFileName()); $couponRoot->appendChild($idElem); $couponRoot->appendChild($nameElem); $couponRoot->appendChild($catagoryElem);
<?php include_once 'DBHandle.php'; Utilities::writeToCsvFile(CouponsDAO::getInstance()->getCoupons());