/src/Nexity/WebServicesBundle/Controller/StudeaWSController.php
PHP | 369 lines | 236 code | 70 blank | 63 comment | 26 complexity | 889cbef7e1a0fdb0759160cc4a051729 MD5 | raw file
Possible License(s): Apache-2.0
- <?php
- namespace Nexity\WebServicesBundle\Controller;
- use Nexity\WebServicesBundle\Soap\Type\DossierList;
- use Symfony\Component\HttpFoundation\Request;
- use Nexity\CoreBundle\Controller\BaseController;
- use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Nexity\WebServicesBundle\SoapDataBuilder\SoapDataBuilder;
- use Nexity\WebServicesBundle\Soap\Type\DossierStatus;
- use Nexity\WebServicesBundle\Soap\Type\Document;
- use Nexity\WebServicesBundle\Soap\Type\DocumentList;
- class StudeaWSController extends BaseController
- {
- const maxLocataires = 2;
- const maxGarants = 4;
- public function testWSAction(Request $request)
- {
- // Set to disable caching of the wsdl file
- ini_set('soap.wsdl_cache_enabled', false);
- ini_set('soap.wsdl_cache_ttl', false);
- $soapOptions = array(
- 'encoding' => 'ISO-8859-1',
- 'trace' => 1,
- 'exceptions' => 1,
- 'cache_wsdl' => null,
- );
- $client = new \SoapClient('http://10.nexity.fr/app_dev.php/ws/Studea', $soapOptions);
- try {
- $detailDocs = $client->integrationDocument(1) ;
- header("Content-Type:text/xml; charset=utf-8'");
- echo $client->__getLastResponse();
- exit;
- } catch (\SoapFault $fault) {
- header("Content-Type:text/xml; charset=utf-8'");
- echo $client->__getLastResponse();
- exit;
- }
- }
- public function testGetNouvDossAction(Request $request)
- {
- // Set to disable caching of the wsdl file
- ini_set('soap.wsdl_cache_enabled', false);
- ini_set('soap.wsdl_cache_ttl', false);
-
- $context = stream_context_create(
- array(
- 'ssl' => array(
- 'verify_peer' => false,
- ),
- 'http' => array(
- 'proxy' => 'proxy01.nexity.net:8080'
- ),
- )
- );
- $soapOptions = array(
- // 'stream_context' => $context,
- 'encoding' => 'ISO-8859-1',
- 'trace' => 1,
- 'exceptions' => 1,
- 'cache_wsdl' => null,
- );
- if (strtolower($this->getParameter('srv_env')) == 'local') {
- $client = new \SoapClient('http://127.nexity/app_dev.php/ws/Studea', $soapOptions);
- //$client = new \SoapClient('http://wwwq.nexity-studea.com/WSStudea/StudeaService.php?wsdl', $soapOptions);
- } else {
- exit;
- }
- try {
- $nouveauxDossiers = $client->getNouveauxDossiers(0);
- echo '$nouveauxDossiers<pre>'; print_r($nouveauxDossiers);echo '</pre>';
- $detailsDossier = $client->getDetailDossier('Z-92');//$nouveauxDossiers->item[0]->NumeroDossier);
- echo '$detailsDossier<pre>'; print_r($detailsDossier);echo '</pre>';
- //header("Content-Type:text/xml; charset=utf-8'");
- echo $client->__getLastResponse();
- } catch (\SoapFault $fault) {
- //header("Content-Type:text/xml; charset=utf-8'");
- echo $client->__getLastResponse();
- }
- // $detailsDossier = $client->getDetailDossier($nouveauxDossiers->item[0]->NumeroDossier);
- // echo '$detailsDossier<pre>'; print_r($detailsDossier);echo '</pre>';
-
- // $retourIntegration = $client->integrationDossier($nouveauxDossiers->item[0]->NumeroDossier);
- // echo '$retourIntegration<pre>'; var_dump($retourIntegration);echo '</pre>';
- // $dossierResidence = $client->getDossiersResidence('PO0000004');
- // echo '$dossierResidence<pre>'; print_r($dossierResidence);echo '</pre>';
-
- // $updateDossier = new DossierStatus();
- // $updateDossier->setDossierNo('I-89');
- // $updateDossier->setDossierNewStatusId(3);
- // $updateStatutDossier = $client->updateStatutDossier($updateDossier);
- // echo '$updateStatutDossier<pre>'; print_r($updateStatutDossier);echo '</pre>';
- exit;
- }
- /**
- * @Soap\Method("getNouveauxDossiers")
- * @Soap\Param("aPartirDeID", phpType = "int")
- * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\NouveauDossier[]")
- */
- function getNouveauxDossiers($aPartirDeID)
- {
- $dossierRepo = $this->getDoctrine()->getManager()->getRepository('StudeaDossierLocationBundle:StudeaDossier');
- if($aPartirDeID && $aPartirDeID > 0) {
- $query = $dossierRepo->createQueryBuilder('sd')
- ->select('sd.id, sd.numeroDossier, sd.dateCreation')
- ->where('sd.id > :idParam')
- ->setParameter('idParam', $aPartirDeID)
- ->getQuery();
- } else {
- $query = $dossierRepo->createQueryBuilder('sd')
- ->select('sd.id, sd.numeroDossier, sd.dateCreation')
- ->where('sd.isSent = 0')
- ->getQuery();
- }
- $dossiers = $query->getResult();
- if ($dossiers) {
- $soapDataBuilder = new SoapDataBuilder();
- return $soapDataBuilder->buildArrayOfNouveauDossier($dossiers);
- }
- return array();
- }
- /**
- * @Soap\Method("getDetailDossier")
- * @Soap\Param("noDossier", phpType = "string")
- * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\Dossier")
- */
- function getDetailDossier($noDossier)
- {
- if ($noDossier) {
- $em = $this->getDoctrine()->getManager();
- $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
- $locataireRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaLocataire');
- $garantRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaGarant');
- $dossier = $dossierRepo->findOneByNumeroDossier($noDossier);
- if ($dossier) {
- // Récupération des garants
- $arrayOfGarant = array();
- for ($iG = 1; $iG <= self::maxGarants; $iG++) {
- $methodG = "getIdGarant" . $iG;
- if ($dossier->$methodG() != 0) {
- $arrayOfGarant[] = $garantRepo->find($dossier->$methodG());
- }
- }
- // Récupération des locataires
- $arrayOfLocataire = array();
- for ($iL = 1; $iL <= self::maxLocataires; $iL++) {
- $methodL = "getIdLocataire" . $iL;
- if ($dossier->$methodL() != 0) {
- $arrayOfLocataire[] = $locataireRepo->find($dossier->$methodL());
- }
- }
- $soapDataBuilder = new SoapDataBuilder();
- return $soapDataBuilder->buildSoapDossier($dossier, $arrayOfGarant, $arrayOfLocataire);
- }
- throw new \SoapFault('Server', 'dossier ' . $dossier . ' not found');
- }
- throw new \SoapFault('Server', 'noDossier is not set');
- }
- /**
- * @Soap\Method("integrationDossier")
- * @Soap\Param("noDossier", phpType = "string")
- * @Soap\Result(phpType = "boolean")
- */
- function integrationDossier($noDossier)
- {
- if ($noDossier) {
- $em = $this->getDoctrine()->getManager();
- $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
- $dossier = $dossierRepo->findOneByNumeroDossier($noDossier);
- if ($dossier) {
- $dossier->setIsSent(1);
- $dossier->setDateSend(date('Y-m-d'));
- $em->flush();
- return true;
- }
- throw new \SoapFault('Server', 'noDossier not found');
- }
- throw new \SoapFault('Server', 'noDossier is not set');
- }
- /**
- * @Soap\Method("getDossiersResidence")
- * @Soap\Param("refResidence", phpType = "string")
- * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DossierSearchResult[]")
- */
- public function getDossiersResidence($refResidence)
- {
- if ($refResidence) {
- $dossierRepo = $this->getDoctrine()->getManager()->getRepository(
- 'StudeaDossierLocationBundle:StudeaDossier'
- );
- $query = $dossierRepo->createQueryBuilder('sd')
- ->where('sd.residenceId = :refRes')
- ->setParameter('refRes', $refResidence)
- ->getQuery();
- $dossiers = $query->getResult();
- if ($dossiers) {
- $soapDataBuilder = new SoapDataBuilder();
- return $soapDataBuilder->buildArrayOfDossierSearchResult($dossiers);
- }
- return array();
- }
- throw new \SoapFault('Server', 'refResidence is not set');
- }
- /**
- * @Soap\Method("updateStatutDossier")
- * @Soap\Param("dossierStatus", phpType = "Nexity\WebServicesBundle\Soap\Type\DossierStatus")
- * @Soap\Result(phpType = "boolean")
- */
- public function updateStatutDossier($dossierStatus)
- {
- if ($dossierStatus->getDossierNo()) {
- $em = $this->getDoctrine()->getManager();
- $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
- $studeaDossier = $dossierRepo->findOneByNumeroDossier($dossierStatus->getDossierNo());
- if ($studeaDossier) {
- if ($studeaDossier->getEtat() != $dossierStatus->getDossierNewStatusId()) {
- $studeaDossier->setEtat($dossierStatus->getDossierNewStatusId());
- $em->flush();
- }
- return true;
- }
- }
- throw new \SoapFault('Server', 'dossier not found');
- }
- /* --------------------------------------------------
- * Ci-dessous, nouvelles fonctions pour les documents
- * -------------------------------------------------- */
- /**
- * @Soap\Method("getDossiersNouveauxDocuments")
- * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DossierList[]")
- */
- public function getDossiersNouveauxDocuments()
- {
- $docs = $this
- ->getManager()
- ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
- ->getDocumentList(0, '>');
- $data = array();
- if ($docs) {
- $keys = array();
- foreach ($docs as $doc) {
- $keys[$doc['dossier_id']] = $doc['dossier_id'];
- }
- foreach ($keys as $key) {
- $dossier = new DossierList();
- $dossier->setIDDossier($key);
- $data[] = $dossier;
- }
- }
- return $data;
- //throw new \SoapFault('Server', 'Aucun dossier');
- }
- /**
- * @Soap\Method("getDetailDocumentByDossier")
- * @Soap\Param("dossier_id", phpType = "int")
- * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DocumentList")
- */
- public function getDetailDocumentByDossierAction($dossier_id)
- {
- $docs = $this
- ->getManager()
- ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
- ->getDocumentList($dossier_id);
- $data = array();
- if ($docs) {
- foreach ($docs as $doc) {
- $document = new Document();
- $document->setId($doc['id']);
- $document->setIdDocAsterion($doc['idDoc']);
- $document->setFilename($doc['filename']);
- $document->setPieceId($doc['pieceId']);
- $document->setPersonneId($doc['personneId']);
- $document->setPersonneType($doc['className']);
- $data[] = $document;
- }
- }
- $documentList = new DocumentList();
- $documentList->setDocuments($data);
- return $documentList;
- //throw new \SoapFault('Server', 'Aucun document');
- }
- /**
- * @Soap\Method("integrationDocument")
- * @Soap\Param("id", phpType = "int")
- * @Soap\Result(phpType = "boolean")
- */
- public function integrationDocumentAction($id)
- {
- $document = $this
- ->getManager()
- ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
- ->find($id);
- if ($document) {
- $document->setIsSent(true);
- $em = $this->getManager();
- $em->persist($document);
- $em->flush();
- return true;
- }
- throw new \SoapFault('Server', 'idDoc is not set');
- }
- }