ImsLtiTool.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * ImsLtiTool
  5. *
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. */
  8. class ImsLtiTool
  9. {
  10. private $id;
  11. private $name;
  12. private $description;
  13. private $launchUrl;
  14. private $consumerKey;
  15. private $sharedSecret;
  16. private $customParams;
  17. public function getId()
  18. {
  19. return $this->id;
  20. }
  21. public function getName()
  22. {
  23. return $this->name;
  24. }
  25. public function getDescription()
  26. {
  27. return $this->description;
  28. }
  29. public function getLaunchUrl()
  30. {
  31. return $this->launchUrl;
  32. }
  33. public function getConsumerKey()
  34. {
  35. return $this->consumerKey;
  36. }
  37. public function getSharedSecret()
  38. {
  39. return $this->sharedSecret;
  40. }
  41. public function getCustomParams()
  42. {
  43. return $this->customParams;
  44. }
  45. public function setId($id)
  46. {
  47. $this->id = $id;
  48. return $this;
  49. }
  50. public function setName($name)
  51. {
  52. $this->name = $name;
  53. return $this;
  54. }
  55. public function setDescription($description)
  56. {
  57. $this->description = $description;
  58. return $this;
  59. }
  60. public function setLaunchUrl($launchUrl)
  61. {
  62. $this->launchUrl = $launchUrl;
  63. return $this;
  64. }
  65. public function setConsumerKey($consumerKey)
  66. {
  67. $this->consumerKey = $consumerKey;
  68. return $this;
  69. }
  70. public function setSharedSecret($sharedSecret)
  71. {
  72. $this->sharedSecret = $sharedSecret;
  73. return $this;
  74. }
  75. public function setCustomParams($customParams)
  76. {
  77. $this->customParams = $customParams;
  78. return $this;
  79. }
  80. public function save()
  81. {
  82. if (!empty($this->id)) {
  83. Database::update(
  84. ImsLtiPlugin::TABLE_TOOL,
  85. [
  86. 'name' => $this->name,
  87. 'description' => $this->description,
  88. 'launch_url' => $this->launchUrl,
  89. 'consumer_key' => $this->consumerKey,
  90. 'shared_secret' => $this->sharedSecret,
  91. 'custom_params' => $this->customParams
  92. ],
  93. ['id' => $this->id]
  94. );
  95. return;
  96. }
  97. $this->id = Database::insert(
  98. ImsLtiPlugin::TABLE_TOOL,
  99. [
  100. 'name' => $this->name,
  101. 'description' => $this->description,
  102. 'launch_url' => $this->launchUrl,
  103. 'consumer_key' => $this->consumerKey,
  104. 'shared_secret' => $this->sharedSecret,
  105. 'custom_params' => $this->customParams
  106. ]
  107. );
  108. }
  109. public static function fetch($id)
  110. {
  111. $result = Database::select(
  112. '*',
  113. ImsLtiPlugin::TABLE_TOOL,
  114. ['where' => [
  115. 'id = ?' => intval($id)
  116. ]],
  117. 'first'
  118. );
  119. if (empty($result)) {
  120. return null;
  121. }
  122. $tool = new self();
  123. $tool->id = $result['id'];
  124. $tool->name = $result['name'];
  125. $tool->description = $result['description'];
  126. $tool->launchUrl = $result['launch_url'];
  127. $tool->consumerKey = $result['consumer_key'];
  128. $tool->sharedSecret = $result['shared_secret'];
  129. $tool->customParams = $result['custom_params'];
  130. return $tool;
  131. }
  132. public static function fetchAll()
  133. {
  134. return Database::select(
  135. '*',
  136. ImsLtiPlugin::TABLE_TOOL
  137. );
  138. }
  139. public function parseCustomParams()
  140. {
  141. $strings = $this->customParams;
  142. $foo = explode('=', $strings);
  143. return [
  144. 'key' => 'custom_'.$foo[0],
  145. 'value' => $foo[1]
  146. ];
  147. }
  148. }