Advertisement
Guest User

Pub\Controller\Username.php

a guest
Jan 24th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. namespace apathy\UsernameStyles\Pub\Controller;
  4.  
  5. class Username extends \XF\Pub\Controller\AbstractController
  6. {
  7. public function actionIndex()
  8. {
  9.  
  10. $repo = $this->repository('apathy\UsernameStyles:Styles');
  11.  
  12. $finder = $repo->findUsernameStyle();
  13. $userStyle = $finder->fetch();
  14.  
  15. $viewParams = [
  16. 'style' => $userStyle
  17. ];
  18.  
  19. if ($this->isPost())
  20. {
  21. $visitor = \XF::visitor();
  22.  
  23. if ($visitor->canEditProfile())
  24. {
  25. $this->usernameSettingsSave($visitor->user_id)->run();
  26. }
  27.  
  28. return $this->redirect($this->buildLink('account/username-settings'));
  29. }
  30. else
  31. {
  32. return $this->view('apathy\UsernameStyles:Username',
  33. 'ap_username_settings',
  34. $viewParams);
  35. }
  36. }
  37.  
  38. protected function usernameSettingsSave($userid)
  39. {
  40. $form = $this->formAction();
  41.  
  42. $input = $this->filter([
  43. 'bold' => 'int',
  44. 'color' => 'str',
  45. 'glow' => 'str',
  46. 'sparkle' => 'int'
  47. ]);
  48.  
  49. $entity = $this->finder('apathy\UsernameStyles:Username')
  50. ->where('user_id', $userid)
  51. ->fetchOne();
  52.  
  53. if(!$entity)
  54. {
  55. $input['user_id'] = $userid;
  56.  
  57. $entity = $this->em()->create('apathy\UsernameStyles:Username');
  58. }
  59.  
  60. $form->basicEntitySave($entity, $input);
  61.  
  62. return $form;
  63. }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement