Advertisement
Guest User

Untitled

a guest
Feb 12th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.40 KB | None | 0 0
  1. <?php
  2. abstract class person
  3. {
  4.     protected $vardas;
  5.     protected $pavarde;
  6.     protected $telefonas;
  7.     protected $adresas;
  8.     protected $asmenskodas;
  9.     protected $kortele = [];
  10.     public function __construct($vardas, $pavarde, $telefonas, $adresas, $asmenskodas)
  11.     {
  12.         $this->vardas = $vardas;
  13.         $this->pavarde = $pavarde;
  14.         $this->telefonas = $telefonas;
  15.         $this->adresas = $adresas;
  16.         $this->asmenskodas = $asmenskodas;
  17.     }
  18.     public function rodykprof()
  19.     {
  20.         $output[] = $this->vardas;
  21.         $output[] .= $this->pavarde;
  22.         $output[] .= $this->telefonas;
  23.         $output[] .= $this->adresas;
  24.         $output[] .= $this->asmenskodas;
  25.         return $output;
  26.     }
  27.     abstract protected function profilioGeneratorius();
  28.     public function loadtodb()
  29.     {
  30.         if(isset($this->vardas) AND isset($this->pavarde) AND isset($this->telefonas) AND isset($this->adresas)
  31.             AND isset($this->asmenskodas)){
  32.             try {
  33.                 $stmt = "INSERT INTO person (vardas, pavarde, telefonas, adresas, asmenskodas) VALUES (:vardas, :pavarde, :telefonas,:adresas, :asmenskodas)";
  34.                 $querie = $pdo->prepare($stmt);
  35.                 $querie->execute(array($this->vardas,$this->pavarde, $this->telefonas, $this->adresas, $this->asmenskodas));
  36.                 return "Irasas sekmingai pridetas";
  37.  
  38.             } catch (Exception $e) {
  39.                 return "Negaliu pridėti naujo įrašo: $e";
  40.                 exit;
  41.             }
  42.         }
  43.     }
  44.  
  45. }
  46. class darbuotojas extends person
  47. {
  48.     protected $pareiga;
  49.     protected $alga;
  50.     public function __construct($pareiga, $alga, $vardas, $pavarde, $telefonas, $adresas, $asmenskodas)
  51. {
  52.     parent::__construct($vardas, $pavarde, $telefonas, $adresas, $asmenskodas);
  53.     $this->pareiga = $pareiga;
  54.     $this->alga = $alga;
  55.     $this->asmenskodas = $asmenskodas;
  56. }
  57.     public function profilioGeneratorius()
  58.     {
  59.         //metodo realizacija
  60.         $this->kortele [] = $this->pareiga;
  61.         $this->kortele [] = $this->alga;
  62.         $this->kortele [] = $this->vardas;
  63.         $this->kortele [] = $this->pavarde;
  64.         $this->kortele [] = $this->telefonas;
  65.         $this->kortele [] = $this->adresas;
  66.         $this->kortele [] = $this->asmenskodas;
  67.  
  68.         return $this->kortele;
  69.     }
  70.     public function loadtodb()
  71.     {
  72.         if(isset($this->vardas) AND isset($this->pavarde) AND isset($this->telefonas) AND isset($this->adresas)
  73.             AND isset($this->asmenskodas) AND isset($this->pareiga) AND isset($this->alga)){
  74.             try {
  75.                 $pdo = new PDO($dsn, $user, $pass, $opt);
  76.             } catch (Exception $e) {
  77.                 echo "Negaliu prisijungti prie DB<br>";
  78.                 echo $e->getMessage();
  79.                 exit;
  80.             }
  81.             try {
  82.                 $stmt = "INSERT INTO darbuotojas (asmenskodas, pareiga, alga) VALUES (:asmenskodas, :pareiga, :alga)";
  83.                 $querie = $pdo->prepare($stmt);
  84.                 $querie->execute(array($this->vardas,$this->pavarde, $this->telefonas, $this->adresas, $this->asmenskodas, $this->pareiga, $this->alga));
  85.                 return "Irasas sekmingai pridetas";
  86.  
  87.             } catch (Exception $e) {
  88.                 return "Negaliu pridėti naujo įrašo: $e";
  89.                 exit;
  90.             }
  91.  
  92.         }
  93.  
  94.     }
  95.  
  96.  
  97. }
  98. class mokytojas extends darbuotojas
  99. {
  100.     protected $destomasdalykas;
  101.     protected $pasalpa;
  102.     protected $mokiniaiklaseje;
  103.     protected $aukletojasklases;
  104.     public function __construct($destomasdalykas,$pasalpa,$aukletojasklases, $mokiniaiklaseje, $pareiga, $alga, $vardas, $pavarde, $telefonas, $adresas, $asmenskodas)
  105.     {
  106.         parent::__construct($pareiga, $alga, $vardas, $pavarde, $telefonas, $adresas, $asmenskodas);
  107.         $this->destomasdalykas = $destomasdalykas;
  108.         $this->pasalpa = $pasalpa;
  109.         $this->aukletojasklases = $aukletojasklases;
  110.         $this->mokiniaiklaseje = $mokiniaiklaseje;
  111.     }
  112.     public function profilioGeneratorius()
  113.     {
  114.         //metodo realizacija
  115.         $this->kortele [] = $this->destomasdalykas;
  116.         $this->kortele [] = $this->pasalpa;
  117.         $this->kortele [] = $this->aukletojasklases;
  118.         $this->kortele [] = $this->mokiniaiklaseje;
  119.         $this->kortele [] = $this->pareiga;
  120.         $this->kortele [] = $this->alga;
  121.         $this->kortele [] = $this->vardas;
  122.         $this->kortele [] = $this->pavarde;
  123.         $this->kortele [] = $this->telefonas;
  124.         $this->kortele [] = $this->adresas;
  125.         $this->kortele [] = $this->asmenskodas;
  126.         return $this->kortele;
  127.     }
  128. }
  129. class mokinys extends person
  130. {
  131.     protected $klase;
  132.     protected $vidurkis;
  133.     protected $stipendija;
  134.     public function __construct($klase, $vidurkis, $stipendija, $vardas, $pavarde, $telefonas, $adresas, $asmenskodas)
  135.     {
  136.         parent::__construct($vardas, $pavarde, $telefonas, $adresas, $asmenskodas);
  137.         $this->klase = $klase;
  138.         $this->vidurkis = $vidurkis;
  139.         $this->stipendija = $stipendija;
  140.     }
  141.     public function profilioGeneratorius()
  142.     {
  143.         //metodo realizacija
  144.         $this->kortele [] = $this->klase;
  145.         $this->kortele [] = $this->vidurkis;
  146.         $this->kortele [] = $this->stipendija;
  147.         $this->kortele [] = $this->vardas;
  148.         $this->kortele [] = $this->pavarde;
  149.         $this->kortele [] = $this->telefonas;
  150.         $this->kortele [] = $this->adresas;
  151.         $this->kortele [] = $this->asmenskodas;
  152.         return $this->kortele;
  153.     }
  154. }
  155. class renderis
  156. {
  157.     public static function renderimas1($uzduotis)
  158.     {
  159.  
  160.         foreach ($uzduotis->profilioGeneratorius() as $user) {
  161.             echo $user . "</br>";
  162.         }
  163.  
  164.  
  165.     }
  166. }
  167. //----????????????????????????????-----------------------
  168. class dbConnect
  169. {
  170.     private $host = "localhost";
  171.     private $user = "root";
  172.     private $pass = "";
  173.     private $db_name = "mokykladb";
  174.     private $connect;
  175.     public function __construct(){
  176.         try{
  177.             $this->connect = new mysqli($host, $user, $pass, $db_name);
  178.             if(mysqli_connect_error()){
  179.                 die('connection error('.mysqli_connect_errno().')' . mysqli_connect_error());
  180.             }
  181.         }
  182.         catch(Exception $e){
  183.             echo $e->getMessage();
  184.         }
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement