40 private static $LEVEL_NAMES = array(
'ToolProxy' =>
'system',
41 'ToolProxyBinding' =>
'context',
67 if (is_a($source,
'ceLTIc\LTI\ToolConsumer')) {
70 $consumer = $source->getConsumer();
73 $mediaType =
'application/vnd.ims.lti.v2.toolsettings.simple+json';
75 $mediaType =
'application/vnd.ims.lti.v2.toolsettings+json';
77 parent::__construct($consumer,
$endpoint, $mediaType);
78 $this->source = $source;
79 $this->simple = $simple;
92 if ($mode === self::MODE_ALL_LEVELS) {
93 $parameter[
'bubble'] =
'all';
94 } elseif ($mode === self::MODE_DISTINCT_NAMES) {
95 $parameter[
'bubble'] =
'distinct';
97 $http = $this->
send(
'GET', $parameter);
100 } elseif ($this->simple) {
101 $response = json_decode($http->response,
true);
102 } elseif (isset($http->responseJson->{
'@graph'})) {
104 foreach ($http->responseJson->{
'@graph'} as $level) {
105 $settings = json_decode(json_encode($level->custom),
true);
106 unset($settings[
'@id']);
107 $response[self::$LEVEL_NAMES[$level->{
'@type'}]] = $settings;
121 public function set($settings)
123 if (!$this->simple) {
124 if (is_a($this->source,
'ToolConsumer')) {
126 } elseif (is_a($this->source,
'ToolConsumer')) {
127 $type =
'ToolProxyBinding';
131 $obj = new \stdClass();
132 $obj->{
'@context'} =
'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings';
133 $obj->{
'@graph'} = array();
134 $level = new \stdClass();
135 $level->{
'@type'} = $type;
136 $level->{
'@id'} = $this->endpoint;
137 $level->{
'custom'} = $settings;
138 $obj->{
'@graph'}[] = $level;
139 $body = json_encode($obj);
141 $body = json_encode($settings);
144 $response = parent::send(
'PUT',
null, $body);
146 return $response->ok;
$endpoint
Service endpoint.
Class to implement a service.
Class to represent a tool consumer context.
send($method, $parameters=array(), $body=null)
Send a service request.
Class to represent a tool consumer resource link.