Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
don
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
25
Issues
25
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
Operations
Operations
Incidents
Environments
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
LQDN Adminsys
don
Commits
811866d6
Commit
811866d6
authored
Nov 29, 2018
by
Okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a recompute total functions in the admin page
parent
094f8ebf
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
74 additions
and
9 deletions
+74
-9
app/controller/admin.php
app/controller/admin.php
+31
-2
app/routes.ini
app/routes.ini
+1
-0
app/view/backend/banque.html
app/view/backend/banque.html
+2
-2
app/view/backend/don.html
app/view/backend/don.html
+2
-3
app/view/backend/dons.html
app/view/backend/dons.html
+2
-0
app/view/toolbar.html
app/view/toolbar.html
+2
-2
src/LQDN/Command/AdminUpdateTotalUsersCommand.php
src/LQDN/Command/AdminUpdateTotalUsersCommand.php
+7
-0
src/LQDN/Handler/UserHandler.php
src/LQDN/Handler/UserHandler.php
+20
-0
tests/functional/Handler/UserHandlerTest.php
tests/functional/Handler/UserHandlerTest.php
+7
-0
No files found.
app/controller/admin.php
View file @
811866d6
...
...
@@ -10,6 +10,7 @@ use LQDN\Command\DonationResetPdfCommand;
use
LQDN\Command\DonationCreateCommand
;
use
LQDN\Command\UserUpdateByAdminCommand
;
use
LQDN\Command\UserCreateCommand
;
use
LQDN\Command\AdminUpdateTotalUsersCommand
;
class
Admin
extends
Controller
{
...
...
@@ -46,12 +47,21 @@ class Admin extends Controller
99
=>
"résilié"
,
100
=>
"non applicable"
,
));
// Test si il y a des messages
if
(
!
$f3
->
exists
(
'SESSION.message'
))
{
$f3
->
push
(
'SESSION.message'
,
''
);
}
if
(
!
$f3
->
exists
(
'SESSION.error'
))
{
$f3
->
push
(
'SESSION.error'
,
''
);
}
if
(
!
$f3
->
get
(
'SESSION.admin'
))
{
$mapper
=
new
\
DB\SQL\Mapper
(
$f3
->
get
(
'DB'
),
'admins'
);
$auth
=
new
\
Auth
(
$mapper
,
array
(
'id'
=>
'user_id'
,
'pw'
=>
'password'
));
$success
=
$auth
->
basic
(
'\Controller\Admin::hash_password'
);
if
(
!
$success
)
{
$f3
->
push
(
'SESSION.error'
,
'Accès non autorisé'
);
$f3
->
error
(
401
);
}
else
{
$f3
->
set
(
'SESSION.admin'
,
true
);
...
...
@@ -61,6 +71,23 @@ class Admin extends Controller
$f3
->
set
(
'PIPLOME_URL'
,
PIPLOME_URL
);
}
public
function
afterRoute
(
$f3
,
$args
)
{
// Rendu de la page
if
(
$this
->
template
!=
''
)
{
echo
\
Template
::
instance
()
->
render
(
$this
->
template
);
}
// Une fois que tout est affiché, on peut supprimer les notifications
$f3
->
clear
(
'SESSION.message'
);
$f3
->
clear
(
'SESSION.error'
);
}
public
static
function
recompute
(
$f3
,
$args
)
{
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
AdminUpdateTotalUsersCommand
());
$f3
->
set
(
'block_content'
,
'backend/dons.html'
);
}
public
static
function
hash_password
(
$password
)
{
return
hash
(
'sha256'
,
$password
);
...
...
@@ -140,6 +167,7 @@ class Admin extends Controller
$cumul
=
$user_amount
[
'total'
]
+
$result
[
'somme'
];
}
if
(
$error
!=
''
)
{
$f3
->
push
(
'SESSION.error'
,
$error
);
}
else
{
$db
->
query
(
"UPDATE dons
...
...
@@ -190,6 +218,7 @@ class Admin extends Controller
}
}
if
(
$error
!=
''
)
{
$f3
->
push
(
'SESSION.error'
,
$error
);
}
else
{
$db
->
query
(
"UPDATE dons
...
...
@@ -990,8 +1019,8 @@ class Admin extends Controller
}
}
$f3
->
set
(
'result'
,
$result
);
$f3
->
set
(
'
error'
,
$error
);
$f3
->
set
(
'
message'
,
$message
);
$f3
->
push
(
'SESSION.
error'
,
$error
);
$f3
->
push
(
'SESSION.
message'
,
$message
);
$f3
->
set
(
'block_content'
,
'backend/banque.html'
);
}
...
...
app/routes.ini
View file @
811866d6
...
...
@@ -29,6 +29,7 @@ GET @edit_support:/admin/support/edit/@id=Controller\Admin->support
POST
@modify_support:/admin/support/
edit
=
Controller
\A
dmin->support
GET
@invalidate_support:/admin/support/invalidate/@
id
=
Controller
\A
dmin->invalidate
GET
@validate_support:/admin/support/validate/@
id
=
Controller
\A
dmin->validate
GET
@recompute:/admin/
recompute
=
Controlle
\A
dmin->recompute
GET|POST
@admin_accounts:/admin/
accounts
=
Controller
\A
dmin->accounts
...
...
app/view/backend/banque.html
View file @
811866d6
...
...
@@ -2,8 +2,8 @@
<h2>
Gestion banque
</h2>
<check
if=
"{{@result}}"
><p
class=
"result"
>
{{@result | raw}}
</p></check>
<check
if=
"{{@
error}}"
><p
class=
"error"
>
{{@error | raw}}
</p
></check>
<check
if=
"{{@
message}}"
><p
class=
"message"
>
{{@message | raw}}
</p></check>
<check
if=
"{{@
SESSION.error}}"
><message
messages=
"{{@SESSION.error}}"
class=
"alert alert-danger"
/
></check>
<check
if=
"{{@
SESSION.message}}"
><message
messages=
"{{@SESSION.message}}"
class=
"alert alert-danger"
/>
</p></check>
<section
id=
"cbs"
>
<h3
>
Mise à jour des dates d'expiration des CB
</h3>
...
...
app/view/backend/don.html
View file @
811866d6
...
...
@@ -52,9 +52,8 @@
<input
type=
"submit"
value=
"Voir ce don"
/>
</form>
<br
/>
<check
if=
"{{ @msg }}"
>
<span
class=
"error"
>
{{ @msg }}
</span>
</check>
<check
if=
"{{ @SESSION.error }}"
>
<message
messages=
"{{ @SESSION.error }}"
class=
"alert alert-danger"
/>
</check>
<check
if=
"{{ @SESSION.message }}"
>
<message
messages=
"{{ @SESSION.message }}"
class=
"alert alert-default"
/>
</check>
</section>
<script
type=
"text/javascript"
>
...
...
app/view/backend/dons.html
View file @
811866d6
...
...
@@ -45,6 +45,8 @@
<input
type=
"submit"
value=
"Filtrer"
/>
</form>
<a
href=
"{{ 'recompute' | alias }}"
>
Recalculer les totaux et cumuls de toute la base de donnée
</a>
<br
/>
<check
if=
"{{ @row_count }}"
><b>
{{ @row_count }} résultats
</b>
<br
/>
<table
cellspacing=
"0"
cellpadding=
"0"
>
...
...
app/view/toolbar.html
View file @
811866d6
...
...
@@ -154,7 +154,7 @@
</nav>
</div>
<section
id=
"messages"
>
<message
messages=
"
@SESSION.message
"
class=
"alert alert-default"
>
<message
messages=
"
@SESSION.error
"
class=
"alert alert-danger"
>
<message
messages=
"
{{ @SESSION.message }}
"
class=
"alert alert-default"
>
<message
messages=
"
{{ @SESSION.error }}
"
class=
"alert alert-danger"
>
</section>
src/LQDN/Command/AdminUpdateTotalUsersCommand.php
0 → 100644
View file @
811866d6
<?php
namespace
LQDN\Command
;
class
AdminUpdateTotalUsersCommand
{
// There is no parameters for this command.
}
src/LQDN/Handler/UserHandler.php
View file @
811866d6
...
...
@@ -7,6 +7,7 @@ use LQDN\Command\UserUpdateByAdminCommand;
use
LQDN\Command\UserUpdateTotalCommand
;
use
LQDN\Command\UserUpdateCumulCommand
;
use
LQDN\Command\UserCreateCommand
;
use
LQDN\Command\AdminUpdateTotalUsersCommand
;
class
UserHandler
{
...
...
@@ -79,4 +80,23 @@ class UserHandler
]
);
}
/**
* Get through all the users and databases to recompute all total from users.
*
* @param AdminUpdateTotalUsersCommand $command
*/
public
function
handleAdminUpdateTotalUsersCommand
(
AdminUpdateTotalUsersCommand
$command
)
{
// Let's get all users first
$user_ids
=
$this
->
connection
->
executeQuery
(
'SELECT id FROM users'
)
->
fetchAll
(
\
PDO
::
FETCH_ASSOC
);
foreach
(
$user_ids
as
$user_id
)
{
$user_id
=
(
int
)
$user_id
;
$total
=
$this
->
connection
->
executeQuery
(
'SELECT SUM(somme) AS total FROM dons WHERE user_id = :user_id AND STATUS IN (1, 102)'
,
[
'user_id'
=>
$user_id
])
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
$this
->
connection
->
executeUpdate
(
'UPDATE users SET total = :total WHERE id = :user_id'
,
[
'total'
=>
$total
[
'total'
],
'user_id'
=>
$user_id
]);
}
}
}
tests/functional/Handler/UserHandlerTest.php
View file @
811866d6
...
...
@@ -6,10 +6,17 @@ use LQDN\Command\UserUpdateByAdminCommand;
use
LQDN\Command\UserUpdateTotalCommand
;
use
LQDN\Command\UserUpdateCumulCommand
;
use
LQDN\Command\UserCreateCommand
;
use
LQDN\Command\AdminUpdateTotalUsersCommand
;
use
LQDN\Tests\Functional\FunctionalTest
;
class
UserHandlerTest
extends
FunctionalTest
{
public
function
testAdminUpdateTotalUsersCommand
()
{
$this
->
container
[
'command_handler'
]
->
handle
(
new
AdminUpdateTotalUsersCommand
());
$this
->
assertSame
(
1000
,
(
int
)
$this
->
getUser
(
1
)[
'total'
]);
}
public
function
testUserUpdateFromAdmin
()
{
$user
=
$this
->
getUser
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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