Skip to content

Commit 4909b8a

Browse files
Merge pull request #148 from gregorybesson/develop
datagrid
2 parents a2cb897 + 883d0e0 commit 4909b8a

File tree

11 files changed

+274
-73
lines changed

11 files changed

+274
-73
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
PlaygroundUser
2-
=========
2+
==============
33

44
[![Develop Branch Build Status](https://travis-ci.org/gregorybesson/PlaygroundUser.svg)](http://travis-ci.org/gregorybesson/PlaygroundUser)
55

66
#Introduction
77

88
Ce module étend ZfcUser qui permet de nombreuses fonctionnalités liées à la gestion d'un compte client.
99

10-
Le fonctionnalités apportées par AdfabUser sont :
10+
Le fonctionnalités apportées par PgUser sont :
1111
* Gestion des autorisations via BjyAuthorize
1212
* Mot de passe oublié
1313
* Activation de compte par mail
@@ -27,7 +27,7 @@ La commande php doctrine-module.php orm:schema-tool:create permet d'installer le
2727

2828
La commande php doctrine-module.php data-fixture:import --append permet d'installer les rôles 'user' et 'admin' ainsi que l'utilisateur 'admin@test.com' (mot de passe 'admin') avec les droits d'administration.
2929

30-
#Extending AdfabUser
30+
#Extending PgUser
3131
## Use your own User entity
3232
If you want to use your own entity :
3333

@@ -53,11 +53,11 @@ If you want to use your own entity :
5353
)
5454
),
5555

56-
3. Create your entity (using the doctrine annotation) in your Module. You'll have to implement the interface AdfabUser\Entity\UserInterface (see below for the explanation)
56+
3. Create your entity (using the doctrine annotation) in your Module. You'll have to implement the interface PgUser\Entity\UserInterface (see below for the explanation)
5757

58-
class User implements \AdfabUser\Entity\UserInterface, ProviderInterface, InputFilterAwareInterface
58+
class User implements \PgUser\Entity\UserInterface, ProviderInterface, InputFilterAwareInterface
5959

60-
4. The entities of other Adfab modules which need to link AdfabUser entity base the relationship on an interface : AdfabUser\Entity\UserInterface. So that, in case you extend the User entity, you can replace this relationship easily. To be able to do that, your user entity needs to implement AdfabUser\Entity\UserInterface.
60+
4. The entities of other Adfab modules which need to link PgUser entity base the relationship on an interface : PgUser\Entity\UserInterface. So that, in case you extend the User entity, you can replace this relationship easily. To be able to do that, your user entity needs to implement PgUser\Entity\UserInterface.
6161
And in your Module.php onBootstrap method, You have then to use the doctrine listener feature to replace the interface with the correct class
6262

6363
public function onBootstrap($e)
@@ -68,7 +68,7 @@ And in your Module.php onBootstrap method, You have then to use the doctrine lis
6868
6969
$listener = new \Doctrine\ORM\Tools\ResolveTargetEntityListener();
7070
$listener->addResolveTargetEntity(
71-
'AdfabUser\Entity\UserInterface',
71+
'PgUser\Entity\UserInterface',
7272
'MyUser\Entity\User',
7373
array()
7474
);
@@ -80,11 +80,11 @@ And in your Module.php onBootstrap method, You have then to use the doctrine lis
8080
## Use your own Form
8181
If you want to change the ChangeInfo Form for example (ie. you want to add a 'children' select list to persist in your user database table). First extend the entity as explained previously. Then :
8282

83-
1. Create the Form class in your Module, which extends the AdfabUser Form
83+
1. Create the Form class in your Module, which extends the PgUser Form
8484

85-
class ChangeInfo extends \AdfabUser\Form\ChangeInfo
85+
class ChangeInfo extends \PgUser\Form\ChangeInfo
8686

87-
If you want to use the default fields of the AdfabUser Form, you can do this by using the parent constructor
87+
If you want to use the default fields of the PgUser Form, you can do this by using the parent constructor
8888

8989
parent::__construct($name, $createOptions, $translator);
9090

