pali_text.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. require_once "../config.php";
  3. require_once "../db/table.php";
  4. class PaliText extends Table
  5. {
  6. function __construct($redis=false) {
  7. parent::__construct(_FILE_DB_PALITEXT_, _TABLE_PALI_TEXT_, "", "",$redis);
  8. }
  9. public function index(){
  10. $view = $_GET["view"];
  11. switch ($view) {
  12. case 'toc':
  13. # code...
  14. $book = $_GET["book"];
  15. $par = $_GET["par"];
  16. do {
  17. # code...
  18. $parent = $this->medoo->get(
  19. $this->table,
  20. ["parent","paragraph","chapter_len","next_chapter","prev_chapter"],
  21. ["book"=>$book,"paragraph"=>$par]
  22. );
  23. $par = $parent["parent"];
  24. } while ($parent["parent"] > -1);
  25. $this->_index(["book","paragraph","level","toc","next_chapter","prev_chapter","parent"],
  26. ["level[<]"=>8,
  27. "book"=>$book,
  28. "paragraph[>]"=>$parent["paragraph"],
  29. "paragraph[<]"=>$parent["paragraph"]+$parent["chapter_len"],
  30. "ORDER"=>[
  31. "paragraph"=>"ASC"
  32. ]
  33. ]);
  34. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  35. break;
  36. default:
  37. # code...
  38. break;
  39. }
  40. }
  41. public function show(){
  42. $output = $this->medoo->get(
  43. $this->table,
  44. ["book","paragraph","level","toc","text"],
  45. ["book"=>$_GET["book"],"paragraph"=>$_GET["par"]]
  46. );
  47. if($this->medoo->error){
  48. $this->result["ok"]=false;
  49. $this->result["message"]=$this->medoo->error;
  50. }else{
  51. $this->result["data"] = $output;
  52. }
  53. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  54. }
  55. public function getTitle($book,$para)
  56. {
  57. if (isset($book) && isset($para)) {
  58. if($this->redis!==false){
  59. $title = $this->redis->hGet("para_title://pali","{$book}-{$para}");
  60. if($title!==FALSE){
  61. return $title;
  62. }
  63. }
  64. $title="";
  65. $query = "SELECT * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ?";
  66. $stmt = $this->dbh->prepare($query);
  67. $stmt->execute(array($book,$para));
  68. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  69. if ($result) {
  70. if($result["level"]>0 && $result["level"]<8){
  71. $title= $result["toc"];
  72. }
  73. else{
  74. $query = "SELECT * from "._TABLE_PALI_TEXT_." where book = ? and paragraph = ?";
  75. $stmt = $this->dbh->prepare($query);
  76. $stmt->execute(array($book,$result["parent"]));
  77. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  78. if ($result) {
  79. $title= $result["toc"];
  80. }
  81. else{
  82. $title= "";
  83. }
  84. }
  85. } else {
  86. $title= "";
  87. }
  88. if($this->redis){
  89. $this->redis->hSet("para_title://pali","{$book}-{$para}",$title);
  90. }
  91. return $title;
  92. } else {
  93. $title= "";
  94. }
  95. }
  96. }
  97. ?>