38 public static $SCOPE =
'https://purl.imsglobal.org/spec/lti-ts/scope/toolsetting';
45 private static $LEVEL_NAMES = array(
'ToolProxy' =>
'system',
46 'ToolProxyBinding' =>
'context',
72 if (is_a($source,
'ceLTIc\LTI\Platform')) {
75 $platform = $source->getPlatform();
77 parent::__construct($platform,
$endpoint);
80 $this->mediaType =
'application/vnd.ims.lti.v2.toolsettings.simple+json';
82 $this->mediaType =
'application/vnd.ims.lti.v2.toolsettings+json';
84 $this->source = $source;
85 $this->simple = $simple;
98 if ($mode === self::MODE_ALL_LEVELS) {
99 $parameter[
'bubble'] =
'all';
100 } elseif ($mode === self::MODE_DISTINCT_NAMES) {
101 $parameter[
'bubble'] =
'distinct';
103 $http = $this->
send(
'GET', $parameter);
106 } elseif ($this->simple) {
108 } elseif (isset($http->responseJson->{
'@graph'})) {
110 foreach ($http->responseJson->{
'@graph'} as $level) {
112 unset($settings[
'@id']);
113 $response[self::$LEVEL_NAMES[$level->{
'@type'}]] = $settings;
127 public function set($settings)
129 if (!$this->simple) {
130 if (is_a($this->source,
'Platform')) {
132 } elseif (is_a($this->source,
'Context')) {
133 $type =
'ToolProxyBinding';
137 $obj = new \stdClass();
138 $obj->{
'@context'} =
'http://purl.imsglobal.org/ctx/lti/v2/ToolSettings';
139 $obj->{
'@graph'} = array();
140 $level = new \stdClass();
141 $level->{
'@type'} = $type;
142 $level->{
'@id'} = $this->endpoint;
143 $level->{
'custom'} = $settings;
144 $obj->{
'@graph'}[] = $level;
145 $body = json_encode($obj);
147 $body = json_encode($settings);
150 $response = parent::send(
'PUT',
null, $body);
152 return $response->ok;
Class to represent a platform context.
Class to represent a platform resource link.
Class to implement a service.
send($method, $parameters=array(), $body=null)
Send a service request.
$endpoint
Service endpoint.
Class to implement utility methods.
static jsonDecode($str, $associative=false)
Decode a JSON string.