View source
<?php
function _submission_resource_definition() {
return array(
'submission' => array(
'retrieve' => array(
'callback' => 'webform_service_get_submission_by_uuid',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => 'The uuid of the submission.',
),
),
'access callback' => 'webform_service_submission_access',
'access arguments' => array(
'view',
),
'access arguments append' => TRUE,
),
'create' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/submission_resource',
),
'callback' => 'webform_service_submission_create',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'data' => 'webform',
),
'type' => 'string',
'description' => 'The uuid of the webform.',
),
array(
'name' => 'submission',
'optional' => FALSE,
'source' => array(
'data' => 'submission',
),
'description' => 'The submission data for this webform.',
'type' => 'array',
'default value' => array(),
),
),
'access callback' => 'webform_service_submission_access',
'access arguments' => array(
'create',
),
'access arguments append' => TRUE,
),
'update' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/submission_resource',
),
'callback' => 'webform_service_submission_update',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => 'The uuid of the submission.',
),
array(
'name' => 'submission',
'optional' => FALSE,
'source' => array(
'data' => 'submission',
),
'description' => 'The submission data to update',
'type' => 'array',
),
),
'access callback' => 'webform_service_submission_access',
'access arguments' => array(
'edit',
),
'access arguments append' => TRUE,
),
'delete' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/submission_resource',
),
'callback' => 'webform_service_submission_delete',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => 'The uuid of the submission.',
),
),
'access callback' => 'webform_service_submission_access',
'access arguments' => array(
'delete',
),
'access arguments append' => TRUE,
),
),
);
}
function webform_service_submission_create($uuid, $submission) {
$webform = webform_service_resource_load($uuid);
if ($webform && $submission) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$sid = webform_submission_insert($webform, webform_service_parse_submission($webform, $submission));
return webform_service_get_submission($webform, webform_get_submission($webform->nid, $sid, TRUE));
}
else {
return FALSE;
}
}
function webform_service_submission_update($uuid, $submission) {
$webform = webform_submission_uuid_webform($uuid);
$current_submission = webform_submission_uuid_get_submission($uuid);
if ($webform && $current_submission) {
foreach ($current_submission as $key => $value) {
if ($key == 'data') {
foreach ($value as $cid => $data) {
if (!isset($submission['data'][$cid])) {
$submission['data'][$cid] = $data;
}
}
}
else {
$submission[$key] = $value;
}
}
module_load_include('inc', 'webform', 'includes/webform.submissions');
$sid = webform_submission_update($webform, webform_service_parse_submission($webform, $submission));
return webform_service_get_submission($webform, webform_get_submission($webform->nid, $sid, TRUE));
}
else {
return FALSE;
}
}
function webform_service_submission_delete($uuid) {
$webform = webform_submission_uuid_webform($uuid);
$submission = webform_submission_uuid_get_submission($uuid);
if ($webform && $submission) {
module_load_include('inc', 'webform', 'includes/webform.submissions');
webform_submission_delete($webform, webform_service_parse_submission($webform, $submission));
return TRUE;
}
else {
return FALSE;
}
}