PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/oms_user/modules/__interfaz_visualizacion/actions/actions.class.php

https://github.com/gaea/oms
PHP | 183 lines | 124 code | 29 blank | 30 comment | 3 complexity | 2bae83fd1d23cd733e853afc6d4564f7 MD5 | raw file
  1. <?php
  2. /**
  3. * interfaz_visualizacion actions.
  4. *
  5. * @package oms
  6. * @subpackage interfaz_visualizacion
  7. * @author Your name here
  8. * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
  9. */
  10. class interfaz_visualizacionActions extends sfActions
  11. {
  12. /**
  13. * Executes index action
  14. *
  15. * @param sfRequest $request A request object
  16. */
  17. public function executeIndex(sfWebRequest $request)
  18. {
  19. //$this->forward('default', 'module');
  20. //echo 'header("Cache-Control: no-cache, must-revalidate")';
  21. $this->valor = $this->getUser()->getAttribute('codigo_usuario');
  22. $this->crearCanalRSS($request);
  23. $this->crearCanalRSSCunia($request);
  24. }
  25. public function executePublicarMensaje(sfWebRequest $request)
  26. {
  27. //$codigo_usuario = 2;
  28. $codigo_usuario = $this->getUser()->getAttribute('codigo_usuario');
  29. $filename = "mensajes/".$codigo_usuario.".txt";
  30. //$filename = "/var/www/oms/web/mensajes/".$codigo_usuario.".txt";
  31. // infinite loop until the data file is not modified
  32. $lastmodif = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
  33. $currentmodif = filemtime($filename);
  34. while ($currentmodif <= $lastmodif) // check if the data file has been modified
  35. {
  36. usleep(10000); // sleep 10ms to unload the CPU
  37. clearstatcache();
  38. $currentmodif = filemtime($filename);
  39. }
  40. // return a json array
  41. $response = array();
  42. $response['msg'] = file_get_contents($filename);
  43. $response['timestamp'] = $currentmodif;
  44. flush();
  45. return $this->renderText(json_encode($response));
  46. }
  47. public function crearCanalRSSCunia(sfWebRequest $request)
  48. {
  49. try
  50. {
  51. $timeZone = new DateTimeZone('America/Bogota');
  52. $hoy = new DateTime("NOW", $timeZone);
  53. $hoy = $hoy->format('Y-m-d');
  54. $conexion = new Criteria();
  55. $conexion->add(ProgramacionCunaPeer::FECHA, $hoy);
  56. $programaciones = ProgramacionCunaPeer::doSelect($conexion);
  57. $file = fopen("rss/cunias.xml",'w');
  58. fwrite($file, "<?xml version=\"1.0\" ?>\n");
  59. fwrite($file, "<rss version=\"2.0\">\n");
  60. fwrite($file, "\t<channel>\n");
  61. fwrite($file, "\t\t<title>OMS</title>\n");
  62. fwrite($file, "\t\t<link>http://localhost/www/oms/web/oms_user.php/interfaz_cliente</link>\n");
  63. fwrite($file, "\t\t<description>Open Music Suscriptores...</description>\n");
  64. fwrite($file, "\t\t<image>\n");
  65. fwrite($file, "\t\t\t<url>http://localhost/www/oms/web/images/oms.png</url> \n");
  66. fwrite($file, "\t\t\t<link>http://localhost/www/oms/web/oms_user.php/interfaz_cliente</link> \n"); // ojo que esta url hay que cambiarla
  67. fwrite($file, "\t\t</image>\n");
  68. if($programaciones)
  69. {
  70. foreach($programaciones as $programacion)
  71. {
  72. fwrite($file, "\t\t<item>\n");
  73. $cunia = CuniaComercialPeer::retrieveByPK($programacion->getCuniaComercial());
  74. //fwrite($file, "\t\t\t".$temporal->getCancion()."\n");
  75. fwrite($file, "\t\t\t<title><![CDATA[".$cunia->getNombre()."]]></title>\n");
  76. fwrite($file, "\t\t\t<link>http://localhost/www/oms/web/".$cunia->getUrl()."</link>\n");
  77. fwrite($file, "\t\t\t<enclosure url=\"http://localhost/www/oms/web/".$cunia->getUrl()."\" length=\"".filesize("/home/legnardz/www/www/oms/web/".$cunia->getUrl())."\" type=\"audio/mpeg\" />\n");
  78. fwrite($file, "\t\t\t<description>\n");
  79. //fwrite($file, "\t\t\t\t<![CDATA[\n");
  80. fwrite($file, "Duracion: ".$cunia->getDuracion()."\n");
  81. //fwrite($file, "\t\t\t\t]]>\n");
  82. fwrite($file, "\t\t\t</description>\n");
  83. fwrite($file, "\t\t\t<pubDate>".$programacion->getFecha()." ".$programacion->getInicio()."</pubDate>\n");
  84. fwrite($file, "\t\t</item>\n");
  85. }
  86. }
  87. fwrite($file, "\t</channel>\n");
  88. fwrite($file, "</rss>\n");
  89. fclose($file);
  90. }
  91. catch (Exception $exception)
  92. {
  93. $salida= "({success: false, errors: { reason: 'Hubo una excepci&oacute;n al crear el canal rss para cunia ' , error: '".$exception->getMessage()."'}})";
  94. //return $this->renderText($salida);
  95. }
  96. $salida = "({success: true, mensaje:'El canal rss para cunia fue creado exitosamente'})";
  97. //return $this->renderText($salida);
  98. }
  99. public function crearCanalRSS(sfWebRequest $request)
  100. {
  101. try
  102. {
  103. //$codigo_usuario = 2;
  104. $codigo_usuario = $this->getUser()->getAttribute('codigo_usuario');
  105. $conexion = new Criteria();
  106. $conexion->addJoin(ProgramacionCancionPeer::CANCION, CancionPeer::CODIGO);
  107. $conexion->addJoin(ProgramacionCancionPeer::VENTA, VentaPeer::CODIGO);
  108. $conexion->add(VentaPeer::USUARIO, $codigo_usuario);
  109. $numero_canciones = ProgramacionCancionPeer::doCount($conexion);
  110. $programacion = ProgramacionCancionPeer::doSelect($conexion);
  111. $file = fopen("rss/".$codigo_usuario.".xml",'w');
  112. fwrite($file, "<?xml version=\"1.0\" ?>\n");
  113. fwrite($file, "<rss version=\"2.0\">\n");
  114. fwrite($file, "\t<channel>\n");
  115. fwrite($file, "\t\t<title>OMS</title>\n");
  116. fwrite($file, "\t\t<link>http://localhost/www/oms/web/oms_user.php/interfaz_cliente</link>\n");
  117. fwrite($file, "\t\t<description>Open Music Suscriptores...</description>\n");
  118. fwrite($file, "\t\t<image>\n");
  119. fwrite($file, "\t\t\t<url>http://localhost/www/oms/web/images/oms.png</url> \n");
  120. fwrite($file, "\t\t\t<link>http://localhost/www/oms/web/oms_user.php/interfaz_cliente</link> \n"); // ojo que esta url hay que cambiarla
  121. fwrite($file, "\t\t</image>\n");
  122. if($programacion)
  123. {
  124. foreach($programacion as $temporal)
  125. {
  126. fwrite($file, "\t\t<item>\n");
  127. $cancion = CancionPeer::retrieveByPk($temporal->getCancion());
  128. //fwrite($file, "\t\t\t".$temporal->getCancion()."\n");
  129. fwrite($file, "\t\t\t<title><![CDATA[".$cancion->getNombre()."]]></title>\n");
  130. fwrite($file, "\t\t\t<link>http://localhost/www/oms/web/".$cancion->getUrl()."</link>\n");
  131. fwrite($file, "\t\t\t<enclosure url=\"http://localhost/www/oms/web/".$cancion->getUrl()."\" length=\"".filesize("/home/legnardz/www/www/oms/web/".$cancion->getUrl())."\" type=\"audio/mpeg\" />\n");
  132. fwrite($file, "\t\t\t<description>\n");
  133. //fwrite($file, "\t\t\t\t<![CDATA[\n");
  134. fwrite($file, "\t\t\t\t\tAlbum: ".$cancion->getAlbum()."\n");
  135. fwrite($file, "Duracion: ".$cancion->getDuracion()."\n");
  136. //fwrite($file, "\t\t\t\t]]>\n");
  137. fwrite($file, "\t\t\t</description>\n");
  138. fwrite($file, "\t\t\t<pubDate>".$temporal->getFecha()." ".$temporal->getInicio()."</pubDate>\n");
  139. fwrite($file, "\t\t</item>\n");
  140. }
  141. }
  142. fwrite($file, "\t</channel>\n");
  143. fwrite($file, "</rss>\n");
  144. fclose($file);
  145. }
  146. catch (Exception $exception)
  147. {
  148. $salida= "({success: false, errors: { reason: 'Hubo una excepci&oacute;n al crear el canal rss ' , error: '".$exception->getMessage()."'}})";
  149. //return $this->renderText($salida);
  150. }
  151. $salida = "({success: true, mensaje:'El canal rss fue creado exitosamente'})";
  152. //return $this->renderText($salida);
  153. }
  154. }