BrowseForeignersController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Holds the PhpMyAdmin\Controllers\BrowseForeignersController
  5. *
  6. * @package PhpMyAdmin\Controllers
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Controllers;
  10. use PhpMyAdmin\BrowseForeigners;
  11. use PhpMyAdmin\DatabaseInterface;
  12. use PhpMyAdmin\Relation;
  13. use PhpMyAdmin\Response;
  14. use PhpMyAdmin\Template;
  15. /**
  16. * Display selection for relational field values
  17. *
  18. * @package PhpMyAdmin\Controllers
  19. */
  20. class BrowseForeignersController extends AbstractController
  21. {
  22. /**
  23. * @var BrowseForeigners
  24. */
  25. private $browseForeigners;
  26. /**
  27. * @var Relation
  28. */
  29. private $relation;
  30. /**
  31. * BrowseForeignersController constructor.
  32. *
  33. * @param Response $response Response instance
  34. * @param DatabaseInterface $dbi DatabaseInterface instance
  35. * @param Template $template Template object
  36. * @param BrowseForeigners $browseForeigners BrowseForeigners instance
  37. * @param Relation $relation Relation instance
  38. */
  39. public function __construct($response, $dbi, Template $template, $browseForeigners, $relation)
  40. {
  41. parent::__construct($response, $dbi, $template);
  42. $this->browseForeigners = $browseForeigners;
  43. $this->relation = $relation;
  44. }
  45. /**
  46. * @param array $params Request parameters
  47. * @return string HTML
  48. */
  49. public function index(array $params): string
  50. {
  51. $foreigners = $this->relation->getForeigners(
  52. $params['db'],
  53. $params['table']
  54. );
  55. $foreignLimit = $this->browseForeigners->getForeignLimit(
  56. $params['foreign_showAll']
  57. );
  58. $foreignData = $this->relation->getForeignData(
  59. $foreigners,
  60. $params['field'],
  61. true,
  62. $params['foreign_filter'] ?? '',
  63. $foreignLimit ?? null,
  64. true
  65. );
  66. return $this->browseForeigners->getHtmlForRelationalFieldSelection(
  67. $params['db'],
  68. $params['table'],
  69. $params['field'],
  70. $foreignData,
  71. $params['fieldkey'] ?? '',
  72. $params['data'] ?? ''
  73. );
  74. }
  75. }