Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8fc55000

Přidáno uživatelem Milan Vacek před téměř 4 roky(ů)

Bug #8639 Metoda insert

Zobrazit rozdíly:

application/model/DB.php
65 65
        }
66 66
    }
67 67

  
68
    function getUser($username) {
69
        $this->stmt = $this->pdo->prepare('SELECT id, username, password, role FROM users WHERE username = :username');
70
        $this->stmt->bindParam(':username', $username);
71
        $this->stmt->execute();
72
        return $this->stmt->fetchAll();
73
    }
74

  
75
    function createUser($userDetails) {
76
        $this->stmt = $this->pdo->prepare('INSERT INTO users (username, password, role) VALUES (:username, :password, :role)');
77
        $password = password_hash($userDetails['username'], PASSWORD_DEFAULT);
78
        $this->stmt->bindParam(':username', $userDetails['username']);
79
        $this->stmt->bindParam(':password',$password);
80
        $this->stmt->bindParam(':role',$userDetails['role']);
81
        $this->stmt->execute();
82
        return $this->stmt->fetchAll();
83
    }
84

  
85
    function updateUserRole($userId, $role) {
86
        $this->stmt = $this->pdo->prepare("UPDATE users SET role = :role WHERE id = :userId");
87
        $this->stmt->bindParam(':role', $role);
88
        $this->stmt->bindParam(':userId',$userId);
89
        $this->stmt->execute();
90
        return $this->stmt->fetchAll();
91
    }
92

  
93
    function deleteUser($userId) {
94
        $this->stmt = $this->pdo->prepare("DELETE from users WHERE id = :userId");
95
        $this->stmt->bindParam(':userId',$userId);
96
        $this->stmt->execute();
97
        return $this->stmt->fetchAll();
98
    }
99

  
100

  
101

  
68 102
function update(){
69 103
    $query = "SELECT id FROM dd_lemma
70 104
              WHERE lemma = :lemma;";
......
382 416
}
383 417

  
384 418
function insert(){
419
  print_r($_POST);
385 420
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
386 421
    $query = "SELECT id FROM dd_lemma
387 422
              WHERE lemma = :lemma;";
......
606 641
    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
607 642
        $query = "SELECT * FROM dd_manuscript WHERE ";
608 643
        $query .= " wordform_id = :wordform_id ;";
609
    }
610 644

  
611
    $this->stmt = $this->pdo->prepare($query);
612
    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
613
        $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
614
    }
615
    $this->stmt->execute();
616
    $result = $this->stmt->fetchAll();
645
        $this->stmt = $this->pdo->prepare($query);
646
            if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
647
                $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
648
            }
649
            $this->stmt->execute();
650
            $result = $this->stmt->fetchAll();
617 651

  
618
    $to_insert = [];
619
    $contained = [];
620
    $found = false;
621
    $integerIDs = [];
652
            $to_insert = [];
653
            $contained = [];
654
            $found = false;
655
            $integerIDs = [];
656

  
657
            foreach ($result as $res) {
658
                $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
659
                foreach ($integerIDs as $new_value){
660
                    if($new_value == $res['manuscript']){
661
                        $found = true;
662
                        array_push($contained, $new_value);
663
                    }
664
                }
665
                if($found == false){
666
                    array_push($to_delete, $res);
667
                }
668
                $found = false;
669
            }
670
            $to_insert = array_diff($integerIDs, $contained);
671
            foreach ($to_insert as $id_to_insert){
672
                $query = "INSERT INTO dd_manuscript VALUES ( ";
673
                $query .= " :wordform_id , ";
674
                $query .= " " . $id_to_insert . " ); ";
622 675

  
623
    foreach ($result as $res) {
624
        $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
625
        foreach ($integerIDs as $new_value){
626
            if($new_value == $res['manuscript']){
627
                $found = true;
628
                array_push($contained, $new_value);
676
                $this->stmt = $this->pdo->prepare($query);
677
                if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
678
                    $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
679
                }
680
                $this->stmt->execute();
629 681
            }
630
        }
631
        if($found == false){
632
            array_push($to_delete, $res);
633
        }
634
        $found = false;
635 682
    }
636
    $to_insert = array_diff($integerIDs, $contained);
637
    foreach ($to_insert as $id_to_insert){
638
        $query = "INSERT INTO dd_manuscript VALUES ( ";
639
        $query .= " :wordform_id , ";
640
        $query .= " " . $id_to_insert . " ); ";
641 683

  
642
        $this->stmt = $this->pdo->prepare($query);
643
        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
644
            $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
645
        }
646
        $this->stmt->execute();
647
    }
684

  
648 685
}
649 686

  
650 687
function remove(){
......
690 727

  
691 728
// (D) DATABASE SETTINGS - CHANGE TO YOUR OWN!
692 729
define('DB_HOST', 'localhost');
693
define('DB_NAME', 'dalimil2');
730
define('DB_NAME', 'dalim2');
694 731
define('DB_CHARSET', 'utf8');
695 732
define('DB_USER', 'postgres');
696
define('DB_PASSWORD', 'ahavole');
733
define('DB_PASSWORD', 'a');

Také k dispozici: Unified diff