Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. <?php
  2. class Business {
  3.     protected $db;
  4.     function __construct ($db,$age,$yelp)
  5.     {
  6.         $this->db       = $db;
  7.         $this->age = $age;
  8.         $this->yelp = $yelp;
  9.     }
  10.  
  11.     public function getBusinessPhone ($id)
  12.     {
  13.     try {
  14.                 $sql = "SELECT phone FROM businesses WHERE id=:id";
  15.         $stmt = $this->db->prepare($sql);
  16.         $stmt->bindValue(':id',$id);
  17.         $stmt->execute();
  18.         $result = $stmt->fetchAll();
  19.         return $result[0]['phone'];
  20.     } catch (PDOException $e) {
  21.             die($e->getMessage());
  22.         }
  23.     }
  24.  
  25.     public function getBusinessInfo ($phone)
  26.     {    
  27.     try {              
  28.         $sql = "SELECT * FROM businesses WHERE phone=:phone";
  29.         $stmt = $this->db->prepare($sql);
  30.         $stmt->bindValue(':phone',$phone);
  31.         $stmt->execute();
  32.         $result = $stmt->fetchAll();
  33.  
  34.         if(count($result) < 1){
  35.             $this->yelp->updateBusiness($phone,"add");
  36.             $sql = "SELECT * FROM businesses WHERE phone=:phone";
  37.             $stmt = $this->db->prepare($sql);
  38.             $stmt->bindValue(':phone',$phone);
  39.             $stmt->execute();
  40.             $result = $stmt->fetchAll();
  41.         }
  42.         if(time()-$result[0]['updated'] > $this->age){
  43.             $this->yelp->updateBusiness($phone,"update");
  44.             $sql = "SELECT * FROM businesses WHERE phone=:phone";
  45.             $stmt = $this->db->prepare($sql);
  46.             $stmt->bindValue(':phone',$phone);
  47.             $stmt->execute();
  48.             $result = $stmt->fetchAll();
  49.         }
  50.         print_r($result[0]);
  51.         return $result[0];
  52.     }
  53.         catch (PDOException $e) {
  54.             die($e->getMessage());
  55.         }
  56.     }
  57.  
  58.     public function refreshStaleBusinesses ()
  59.     {    
  60.     try {              
  61.         $sql = "SELECT * FROM businesses WHERE updated<:calc";
  62.         $stmt = $this->db->prepare($sql);
  63.         $stmt->bindValue(':calc',time()-$this->age);
  64.         $stmt->execute();
  65.         $result = $stmt->fetchAll();
  66.         foreach($result as $row) {
  67.             $this->yelp->updateBusiness($row['phone'],"update");        
  68.         }
  69.     }
  70.         catch (PDOException $e) {
  71.             die($e->getMessage());
  72.         }
  73.     }
  74.  
  75.  
  76. }
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement