From 034740a90626eb5db7bffd1085ff9073fbc84b2d Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 16 Oct 2012 12:57:18 +0000 Subject: [PATCH] issue #0000930 : Gestion des services et des tarifs --- application/models/ClientsTarif.php | 5 - application/models/Sdv1ClientsServices.php | 5 + application/models/Sdv1ClientsTarifs.php | 5 + .../models/Sdv1UtilisateursService.php | 5 + config/_sql/sdv1.clients_services.sql | 6 + ...ientsTarif.sql => sdv1.clients_tarifs.sql} | 29 ++- config/_sql/sdv1.utilisateurs_service.sql | 5 + library/WsScore/Gestion/v0.3/Gestion.ini | 3 +- library/WsScore/Gestion/v0.3/Gestion.php | 193 +++++++++++++++++- library/WsScore/Gestion/v0.3/Types.php | 18 +- 10 files changed, 242 insertions(+), 32 deletions(-) delete mode 100644 application/models/ClientsTarif.php create mode 100644 application/models/Sdv1ClientsServices.php create mode 100644 application/models/Sdv1ClientsTarifs.php create mode 100644 application/models/Sdv1UtilisateursService.php create mode 100644 config/_sql/sdv1.clients_services.sql rename config/_sql/{clientsTarif.sql => sdv1.clients_tarifs.sql} (76%) create mode 100644 config/_sql/sdv1.utilisateurs_service.sql diff --git a/application/models/ClientsTarif.php b/application/models/ClientsTarif.php deleted file mode 100644 index a07ed928..00000000 --- a/application/models/ClientsTarif.php +++ /dev/null @@ -1,5 +0,0 @@ -dbConfig->db->sdv1); - $tarifM = new Application_Model_ClientsTarif($db); + $tarifM = new Application_Model_Sdv1ClientsTarifs($db); if (!in_array($tarif->log, array_keys($this->listeDroits))) { throw new SoapFault('ClientTarif', 'log inexistant'); @@ -1278,7 +1278,6 @@ class Gestion extends WsScore $data = array( 'idClient' => $tarif->idClient, 'service' => $tarif->service, - 'login' => $tarif->login, 'log' => $tarif->log, 'type' => $tarif->type, 'priceForfait' => $tarif->priceForfait, @@ -1311,7 +1310,7 @@ class Gestion extends WsScore $db = Zend_Db::factory($this->dbConfig->db->sdv1); - $tarifM = new Application_Model_ClientsTarif($db); + $tarifM = new Application_Model_Sdv1ClientsTarifs($db); //Au client $sql = $tarifM->select() @@ -1489,5 +1488,193 @@ class Gestion extends WsScore return $result; } + + /** + * Define a Service in Client + * @param int $idClient + * @param string $code + * @param string $label + * @throws SoapFault + * @return int + */ + public function setService($idClient, $code, $label) + { + $this->authenticate(); + + if ($this->tabInfoUser['profil']!='SuperAdministrateur') { + $this->sendError('0902'); + } + + //Connect to the database + try { + $db = Zend_Db::factory($this->dbConfig->db->sdv1); + $db->getConnection(); + } catch (Zend_Db_Adapter_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } catch (Zend_Exception $e) { + throw new SoapFault('ERR', "Application error"); + } + + try { + $serviceM = new Application_Model_Sdv1ClientsServices(); + //Check if code exist in idClient + $sql = $serviceM->select() + ->where('idClient=?',$idClient) + ->where('code=?',$code); + + $row = $serviceM->fetchAll($sql); + + if ($row->count()>0) { + $data = array( + 'label' => $label, + ); + $result = $serviceM->update($data, array('idClient'=>$idClient, 'code'=> $code)); + } else { + $data = array( + 'code' => $code, + 'label' => $label, + 'idClient' => $idClient + ); + $result = $serviceM->insert($data); + } + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } + + return $result; + } + + /** + * Set a User in a Service + * @param string $login + * @param string $code + * @throws SoapFault + * @return int + */ + public function setUtilisateurService($login, $code) + { + $this->authenticate(); + + if ($this->tabInfoUser['profil']!='SuperAdministrateur') { + $this->sendError('0902'); + } + + //Connect to the database + try { + $db = Zend_Db::factory($this->dbConfig->db->sdv1); + $db->getConnection(); + } catch (Zend_Db_Adapter_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } catch (Zend_Exception $e) { + throw new SoapFault('ERR', "Application error"); + } + + try { + $serviceM = new Application_Model_Sdv1UtilisateursService(); + + //Check if code exist in idClient + $sql = $serviceM->select()->where('login=?',$login); + + $row = $serviceM->fetchAll($sql); + + if ($row->count()>0) { + $data = array( + 'serviceCode' => $label, + ); + $result = $serviceM->update($data, array('login'=>$login)); + } else { + $data = array( + 'login' => $login, + 'serviceCode' => $code, + ); + $result = $serviceM->insert($data); + } + } catch (Zend_Db_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } + + return $result; + } + + /** + * List Services + * @param int $idClient + * @throws SoapFault + * @return Service + */ + public function getServices($idClient) + { + $this->authenticate(); + + if ($this->tabInfoUser['profil']!='SuperAdministrateur') { + $this->sendError('0902'); + } + + //Connect to the database + try { + $db = Zend_Db::factory($this->dbConfig->db->sdv1); + $db->getConnection(); + } catch (Zend_Db_Adapter_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } catch (Zend_Exception $e) { + throw new SoapFault('ERR', "Application error"); + } + + try { + $serviceM = new Application_Model_Sdv1ClientsServices(); + $sql = $serviceM->select()->where('idClient=?', $idClient); + $rows = $serviceM->fetchAll($sql); + } catch (Zend_Db_Adapter_Exception $e) { + if ($this->tabInfoUser['idClient']!=1) { + throw new SoapFault('ERR', "Application error"); + } else { + throw new SoapFault('ERR', $e->getMessage()); + } + } catch (Zend_Exception $e) { + throw new SoapFault('ERR', "Application error"); + } + + $output = array(); + if ($rows->count()>0) { + foreach($rows as $item) { + $service = new Service(); + $service->code = $item->code; + $service->label = $item->label; + + //Get logins + $userserviceM = new Application_Model_Sdv1UtilisateursService(); + $sql = $userserviceM->select()->where('code=?',$item->code); + $logins = $userserviceM->fetchAll($sql); + + if ($logins->count()>0) { + foreach($logins as $login) { + $service->login[] = $login; + } + } + $output[] = $service; + } + } + return $output; + } } \ No newline at end of file diff --git a/library/WsScore/Gestion/v0.3/Types.php b/library/WsScore/Gestion/v0.3/Types.php index 33322379..06e245ab 100644 --- a/library/WsScore/Gestion/v0.3/Types.php +++ b/library/WsScore/Gestion/v0.3/Types.php @@ -454,12 +454,6 @@ class ClientTarif */ public $service; - /** - * Identifiant de l'utilisateur - * @var string - */ - public $login; - /** * Type du forfait ('Unitaire'|'ForfaitLimit'|'ForfaitIllimit') * @var string @@ -553,3 +547,15 @@ class ClientPrestation /** @var string */ public $dateFin; } + +class Service +{ + /** @var string*/ + public $code; + + /** @var string*/ + public $label; + + /** @var string[]*/ + public $login; +} \ No newline at end of file