EnumValuesController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Sql;
  4. use PhpMyAdmin\CheckUserPrivileges;
  5. use PhpMyAdmin\Controllers\AbstractController;
  6. use PhpMyAdmin\ResponseRenderer;
  7. use PhpMyAdmin\Sql;
  8. use PhpMyAdmin\Template;
  9. use function __;
  10. use function strval;
  11. final class EnumValuesController extends AbstractController
  12. {
  13. /** @var Sql */
  14. private $sql;
  15. /** @var CheckUserPrivileges */
  16. private $checkUserPrivileges;
  17. public function __construct(
  18. ResponseRenderer $response,
  19. Template $template,
  20. Sql $sql,
  21. CheckUserPrivileges $checkUserPrivileges
  22. ) {
  23. parent::__construct($response, $template);
  24. $this->sql = $sql;
  25. $this->checkUserPrivileges = $checkUserPrivileges;
  26. }
  27. /**
  28. * Get possible values for enum fields during grid edit.
  29. */
  30. public function __invoke(): void
  31. {
  32. global $db, $table;
  33. $this->checkUserPrivileges->getPrivileges();
  34. $column = $_POST['column'];
  35. $currValue = $_POST['curr_value'];
  36. $values = $this->sql->getValuesForColumn($db, $table, $column);
  37. if ($values === null) {
  38. $this->response->addJSON('message', __('Error in processing request'));
  39. $this->response->setRequestStatus(false);
  40. return;
  41. }
  42. $dropdown = $this->template->render('sql/enum_column_dropdown', [
  43. 'values' => $values,
  44. 'selected_values' => [strval($currValue)],
  45. ]);
  46. $this->response->addJSON('dropdown', $dropdown);
  47. }
  48. }