Gestion des criteres pour le profil utilisateur

This commit is contained in:
Michael RICOIS 2012-12-21 09:17:31 +00:00
parent acb2313b99
commit afcd6f0b4d

View File

@ -58,37 +58,47 @@ class GestionController extends Zend_Controller_Action
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Get default profil
$profilClientM = new Application_Model_CustomerParams();
$profilClient = $profilClientM->find($request->getParam('idClient'));
//Sauvegarde du formulaire
if ( $request->isPost() ){
if ( $request->isPost() )
{
$params = $request->getParams();
if ($params['reference']=='default') {
$params['criteres'] = json_decode($profilClient->current()->criteres,true);
//Get default profil
$profilClientM = new Application_Model_CustomerParams();
$sql = $profilClientM->select()->where('idClient=?',$request->getParam('idClient'));
$profilClient = $profilClientM->fetchRow($sql);
if ( null !== $profilClient ) {
$params['criteres'] = json_decode($profilClient->criteres,true);
}
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'dataInsee' => 0,
'dateAjout' => date('Y-m-d H:i:s'),
'actif' => 1,
);
$profilM = new Application_Model_EnrichissementProfils();
if ( $profilM->insert($data) ){
$this->view->assign('message', "Profil enregistré");
$this->view->assign('disableForm', true);
if (empty($params['criteres'])) {
$this->view->assign('message', "Erreur profil vide");
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'dataInsee' => 0,
'dateAjout' => date('Y-m-d H:i:s'),
'actif' => 1,
);
$profilM = new Application_Model_EnrichissementProfils();
if ( $profilM->insert($data) ) {
$this->view->assign('message', "Profil enregistré");
$this->view->assign('disableForm', true);
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
}
}
//Affichage du formulaire
@ -232,7 +242,7 @@ class GestionController extends Zend_Controller_Action
->order('dateAdded DESC')
->group('idClient');
$customers = $customersM->fetchAll($sql)->toArray();
//List login
$customerlist = array();
$profilsM = new Application_Model_EnrichissementProfils();
@ -241,14 +251,14 @@ class GestionController extends Zend_Controller_Action
->from($profilsM, array('login'))
->where('idClient=?',$item['idClient']);
$result = $profilsM->fetchAll($sql)->toArray();
$logins = array();
if (count($result)>0) {
foreach($result as $login) {
$logins[] = $login['login'];
}
}
$item['logins'] = $logins;
$customerlist[] = $item;
}
@ -265,12 +275,12 @@ class GestionController extends Zend_Controller_Action
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
$request = $this->getRequest();
$idClient= $request->getParam('id', null);
$this->view->assign('idClient', $idClient);
if ($idClient !== null) {
$paramsM = new Application_Model_CustomerParams();
$sql = $paramsM->select()->where('idClient = ?', $idClient);
@ -281,15 +291,15 @@ class GestionController extends Zend_Controller_Action
$infos['criteres'] = json_decode($infos['criteres'], true);
}
$this->view->assign('infos',$infos);
$loginsM = new Application_Model_EnrichissementProfils();
$sql = $loginsM->select()->where('idClient = ?', $idClient);
$logins = $loginsM->fetchAll($sql)->toArray();
$this->view->assign('logins', $logins);
}
}
public function customerparamaddAction()
{
//Fields
@ -297,13 +307,13 @@ class GestionController extends Zend_Controller_Action
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
$request = $this->getRequest();
//Sauvegarde du formulaire
if ( $request->isPost() && in_array($request->getParam('submit'), array('Enregistrer','Modifier')) ) {
$params = $request->getParams();
//Vérifier le formulaire
$errForm = 0;
foreach ( $params as $key => $value ) {
@ -312,7 +322,7 @@ class GestionController extends Zend_Controller_Action
}
}
if (!$errForm) {
$checkValues = array(
'filterRNCS' => 0,
'licenceINSEE' => 0,
@ -323,7 +333,7 @@ class GestionController extends Zend_Controller_Action
$params[$key] = $value;
}
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
@ -340,14 +350,14 @@ class GestionController extends Zend_Controller_Action
'criteres' => json_encode($params['criteres']),
'dateAdded' => date('Y-m-d H:i:s'),
);
if ($request->getParam('submit')=='Modifier') {
//Overwrite default profil for each login
$profilM = new Application_Model_EnrichissementProfils();
$profilM->update(
array('criteres', json_encode($params['criteres'])),
"reference='default' AND idClient=".$params['idClient']);
//Set parameters
$customerParamsM = new Application_Model_CustomerParams();
if ( $customerParamsM->update($data, 'id='.$params['id']) ){
@ -355,7 +365,7 @@ class GestionController extends Zend_Controller_Action
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
} else {
//Set parameters
$customerParamsM = new Application_Model_CustomerParams();
@ -365,14 +375,14 @@ class GestionController extends Zend_Controller_Action
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
}
} else {
$this->view->assign('message', "Erreur lors de la saisie");
}
} else {
$idClient = $request->getParam('id', null);
if ($idClient !== null) {
$paramsM = new Application_Model_CustomerParams();
$sql = $paramsM->select()->where('idClient = ?', $idClient);
@ -392,7 +402,7 @@ class GestionController extends Zend_Controller_Action
}
}
}
} else {
$this->view->assign('filterRNCS', 1);
$this->view->assign('licenceINSEE', 0);
@ -400,7 +410,7 @@ class GestionController extends Zend_Controller_Action
$this->view->assign('limitLines', 50000);
$this->view->assign('limitFiles', 0);
}
}
}