1
0

TitleBasics.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2013-2020 Johannes 'Banana' Keßler
  5. *
  6. * https://www.bananas-playground.net
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  10. *
  11. * You should have received a copy of the
  12. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  13. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  14. */
  15. /**
  16. * Class TitleBasics
  17. * Import the data from imdb dataset title.basics.tsv
  18. */
  19. class TitleBasics extends TSVImport {
  20. /**
  21. * @inheritDoc
  22. */
  23. public function setup() {
  24. $this->_db_table_name = 'title_basics';
  25. $this->_db_table_crate_str = "CREATE TABLE `".$this->_db_table_name."` (
  26. `tconst` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  27. `titleType` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  28. `primaryTitle` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  29. `originalTitle` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  30. `isAdult` tinyint(1) NOT NULL,
  31. `startYear` char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  32. `endYear` char(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  33. `runtimeMinutes` int NOT NULL,
  34. `genres` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  35. UNIQUE KEY `tconst` (`tconst`)
  36. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin";
  37. if($this->_createFulltext) {
  38. $this->_db_table_after_import_query[] = "ALTER TABLE `" . $this->_db_table_name . "` ADD FULLTEXT (`primaryTitle`)";
  39. $this->_db_table_after_import_query[] = "ALTER TABLE `" . $this->_db_table_name . "` ADD FULLTEXT (`originalTitle`)";
  40. $this->_db_table_after_import_query[] = "OPTIMIZE TABLE `" . $this->_db_table_name . "`";
  41. }
  42. }
  43. /**
  44. * @inheritDoc
  45. */
  46. public function queryValuePart($data) {
  47. $ret = '';
  48. if(!empty($data)) {
  49. if(!isset($data[8])) {
  50. return $ret;
  51. }
  52. $ret .= "(
  53. '".$this->_DB->real_escape_string($data[0])."',
  54. '".$this->_DB->real_escape_string($data[1])."',
  55. '".$this->_DB->real_escape_string($data[2])."',
  56. '".$this->_DB->real_escape_string($data[3])."',
  57. '".$this->_DB->real_escape_string($data[4])."',
  58. '".$this->_DB->real_escape_string($data[5])."',
  59. '".$this->_DB->real_escape_string($data[6])."',
  60. '".$this->_DB->real_escape_string($data[7])."',
  61. '".$this->_DB->real_escape_string($data[8])."'
  62. )";
  63. }
  64. return $ret;
  65. }
  66. }