@@ -103,20 +103,20 @@ If you want to change the ChangeInfo Form for example (ie. you want to add a 'ch
103103
),
104104
),
105105
'options' => array(
106-
'empty_option' => $translator->translate('Select', 'adfabuser'),
107-
'label' => $translator->translate('Children', 'adfabuser'),
106+
'empty_option' => $translator->translate('Select', 'pguser'),
107+
'label' => $translator->translate('Children', 'pguser'),
108108
),
109109
));
110110

111-
2. Declare your Form in your Module.php factories definition by reusing the same form name used in AdfabUser (as your module is loaded after AdfabUser, your definition will be taken instead of the AdfabUser definition)
111+
2. Declare your Form in your Module.php factories definition by reusing the same form name used in PgUser (as your module is loaded after PgUser, your definition will be taken instead of the PgUser definition)
112112

113113
public function getServiceConfig()
114114
{
115115
return array(
116116
'factories' => array(
117-
'adfabuser_change_info_form' => function($sm) {
117+
'pguser_change_info_form' => function($sm) {
118118
$translator = $sm->get('MvcTranslator');
119-
$options = $sm->get('adfabuser_module_options');
119+
$options = $sm->get('pguser_module_options');
120120
$form = new Form\ChangeInfo(null, $options, $translator);
121121
return $form;
122122
},
@@ -127,9 +127,9 @@ If you want to change the ChangeInfo Form for example (ie. you want to add a 'ch
127127
## Use your own User controller
128128
If you want to add an action or modify an existing one.
129129

130-
1. Create the controller in your Module (extend the AdfabUser one if you want to use its methods)
130+
1. Create the controller in your Module (extend the PgUser one if you want to use its methods)
131131

132-
class UserController extends \AdfabUser\Controller\Frontend\UserController
132+
class UserController extends \PgUser\Controller\Frontend\UserController
133133
{
134134
public function profileAction ()
135135
{
@@ -172,7 +172,7 @@ If you want to add an action or modify an existing one.
172172
),
173173
'view_manager' => array(
174174
'template_path_stack' => array(
175-
'adfabuser' => __DIR__ . '/../view',
175+
'pguser' => __DIR__ . '/../view',
176176
),
177177
'template_map' => array(
178178
'adfab-user/header/login.phtml' => __DIR__ . '/../view/adfab-user/frontend/header/login.phtml',

src/Controller/Admin/AdminController.php

Lines changed: 115 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator as DoctrineAdapter;
1010
use PlaygroundCore\ORM\Pagination\LargeTablePaginator as ORMPaginator;
1111
use Zend\ServiceManager\ServiceLocatorInterface;
12+
use ZfcDatagrid\Column;
13+
use ZfcDatagrid\Action;
14+
use ZfcDatagrid\Column\Formatter;
15+
use ZfcDatagrid\Column\Type;
16+
use ZfcDatagrid\Column\Style;
17+
use ZfcDatagrid\Filter;
1218

1319
class AdminController extends AbstractActionController
1420
{
@@ -33,30 +39,116 @@ public function getServiceLocator()
3339

3440
public function listAction()
3541
{
36-
$filter = $this->getEvent()->getRouteMatch()->getParam('filter');
37-
$roleId = $this->getEvent()->getRouteMatch()->getParam('roleId');
38-
$search = $this->params()->fromQuery('name');
39-
40-
$role = $this->getAdminUserService()->getRoleMapper()->findByRoleId($roleId);
41-
42-
$adapter = new DoctrineAdapter(new ORMPaginator($this->getAdminUserService()->getQueryUsersByRole($role, null, $search)));
43-
44-
$paginator = new Paginator($adapter);
45-
$paginator->setItemCountPerPage(50);
46-
$paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
47-
48-
$roles = $this->getAdminUserService()->getRoleMapper()->findAll();
49-
50-
return new ViewModel(
51-
array(
52-
'users' => $paginator,
53-
'userlistElements' => $this->getOptions()->getUserListElements(),
54-
'filter' => $filter,
55-
'roleId' => $roleId,
56-
'roles' => $roles,
57-
'search' => $search,
58-
)
42+
// $filter = $this->getEvent()->getRouteMatch()->getParam('filter');
43+
// $roleId = $this->getEvent()->getRouteMatch()->getParam('roleId');
44+
// $search = $this->params()->fromQuery('name');
45+
46+
// $role = $this->getAdminUserService()->getRoleMapper()->findByRoleId($roleId);
47+
48+
// $qb = $this->getAdminUserService()->getQueryUsersByRole($role, null, $search);
49+
// $query = $qb->getQuery();
50+
// $adapter = new DoctrineAdapter(new ORMPaginator($query));
51+
52+
// $paginator = new Paginator($adapter);
53+
// $paginator->setItemCountPerPage(50);
54+
// $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p'));
55+
56+
// $roles = $this->getAdminUserService()->getRoleMapper()->findAll();
57+
58+
// return new ViewModel(
59+
// array(
60+
// 'users' => $paginator,
61+
// 'userlistElements' => $this->getOptions()->getUserListElements(),
62+
// 'filter' => $filter,
63+
// 'roleId' => $roleId,
64+
// 'roles' => $roles,
65+
// 'search' => $search,
66+
// )
67+
// );
68+
69+
$qb = $this->getAdminUserService()->getQueryUsersByRole();
70+
/* @var $grid \ZfcDatagrid\Datagrid */
71+
$grid = $this->getServiceLocator()->get('ZfcDatagrid\Datagrid');
72+
$grid->setTitle('Minimal grid');
73+
$grid->setDataSource($qb);
74+
75+
$col = new Column\Select('id', 'u');
76+
$col->setLabel('Id');
77+
$col->setIdentity(true);
78+
$grid->addColumn($col);
79+
80+
$colType = new Type\DateTime(
81+
'Y-m-d H:i:s',
82+
\IntlDateFormatter::MEDIUM,
83+
\IntlDateFormatter::MEDIUM
5984
);
85+
$colType->setSourceTimezone('UTC');
86+
87+
$col = new Column\Select('created_at', 'u');
88+
$col->setLabel('Created');
89+
$col->setType($colType);
90+
$grid->addColumn($col);
91+
92+
$col = new Column\Select('username', 'u');
93+
$col->setLabel('Username');
94+
$grid->addColumn($col);
95+
96+
$col = new Column\Select('email', 'u');
97+
$col->setLabel('Email');
98+
$grid->addColumn($col);
99+
100+
$col = new Column\Select('firstname', 'u');
101+
$col->setLabel('Firstname');
102+
$grid->addColumn($col);
103+
104+
$col = new Column\Select('lastname', 'u');
105+
$col->setLabel('Lastname');
106+
$grid->addColumn($col);
107+
108+
$col = new Column\Select('roleId', 'r');
109+
$col->setLabel('Role');
110+
$grid->addColumn($col);
111+
112+
$actions = new Column\Action();
113+
$actions->setLabel('');
114+
//$actions->setAttribute('style', 'white-space: nowrap');
115+
116+
$viewAction = new Column\Action\Button();
117+
$viewAction->setLabel('Reset Password');
118+
$rowId = $viewAction->getRowIdPlaceholder();
119+
$viewAction->setLink('/admin/user/reset/'.$rowId);
120+
$actions->addAction($viewAction);
121+
122+
$viewAction = new Column\Action\Button();
123+
$viewAction->setLabel('Edit');
124+
$rowId = $viewAction->getRowIdPlaceholder();
125+
$viewAction->setLink('/admin/user/edit/'.$rowId);
126+
$actions->addAction($viewAction);
127+
128+
$viewAction = new Column\Action\Button();
129+
$viewAction->setLabel('Inactivate');
130+
$rowId = $viewAction->getRowIdPlaceholder();
131+
$viewAction->setLink('/admin/user/remove/'.$rowId);
132+
$actions->addAction($viewAction);
133+
134+
$grid->addColumn($actions);
135+
136+
// $action = new Action\Mass();
137+
// $action->setTitle('This is incredible');
138+
// $action->setLink('/test');
139+
// $action->setConfirm(true);
140+
// $grid->addMassAction($action);
141+
142+
$grid->setToolbarTemplateVariables(
143+
[
144+
'globalActions' => [
145+
$this->translate('New User') => $this->adminUrl()->fromRoute('playgrounduser/create', ['userId' => 0])
146+
]
147+
]
148+
);
149+
$grid->render();
150+
151+
return $grid->getResponse();
60152
}
61153

62154
public function downloadAction()

src/Controller/Frontend/UserController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public function registerAction()
203203
} else {
204204
$post['optin2'] = 0;
205205
}
206+
if (isset($post['optin3'])) {
207+
$post['optin3'] = 1;
208+
} else {
209+
$post['optin3'] = 0;
210+
}
206211
if (isset($post['optinPartner'])) {
207212
$post['optinPartner'] = 1;
208213
} else {

src/Entity/User.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ class User implements \ZfcUser\Entity\UserInterface, ProviderInterface, InputFil
150150
*/
151151
protected $optin2 = 0;
152152

153+
/**
154+
* @ORM\Column(type="boolean", nullable=true)
155+
*/
156+
protected $optin3 = 0;
157+
153158
/**
154159
* @ORM\Column(type="datetime", nullable=true)
155160
*/
@@ -711,6 +716,26 @@ public function setOptin2($optin2)
711716
return $this;
712717
}
713718

719+
/**
720+
*
721+
* @return the $optin3
722+
*/
723+
public function getOptin3()
724+
{
725+
return $this->optin3;
726+
}
727+
728+
/**
729+
*
730+
* @param field_type $optin3
731+
*/
732+
public function setOptin3($optin3)
733+
{
734+
$this->optin3 = $optin3;
735+
736+
return $this;
737+
}
738+
714739
/**
715740
*
716741
* @return the $optinPartner
@@ -859,6 +884,10 @@ public function populate($data = array())
859884
$this->optin2 = $data['optin2'];
860885
}
861886

887+
if (isset($data['optin3'])) {
888+
$this->optin3 = $data['optin3'];
889+
}
890+
862891
if (isset($data['optinPartner'])) {
863892
$this->optinPartner = $data['optinPartner'];
864893
}
@@ -1166,6 +1195,14 @@ public function getInputFilter()
11661195
),
11671196
)));
11681197

1198+
$inputFilter->add($factory->createInput(array(
1199+
'name' => 'optin3',
1200+
'required' => false,
1201+
'filters' => array(
1202+
array('name' => 'Int'),
1203+
),
1204+
)));
1205+
11691206
$inputFilter->add($factory->createInput(array(
11701207
'name' => 'optinPartner',
11711208
'required' => false,

src/Form/Admin/User.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ public function __construct($name, UserCreateOptionsInterface $createOptions, Re
220220
),
221221
));
222222

223+
$this->add(array(
224+
'name' => 'optin3',
225+
'type' => 'Zend\Form\Element\Checkbox',
226+
'options' => array(
227+
'label' => $translator->translate('Optin 3', 'playgrounduser'),
228+
'value_options' => array(
229+
'1' => $translator->translate('Yes', 'playgrounduser'),
230+
'0' => $translator->translate('No', 'playgrounduser'),
231+
),
232+
),
233+
));
234+
223235
$this->add(array(
224236
'name' => 'optinPartner',
225237
'type' => 'Zend\Form\Element\Checkbox',

src/Form/ChangeInfo.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ public function __construct($name, UserCreateOptionsInterface $createOptions, Tr
231231
)
232232
);
233233

234+
$this->add(
235+
array(
236+
'name' => 'optin3',
237+
'type' => 'Zend\Form\Element\Checkbox',
238+
'options' => array(
239+
'label' => $translator->translate('optin 3', 'playgrounduser'),
240+
'value_options' => array(
241+
'1' => $translator->translate('Yes', 'playgrounduser'),
242+
'0' => $translator->translate('No', 'playgrounduser'),
243+
),
244+
),
245+
)
246+
);
247+
234248
$this->add(
235249
array(
236250
'name' => 'optinPartner',

src/Form/Newsletter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function __construct($name, RegistrationOptionsInterface $registerOptions
4646
),
4747
));
4848

49+
$this->add(array(
50+
'name' => 'optin3',
51+
'type' => 'Zend\Form\Element\Checkbox',
52+
'options' => array(
53+
'label' => $translator->translate('Optin 3', 'playgrounduser'),
54+
'value_options' => array(
55+
'1' => $translator->translate('Yes', 'playgrounduser'),
56+
'0' => $translator->translate('No', 'playgrounduser'),
57+
),
58+
),
59+
));
60+
4961
$this->add(array(
5062
'name' => 'optinPartner',
5163
'type' => 'Zend\Form\Element\Checkbox',

0 commit comments

Comments
 (0)