PageRenderTime 86ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Nexity/WebServicesBundle/Controller/StudeaWSController.php

https://bitbucket.org/wizzmedia/nexity-generateur
PHP | 369 lines | 236 code | 70 blank | 63 comment | 26 complexity | 889cbef7e1a0fdb0759160cc4a051729 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. namespace Nexity\WebServicesBundle\Controller;
  3. use Nexity\WebServicesBundle\Soap\Type\DossierList;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Nexity\CoreBundle\Controller\BaseController;
  6. use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
  7. use Symfony\Component\DependencyInjection\ContainerAware;
  8. use Nexity\WebServicesBundle\SoapDataBuilder\SoapDataBuilder;
  9. use Nexity\WebServicesBundle\Soap\Type\DossierStatus;
  10. use Nexity\WebServicesBundle\Soap\Type\Document;
  11. use Nexity\WebServicesBundle\Soap\Type\DocumentList;
  12. class StudeaWSController extends BaseController
  13. {
  14. const maxLocataires = 2;
  15. const maxGarants = 4;
  16. public function testWSAction(Request $request)
  17. {
  18. // Set to disable caching of the wsdl file
  19. ini_set('soap.wsdl_cache_enabled', false);
  20. ini_set('soap.wsdl_cache_ttl', false);
  21. $soapOptions = array(
  22. 'encoding' => 'ISO-8859-1',
  23. 'trace' => 1,
  24. 'exceptions' => 1,
  25. 'cache_wsdl' => null,
  26. );
  27. $client = new \SoapClient('http://10.nexity.fr/app_dev.php/ws/Studea', $soapOptions);
  28. try {
  29. $detailDocs = $client->integrationDocument(1) ;
  30. header("Content-Type:text/xml; charset=utf-8'");
  31. echo $client->__getLastResponse();
  32. exit;
  33. } catch (\SoapFault $fault) {
  34. header("Content-Type:text/xml; charset=utf-8'");
  35. echo $client->__getLastResponse();
  36. exit;
  37. }
  38. }
  39. public function testGetNouvDossAction(Request $request)
  40. {
  41. // Set to disable caching of the wsdl file
  42. ini_set('soap.wsdl_cache_enabled', false);
  43. ini_set('soap.wsdl_cache_ttl', false);
  44. $context = stream_context_create(
  45. array(
  46. 'ssl' => array(
  47. 'verify_peer' => false,
  48. ),
  49. 'http' => array(
  50. 'proxy' => 'proxy01.nexity.net:8080'
  51. ),
  52. )
  53. );
  54. $soapOptions = array(
  55. // 'stream_context' => $context,
  56. 'encoding' => 'ISO-8859-1',
  57. 'trace' => 1,
  58. 'exceptions' => 1,
  59. 'cache_wsdl' => null,
  60. );
  61. if (strtolower($this->getParameter('srv_env')) == 'local') {
  62. $client = new \SoapClient('http://127.nexity/app_dev.php/ws/Studea', $soapOptions);
  63. //$client = new \SoapClient('http://wwwq.nexity-studea.com/WSStudea/StudeaService.php?wsdl', $soapOptions);
  64. } else {
  65. exit;
  66. }
  67. try {
  68. $nouveauxDossiers = $client->getNouveauxDossiers(0);
  69. echo '$nouveauxDossiers<pre>'; print_r($nouveauxDossiers);echo '</pre>';
  70. $detailsDossier = $client->getDetailDossier('Z-92');//$nouveauxDossiers->item[0]->NumeroDossier);
  71. echo '$detailsDossier<pre>'; print_r($detailsDossier);echo '</pre>';
  72. //header("Content-Type:text/xml; charset=utf-8'");
  73. echo $client->__getLastResponse();
  74. } catch (\SoapFault $fault) {
  75. //header("Content-Type:text/xml; charset=utf-8'");
  76. echo $client->__getLastResponse();
  77. }
  78. // $detailsDossier = $client->getDetailDossier($nouveauxDossiers->item[0]->NumeroDossier);
  79. // echo '$detailsDossier<pre>'; print_r($detailsDossier);echo '</pre>';
  80. // $retourIntegration = $client->integrationDossier($nouveauxDossiers->item[0]->NumeroDossier);
  81. // echo '$retourIntegration<pre>'; var_dump($retourIntegration);echo '</pre>';
  82. // $dossierResidence = $client->getDossiersResidence('PO0000004');
  83. // echo '$dossierResidence<pre>'; print_r($dossierResidence);echo '</pre>';
  84. // $updateDossier = new DossierStatus();
  85. // $updateDossier->setDossierNo('I-89');
  86. // $updateDossier->setDossierNewStatusId(3);
  87. // $updateStatutDossier = $client->updateStatutDossier($updateDossier);
  88. // echo '$updateStatutDossier<pre>'; print_r($updateStatutDossier);echo '</pre>';
  89. exit;
  90. }
  91. /**
  92. * @Soap\Method("getNouveauxDossiers")
  93. * @Soap\Param("aPartirDeID", phpType = "int")
  94. * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\NouveauDossier[]")
  95. */
  96. function getNouveauxDossiers($aPartirDeID)
  97. {
  98. $dossierRepo = $this->getDoctrine()->getManager()->getRepository('StudeaDossierLocationBundle:StudeaDossier');
  99. if($aPartirDeID && $aPartirDeID > 0) {
  100. $query = $dossierRepo->createQueryBuilder('sd')
  101. ->select('sd.id, sd.numeroDossier, sd.dateCreation')
  102. ->where('sd.id > :idParam')
  103. ->setParameter('idParam', $aPartirDeID)
  104. ->getQuery();
  105. } else {
  106. $query = $dossierRepo->createQueryBuilder('sd')
  107. ->select('sd.id, sd.numeroDossier, sd.dateCreation')
  108. ->where('sd.isSent = 0')
  109. ->getQuery();
  110. }
  111. $dossiers = $query->getResult();
  112. if ($dossiers) {
  113. $soapDataBuilder = new SoapDataBuilder();
  114. return $soapDataBuilder->buildArrayOfNouveauDossier($dossiers);
  115. }
  116. return array();
  117. }
  118. /**
  119. * @Soap\Method("getDetailDossier")
  120. * @Soap\Param("noDossier", phpType = "string")
  121. * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\Dossier")
  122. */
  123. function getDetailDossier($noDossier)
  124. {
  125. if ($noDossier) {
  126. $em = $this->getDoctrine()->getManager();
  127. $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
  128. $locataireRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaLocataire');
  129. $garantRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaGarant');
  130. $dossier = $dossierRepo->findOneByNumeroDossier($noDossier);
  131. if ($dossier) {
  132. // Récupération des garants
  133. $arrayOfGarant = array();
  134. for ($iG = 1; $iG <= self::maxGarants; $iG++) {
  135. $methodG = "getIdGarant" . $iG;
  136. if ($dossier->$methodG() != 0) {
  137. $arrayOfGarant[] = $garantRepo->find($dossier->$methodG());
  138. }
  139. }
  140. // Récupération des locataires
  141. $arrayOfLocataire = array();
  142. for ($iL = 1; $iL <= self::maxLocataires; $iL++) {
  143. $methodL = "getIdLocataire" . $iL;
  144. if ($dossier->$methodL() != 0) {
  145. $arrayOfLocataire[] = $locataireRepo->find($dossier->$methodL());
  146. }
  147. }
  148. $soapDataBuilder = new SoapDataBuilder();
  149. return $soapDataBuilder->buildSoapDossier($dossier, $arrayOfGarant, $arrayOfLocataire);
  150. }
  151. throw new \SoapFault('Server', 'dossier ' . $dossier . ' not found');
  152. }
  153. throw new \SoapFault('Server', 'noDossier is not set');
  154. }
  155. /**
  156. * @Soap\Method("integrationDossier")
  157. * @Soap\Param("noDossier", phpType = "string")
  158. * @Soap\Result(phpType = "boolean")
  159. */
  160. function integrationDossier($noDossier)
  161. {
  162. if ($noDossier) {
  163. $em = $this->getDoctrine()->getManager();
  164. $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
  165. $dossier = $dossierRepo->findOneByNumeroDossier($noDossier);
  166. if ($dossier) {
  167. $dossier->setIsSent(1);
  168. $dossier->setDateSend(date('Y-m-d'));
  169. $em->flush();
  170. return true;
  171. }
  172. throw new \SoapFault('Server', 'noDossier not found');
  173. }
  174. throw new \SoapFault('Server', 'noDossier is not set');
  175. }
  176. /**
  177. * @Soap\Method("getDossiersResidence")
  178. * @Soap\Param("refResidence", phpType = "string")
  179. * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DossierSearchResult[]")
  180. */
  181. public function getDossiersResidence($refResidence)
  182. {
  183. if ($refResidence) {
  184. $dossierRepo = $this->getDoctrine()->getManager()->getRepository(
  185. 'StudeaDossierLocationBundle:StudeaDossier'
  186. );
  187. $query = $dossierRepo->createQueryBuilder('sd')
  188. ->where('sd.residenceId = :refRes')
  189. ->setParameter('refRes', $refResidence)
  190. ->getQuery();
  191. $dossiers = $query->getResult();
  192. if ($dossiers) {
  193. $soapDataBuilder = new SoapDataBuilder();
  194. return $soapDataBuilder->buildArrayOfDossierSearchResult($dossiers);
  195. }
  196. return array();
  197. }
  198. throw new \SoapFault('Server', 'refResidence is not set');
  199. }
  200. /**
  201. * @Soap\Method("updateStatutDossier")
  202. * @Soap\Param("dossierStatus", phpType = "Nexity\WebServicesBundle\Soap\Type\DossierStatus")
  203. * @Soap\Result(phpType = "boolean")
  204. */
  205. public function updateStatutDossier($dossierStatus)
  206. {
  207. if ($dossierStatus->getDossierNo()) {
  208. $em = $this->getDoctrine()->getManager();
  209. $dossierRepo = $em->getRepository('StudeaDossierLocationBundle:StudeaDossier');
  210. $studeaDossier = $dossierRepo->findOneByNumeroDossier($dossierStatus->getDossierNo());
  211. if ($studeaDossier) {
  212. if ($studeaDossier->getEtat() != $dossierStatus->getDossierNewStatusId()) {
  213. $studeaDossier->setEtat($dossierStatus->getDossierNewStatusId());
  214. $em->flush();
  215. }
  216. return true;
  217. }
  218. }
  219. throw new \SoapFault('Server', 'dossier not found');
  220. }
  221. /* --------------------------------------------------
  222. * Ci-dessous, nouvelles fonctions pour les documents
  223. * -------------------------------------------------- */
  224. /**
  225. * @Soap\Method("getDossiersNouveauxDocuments")
  226. * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DossierList[]")
  227. */
  228. public function getDossiersNouveauxDocuments()
  229. {
  230. $docs = $this
  231. ->getManager()
  232. ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
  233. ->getDocumentList(0, '>');
  234. $data = array();
  235. if ($docs) {
  236. $keys = array();
  237. foreach ($docs as $doc) {
  238. $keys[$doc['dossier_id']] = $doc['dossier_id'];
  239. }
  240. foreach ($keys as $key) {
  241. $dossier = new DossierList();
  242. $dossier->setIDDossier($key);
  243. $data[] = $dossier;
  244. }
  245. }
  246. return $data;
  247. //throw new \SoapFault('Server', 'Aucun dossier');
  248. }
  249. /**
  250. * @Soap\Method("getDetailDocumentByDossier")
  251. * @Soap\Param("dossier_id", phpType = "int")
  252. * @Soap\Result(phpType = "Nexity\WebServicesBundle\Soap\Type\DocumentList")
  253. */
  254. public function getDetailDocumentByDossierAction($dossier_id)
  255. {
  256. $docs = $this
  257. ->getManager()
  258. ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
  259. ->getDocumentList($dossier_id);
  260. $data = array();
  261. if ($docs) {
  262. foreach ($docs as $doc) {
  263. $document = new Document();
  264. $document->setId($doc['id']);
  265. $document->setIdDocAsterion($doc['idDoc']);
  266. $document->setFilename($doc['filename']);
  267. $document->setPieceId($doc['pieceId']);
  268. $document->setPersonneId($doc['personneId']);
  269. $document->setPersonneType($doc['className']);
  270. $data[] = $document;
  271. }
  272. }
  273. $documentList = new DocumentList();
  274. $documentList->setDocuments($data);
  275. return $documentList;
  276. //throw new \SoapFault('Server', 'Aucun document');
  277. }
  278. /**
  279. * @Soap\Method("integrationDocument")
  280. * @Soap\Param("id", phpType = "int")
  281. * @Soap\Result(phpType = "boolean")
  282. */
  283. public function integrationDocumentAction($id)
  284. {
  285. $document = $this
  286. ->getManager()
  287. ->getRepository('StudeaDossierLocationBundle:StudeaDocumentList')
  288. ->find($id);
  289. if ($document) {
  290. $document->setIsSent(true);
  291. $em = $this->getManager();
  292. $em->persist($document);
  293. $em->flush();
  294. return true;
  295. }
  296. throw new \SoapFault('Server', 'idDoc is not set');
  297. }
  298. }