ExpertManager.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace AdminAddonUserManager\Users;
  3. use Grav\Common\Grav;
  4. use Grav\Plugin\AdminAddonUserManagerPlugin;
  5. use Grav\Common\Assets;
  6. use RocketTheme\Toolbox\Event\Event;
  7. use AdminAddonUserManager\Manager as IManager;
  8. use Grav\Common\User\User;
  9. use Grav\Common\Data\Blueprints;
  10. class ExpertManager implements IManager {
  11. private $grav;
  12. private $plugin;
  13. public static $instance;
  14. public function __construct(Grav $grav, AdminAddonUserManagerPlugin $plugin) {
  15. $this->grav = $grav;
  16. $this->plugin = $plugin;
  17. self::$instance = $this;
  18. }
  19. /**
  20. * Returns the required permission to access the manager
  21. *
  22. * @return string
  23. */
  24. public function getRequiredPermission() {
  25. return $this->plugin->name . '.users_expert';
  26. }
  27. /**
  28. * Returns the location of the manager
  29. * It will be accessible at this path
  30. *
  31. * @return string
  32. */
  33. public function getLocation() {
  34. return 'user-expert';
  35. }
  36. /**
  37. * Returns the plugin hooked nav array
  38. *
  39. * @return array
  40. */
  41. public function getNav() {
  42. return false;
  43. }
  44. /**
  45. * Initialiaze required assets
  46. *
  47. * @param \Grav\Common\Assets $assets
  48. * @return void
  49. */
  50. public function initializeAssets(Assets $assets) {
  51. $assets->addCss('plugin://admin/themes/grav/css/codemirror/codemirror.css');
  52. }
  53. /**
  54. * Handle task requests
  55. *
  56. * @param \RocketTheme\Toolbox\Event\Event $event
  57. * @return boolean
  58. */
  59. public function handleTask(Event $event) {}
  60. /**
  61. * Logic of the manager goes here
  62. *
  63. * @return array The array to be merged to Twig vars
  64. */
  65. public function handleRequest() {
  66. $vars = [];
  67. $twig = $this->grav['twig'];
  68. $uri = $this->grav['uri'];
  69. $username = $uri->paths()[2];
  70. $user = $this->grav['accounts']->load($username);
  71. if (isset($_POST['raw'])) {
  72. $user->file()->raw($_POST['raw']);
  73. $user->file()->save();
  74. }
  75. $vars['raw'] = $user->file()->raw();
  76. $vars['user'] = $user;
  77. $blueprints = new Blueprints;
  78. $vars['blueprint'] = $blueprints->get('user/account-raw');
  79. return $vars;
  80. }
  81. }