PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/app/LTIModule/presenters/InstallPresenter.php

https://bitbucket.org/svanda777/recodex-api-with-lti
PHP | 74 lines | 41 code | 12 blank | 21 comment | 2 complexity | d5245ae4d8e1cc858090cbceca9fc7b7 MD5 | raw file
  1. <?php
  2. namespace App\LTIModule\Presenters;
  3. use IMSGlobal\LTI\ToolProvider\ToolConsumer;
  4. use Nette\Application\UI\Form;
  5. /**
  6. * Class InstallPresenter
  7. *
  8. * Creates LTI v2 connection between TP and TC.
  9. *
  10. * @package App\LTIModule\Presenters
  11. */
  12. class InstallPresenter extends BasePresenter {
  13. /**
  14. * First communication between tool provider and consumer.
  15. */
  16. public function actionDefault() {
  17. }
  18. /**
  19. * Confirmation form for user.
  20. *
  21. * @return Form
  22. */
  23. protected function createComponentConfirmationForm() {
  24. $form = new Form();
  25. $form->addSubmit( 'confirm', 'Register' );
  26. $form->addSubmit( 'cancel', 'Cancel' )->setValidationScope( false )->onClick[] = [
  27. $this,
  28. 'confirmationFormCancel'
  29. ];
  30. $form->onSuccess[] = [
  31. $this,
  32. 'confirmationFormOnSucceeded'
  33. ];
  34. return $form;
  35. }
  36. /**
  37. * Send cancel request back to tool consumer.
  38. */
  39. public function confirmationFormCancel() {
  40. $url = $_SESSION['return_url'];
  41. $sep = strpos( $url, '?' ) === false ? '?' : '&';
  42. header( "Location: {$url}{$sep}lti_msg=The%20tool%20registration%20has%20been%20cancelled&status=failure" );
  43. exit;
  44. }
  45. /**
  46. * Confirm cooperation between TP and TC.
  47. */
  48. public function confirmationFormOnSucceeded() {
  49. $url = $_SESSION['return_url'];
  50. $sep = strpos( $url, '?' ) === false ? '?' : '&';
  51. $this->toolProvider->consumer = ToolConsumer::fromRecordId( $_SESSION['consumer_pk'], $this->dataConnector );
  52. $ok = $this->toolProvider->doToolProxyService( $_SESSION['tc_profile_url'] );
  53. if ( $ok ) {
  54. $guid = $this->toolProvider->consumer->getKey();
  55. header( "Location: {$url}{$sep}lti_msg=The%20tool%20has%20been%20registered&status=success&tool_proxy_guid={$guid}" );
  56. exit;
  57. } else {
  58. header( "Location: {$url}{$sep}lti_msg=Error%20setting%20tool%20proxy&status=failure" );
  59. exit;
  60. }
  61. }
  62. }