Commit 2a65b5b2 authored by Christian BUFFIN's avatar Christian BUFFIN
Browse files

Factorisation de code dans une méthode WebcilUsersComponent::mesOrganisations

parent b09639ef
......@@ -152,7 +152,7 @@ class ArticlesController extends AppController {
$articles = $this->paginate($this->Article);
$this->set(compact('articles'));
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
$options = $this->_optionsFiltre();
......@@ -265,20 +265,7 @@ class ArticlesController extends AppController {
// $options = $this->_optionsFiltre($organisation_id);
// $this->set(compact('options'));
}
private function _mesOrganisations() {
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
return($mesOrganisations);
}
public function add() {
return $this->edit();
}
......@@ -392,7 +379,7 @@ class ArticlesController extends AppController {
$this->set(compact('filesSave'));
}
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
......@@ -438,7 +425,7 @@ class ArticlesController extends AppController {
];
$this->request->data += $optionsAffecter;
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
}
......
......@@ -9,6 +9,7 @@
* @license CeCiLL V2 (http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html)
*/
App::uses('Component', 'Controller');
App::uses('ListeDroit', 'Model');
/**
* La classe WebcilUsersComponent ...
......@@ -409,5 +410,15 @@ class WebcilUsersComponent extends Component {
}
}
}
public function mesOrganisations($type, array $params = []) {
$controller = $this->_Collection->getController();
$params += [
'droits' => 'add' === $controller->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
];
return $this->organisations($type, $params);
}
}
......@@ -75,18 +75,12 @@ class FormulairesController extends AppController {
]
]);
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'conditions' => [
'OrganisationUser.organisation_id !=' => $this->Session->read('Organisation.id')
],
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
$params = [
'conditions' => [
'OrganisationUser.organisation_id !=' => $this->Session->read('Organisation.id')
]
);
];
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list', $params);
$this->set(compact('formulaires', 'mesOrganisations'));
}
......
......@@ -122,15 +122,7 @@ class OrganisationsController extends AppController
]);
}
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('organisations', 'mesOrganisations'));
}
......
......@@ -159,25 +159,12 @@ class ResponsablesController extends AppController {
}
$this->set([
'mesOrganisations' => $this->_mesOrganisations(),
'mesOrganisations' => $this->WebcilUsers->mesOrganisations('list'),
'options' => $this->_optionsFiltre(),
'responsables' => $this->_getSearchResults(),
]);
}
protected function _mesOrganisations() {
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
return $mesOrganisations;
}
protected function _optionsFiltre($organisation_id = null) {
$options = [
'apestructure' => $this->Responsable->getStringOptionList('apestructure', $organisation_id),
......@@ -268,7 +255,7 @@ class ResponsablesController extends AppController {
$this->request->data = $responsable;
}
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
$this->view = 'edit';
......@@ -314,7 +301,7 @@ class ResponsablesController extends AppController {
$this->request->data = $record;
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
$this->view = 'edit';
......
......@@ -157,25 +157,12 @@ class SoustraitantsController extends AppController {
}
$this->set([
'mesOrganisations' => $this->_mesOrganisations(),
'mesOrganisations' => $this->WebcilUsers->mesOrganisations('list'),
'options' => $this->_optionsFiltre(),
'soustraitants' => $this->_getSearchResults(),
]);
}
protected function _mesOrganisations() {
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
return $mesOrganisations;
}
/**
* Retourne les options à utiliser dans les formulaires de recherche.
*
......@@ -266,7 +253,7 @@ class SoustraitantsController extends AppController {
$this->request->data = $soustraitant;
}
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
$this->view = 'edit';
......@@ -312,7 +299,7 @@ class SoustraitantsController extends AppController {
$this->request->data = $record;
$mesOrganisations = $this->_mesOrganisations();
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
$this->set(compact('mesOrganisations'));
$this->view = 'edit';
......
......@@ -145,17 +145,8 @@ class TypagesController extends AppController {
}
}
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
$this->set([
'mesOrganisations' => $mesOrganisations,
'mesOrganisations' => $this->WebcilUsers->mesOrganisations('list'),
'options' => $this->_optionsFiltre(),
'typages' => $this->_getSearchResults(),
]);
......
......@@ -322,14 +322,7 @@ class UsersController extends AppController {
$this->Droits->assertRecordAuthorized('User', $id, ['superadmin' => true]);
$edit = false;
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
$mesOrganisations = $this->WebcilUsers->mesOrganisations('list');
if ($this->request->is('post') || $this->request->is('put')) {
if ('Cancel' === Hash::get($this->request->data, 'submit')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment