Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

root / models / nouveau_model.php @ bbfc0e16

Historique | Voir | Annoter | Télécharger (3,32 ko)

1
<?php
2
/************************************************************************************
3
 *
4
 *  Projet AbulEdu Mur de Classe  - Licence: GNU/Affero GPL v3 ou +
5
 *
6
 *  (c) 2020 Frédéric Adamczak <fred@fadamczak.fr>
7
 *
8
 *   This file is part of AbulEdu Mur de Classe.
9
 *
10
 *   AbulEdu Mur de Classe is free software: you can redistribute it and/or modify
11
 *   it under the terms of the GNU Affero General Public License as published by
12
 *   the Free Software Foundation, either version 3 of the License, or
13
 *   (at your option) any later version.
14
 *
15
 *   AbulEdu Mur de Classe is distributed in the hope that it will be useful,
16
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *   GNU Affero General Public License for more details.
19
 *
20
 *   You should have received a copy of the GNU General Public License
21
 *   along with ClicAlbum. If not, see <https://www.gnu.org/licenses/>.
22
 *
23
 ************************************************************************************/
24

    
25
function insereMur($mur) {
26
  global $db;
27

    
28
  $sql = "INSERT INTO mur (nom,slug,descriptif,date_creation,date_acces,mdp_admin,mel_admin, mdp_acces, id_theme) ";
29
  $sql.= "VALUES (:nom,:slug,:desc,CURDATE(),CURDATE(),:admin,:mel,:acces,:theme)";
30

    
31
  //$query->bindParam(':titre', $brique->getTitre());
32

    
33
  try {
34
    $query = $db->prepare($sql);
35
    $query->bindParam(':nom', $mur->getNom());
36
    $query->bindParam(':slug', $mur->getSlug());
37
    $query->bindParam(':desc', $mur->getDescriptif());
38
    $query->bindParam(':admin', $mur->getMdpAdmin());
39
    $query->bindParam(':mel', $mur->getMelAdmin());
40
    $query->bindParam(':acces', $mur->getMdpAcces());
41
    $query->bindParam(':theme', $mur->getTheme());
42
    if (!$query->execute()) {
43
      throw new  MyException("Erreur dans l'insertion du mur");
44
    } else {
45
      return $db->lastInsertId();
46
    }
47
  } catch (MyException $e) {
48
    $e->errorMessage();
49
  }
50

    
51

    
52
  /*
53
  $sql = "INSERT INTO mur ";
54
  $sql.= "(nom, slug, descriptif, date_creation, date_acces, mdp_admin, ";
55
  $sql.= "mel_admin, mdp_acces, id_theme) VALUES";
56
  $sql.= "(";
57
  $sql.= "'".$m->getNom()."','".$m->getSlug()."','".$m->getDescriptif()."',";
58
  $sql.= "CURDATE(), CURDATE(),";
59
  $sql.= "'".$m->getMdpAdmin()."','".$m->getMelAdmin()."',";
60
  $sql.= "'".$m->getMdpAcces()."','".$m->getTheme()."'";
61
  $sql.= ")";
62

63
  try {
64
    if(!$query=$db->query($sql)) {
65
      throw new  MyException("Erreur dans INSERT");
66
    }
67
  } catch (MyException $e) {
68
    $e->errorMessage();
69
  }
70
  */
71
}
72
/**
73
 * Renvoie l'ensemble des thèmes de la BDD
74
 * @return [Array] [Tableau d'objets Theme]
75
 */
76
function getAllThemes() {
77
  global $db;
78

    
79
  $sql = "SELECT * FROM theme ORDER BY nom";
80

    
81
  try {
82
    if(!$query = $db->query($sql)) {
83
      throw new MyException("Erreur");
84
    } else {
85
      return $query->fetchAll(PDO::FETCH_CLASS, "Theme");
86
    }
87
  } catch (MyException $e) {
88
    $e->errorMessage();
89
  }
90
}
91

    
92
/**
93
 * Recherche un mur par son nom
94
 * @param  [String] $nom [nom du mur]
95
 * @return [Array]      [Tableau contenant le nom du mur ou vide]
96
 */
97
function nomMurExiste($nom) {
98
  global $db;
99

    
100
  $sql = "SELECT nom FROM mur WHERE nom='$nom'";
101

    
102
  try {
103
    if(!$query = $db->query($sql)) {
104
      throw new MyException("Erreur");
105
    } else {
106
      return $query->fetch(PDO::FETCH_COLUMN);
107
    }
108
  } catch (MyException $e) {
109
    $e->errorMessage();
110
  }
111
}
Redmine Appliance - Powered by TurnKey Linux