View source
<?php
function _webform_resource_definition() {
$resources = array();
$types = webform_variable_get('webform_node_types');
foreach ($types as $type) {
$resources[$type] = array(
'retrieve' => array(
'callback' => 'webform_service_get_resource',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => 'The uuid of the node to get',
),
),
'access callback' => 'webform_service_resource_access',
'access arguments' => array(
'view',
$type,
),
'access arguments append' => TRUE,
),
'create' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/webform_resource',
),
'callback' => 'webform_service_resource_create',
'args' => array(
array(
'name' => 'webform',
'optional' => FALSE,
'source' => 'data',
'description' => 'All the elements that make up the webform node.',
'type' => 'array',
'default value' => array(),
),
array(
'name' => 'type',
'optional' => TRUE,
'type' => 'string',
'description' => 'Webform Type',
'default value' => $type,
'source' => array(
'param' => 'type',
),
),
),
'access callback' => 'webform_service_resource_access',
'access arguments' => array(
'create',
$type,
),
'access arguments append' => TRUE,
),
'update' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/webform_resource',
),
'callback' => 'webform_service_resource_update',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => 'The uuid of the node to get',
),
array(
'name' => 'node',
'optional' => FALSE,
'source' => 'data',
'description' => 'The node data to update',
'type' => 'array',
),
),
'access callback' => 'webform_service_resource_access',
'access arguments' => array(
'update',
$type,
),
'access arguments append' => TRUE,
),
'delete' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/webform_resource',
),
'callback' => 'webform_service_resource_delete',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
),
),
'access callback' => 'webform_service_resource_access',
'access arguments' => array(
'delete',
$type,
),
'access arguments append' => TRUE,
),
'index' => array(
'file' => array(
'type' => 'inc',
'module' => 'webform_service',
'name' => 'resources/webform_resource',
),
'help' => t('Return all webforms.'),
'callback' => '_webform_resource_index',
'args' => array(
array(
'name' => 'page',
'optional' => TRUE,
'type' => 'int',
'description' => 'The zero-based index of the page to get, defaults to 0.',
'default value' => 0,
'source' => array(
'param' => 'page',
),
),
array(
'name' => 'pagesize',
'optional' => TRUE,
'type' => 'int',
'description' => 'Number of records to get per page.',
'default value' => variable_get('services_node_index_page_size', 20),
'source' => array(
'param' => 'pagesize',
),
),
array(
'name' => 'type',
'optional' => TRUE,
'type' => 'string',
'description' => 'Webform Type',
'default value' => $type,
'source' => array(
'param' => 'type',
),
),
),
'access arguments' => array(
'access content',
),
),
'relationships' => array(
'submissions' => array(
'help' => t('Retrieve the submissions provided a webform.'),
'callback' => 'webform_service_submission_index',
'args' => array(
array(
'name' => 'uuid',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'string',
'description' => t('The uuid of the webform you want the relationship for.'),
),
array(
'name' => 'pagefrom',
'optional' => TRUE,
'type' => 'int',
'description' => 'The offset where to start getting submissions, defaults to 0.',
'default value' => 0,
'source' => array(
'param' => 'pagefrom',
),
),
array(
'name' => 'pagesize',
'optional' => TRUE,
'type' => 'int',
'description' => 'Number of records to get per page.',
'default value' => variable_get('services_node_index_page_size', 20),
'source' => array(
'param' => 'pagesize',
),
),
),
'access arguments' => array(
'access content',
),
),
),
);
}
return $resources;
}
function webform_service_resource_create($webform, $type) {
module_load_include('inc', 'services', 'resources/node_resource');
$webform['type'] = $type;
drupal_alter('webform_service_webform', $webform, $type);
if (!isset($webform['webform'])) {
$webform['webform'] = array();
}
$node = _node_resource_create(webform_service_webform_prepare($webform));
return webform_service_get_resource(node_load($node['nid'], NULL, TRUE));
}
function webform_service_resource_update($uuid, $webform) {
if ($node = webform_service_resource_load($uuid)) {
webform_service_webform_prepare($webform, $node);
webform_node_update($node);
return webform_service_get_resource(node_load($node->nid, NULL, TRUE));
}
else {
return services_error(t('@uuid could not be found', array(
'@uuid' => $uuid,
)), 404);
}
}
function webform_service_resource_delete($uuid) {
if ($node = webform_service_resource_load($uuid)) {
node_delete($node->nid);
return TRUE;
}
else {
return services_error(t('@uuid could not be found', array(
'@uuid' => $uuid,
)), 404);
}
}