pali_text.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 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"],
  21. ["book"=>$book,"paragraph"=>$par]
  22. );
  23. $par = $parent["parent"];
  24. } while ($parent["parent"] > -1);
  25. $this->_index(["book","paragraph","level","toc","next_chapter","parent"],["level[<]"=>8,"book"=>$book,"paragraph[>]"=>$parent["paragraph"],"paragraph[<]"=>$parent["paragraph"]+$parent["chapter_len"]]);
  26. echo json_encode($this->result, JSON_UNESCAPED_UNICODE);
  27. break;
  28. default:
  29. # code...
  30. break;
  31. }
  32. }
  33. public function getTitle($book,$para)
  34. {
  35. if (isset($book) && isset($para)) {
  36. if($this->redis!==false){
  37. $title = $this->redis->hGet("para_title://pali","{$book}-{$para}");
  38. if($title!==FALSE){
  39. return $title;
  40. }
  41. }
  42. $title="";
  43. $query = "select * from pali_text where book = ? and paragraph = ?";
  44. $stmt = $this->dbh->prepare($query);
  45. $stmt->execute(array($book,$para));
  46. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  47. if ($result) {
  48. if($result["level"]>0 && $result["level"]<8){
  49. $title= $result["toc"];
  50. }
  51. else{
  52. $query = "select * from pali_text where book = ? and paragraph = ?";
  53. $stmt = $this->dbh->prepare($query);
  54. $stmt->execute(array($book,$result["parent"]));
  55. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  56. if ($result) {
  57. $title= $result["toc"];
  58. }
  59. else{
  60. $title= "";
  61. }
  62. }
  63. } else {
  64. $title= "";
  65. }
  66. if($this->redis){
  67. $this->redis->hSet("para_title://pali","{$book}-{$para}",$title);
  68. }
  69. return $title;
  70. } else {
  71. $title= "";
  72. }
  73. }
  74. }
  75. ?>