Repository navigation
Expand file tree
/
Copy pathmon_model.php
More file actions
173 lines (145 loc) · 4.52 KB
/
Copy pathmon_model.php
File metadata and controls
173 lines (145 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* (c) Stephane Agoume <agoumekoufanas@gmail.com>
* Date: 26/08/2015
*/
/**
* @author Stephane Agoume <agoumekoufanas@gmail.com> <stephaneagoume.com>
* @description : Bibliotheque de gestion de la base de données s'appuyant sur l'active
* record . Cette bibliotheque ou librairie s'integre facilement à CodeIgniter
*
* @version 1.0
* 03/10/2015
*/
class mon_model extends CI_Model
{
private $table;
public function __construct()
{
$this->table = "chambre";
}
public function set($table,$data)
{
$this->db->insert($table, $data);
$insert_id = $this->db->insert_id();
return $insert_id;
}
/**
* @description : when 'id' is the attribute condition is based on
* you can use this when your table content an attribute witch name is "id"
*
* otherwise just use the "updates" function , witch is more flexible
* @param type $table
* @param type $data
* @param type $id
*/
public function edit($table,$data,$id)
{
$this->db->where('id', $id);
$this->db->update($table, $data);
}
/**
*
* @param type $table : the concerned table
* @param type $data : set the new data , into an array
* @param type $data_where : specify the condition of edit
* exemple $data_where = array("nom"=>"Léana")
*/
public function updates($table,$data,$data_where)
{
$this->db->where($data_where);
$this->db->update($table, $data);
}
/**
* mise à jour 02/02/2016
* @var field_order permet de definir l'attribut sur lequel une condition d'ordre existe
* @var order permet de definir le type d'ordre
* exemple get($table,'date_','ASC');
*/
public function get($table,$field_order = NULL,$order = NULL,$field_where = NULL)
{
// test s'il y'a une sur l'ordre
if(($field_order != NULL)&&($order != NULL)){
$this->db->order_by($field_order, $order);
}
// test s'il y'a une condition sur Where
if($field_where != NULL){
$this->db->where($field_where);
}
$query = $this->db->get($table);
return $query->result();
}
public function getbyid($table,$id)
{
$limit = 1;
$offset = 0;
$query = $this->db->get_where($table, array('id' => $id), $limit, $offset);
return $query->row();
}
/*
* j'appelle ce concept scène de ménage , ou guere des roles
* parfois faire des chose dans une incompletude est benefique pour la personne qui doit continuer avec
*/
public function getbyidinc($table,$id)
{
$limit = 1;
$offset = 0;
$query = $this->db->get_where($table, array('id' => $id), $limit, $offset);
return $query;
}
public function getbyid_chambre($table,$id)
{
$limit = 1;
$offset = 0;
$query = $this->db->get_where($table, array('id_chambre' => $id), $limit, $offset);
return $query->row();
}
/**
* get the asking element in parameter array ( we can call data_where)
* @param type $table
* @param type $data_where
* @return type
*/
public function getbyelement($table,$data_where)
{
$query = $this->db->get_where($table, $data_where);
return $query->row();
}
public function getAllbyelement($table,$data_where)
{
$query = $this->db->get_where($table, $data_where);
return $query->result();
}
public function getAllelementwithrelation()
{
$this->db->select('*');
$this->db->from('photo');
$this->db->join('chambre', 'chambre.id = photo.id_chambre');
$query = $this->db->get();
return $query->result();
}
/**
* @param int $id
* @param array $photo
* @return array
*/
public function get_photo($id = null,$photo = null)
{
$id = 31;
$photo = $this->chambre->getAllbyelement('photo',array('id_chambre'=>$id));
return $photo;
}
/**
* code portion of delete
* NB : Never delete data from database
*/
/**
*
* @param type $table
* @param type $id
*/
public function delete($table,$data,$data_where)
{
$this->updates($table, $data, $data_where);
}
}