Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

root / models / adminsite_model.php @ ff47f4e6

Historique | Voir | Annoter | Télécharger (3,55 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
/**
26
 * Retourne le nombre total de mur présents dans la BDD
27
 * @return [Array] [Nombre de murs (tableau inidce)]
28
 */
29
function getNbMurs() {
30
  global $db;
31

    
32
  $sql="SELECT COUNT(id_mur) FROM mur";
33

    
34
  try {
35
    if (!$query=$db->query($sql)) {
36
      throw new  MyException("Erreur dans le SELECT");
37
    } else {
38
      $query->setFetchMode(PDO::FETCH_NUM);
39
      return ($query->fetch());
40
    }
41
  } catch (MyException $e) {
42
    $e->errorMessage();
43
  }
44
}
45

    
46
/**
47
 * Retourne le nombre de murs publics
48
 * @return [Arrazy] [tableau indicé ]
49
 */
50
function getNbMursPublics() {
51
  global $db;
52

    
53
  $sql="SELECT COUNT(id_mur) FROM mur WHERE mdp_acces =''";
54
  try {
55
    if (!$query=$db->query($sql)) {
56
      throw new  MyException("Erreur dans le SELECT");
57
    } else {
58
      $query->setFetchMode(PDO::FETCH_NUM);
59
      return ($query->fetch());
60
    }
61
  } catch (MyException $e) {
62
    $e->errorMessage();
63
  }
64
}
65

    
66
/**
67
 * Retourne les murs dont la dernière activité remonte à plus de 6 mois
68
 * @param  [type] $sixMois [description]
69
 * @return [type]          [description]
70
 */
71
function getNbMursInactifs($periode) {
72
  global $db;
73

    
74
  $sql = "SELECT COUNT(id_mur) FROM mur WHERE date_acces < '$periode'";
75
  try {
76
    if (!$query=$db->query($sql)) {
77
      throw new  MyException("Erreur dans le SELECT");
78
    } else {
79
      $query->setFetchMode(PDO::FETCH_NUM);
80
      return ($query->fetch());
81
    }
82
  } catch (MyException $e) {
83
    $e->errorMessage();
84
  }
85
}
86

    
87
/**
88
 * Retourne l'ensemble des murs
89
 * @return [Array] [Classe Mur]
90
 */
91
function getAllMurs() {
92
  global $db;
93
  $sql = "SELECT * FROM mur ORDER BY id_mur";
94
  try {
95
    if (!$query=$db->query($sql)) {
96
      throw new  MyException("Erreur dans le SELECT");
97
    } else {
98
      return ($query->fetchAll(PDO::FETCH_CLASS,"Mur"));
99
    }
100
  } catch (MyException $e) {
101
    $e->errorMessage();
102
  }
103
}
104

    
105
/**
106
 * Retourne l'ensemble des briques
107
 * @return [Array] [Assoc]
108
 */
109
function getAllBriques() {
110
  global $db;
111
  $sql = "SELECT * FROM brique ORDER BY id_mur";
112
  try {
113
    if (!$query=$db->query($sql)) {
114
      throw new  MyException("Erreur dans le SELECT");
115
    } else {
116
      return ($query->fetchAll(PDO::FETCH_ASSOC));
117
    }
118
  } catch (MyException $e) {
119
    $e->errorMessage();
120
  }
121
}
122

    
123
/**
124
 * Exécute une requete SQL passée en paramètres
125
 * @param  [String] $sql [Requete à exécuter]
126
 * @return [Array/Boolean]      [Faux si la requete n'a pu s'exécuter / Array de resultats]
127
 */
128
function execSql($sql) {
129
  global $db;
130
  if ($query = $db->query($sql)) {
131
    return $query->fetchAll(PDO::FETCH_ASSOC);
132
  } else {
133
    return(false);
134
  }
135
}
136
?>
Redmine Appliance - Powered by TurnKey Linux