Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephane Crozat
apisub
Commits
3f7100e4
Commit
3f7100e4
authored
Nov 15, 2018
by
Stephane Crozat
Browse files
Suppr typing for functions and parameters, using bindValue instead of arrys in execute()
parent
b33c756f
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/db.php
View file @
3f7100e4
...
...
@@ -13,54 +13,46 @@ class DB {
}
}
public
function
subList
(
string
$utclogin
)
:
array
{
public
function
subList
(
$utclogin
)
{
$sql
=
'SELECT *
FROM vsubscription
WHERE utclogin=:utclogin'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
([
'utclogin'
=>
$utclogin
,
]);
$st
->
bindValue
(
':utclogin'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$res
;
}
public
function
apiList
(
string
$semester
,
int
$year
)
:
array
{
public
function
apiList
(
$semester
,
$year
)
{
$sql
=
'SELECT *
FROM vApi
WHERE semester=:semester AND year=:year'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
([
'semester'
=>
$semester
,
'year'
=>
$year
,
]);
$st
->
bindValue
(
':semester'
,
$semester
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':year'
,
$year
,
PDO
::
PARAM_INT
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
return
$res
;
}
public
function
subToApi
(
string
$utclogin
,
int
$api
)
:
bool
{
public
function
subToApi
(
$utclogin
,
$api
)
{
$today
=
date
(
'Ymd'
);
$sql
=
'INSERT INTO subscribe(utclogin, api, subdate) VALUES (:utclogin, :api, :today)'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$res
=
$st
->
execute
([
'utclogin'
=>
$utclogin
,
'api'
=>
$api
,
'today'
=>
$today
,
]);
$st
->
bindValue
(
':utclogin'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_INT
);
$st
->
bindValue
(
':today'
,
$today
,
PDO
::
PARAM_STR
);
$res
=
$st
->
execute
();
return
$res
;
}
public
function
unsubToApi
(
string
$utclogin
,
int
$api
)
:
bool
{
public
function
unsubToApi
(
$utclogin
,
$api
)
{
$sql
=
'DELETE FROM subscribe WHERE utclogin=:utclogin AND api=:api'
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$res
=
$st
->
execute
([
'utclogin'
=>
$utclogin
,
'api'
=>
$api
,
]);
$st
->
bindValue
(
':utclogin'
,
$utclogin
,
PDO
::
PARAM_STR
);
$st
->
bindValue
(
':api'
,
$api
,
PDO
::
PARAM_INT
);
$res
=
$st
->
execute
();
return
$res
;
}
}
lib/views.php
View file @
3f7100e4
<?php
class
Views
{
public
static
function
printHtmlBegin
()
:
void
{
public
static
function
printHtmlBegin
()
{
echo
'<html>'
;
echo
'<head>'
;
echo
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'
;
...
...
@@ -13,11 +13,11 @@ class Views {
echo
'<h1>Inscriptions Api</h1>'
;
}
public
static
function
printUser
(
string
$utclogin
,
string
$surname
,
string
$firstname
)
:
void
{
public
static
function
printUser
(
$utclogin
,
$surname
,
$firstname
)
{
echo
'<p><i>'
.
$firstname
.
' '
.
$surname
.
'</i> (<b>'
.
$utclogin
.
'</b>)</p>'
;
}
public
static
function
printSubList
(
array
$list
,
string
$utclogin
)
:
void
{
public
static
function
printSubList
(
$list
,
$utclogin
)
{
if
(
$list
)
{
echo
'<h2>Vos inscriptions</h2>'
;
foreach
(
$list
as
$row
)
{
...
...
@@ -31,10 +31,10 @@ class Views {
echo
'<h2>Aucune inscription</h2>'
;
}
}
public
static
function
printApiList
(
array
$list
,
string
$utclogin
)
:
void
{
public
static
function
printApiList
(
$list
,
$utclogin
)
{
if
(
$list
)
{
echo
'<h2>Liste des Api
'
.
$semester
.
$year
.
'
</h2>'
;
echo
'<h2>Liste des Api</h2>'
;
foreach
(
$list
as
$row
)
{
echo
'<p>'
;
echo
'<a href="index.php?action=sub&api='
.
$row
[
'code'
]
.
'&utclogin='
.
$utclogin
.
'">[inscription]</a> '
;
...
...
@@ -46,4 +46,4 @@ class Views {
echo
'<h2>Aucune Api</h2>'
;
}
}
}
\ No newline at end of file
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment