Gestion - Doctrine
This commit is contained in:
parent
40420f890c
commit
cac6a65eef
@ -212,14 +212,6 @@ class Gestion extends Scores_Ws_Server
|
||||
{
|
||||
$this->authenticate();
|
||||
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
$sql = $userM->select()
|
||||
->from($userM, array('id','login','actif','deleted'))
|
||||
->where('idClient=?', $idClient)
|
||||
->where('login LIKE "'.$query.'%"')
|
||||
->limit(20);
|
||||
$result = $userM->fetchAll($sql);
|
||||
|
||||
$sql = "SELECT id, login, actif, deleted FROM sdv1.utilisateurs
|
||||
WHERE idClient = :clientId AND login LIKE ':q%' LIMIT, 0,20";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
@ -250,9 +242,6 @@ class Gestion extends Scores_Ws_Server
|
||||
$infos = json_decode($infos, true);
|
||||
|
||||
//Get user infos
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
$row = $userM->select()->where('login=?',$login);
|
||||
|
||||
$sql = "SELECT * FROM sdv1.utilisateurs WHERE login = :login";
|
||||
$stmt = $this->conn->executeQuery($sql);
|
||||
|
||||
@ -1167,7 +1156,8 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// --- Droits client actuel avant modification
|
||||
if (isset($tabInfos['droits'])) {
|
||||
$iDbCrm = new Metier_Util_Db();
|
||||
@ -1264,216 +1254,6 @@ class Gestion extends Scores_Ws_Server
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Definir la méthode de tarification
|
||||
* @param int $idClient Nom de l'élément à facturer
|
||||
* @param ClientTarif $tarif Informations de facturation
|
||||
* @param int $id Identifiant pour l'update
|
||||
* @return int
|
||||
*/
|
||||
public function setClientTarif($idClient, $tarif, $id=null)
|
||||
{
|
||||
/**
|
||||
* Une tarification est toujours affecté à un élément $log.
|
||||
* Celle ci est définie sur un compte client (tous les utilisateurs) ou un service,
|
||||
* Pour un type de facturation
|
||||
* - Unitaire : Chaque élement est à facturer
|
||||
* - Forfait limité : Si tarif unitaire>0 alors on applique le prix unitaire pour chaque
|
||||
* dépassement, sinon on coupe
|
||||
* - Forfait illimité :
|
||||
*/
|
||||
|
||||
$this->authenticate();
|
||||
|
||||
if ($this->User->profil!='SuperAdministrateur') {
|
||||
$this->sendError('0902');
|
||||
}
|
||||
|
||||
if (!in_array($tarif->log, array_keys($this->logs))) {
|
||||
throw new SoapFault('ClientTarif', 'log inexistant');
|
||||
}
|
||||
|
||||
if (!in_array($tarif->type, array('Unitaire','ForfaitLimit','ForfaitNoLimit'))) {
|
||||
throw new SoapFault('ClientTarif', 'Erreur type');
|
||||
}
|
||||
|
||||
if (!in_array($tarif->doublon, array('jour','mois', 'period','none'))) {
|
||||
throw new SoapFault('ClientTarif', 'Erreur doublon');
|
||||
}
|
||||
|
||||
$time = mktime(0,0,0,substr($tarif->date,4,2), substr($tarif->date,6,2), substr($tarif->date,0,4));
|
||||
|
||||
$data = array(
|
||||
'idClient' => $idClient,
|
||||
'service' => $tarif->service,
|
||||
'log' => $tarif->log,
|
||||
'type' => $tarif->type,
|
||||
'priceUnit' => $tarif->priceUnit,
|
||||
'limit' => $tarif->limit,
|
||||
'dateDebut' => date('Y-m-d H:i:s', $time),
|
||||
'duree' => $tarif->duree,
|
||||
'doublon' => $tarif->doublon,
|
||||
);
|
||||
|
||||
try {
|
||||
$tarifM = new Application_Model_Sdv1ClientsTarifs();
|
||||
if ( null === $id) {
|
||||
$result = $tarifM->insert($data);
|
||||
} else {
|
||||
$result = $tarifM->update($data, 'id='.$id);
|
||||
}
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of tarif
|
||||
* @param int $idClient
|
||||
* @param string $service
|
||||
* @throws SoapFault
|
||||
* @return ClientContrat[]
|
||||
*/
|
||||
public function getClientTarifs($idClient, $service = null)
|
||||
{
|
||||
$this->authenticate();
|
||||
|
||||
if ( null === $service ) {
|
||||
$service = 'DEFAULT';
|
||||
}
|
||||
|
||||
//Liste dateDebut-duree disponible
|
||||
$tarifM = new Application_Model_Sdv1ClientsTarifs();
|
||||
try {
|
||||
$sql = $tarifM->select()->from($tarifM,array(
|
||||
'dateDebut',
|
||||
'duree'
|
||||
))
|
||||
->where('service=?',$service)
|
||||
->order('dateDebut DESC')
|
||||
->group(array('dateDebut', 'duree'));
|
||||
$contrats = $tarifM->fetchAll($sql);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
$listeContrat = array();
|
||||
//Retrouver les éléments à facturer
|
||||
if ( count($contrats)>0 ) {
|
||||
foreach ( $contrats as $contrat ) {
|
||||
try {
|
||||
$sql = $tarifM->select()
|
||||
->where('idClient=?', $idClient)
|
||||
->where('service=?',$service)
|
||||
->where('dateDebut=?',$contrat->dateDebut)
|
||||
->where('duree=?',$contrat->duree);
|
||||
$rows = $tarifM->fetchAll($sql);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
$output = array();
|
||||
if ( $rows->count()>0 ) {
|
||||
foreach ( $rows as $row ) {
|
||||
$item = new ClientTarif();
|
||||
$item->id = $row->id;
|
||||
$item->idClient = $row->idClient;
|
||||
$item->service = $row->service;
|
||||
$item->log = $row->log;
|
||||
$item->type = $row->type;
|
||||
$item->priceUnit = $row->priceUnit;
|
||||
$item->limit = $row->limit;
|
||||
$item->date = substr($row->dateDebut,0,10);
|
||||
$item->duree = $row->duree;
|
||||
$item->doublon = $row->doublon;
|
||||
|
||||
$output[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$date = DateTime::createFromFormat('Ymd', $contrat->dateDebut);
|
||||
$dateBegin = $date->format('Y-m-d');
|
||||
$date->add(new DateInterval('P'.$contrat->duree.'D'));
|
||||
$dateEnd = $date->format('Y-m-d');
|
||||
|
||||
$ElementContrat = new ClientContrat();
|
||||
$ElementContrat->dateBegin = $dateBegin;
|
||||
$ElementContrat->dateEnd = $dateEnd;
|
||||
$ElementContrat->tarifs = $output;
|
||||
|
||||
$listeContrat[] = $ElementContrat;
|
||||
}
|
||||
}
|
||||
|
||||
return $listeContrat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a tarif and his details by date
|
||||
* @param string $log
|
||||
* @param int $idClient
|
||||
* @param string $service
|
||||
* @param string $date
|
||||
* @throws SoapFault
|
||||
* @return ClientTarif
|
||||
*/
|
||||
public function getClientTarif($log, $idClient, $service='default', $date=null)
|
||||
{
|
||||
$this->authenticate();
|
||||
|
||||
if ( empty($service) ) {
|
||||
$service = 'default';
|
||||
}
|
||||
|
||||
//Date not define, looks for the actual price
|
||||
if ( empty($date) ) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
$tarifM = new Application_Model_Sdv1ClientsTarifs();
|
||||
$sql = $tarifM->select()
|
||||
->from($tarifM, array(
|
||||
'id', 'idClient', 'service', 'log', 'type', 'priceUnit', 'limit', 'dateDebut',
|
||||
'duree', 'doublon', 'DATE_ADD(dateDebut, INTERVAL duree DAY) AS dateFin'
|
||||
))
|
||||
->where('log=?',$log)
|
||||
->where('idClient=?', $idClient)
|
||||
->where('service=?',$service);
|
||||
//->where('dateDebut<=?', $date);
|
||||
//->where('dateFin>?',$date);
|
||||
//@todo : get date between
|
||||
|
||||
$row = $tarifM->fetchRow($sql);
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste des prestations pour un client
|
||||
* @param int $idClient
|
||||
@ -1486,23 +1266,23 @@ class Gestion extends Scores_Ws_Server
|
||||
|
||||
// Read prestations
|
||||
try {
|
||||
$prestationsM = new Application_Model_Sdv1Prestations();
|
||||
$sql = $prestationsM->select()
|
||||
->from($prestationsM, array('id', 'typeprestation', 'datemiseenplace',
|
||||
'datefinprestation' ,'identifiantPrestation', 'prestationactive'))
|
||||
->where('idClient=?', $idClient);
|
||||
$result = $prestationsM->fetchAll($sql);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
if ($this->User->idClient!=1) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
} else {
|
||||
$sql = "SELECT id, typeprestation, datemiseenplace , datefinprestation,
|
||||
identifiantPrestation, prestationactive FROM sdv1.prestations WHERE idClient = :id";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $idClient);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
$output = array();
|
||||
if ($result->count()>0) {
|
||||
foreach ( $result as $item ) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$clientprestation = new ClientPrestation();
|
||||
$clientprestation->id = $item->id;
|
||||
$clientprestation->type = $item->typeprestation;
|
||||
@ -1529,70 +1309,28 @@ class Gestion extends Scores_Ws_Server
|
||||
{
|
||||
$this->authenticate();
|
||||
|
||||
//Read prestations
|
||||
// Read prestation
|
||||
try {
|
||||
$prestationsM = new Application_Model_Sdv1Prestations();
|
||||
$sql = $prestationsM->select()->where('id=?', $id);
|
||||
$result = $prestationsM->fetchRow($sql);
|
||||
if ($result!==null) {
|
||||
return json_encode($result->toArray());
|
||||
$sql = "SELECT id, typeprestation, datemiseenplace , datefinprestation,
|
||||
identifiantPrestation, prestationactive FROM sdv1.prestations WHERE id = :id";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $id);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
if ($stmt->rowCount()) {
|
||||
return json_encode($stmt->fetch(\PDO::FETCH_ASSOC));
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
if ($this->User->idClient!=1) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
} else {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistre les paramètres des la prestation
|
||||
* @param int $idClient
|
||||
* @param string $prestation
|
||||
* @return int
|
||||
* @throws SoapFault
|
||||
*/
|
||||
public function setPrestation($idClient, $prestation)
|
||||
{
|
||||
$this->authenticate();
|
||||
|
||||
if ($this->User->profil!='SuperAdministrateur') {
|
||||
$this->sendError('0902');
|
||||
}
|
||||
|
||||
$prestationParameters = json_decode($prestation, true);
|
||||
|
||||
//Insert or update a prestation
|
||||
try {
|
||||
$prestationsM = new Application_Model_Sdv1Prestations();
|
||||
|
||||
//Update
|
||||
if (!empty($prestationParameters['id'])) {
|
||||
$id = $prestationParameters['id'];
|
||||
unset($prestationParameters['id']);
|
||||
$result = $prestationsM->update($prestationParameters, 'id='.$id);
|
||||
}
|
||||
|
||||
//Insert
|
||||
else {
|
||||
//@todo : Some control before save
|
||||
|
||||
$result = $prestationsM->insert($prestationParameters);
|
||||
}
|
||||
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
if ($this->User->idClient!=1) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
} else {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a Service in Client
|
||||
@ -1610,27 +1348,28 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
try {
|
||||
$serviceM = new Application_Model_Sdv1ClientsServices();
|
||||
|
||||
$dataIn = json_decode($infos, true);
|
||||
$code = $dataIn['code'];
|
||||
$label = $dataIn['label'];
|
||||
$droits = $dataIn['droits'];
|
||||
|
||||
//Check if code exist in idClient
|
||||
$sql = $serviceM->select()
|
||||
->where('idClient=?',$idClient)
|
||||
->where('code=?',$code);
|
||||
$sql = "SELECT * FROM sdv1.clients_services WHERE idClient = :idClient AND code = :code";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->bindValue('code', $code);
|
||||
$stmt->execute();
|
||||
|
||||
$row = $serviceM->fetchAll($sql);
|
||||
|
||||
if ($row->count()>0) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$row = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$data = array(
|
||||
'label' => $label,
|
||||
'droits' => $droits
|
||||
);
|
||||
$result = $serviceM->update($data, array('idClient='.$idClient, 'code='.$code));
|
||||
|
||||
$result = $this->conn->update('sdv1.clients_services', $data, array(
|
||||
'idClient' => $idClient,
|
||||
'code' => $code,
|
||||
));
|
||||
// Delete
|
||||
if ( isset($row->droits) ) {
|
||||
$droitsPre = explode(' ', $row->droits);
|
||||
@ -1644,16 +1383,18 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'code' => $code,
|
||||
'label' => $label,
|
||||
'droits' => $droits,
|
||||
'idClient' => $idClient
|
||||
);
|
||||
$result = $serviceM->insert($data);
|
||||
$result = $this->conn->insert('sdv1.clients_services', $data);
|
||||
}
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -1680,25 +1421,21 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
try {
|
||||
$serviceM = new Application_Model_Sdv1UtilisateursService();
|
||||
|
||||
// Check if a login exist
|
||||
$sql = $serviceM->select()->where('login=?',$login);
|
||||
$row = $serviceM->fetchAll($sql);
|
||||
$sql = "SELECT * FROM sdv1.utilisateurs_service WHERE login = :login";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('login', $login);
|
||||
$stmt->execute();
|
||||
|
||||
if ($row->count()>0) {
|
||||
$data = array(
|
||||
'serviceCode' => $code,
|
||||
);
|
||||
$result = $serviceM->update($data, 'login='.$login);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$data = array('serviceCode' => $code);
|
||||
$result = $this->conn->update('sdv1.utilisateurs_service', $data, array('login' => $login));
|
||||
} else {
|
||||
$data = array(
|
||||
'login' => $login,
|
||||
'serviceCode' => $code,
|
||||
);
|
||||
$result = $serviceM->insert($data);
|
||||
$data = array('login' => $login, 'serviceCode' => $code);
|
||||
$result = $this->conn->insert('sdv1.utilisateurs_service', $data);
|
||||
}
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -1707,12 +1444,13 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
// Override login right access - always
|
||||
$serviceM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $serviceM->select()->where('code=?',$code);
|
||||
$serviceInfo = $serviceM->fetchRow($sql);
|
||||
if ( null !== $serviceInfo ) {
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
$userM->update(array('droits'=>$serviceInfo->droits), 'login='.$login);
|
||||
$sql = "SELECT * FROM sdv1.clients_services WHERE code = :code";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('code', $code);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$this->conn->update('sdv1.utilisateurs', array('droits'=>$result->droits),
|
||||
array('login' => $login));
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -1733,24 +1471,22 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
try {
|
||||
$serviceM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $serviceM->select()
|
||||
->where('idClient=?', $idClient)
|
||||
->order('label ASC');
|
||||
$rows = $serviceM->fetchAll($sql);
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
$sql = "SELECT * FROM sdv1.clients_services WHERE idClient = :idClient ORDER BY LABEL ASC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
$output = array();
|
||||
if ($rows->count()>0) {
|
||||
foreach($rows as $item) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$service = new Service();
|
||||
$service->code = $item->code;
|
||||
$service->label = $item->label;
|
||||
@ -1776,23 +1512,23 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
try {
|
||||
$serviceM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $serviceM->select()
|
||||
->where('idClient=?', $idClient)
|
||||
->where('serviceCode=?', $code);
|
||||
$row = $serviceM->fetchRow($sql);
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
$sql = "SELECT * FROM sdv1.clients_services
|
||||
WHERE idClient = :idClient AND serviceCode = :code";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->bindValue('code', $code);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
if (null !== $row) {
|
||||
return json_encode($row->toArray());
|
||||
if ($stmt->rowCount() > 0) {
|
||||
return json_encode($stmt->fetch(\PDO::FETCH_ASSOC));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -1823,50 +1559,46 @@ class Gestion extends Scores_Ws_Server
|
||||
|
||||
//Check if service exist
|
||||
try {
|
||||
$servicesM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $servicesM->select()
|
||||
->from($servicesM, array('code'))
|
||||
->where('idClient=?', $idClient);
|
||||
$result = $servicesM->fetchAll($sql);
|
||||
if ($result->count()==0) {
|
||||
$sql = "SELECT code FROM sdv1.clients_services WHERE idClient = :idClient";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 0) {
|
||||
throw new SoapFault('ERR', 'Service inexistant');
|
||||
}
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
// List login
|
||||
try {
|
||||
$userserviceM = new Application_Model_Sdv1UtilisateursService();
|
||||
$sql = $userserviceM->select()
|
||||
->where('serviceCode=?', $serviceCode)
|
||||
->order('login ASC');
|
||||
$logins = $userserviceM->fetchAll($sql);
|
||||
} catch (Zend_Db_Adapter_Exception $e) {
|
||||
$sql = "SELECT * FROM sdv1.utilisateurs_service WHERE serviceCode = :code ORDER BY login ASC";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('code', $serviceCode);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
} catch (Zend_Exception $e) {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
|
||||
// Get login informations
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while($login = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$sql = "SELECT * FROM sdv1.utilisateurs WHERE login = :login AND deleted=0";
|
||||
$userStmt = $this->conn->prepare($sql);
|
||||
$userStmt->bindValue('login', $login);
|
||||
$userStmt->execute();
|
||||
$result = $userStmt->fetch(\PDO::FETCH_OBJ);
|
||||
|
||||
if ($logins->count()>0) {
|
||||
foreach($logins as $login) {
|
||||
$sql = $userM->select()
|
||||
->where('login=?', $login->login)
|
||||
->where('deleted=0');
|
||||
$result = $userM->fetchRow($sql);
|
||||
$utilisateur = new Utilisateur();
|
||||
$utilisateur->idUti = $result->id;
|
||||
$utilisateur->login = $result->login;
|
||||
@ -1883,28 +1615,26 @@ class Gestion extends Scores_Ws_Server
|
||||
|
||||
//Select all logins which have service to display only login without service
|
||||
else {
|
||||
|
||||
$servicesM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $servicesM->select()
|
||||
->from($servicesM, array('code'))
|
||||
->where('idClient=?', $idClient);
|
||||
$result = $servicesM->fetchAll($sql);
|
||||
$codes = array();
|
||||
$notlogins = array();
|
||||
if ($result->count()>0) {
|
||||
foreach ($result as $item) {
|
||||
|
||||
$sql = "SELECT code FROM sdv1.clients_services WHERE idClient = :client";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('client', $idClient);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$codes[] = $item->code;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($codes) > 0) {
|
||||
|
||||
try {
|
||||
$userserviceM = new Application_Model_Sdv1UtilisateursService();
|
||||
$sql = $userserviceM->select()
|
||||
->where('serviceCode IN ("'.join(',',$codes).'")');
|
||||
$result = $userserviceM->fetchAll($sql);
|
||||
} catch (Zend_Exception $e) {
|
||||
$sql = "SELECT * FROM sdv1.utilisateurs_service
|
||||
WHERE serviceCode IN ('".join("','",$codes)."')";
|
||||
$stmt = $this->conn->executeQuery($sql);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient==1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -1912,33 +1642,28 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
}
|
||||
|
||||
if ($result->count()>0) {
|
||||
foreach ($result as $item) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$notlogins[] = $item->login;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
if (count($notlogins) > 0) {
|
||||
$sql = $userM->select()
|
||||
->from($userM, array('id', 'login', 'actif', 'nom', 'prenom', 'email', 'referenceParDefaut'))
|
||||
->where('login NOT IN('.join(',',$notlogins).')')
|
||||
->where('idClient=?',$idClient)
|
||||
->where('deleted=0')
|
||||
->order('login ASC');
|
||||
} else {
|
||||
$sql = $userM->select()
|
||||
->from($userM, array('id', 'login', 'actif', 'nom', 'prenom', 'email', 'referenceParDefaut'))
|
||||
->where('idClient=?',$idClient)
|
||||
->where('deleted=0')
|
||||
->order('login ASC');
|
||||
$sql = "SELECT id, login, actif, nom, prenom, email, referenceParDefaut
|
||||
FROM sdv1.utilisateurs WHERE login NOT IN('".join("','",$notlogins)."')
|
||||
AND idClient = :idClient AND deleted = 0 ORDER BY login ASC";
|
||||
}
|
||||
|
||||
$logins = $userM->fetchAll($sql);
|
||||
|
||||
if ($logins->count()>0) {
|
||||
foreach ($logins as $result) {
|
||||
else {
|
||||
$sql = "SELECT id, login, actif, nom, prenom, email, referenceParDefaut
|
||||
FROM sdv1.utilisateurs WHERE idClient = :idClient
|
||||
AND deleted = 0 ORDER BY login ASC";
|
||||
}
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while($result = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$utilisateur = new Utilisateur();
|
||||
$utilisateur->idUti = $result->id;
|
||||
$utilisateur->login = $result->login;
|
||||
@ -1990,19 +1715,23 @@ class Gestion extends Scores_Ws_Server
|
||||
if ( count($logins)>0 ) {
|
||||
// Get access
|
||||
if ($service == 'DEFAULT') {
|
||||
$clientM = new Application_Model_Sdv1Clients();
|
||||
$sql = $clientM->select()->where('idClient=?', $idClient);
|
||||
$row = $clientM->fetchRow($sql);
|
||||
$droits = $row->droits;
|
||||
$sql = "SELECT droits FROM sdv1.clients WHERE idClient = :idClient";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$droits = $result->droits;
|
||||
} else {
|
||||
$serviceM = new Application_Model_Sdv1ClientsServices();
|
||||
$sql = $serviceM->select()->where('code=?', $service);
|
||||
$row = $serviceM->fetchRow($sql);
|
||||
$droits = $row->droits;
|
||||
$sql = "SELECT droits FROM sdv1.clients_services WHERE code = :code";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('code', $service);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$droits = $result->droits;
|
||||
}
|
||||
// Override access
|
||||
$userM = new Application_Model_Sdv1Utilisateurs();
|
||||
$result = $userM->update(array('droits'=>$droits), 'login IN ('.join(',',$logins).')');
|
||||
$result = $this->conn->executeUpdate("UPDATE sdv1.utilisateurs
|
||||
SET droits = $droits WHERE login IN ('.join(',',$logins).')");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2026,9 +1755,13 @@ class Gestion extends Scores_Ws_Server
|
||||
$this->authenticate();
|
||||
|
||||
try {
|
||||
$surveillanceM = new Application_Model_JoSurveillancesSite();
|
||||
$result = $surveillanceM->update(array('email'=>$email), "login='$login'");
|
||||
} catch (Zend_Exception $e) {
|
||||
$sql = "UPDATE IGNORE jo.surveillances_site SET email = :email AND login = :login";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('email', $email);
|
||||
$stmt->bindValue('login', $login);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -2036,7 +1769,7 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2055,64 +1788,60 @@ class Gestion extends Scores_Ws_Server
|
||||
$idClient = $this->User->idClient;
|
||||
|
||||
if ($action == 'set') {
|
||||
|
||||
if ($id === null) {
|
||||
|
||||
try {
|
||||
$emailsM = new Application_Model_Sdv1UtilisateursEmails();
|
||||
$data = array(
|
||||
'email' => $email,
|
||||
'login' => $login,
|
||||
'idClient' => $idClient,
|
||||
);
|
||||
$result = $emailsM->insert($data);
|
||||
} catch (Zend_Exception $e) {
|
||||
$result = $this->conn->insert('sdv1.utilisateurs_emails', $data);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
$emailsM = new Application_Model_Sdv1UtilisateursEmails();
|
||||
$data = array(
|
||||
'email' => $email,
|
||||
);
|
||||
$result = $emailsM->update($data, array(
|
||||
'login="'.$login.'"',
|
||||
'idClient='.$idClient,
|
||||
'id='.$id,
|
||||
$result = $this->conn->update('sdv1.utilisateurs_emails', $data, array(
|
||||
'login' => $login,
|
||||
'idClient' => $idClient,
|
||||
'id' => $id,
|
||||
));
|
||||
} catch (Zend_Exception $e) {
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} elseif ( $action == 'del' ) {
|
||||
|
||||
}
|
||||
elseif ($action == 'del') {
|
||||
try {
|
||||
$emailsM = new Application_Model_Sdv1UtilisateursEmails();
|
||||
$result = $emailsM->delete(array(
|
||||
'login="'.$login.'"',
|
||||
'idClient='.$idClient,
|
||||
'id='.$id,
|
||||
$result = $this->conn->delete('sdv1.utilisateurs_emails', array(
|
||||
'login' => $login,
|
||||
'idClient' => $idClient,
|
||||
'id' => $id,
|
||||
));
|
||||
} catch (Zend_Exception $e) {
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
throw new SoapFault('ERR', "Application error");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -2132,12 +1861,14 @@ class Gestion extends Scores_Ws_Server
|
||||
$idClient = $this->User->idClient;
|
||||
|
||||
try {
|
||||
$emailsM = new Application_Model_Sdv1UtilisateursEmails();
|
||||
$sql = $emailsM->select()
|
||||
->where('login=?', $login)
|
||||
->where('idClient=?', $idClient);
|
||||
$result = $emailsM->fetchAll($sql);
|
||||
} catch (Zend_Exception $e) {
|
||||
$sql = "SELECT id, email FROM sdv1.utilisateurs_emails
|
||||
WHERE login = :login AND idClient = :id";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('login', $login);
|
||||
$stmt->bindValue('id', $idClient);
|
||||
$stmt->execute();
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->User->idClient == 1) {
|
||||
throw new SoapFault('ERR', $e->getMessage());
|
||||
} else {
|
||||
@ -2146,8 +1877,8 @@ class Gestion extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
$emails = array();
|
||||
if ( count($result)>0 ) {
|
||||
foreach ( $result as $item ) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
while ($item = $stmt->fetch(\PDO::FETCH_OBJ)) {
|
||||
$email = new Email();
|
||||
$email->id = $item->id;
|
||||
$email->value = $item->email;
|
||||
|
Loading…
Reference in New Issue
Block a user