votako

do not ander

Oct 9th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. <?
  2. $db = new sqlite_db("db.sqlite");
  3. $db->query
  4. ("BEGIN;
  5.     CREATE TABLE products ( id          INEGER PRIMARY KEY AUTOINCREMENT,
  6.                             type        TEXT,
  7.                             firstname   TEXT,
  8.                             mainname    TEXT,
  9.                             title       TEXT,
  10.                             price       float,
  11.                             numpage     int,
  12.                             playlength  int,
  13.                             discount    int
  14. COMMIT;");
  15.  
  16.  
  17. class ShopProduct
  18. {
  19.     private          $title;   
  20.     private          $producerFirstName;
  21.     private          $producerMainName;
  22.     protected        $price;
  23.     private          $discount = 0;
  24.     private          $id = 0;
  25.  
  26.     public function __construct($title, $firstName, $mainName, $price)
  27.     {
  28.         $this->title                =$title;
  29.         $this->producerFirstName    =$firstName;
  30.         $this->producerMainName     =$mainName;
  31.         $this->price                =$price;
  32.     }
  33.  
  34.     public function getTitle()
  35.     {
  36.         return $this->title;
  37.     }
  38.  
  39.     public function getProducer()
  40.     {
  41.         return $this->producerFirstName . $this->producerMainName;
  42.     }
  43.  
  44.     public function getSummaryLine()
  45.     {
  46.         $base = $this->title . $this->producerFirstName . $this->producerMainName;
  47.         return $base;
  48.     }
  49.  
  50.     public function getDiscount()
  51.     {
  52.         return $this->discount;
  53.     }
  54.  
  55.     public function setDiscount($num)
  56.     {
  57.         $this->discount=$num;
  58.     }
  59.  
  60.     public function getPrice()
  61.     {
  62.         return ($this->price - $this->discount);
  63.     }
  64. }
  65.  
  66.  
  67.  
  68. /**
  69. *
  70. */
  71. class CDproduct extends ShopProduct
  72. {
  73.     private $playLength;
  74.  
  75.     public function __construct( $title, $firstName, $mainName, $price, $playLength)
  76.     {
  77.         parent::__construct($title, $firstName, $mainName, $price);
  78.         $this->playLength = $playLength;
  79.     }
  80.  
  81.     public function getPlayLength()
  82.     {
  83.         return $this->playLength;
  84.     }
  85.     public function getSummaryLine()
  86.     {
  87.         $base  = parent::getSummaryLine();
  88.         $base .= ": play - {$this->playLength} ";
  89.             return $base;
  90.     }
  91. }
  92.  
  93. /**
  94. *
  95. */
  96. class BookProduct extends ShopProduct
  97. {
  98.     private $numPages;
  99.  
  100.     public function __construct( $title, $firstName, $mainName, $price, $numPages)
  101.     {
  102.         parent::__construct($title, $firstName, $mainName, $price);
  103.         $this->numPages = $numPages;
  104.     }
  105.  
  106.     public function getNumPages()
  107.     {
  108.         return $this->numPages;
  109.     }
  110.     public function getSummaryLine()
  111.     {
  112.         $base  = parent::getSummaryLine();
  113.         $base .= ": {$this->numPages} str.";
  114.             return $base;
  115.     }
  116.     public function getPrice()
  117.     {
  118.         return $this->price;
  119.     }
  120. }
  121.  
  122.  
  123.  
  124. class ShopProductWriter
  125. {
  126.     private $products = array();
  127.  
  128.     public function addProduct ( ShopProduct $shopProduct )
  129.     {
  130.         $this->products[] = $shopProduct;
  131.     }
  132.  
  133.     public function write()
  134.     {
  135.         $str = "";
  136.         foreach ($this->products as $shopProduct)
  137.         {
  138.             $str .=     "{$shopProduct->getTitle}: ";
  139.             $str .=     $shopProduct->getProducer();
  140.             $str .=     "({$shopProduct->getPrice()})\n";
  141.         }
  142.         print $str;
  143.     }
  144. }
  145. ?>
  146. <?
  147. class StaticExample
  148. {
  149.     static public $aNum;
  150.  
  151.     static public function sayHello($aNum)
  152.     {
  153.        
  154.         print "hell (" . self::$aNum=1 .")";
  155.     }
  156. }
  157.  
  158. ?>
Advertisement
Add Comment
Please, Sign In to add comment