pali_text.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. require_once "../path.php";
  3. require_once "../db/table.php";
  4. class PaliText extends Table
  5. {
  6. function __construct($redis=false) {
  7. parent::__construct(_FILE_DB_PALITEXT_, "pali_text", "", "",$redis);
  8. }
  9. public function getTitle($book,$para)
  10. {
  11. if (isset($book) && isset($para)) {
  12. if($this->redis!==false){
  13. $title = $this->redis->hGet("para_title://pali","{$book}-{$para}");
  14. if($title!==FALSE){
  15. return $title;
  16. }
  17. }
  18. $title="";
  19. $query = "select * from pali_text where book = ? and paragraph = ?";
  20. $stmt = $this->dbh->prepare($query);
  21. $stmt->execute(array($book,$para));
  22. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  23. if ($result) {
  24. if($result["level"]>0 && $result["level"]<8){
  25. $title= $result["toc"];
  26. }
  27. else{
  28. $query = "select * from pali_text where book = ? and paragraph = ?";
  29. $stmt = $this->dbh->prepare($query);
  30. $stmt->execute(array($book,$result["parent"]));
  31. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  32. if ($result) {
  33. $title= $result["toc"];
  34. }
  35. else{
  36. $title= "";
  37. }
  38. }
  39. } else {
  40. $title= "";
  41. }
  42. if($this->redis){
  43. $this->redis->hSet("para_title://pali","{$book}-{$para}",$title);
  44. }
  45. return $title;
  46. } else {
  47. $title= "";
  48. }
  49. }
  50. }
  51. ?>