Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
opacce
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
afi
opacce
Commits
9c1717fb
Commit
9c1717fb
authored
Sep 01, 2016
by
Patrick Barroca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev #46014 : user search in recipients list, work in progress
parent
8b3469ed
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
292 additions
and
118 deletions
+292
-118
NewsletterController.php
...cation/modules/admin/controllers/NewsletterController.php
+2
-0
UsersController.php
application/modules/admin/controllers/UsersController.php
+1
-43
edit-subscribers.phtml
...les/admin/views/scripts/newsletter/edit-subscribers.phtml
+38
-0
index.phtml
...cation/modules/admin/views/scripts/newsletter/index.phtml
+17
-17
index.phtml
application/modules/admin/views/scripts/users/index.phtml
+38
-2
Newsletter.php
library/Class/Newsletter.php
+10
-4
Blacklist.php
library/Class/Newsletter/Blacklist.php
+1
-1
UserSearch.php
library/ZendAfi/Controller/Action/Helper/UserSearch.php
+94
-0
SearchUsers.php
library/ZendAfi/Form/Admin/SearchUsers.php
+0
-3
SearchUsers.php
library/ZendAfi/View/Helper/Admin/SearchUsers.php
+7
-38
NewsletterControllerTest.php
...on/modules/admin/controllers/NewsletterControllerTest.php
+84
-10
No files found.
application/modules/admin/controllers/NewsletterController.php
View file @
9c1717fb
...
...
@@ -67,6 +67,8 @@ class Admin_NewsletterController extends ZendAfi_Controller_Action {
$this
->
view
->
newsletter
=
$model
;
$this
->
view
->
groups
=
$model
->
getSortedRecipientsByDedicatedAndLabel
();
$this
->
_helper
->
userSearch
([
'id'
=>
$model
->
getId
()]);
}
...
...
application/modules/admin/controllers/UsersController.php
View file @
9c1717fb
...
...
@@ -40,49 +40,7 @@ class Admin_UsersController extends ZendAfi_Controller_Action {
public
function
indexAction
()
{
$this
->
view
->
titre
=
$this
->
_
(
'Gestion des utilisateurs'
);
$this
->
view
->
page
=
$this
->
_getParam
(
'page'
,
1
);
$id_site
=
$this
->
_getParam
(
'by_id_site'
,
'all'
);
$role_level
=
Class_Users
::
getIdentity
()
->
isAdmin
()
?
$this
->
_getParam
(
'by_role_level'
,
'all'
)
:
$this
->
_getParam
(
'by_role_level'
,
ZendAfi_Acl_AdminControllerRoles
::
ABONNE_SIGB
);
$search_value
=
str_replace
([
"
\000
"
,
"
\n
"
,
"
\r
"
,
"
\"
"
,
"\'"
,
"'"
,
"
\032
"
],
''
,
$this
->
_getParam
(
'search_for'
,
null
));
$valide_subscription
=
$this
->
_getParam
(
'by_valide_subscription'
,
null
);
$params
=
[
'id_site'
=>
$id_site
,
'role_level'
=>
$role_level
];
$where
=
array_fill_keys
([
'login'
,
'nom'
,
'prenom'
,
'pseudo'
,
'mail'
,
'idabon'
],
$search_value
);
$this
->
view
->
params
=
[
'by_id_site'
=>
$id_site
,
'by_role_level'
=>
$role_level
,
'search_for'
=>
$search_value
,
'by_valide_subscription'
=>
$valide_subscription
,
'page'
=>
$this
->
view
->
page
];
$this
->
view
->
users
=
Class_Users
::
findSearched
(
$params
,
$where
,
$valide_subscription
,
[
$this
->
view
->
page
,
20
]);
$this
->
view
->
total
=
Class_Users
::
countSearched
(
$params
,
$where
,
$valide_subscription
);
$this
->
view
->
form
=
ZendAfi_Form_Admin_SearchUsers
::
newWith
(
$this
->
view
->
params
);
$this
->
_helper
->
userSearch
();
}
...
...
application/modules/admin/views/scripts/newsletter/edit-subscribers.phtml
View file @
9c1717fb
...
...
@@ -40,3 +40,41 @@ echo $this->tagModelTable($this->groups,
[
'libelle'
],
[
$actions
],
'newsletter_user_groups'
);
$build_url
=
function
(
$action
)
{
return
$this
->
url
(
array_merge
([
'module'
=>
'admin'
,
'controller'
=>
'newsletter'
,
'action'
=>
'edit-subscribers'
,
'id'
=>
$this
->
newsletter
->
getId
(),
'page'
=>
$this
->
page
?
$this
->
page
:
null
],
$this
->
params
),
null
,
true
)
.
'/'
.
$action
.
'/%s'
;
};
$actions
=
function
(
$model
)
use
(
$build_url
)
{
$is_recipient
=
$this
->
newsletter
->
hasRecipient
(
$model
,
false
);
$is_blacklisted
=
$this
->
newsletter
->
isBlackListed
(
$model
);
if
(
!
$is_recipient
)
return
$this
->
modelActions
(
$model
,
[[
'url'
=>
$build_url
(
'subscribe'
),
'icon'
=>
'add'
,
'label'
=>
$this
->
_
(
'Inscrire'
)]
]);
if
(
$is_blacklisted
)
return
$this
->
modelActions
(
$model
,
[[
'url'
=>
$build_url
(
'resubscribe'
),
'icon'
=>
'back'
,
'label'
=>
$this
->
_
(
'Réinscrire'
)]
]);;
return
$this
->
modelActions
(
$model
,
[[
'url'
=>
$build_url
(
'unsubscribe'
),
'icon'
=>
'cancel'
,
'label'
=>
$this
->
_
(
'Désinscrire'
)]
]);
};
echo
'<br><br>'
.
$this
->
Admin_SearchUsers
(
$this
->
users
,
$this
->
total
,
$this
->
form
,
$this
->
page
,
$this
->
params
,
$actions
);
application/modules/admin/views/scripts/newsletter/index.phtml
View file @
9c1717fb
<?php
echo
$this
->
bouton
(
'id=_create_newsletter'
,
'picto=add'
,
'texte='
.
$this
->
traduire
(
"Créer une lettre d'information"
),
'url='
.
$this
->
url
(
array
(
'action'
=>
'add'
,
'id'
=>
null
)
));
'texte='
.
$this
->
_
(
"Créer une lettre d'information"
),
'url='
.
$this
->
url
(
[
'action'
=>
'add'
,
'id'
=>
null
]
));
?>
<table
id=
'newsletters'
class=
'models'
>
<thead>
<tr>
<th>
Titre
</th>
<th>
Dernière distribution
</th>
<th
colspan=
'7'
class=
"actions"
>
Action
</th>
</tr>
</thead>
<tbody>
<?php
echo
$this
->
partialCycle
(
'newsletter/_newsletter_row.phtml'
,
'newsletter'
,
$this
->
newsletters
,
[
'first'
,
'second'
]);
?>
</tbody>
<thead>
<tr>
<th>
<?php
echo
$this
->
_
(
'Titre'
);
?>
</th>
<th>
<?php
echo
$this
->
_
(
'Dernière distribution'
);
?>
</th>
<th
colspan=
'7'
class=
"actions"
>
<?php
echo
$this
->
_
(
'Action'
);
?>
</th>
</tr>
</thead>
<tbody>
<?php
echo
$this
->
partialCycle
(
'newsletter/_newsletter_row.phtml'
,
'newsletter'
,
$this
->
newsletters
,
[
'first'
,
'second'
]);
?>
</tbody>
</table>
...
...
application/modules/admin/views/scripts/users/index.phtml
View file @
9c1717fb
<?php
echo
$this
->
Admin_SearchUsers
(
$this
->
users
,
$this
->
total
,
$this
->
form
,
$this
->
page
,
$this
->
params
);
?>
echo
Class_Users
::
getIdentity
()
->
isAdmin
()
?
(
$this
->
tag
(
'center'
,
$this
->
tag
(
'div'
,
$this
->
bouton
(
'id=19'
,
'picto=add'
,
'texte='
.
$this
->
_
(
'Ajouter un utilisateur'
),
'url='
.
$this
->
url
([
'action'
=>
'add'
]),
'largeur=210px'
))))
:
''
;
$placeholder
=
'PLACEHOLDER_ID_USER'
;
$tag_edit
=
$this
->
tagAnchor
(
$this
->
url
(
array_merge
([
'module'
=>
'admin'
,
'controller'
=>
'users'
,
'action'
=>
'edit'
,
'id'
=>
$placeholder
],
$this
->
params
)),
$this
->
boutonIco
(
'type=edit'
));
$tag_delete
=
$this
->
tagAnchor
(
$this
->
url
(
array_merge
([
'module'
=>
'admin'
,
'controller'
=>
'users'
,
'action'
=>
'delete'
,
'id'
=>
$placeholder
],
$this
->
params
)),
$this
->
boutonIco
(
'type=del'
));
$actions
=
function
(
$user
)
use
(
$tag_edit
,
$tag_delete
,
$placeholder
)
{
if
(
!
Class_Users
::
getIdentity
()
->
isAdmin
())
return
;
return
str_replace
(
$placeholder
,
$user
->
getId
(),
$tag_edit
)
.
str_replace
(
$placeholder
,
$user
->
getId
(),
$tag_delete
);
};
echo
$this
->
Admin_SearchUsers
(
$this
->
users
,
$this
->
total
,
$this
->
form
,
$this
->
page
,
$this
->
params
,
$actions
);
library/Class/Newsletter.php
View file @
9c1717fb
...
...
@@ -146,7 +146,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
public
function
hasRecipient
(
$user
,
$with_blacklist
=
true
)
{
if
(
$with_blacklist
&&
Class_Newsletter_Blacklist
::
isBlackListed
(
$user
->
getMail
(),
$this
->
getId
()
))
if
(
$with_blacklist
&&
$this
->
isBlackListed
(
$user
))
return
false
;
foreach
(
$this
->
getRecipientsGroups
()
as
$group
)
...
...
@@ -157,6 +157,11 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
public
function
isBlackListed
(
$user
)
{
return
Class_Newsletter_Blacklist
::
isBlackListed
(
$user
->
getMail
(),
$this
->
getId
());
}
public
function
getRecipientsGroups
()
{
$groups
=
[
$this
->
getDedicatedGroup
()];
foreach
(
$this
->
getUserGroups
()
as
$group
)
...
...
@@ -336,10 +341,11 @@ class Class_Newsletter extends Storm_Model_Abstract {
return
$this
;
}
public
function
unsubscribeByMail
(
$mail
)
{
if
(
!
$mail
)
return
false
;
return
Class_Newsletter_Blacklist
::
unsubscribeByMail
(
$mail
,
$this
->
getId
())
;
return
$mail
?
Class_Newsletter_Blacklist
::
unsubscribeByMail
(
$mail
,
$this
->
getId
())
:
false
;
}
...
...
library/Class/Newsletter/Blacklist.php
View file @
9c1717fb
...
...
@@ -34,12 +34,12 @@ class Newsletter_BlacklistLoader extends Storm_Model_Loader {
return
$blacklist
->
save
();
}
public
function
isBlackListed
(
$mail
,
$newsletter_id
)
{
if
(
!
$mail
)
return
false
;
return
Class_Newsletter_Blacklist
::
findFirstBy
([
'newsletter_id'
=>
$newsletter_id
,
'mail'
=>
$mail
]);
}
}
...
...
library/ZendAfi/Controller/Action/Helper/UserSearch.php
0 → 100644
View file @
9c1717fb
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class
ZendAfi_Controller_Action_Helper_UserSearch
extends
Zend_Controller_Action_Helper_Abstract
{
protected
$view
;
public
function
userSearch
(
$action_params
=
[])
{
$this
->
view
=
$this
->
getActionController
()
->
view
;
$this
->
view
->
page
=
$this
->
_getParam
(
'page'
,
1
);
$id_site
=
$this
->
_getParam
(
'by_id_site'
,
'all'
);
$role_level
=
Class_Users
::
getIdentity
()
->
isAdmin
()
?
$this
->
_getParam
(
'by_role_level'
,
'all'
)
:
$this
->
_getParam
(
'by_role_level'
,
ZendAfi_Acl_AdminControllerRoles
::
ABONNE_SIGB
);
$search_value
=
str_replace
([
"
\000
"
,
"
\n
"
,
"
\r
"
,
"
\"
"
,
"\'"
,
"'"
,
"
\032
"
],
''
,
$this
->
_getParam
(
'search_for'
,
null
));
$valide_subscription
=
$this
->
_getParam
(
'by_valide_subscription'
,
null
);
$params
=
[
'id_site'
=>
$id_site
,
'role_level'
=>
$role_level
];
$where
=
array_fill_keys
([
'login'
,
'nom'
,
'prenom'
,
'pseudo'
,
'mail'
,
'idabon'
],
$search_value
);
$this
->
view
->
params
=
[
'by_id_site'
=>
$id_site
,
'by_role_level'
=>
$role_level
,
'search_for'
=>
$search_value
,
'by_valide_subscription'
=>
$valide_subscription
,
'page'
=>
$this
->
view
->
page
];
$this
->
view
->
users
=
Class_Users
::
findSearched
(
$params
,
$where
,
$valide_subscription
,
[
$this
->
view
->
page
,
20
]);
$this
->
view
->
total
=
Class_Users
::
countSearched
(
$params
,
$where
,
$valide_subscription
);
$this
->
view
->
form
=
ZendAfi_Form_Admin_SearchUsers
::
newWith
(
$this
->
view
->
params
);
$url_params
=
array_merge
([
'module'
=>
$this
->
getRequest
()
->
getModuleName
(),
'controller'
=>
$this
->
getRequest
()
->
getControllerName
(),
'action'
=>
$this
->
getRequest
()
->
getActionName
()],
$action_params
);
$this
->
view
->
form
->
setAction
(
Class_Url
::
absolute
(
$url_params
,
null
,
true
));
}
protected
function
_getParam
(
$name
,
$default
=
null
)
{
return
$this
->
getRequest
()
->
getParam
(
$name
,
$default
);
}
public
function
direct
(
$action_params
=
[])
{
return
$this
->
userSearch
(
$action_params
);
}
}
\ No newline at end of file
library/ZendAfi/Form/Admin/SearchUsers.php
View file @
9c1717fb
...
...
@@ -36,9 +36,6 @@ class ZendAfi_Form_Admin_SearchUsers extends ZendAfi_Form {
public
function
setAttributes
()
{
return
$this
->
setAction
(
Class_Url
::
absolute
([
'module'
=>
'admin'
,
'controller'
=>
'users'
,
'action'
=>
'index'
],
null
,
true
))
->
setAttrib
(
'style'
,
'position: relative'
)
->
setMethod
(
'get'
);
}
...
...
library/ZendAfi/View/Helper/Admin/SearchUsers.php
View file @
9c1717fb
...
...
@@ -22,20 +22,22 @@
class
ZendAfi_View_Helper_Admin_SearchUsers
extends
ZendAfi_View_Helper_BaseHelper
{
protected
$placeholder
=
'PLACEHOLDER_ID_USER'
,
protected
$users
,
$total
,
$params
;
$params
,
$actions
;
public
function
admin_searchUsers
(
$users
,
$total
,
$form
,
$page
,
$params
)
{
public
function
admin_searchUsers
(
$users
,
$total
,
$form
,
$page
,
$params
,
$actions
)
{
Class_ScriptLoader
::
getInstance
()
->
addJQueryReady
(
'$("#by_role_level option[value=2]:not(:selected)").closest("form").find("tr:nth-child(3)").hide();$("#by_role_level").change(function() {$("#by_role_level option[value=2]:not(:selected)").closest("form").find("tr:nth-child(3)").hide();$("#by_role_level option[value=2]:selected").closest("form").find("tr:nth-child(3)").show();});'
);
$this
->
users
=
$users
;
$this
->
total
=
$total
;
$this
->
page
=
$page
;
$this
->
params
=
$params
;
$this
->
actions
=
$actions
;
return
$this
->
_addButton
()
.
return
$this
->
view
->
renderForm
(
$form
)
.
$this
->
view
->
tag
(
'p'
,
$this
->
view
->
_plural
(
$this
->
total
,
'Auncun utilisateur trouvé'
,
...
...
@@ -46,19 +48,6 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp
}
protected
function
_addButton
()
{
return
Class_Users
::
getIdentity
()
->
isAdmin
()
?
(
$this
->
view
->
tag
(
'center'
,
$this
->
view
->
tag
(
'div'
,
$this
->
view
->
bouton
(
'id=19'
,
'picto=add'
,
'texte='
.
$this
->
view
->
_
(
'Ajouter un utilisateur'
),
'url='
.
$this
->
view
->
url
([
'action'
=>
'add'
]),
'largeur=210px'
))))
:
''
;
}
protected
function
_getUsersTable
()
{
$pager
=
$this
->
view
->
Pager
(
$this
->
total
,
20
,
...
...
@@ -82,26 +71,6 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp
return
$model
->
getLibelleBib
();
};
$tag_edit
=
$this
->
view
->
tagAnchor
(
$this
->
view
->
url
(
array_merge
([
'module'
=>
'admin'
,
'controller'
=>
'users'
,
'action'
=>
'edit'
,
'id'
=>
$this
->
placeholder
],
$this
->
params
)),
$this
->
view
->
boutonIco
(
'type=edit'
));
$tag_delete
=
$this
->
view
->
tagAnchor
(
$this
->
view
->
url
(
array_merge
([
'module'
=>
'admin'
,
'controller'
=>
'users'
,
'action'
=>
'delete'
,
'id'
=>
$this
->
placeholder
],
$this
->
params
)),
$this
->
view
->
boutonIco
(
'type=del'
));
$actions
=
function
(
$user
)
use
(
$tag_edit
,
$tag_delete
){
if
(
!
Class_Users
::
getIdentity
()
->
isAdmin
())
return
;
return
str_replace
(
$this
->
placeholder
,
$user
->
getId
(),
$tag_edit
)
.
str_replace
(
$this
->
placeholder
,
$user
->
getId
(),
$tag_delete
);
};
return
$this
->
view
->
tagModelTable
(
$this
->
users
,
[
$this
->
view
->
_
(
'Identifiant'
),
$this
->
view
->
_
(
'Nom'
),
...
...
@@ -113,7 +82,7 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp
'prenom'
,
'role_level'
,
'library'
],
[
$actions
],
[
$
this
->
actions
],
null
,
null
,
[
'role_level'
=>
$role_renderer
,
...
...
tests/application/modules/admin/controllers/NewsletterControllerTest.php
View file @
9c1717fb
...
...
@@ -770,17 +770,16 @@ abstract class Admin_NewsletterControllerEditSubcsribersTestCase extends Admin_A
public
function
setUp
()
{
parent
::
setUp
();
Class_Newsletter
::
setTimeSource
(
new
TimeSourceForTest
(
'2005-03-27 12:30:00'
));
Class_UserGroup
::
setMemoryCleaner
(
function
(){});
$this
->
_nl_nouveautes
=
$this
->
fixture
(
'Class_Newsletter'
,
[
'id'
=>
1
,
'titre'
=>
'Nouveautés'
,
'last_distribution_date'
=>
'2013-09-23'
,
'user_groups'
=>
[
$this
->
fixture
(
'Class_UserGroup'
,
[
'id'
=>
23
,
'libelle'
=>
'My Group'
])
]]);
$this
->
_nl_nouveautes
=
$this
->
fixture
(
'Class_Newsletter'
,
[
'id'
=>
1
,
'titre'
=>
'Nouveautés'
,
'last_distribution_date'
=>
'2013-09-23'
,
'user_groups'
=>
[
$this
->
fixture
(
'Class_UserGroup'
,
[
'id'
=>
23
,
'libelle'
=>
'My Group'
])
]]);
}
}
...
...
@@ -843,6 +842,81 @@ class Admin_NewsletterControllerEditSubcsribersTest extends Admin_NewsletterCont
class
Admin_NewsletterControllerEditSubcsribersSearchTest
extends
Admin_NewsletterControllerEditSubcsribersTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
Class_Newsletter
::
find
(
1
)
->
subscribeToDedicatedGroup
(
$this
->
fixture
(
'Class_Users'
,
[
'id'
=>
566
,
'login'
=>
'laurent'
,
'password'
=>
'677'
]));
$this
->
fixture
(
'Class_Users'
,
[
'id'
=>
3232
,
'login'
=>
'pat'
,
'password'
=>
'8890'
]);
Class_Newsletter
::
find
(
1
)
->
subscribeToDedicatedGroup
(
$this
->
fixture
(
'Class_Users'
,
[
'id'
=>
444
,
'login'
=>
'ghislo'
,
'password'
=>
'8989'
,
'mail'
=>
'g@serv.eur.fr'
]))
->
unsubscribeUser
(
Class_Users
::
find
(
444
));
$this
->
dispatch
(
'/admin/newsletter/edit-subscribers/id/1'
,
true
);
}
/** @test */
public
function
userSearchShouldBePresent
()
{
$this
->
assertXPathContentContains
(
'//form//legend'
,
'Recherche'
);
}
/** @test */
public
function
laurentShouldBeInList
()
{
$this
->
assertXPathContentContains
(
'//table[contains(@class, "models")]//td'
,
'laurent'
);
}
/** @test */
public
function
laurentActionShouldBeUnsubscribe
()
{
$this
->
assertXPath
(
'//table[contains(@class, "models")]//a[contains(@href, "/unsubscribe/566")]'
);
}
/** @test */
public
function
patShouldBePresent
()
{
$this
->
assertXPathContentContains
(
'//table[contains(@class, "models")]//td'
,
'pat'
);
}
/** @test */
public
function
patActionShouldBeSubscribe
()
{
$this
->
assertXPath
(
'//table[contains(@class, "models")]//a[contains(@href, "/subscribe/3232")]'
);
}
/** @test */
public
function
ghisloShouldBePresent
()
{
$this
->
assertXPathContentContains
(
'//table[contains(@class, "models")]//td'
,
'ghislo'
);
}
/** @test */
public
function
ghisloActionShouldBeReSubscribe
()
{
$this
->
assertXPath
(
'//table[contains(@class, "models")]//a[contains(@href, "/resubscribe/444")]'
);
}
}
class
Admin_NewsletterControllerScriptTest
extends
Admin_NewsletterControllerTestCase
{
public
function
setup
()
{
parent
::
setup
();
...
...
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