PageRenderTime 164ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/utilidades/GestionTematica.php

https://bitbucket.org/veroreinah/bookworm
PHP | 198 lines | 152 code | 37 blank | 9 comment | 19 complexity | c1ccf0ae4e9b55b25902dfa067ee35ed MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. require_once 'conexion.php';
  3. require_once 'clases/Tematica.php';
  4. /*
  5. * To change this template, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8. /**
  9. * Description of GestionCitas
  10. *
  11. * @author Vero
  12. */
  13. class GestionTematica {
  14. public static function crearTematica($tematica) {
  15. global $conexion;
  16. $t = new Tematica();
  17. $t = $tematica;
  18. try {
  19. $query = "insert into t_tematica
  20. (descripcion_tematica)
  21. values ('" . $t->getDescripcion() . "')";
  22. $result = mysql_query($query, $conexion);
  23. $_SESSION["insertada"] = "La temática se ha insertado con éxito.";
  24. return mysql_insert_id($conexion);
  25. } catch (Exception $e) {
  26. $_SESSION["error"] = "No se ha podido crear la nueva temática. Inténtelo de nuevo más tarde.";
  27. }
  28. }
  29. public static function modificarTematica($tematica) {
  30. global $conexion;
  31. $t = new Tematica();
  32. $t = $tematica;
  33. try {
  34. $query = "update t_tematica
  35. set descripcion_tematica = '" . $t->getDescripcion() . "'
  36. where id_tematica = '" . $t->getId() . "'";
  37. $result = mysql_query($query, $conexion);
  38. return mysql_affected_rows();
  39. } catch (Exception $e) {
  40. $_SESSION["error"] = "No se ha podido modificar la temática. Inténtelo de nuevo más tarde.";
  41. }
  42. }
  43. public static function eliminarTematica($id) {
  44. global $conexion;
  45. try {
  46. $query = "delete from t_tematica
  47. where id_tematica = '" . $id . "'";
  48. $result = mysql_query($query, $conexion);
  49. return mysql_affected_rows();
  50. } catch (Exception $e) {
  51. $_SESSION["error"] = "No se ha podido eliminar la temática. Inténtelo de nuevo más tarde.";
  52. }
  53. }
  54. public static function totalTematicas() {
  55. global $conexion;
  56. try {
  57. $query = "select count(*) as total
  58. from t_tematica";
  59. $result = mysql_query($query, $conexion);
  60. $row = mysql_fetch_array($result);
  61. $total = $row["total"];
  62. return $total;
  63. } catch (Exception $e) {
  64. $_SESSION["error"] = "No se han podido recuperar las temáticas. Inténtelo de nuevo más tarde.";
  65. }
  66. }
  67. public static function totalFiltered($where) {
  68. global $conexion;
  69. if ($where != "") {
  70. $w = " where descripcion_tematica like '%$where%' ";
  71. }
  72. try {
  73. $query = "select count(*) as total
  74. from t_tematica
  75. $w";
  76. $result = mysql_query($query, $conexion);
  77. $row = mysql_fetch_array($result);
  78. $total = $row["total"];
  79. return $total;
  80. } catch (Exception $e) {
  81. $_SESSION["error"] = "No se han podido recuperar las temáticas. Inténtelo de nuevo más tarde.";
  82. }
  83. }
  84. public static function recuperarTematicasL($begin, $limit, $field, $order, $where) {
  85. global $conexion;
  86. $tematicas = array();
  87. if ($begin != "" && $limit != "") {
  88. $l = " limit $begin, $limit ";
  89. }
  90. if ($field != "" && $order != "") {
  91. $orderBy = " order by $field $order ";
  92. }
  93. if ($where != "") {
  94. $w = " where descripcion_tematica like '%$where%' ";
  95. }
  96. try {
  97. $query = "select *
  98. from t_tematica";
  99. if (isset($w)) {
  100. $query = $query . $w;
  101. }
  102. if (isset($orderBy)) {
  103. $query = $query . $orderBy;
  104. }
  105. if (isset($l)) {
  106. $query = $query . $l;
  107. }
  108. $result = mysql_query($query, $conexion);
  109. while($row = mysql_fetch_array($result)) {
  110. $tematica = new Tematica();
  111. $tematica->setId($row["id_tematica"]);
  112. $tematica->setDescripcion($row["descripcion_tematica"]);
  113. $tematicas[] = $tematica;
  114. }
  115. return $tematicas;
  116. } catch (Exception $e) {
  117. $_SESSION["error"] = "No se han podido recuperar las temáticas. Inténtelo de nuevo más tarde.";
  118. }
  119. }
  120. public static function recuperarTematicas() {
  121. global $conexion;
  122. $tematicas = array();
  123. try {
  124. $query = "select *
  125. from t_tematica
  126. order by descripcion_tematica";
  127. $result = mysql_query($query, $conexion);
  128. while($row = mysql_fetch_array($result)) {
  129. $tematica = new Tematica();
  130. $tematica->setId($row["id_tematica"]);
  131. $tematica->setDescripcion($row["descripcion_tematica"]);
  132. $tematicas[] = $tematica;
  133. }
  134. if ($tematicas != null && count($tematicas) > 0) {
  135. } else {
  136. $_SESSION["noHay"] = "No existe ninguna temática en BookWorm.";
  137. }
  138. return $tematicas;
  139. } catch (Exception $e) {
  140. $_SESSION["error"] = "No se han podido recuperar las temáticas. Inténtelo de nuevo más tarde.";
  141. }
  142. }
  143. public static function recuperarTematica($id) {
  144. global $conexion;
  145. try {
  146. $query = "select *
  147. from t_tematica
  148. where id_tematica = $id";
  149. $result = mysql_query($query, $conexion);
  150. while($row = mysql_fetch_array($result)) {
  151. $tematica = new Tematica();
  152. $tematica->setId($row["id_tematica"]);
  153. $tematica->setDescripcion($row["descripcion_tematica"]);
  154. return $tematica;
  155. }
  156. } catch (Exception $e) {
  157. $_SESSION["error"] = "No se han podido recupera la temática. Inténtelo de nuevo más tarde.";
  158. }
  159. }
  160. }
  161. ?>