-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compte.php
155 lines (128 loc) · 4.23 KB
/
Compte.php
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
<?php
class Model_Compte
{
protected $_table;
public function getTable()
{
if (null === $this->_table) {
require_once APPLICATION_PATH_COMMONS . '/models/DbTable/Compte.php';
$this->_table = new Model_DbTable_Compte;
}
return $this->_table;
}
public function save($id,array $data)
{
$table = $this->getTable();
$fields = $table->info(Zend_Db_Table_Abstract::COLS);
foreach ($data as $field => $value) {
if (!in_array($field, $fields)) {
unset($data[$field]);
}
}
if($id > 0) {
$where = $table->getAdapter()->quoteInto('idCompte = ?', $id);
return $table->update($data,$where);
}
else
return $table->insert($data);
}
public function fetchEntries()
{
return $this->getTable()->fetchAll('1')->toArray();
}
public function fetchEntry($id)
{
$table = $this->getTable();
$select = $table->select()->where('idCompte = ?', $id);
return $table->fetchRow($select)->toArray();
}
public function fetchEntryField($id,$array)
{
$table = $this->getTable();
$select = $table->select()->from('compte', $array)->where('idCompte = ?', $id);
return $table->fetchRow($select)->toArray();
}
public function fetchEntryLast()
{
$table = $this->getTable();
$select = $table->select()->from('compte', array('idCompte', 'login'))->where('actif = 1')->order('dateins DESC')->limit(1);
return $table->fetchRow($select)->toArray();
}
public function fetchEntryForum($id)
{
$table = $this->getTable();
$select = $table->select()->from(array('c'=>'compte'), array('idCompte','login', 'img', 'citationpreferee', 'dateins'))
->join(array('g' => 'grade'),'g.idGrade=c.idGrade', array('nom as nom_g'))
->join(array('fc' => 'fonctioncompte'),'fc.idCompte=c.idCompte', array(''))
->join(array('f' => 'fonction'),'f.idFonction=fc.idFonction', array('nom as nom_f'))
->where('c.idCompte = ?', $id)
->setIntegrityCheck(false);
return $table->fetchRow($select)->toArray();
}
public function fetchEntryByLogin($login)
{
$table = $this->getTable();
$select = $table->select()->where('login = ?', $login);
$temp=$table->fetchRow($select);
if(isset($temp))
return $temp->toArray();
else
return -1;
}
public function fetchEntryByMail($mail)
{
$table = $this->getTable();
$select = $table->select()->where('email = ?', $mail);
$temp=$table->fetchRow($select);
if(isset($temp))
return $temp->toArray();
else
return -1;
}
public function fetchEntryByKeyAndMail($key)
{
$table = $this->getTable();
$select = $table->select()->where('keyvalidation = ?', $key);
return $table->fetchRow($select)->toArray();
}
public function fetchEntriesLogField($time, $array)
{
$table = $this->getTable();
$select = $table->select()
->from('compte', $array)
->join('fonctioncompte', 'fonctioncompte.idCompte=compte.idCompte', array('idFonction'))
->where('last_time_connexion > ?', $time)
->setIntegrityCheck(false);
return $table->fetchAll($select)->toArray();
}
public function countEntries()
{
$table = $this->getTable();
$select = $table->select()->from('compte','COUNT(idCompte) AS num');
$row = $table->fetchRow($select);
return $row->num;
}
public function countEntriesActif()
{
$table = $this->getTable();
$select = $table->select()->from('compte','COUNT(idCompte) AS num')->where('actif = 1');
$row = $table->fetchRow($select);
return $row->num;
}
public function delete($id)
{
$table = $this->getTable();
$where = $table->getAdapter()->quoteInto('idCompte = ?', $id);
return $table->delete($where);
}
public function existLog(array $data)
{
$table = $this->getTable();
$select = $table->select()->where('login = ?', $data['login'])->where('password = ?', $data['password'])->where('actif = 1');
if($table->fetchRow($select)) {
return $table->fetchRow($select)->toArray();
} else {
return false;
}
}
}