MDL-62589 dataprivacy: Add ability to resubmit a request
This commit is contained in:
@@ -158,8 +158,6 @@ class data_request extends persistent {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch completed data requests which are due to expire.
|
||||
*
|
||||
@@ -224,4 +222,66 @@ class data_request extends persistent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this request is in a state appropriate for reset/resubmission.
|
||||
*
|
||||
* Note: This does not check whether any other completed requests exist for this user.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_resettable() : bool {
|
||||
if (api::DATAREQUEST_TYPE_OTHERS == $this->get('type')) {
|
||||
// It is not possible to reset 'other' reqeusts.
|
||||
return false;
|
||||
}
|
||||
|
||||
$resettable = [
|
||||
api::DATAREQUEST_STATUS_APPROVED => true,
|
||||
api::DATAREQUEST_STATUS_REJECTED => true,
|
||||
];
|
||||
|
||||
return isset($resettable[$this->get('status')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this request is 'active'.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_active() : bool {
|
||||
$active = [
|
||||
api::DATAREQUEST_STATUS_APPROVED => true,
|
||||
];
|
||||
|
||||
return isset($active[$this->get('status')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject this request and resubmit it as a fresh request.
|
||||
*
|
||||
* Note: This does not check whether any other completed requests exist for this user.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function resubmit_request() : data_request {
|
||||
if ($this->is_active()) {
|
||||
$this->set('status', api::DATAREQUEST_STATUS_REJECTED)->save();
|
||||
}
|
||||
|
||||
if (!$this->is_resettable()) {
|
||||
throw new \moodle_exception('cannotreset', 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
$currentdata = $this->to_record();
|
||||
unset($currentdata->id);
|
||||
|
||||
$clone = api::create_data_request($this->get('userid'), $this->get('type'));
|
||||
$clone->set('comments', $this->get('comments'));
|
||||
$clone->set('dpo', $this->get('dpo'));
|
||||
$clone->set('requestedby', $this->get('requestedby'));
|
||||
$clone->save();
|
||||
|
||||
return $clone;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user