Skip to content

Commit

Permalink
Rename AssessmentControl object to AssessmentControlAction
Browse files Browse the repository at this point in the history
Also add hasAssessmentControlService method to ResourceLink object
  • Loading branch information
spvickers committed Aug 3, 2021
1 parent 7f7ec53 commit ac71768
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright SPV Software Products
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3
*/
class AssessmentControl
class AssessmentControlAction
{

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,15 @@ protected function onAuthenticate()
*/
protected function onContentItem()
{
$this->onError();
}

/**
* Process a valid start assessment message
*/
protected function onLtiStartAssessment()
{
$this->onError();
}

/**
Expand Down
29 changes: 20 additions & 9 deletions src/ResourceLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,18 @@ public function hasResultService()
return $has;
}

/**
* Check if the Assessment Control service is available.
*
* @return bool True if this resource link supports the Assessment Control service
*/
public function hasAssessmentControlService()
{
$url = $this->getSetting('custom_ap_acs_url');

return !empty($url);
}

/**
* Perform an Outcomes service request.
*
Expand Down Expand Up @@ -1296,15 +1308,15 @@ public function getOutcomes($limit = null)
/**
* Perform an Assessment Control action.
*
* @param AssessmentControl $assessmentControl Assessment control object
* @param User $user User object
* @param int $attemptNumber Number of attempt
* @param AssessmentControlAction $assessmentControlAction Assessment control object
* @param User $user User object
* @param int $attemptNumber Number of attempt
*
* @return bool True if the request was successfully processed
* @return string|bool The response status or false if the request was not successfully processed
*/
public function doAssessmentControl($asessmentControl, $user, $attemptNumber)
public function doAssessmentControlAction($assessmentControlAction, $user, $attemptNumber)
{
$ok = false;
$status = false;
$this->extRequest = '';
$this->extRequestHeaders = '';
$this->extResponse = '';
Expand All @@ -1313,17 +1325,16 @@ public function doAssessmentControl($asessmentControl, $user, $attemptNumber)
$url = $this->getSetting('custom_ap_acs_url');
if (!empty($url)) {
$assessmentControlService = new Service\AssessmentControl($this, $url);
$assessmentControlService->submit($asessmentControl, $user, $attemptNumber);
$status = $assessmentControlService->submitAction($assessmentControlAction, $user, $attemptNumber);
$http = $assessmentControlService->getHttpMessage();
$this->extResponse = $http->response;
$this->extResponseHeaders = $http->responseHeaders;
$ok = $http->ok;
$this->extRequest = $http->request;
$this->extRequestHeaders = $http->requestHeaders;
$this->lastServiceRequest = $http;
}

return $ok;
return $status;
}

/**
Expand Down
37 changes: 22 additions & 15 deletions src/Service/AssessmentControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,42 @@ public function __construct($resourceLink, $endpoint)
/**
* Submit an assessment control action.
*
* @param LTI\AssessmentControl $assessmentControl AssessmentControl object
* @param LTI\User $user User object
* @param int $attemptNumber Attempt number
* @param LTI\AssessmentControlAction $assessmentControlAction AssessmentControlAction object
* @param LTI\User $user User object
* @param int $attemptNumber Attempt number
*
* @return bool True if successful, otherwise false
* @return string|bool Value of the status response, or false if not successful
*/
public function submit($assessmentControl, $user, $attemptNumber)
public function submitAction($assessmentControlAction, $user, $attemptNumber)
{
$status = false;
$json = array(
'user' => array('iss' => $this->resourceLink->getPlatform()->platformId, 'sub' => $user->ltiUserId),
'resource_link' => array('id' => $this->resourceLink->ltiResourceLinkId),
'attempt_number' => $attemptNumber,
'action' => $assessmentControl->getAction(),
'incident_time' => $assessmentControl->getDate()->format('Y-m-d\TH:i:s\Z'),
'incident_severity' => $assessmentControl->getSeverity()
'action' => $assessmentControlAction->getAction(),
'incident_time' => $assessmentControlAction->getDate()->format('Y-m-d\TH:i:s\Z'),
'incident_severity' => $assessmentControlAction->getSeverity()
);
if (!empty($assessmentControl->extraTime)) {
$json['extra_time'] = $assessmentControl->extraTime;
if (!empty($assessmentControlAction->extraTime)) {
$json['extra_time'] = $assessmentControlAction->extraTime;
}
if (!empty($assessmentControl->code)) {
$json['reason_code'] = $assessmentControl->code;
if (!empty($assessmentControlAction->code)) {
$json['reason_code'] = $assessmentControlAction->code;
}
if (!empty($assessmentControl->message)) {
$json['reason_msg'] = $assessmentControl->message;
if (!empty($assessmentControlAction->message)) {
$json['reason_msg'] = $assessmentControlAction->message;
}
$data = json_encode($json);
$http = $this->send('POST', null, $data);
if ($http->ok) {
$http->ok = !empty($http->responseJson->status);
if ($http->ok) {
$status = $http->responseJson->status;
}
}

return $http->ok;
return $status;
}

}

0 comments on commit ac71768

Please sign in to comment.