diff --git a/modules/content_profile_service.info b/modules/content_profile_service.info old mode 100644 new mode 100755 diff --git a/modules/content_profile_service.module b/modules/content_profile_service.module old mode 100644 new mode 100755 index f17ebd4..e1aa79a --- a/modules/content_profile_service.module +++ b/modules/content_profile_service.module @@ -7,7 +7,7 @@ * Implementation of hook_perm() */ function content_profile_service_perm(){ - return array('get content profiles of users'); + return array('get content profiles of users', 'set content profiles of users'); } /** @@ -50,6 +50,39 @@ function content_profile_service_services_resources() { 'access arguments' => array('get content profiles of users') ); + $resources['content_profile']['update'] = array( + 'callback' => 'content_profile_service_resource_set', + 'args' => array( + array( + 'name' => 'uid', + 'source' => array('path' => 0), + 'type' => 'int', + 'description' => t('A user ID.'), + ), + array( + 'name' => 'type', + 'source' => array('param' => 'type'), + 'type' => 'string', + 'description' => t('A valid content profile node type.'), + ), + array( + 'name' => 'lang', + 'source' => array('param' => 'lang'), + 'type' => 'string', + 'optional' => TRUE, + 'description' => t('Try specific language'), + ), + array( + 'name' => 'fields', + 'source' => 'data', + 'type' => 'array', + 'description' => t('A list of fields to update.'), + ), + ), + 'access callback' => 'user_access', + 'access arguments' => array('set content profiles of users') + ); + return $resources; } @@ -65,6 +98,7 @@ function content_profile_service_services_resources() { * @param $fields * Array (optinonal). The node fields needed. If its empty, * all fields will be returned + * * @return * Object. The node object. */ @@ -93,3 +127,48 @@ function content_profile_service_resource_get($uid, $type, $lang = '', $fields = return $result; } + +/** + * Updates a content profile node for a given type/user. + * + * @param $uid + * Number. The users ID + * @param $type + * String. The content profile node type. + * @param $lang + * String (optinonal). The language the node shall be in + * @param $fields + * Array. The node fields to be updated. + * + * @return + * Object. The node object. + */ +function content_profile_service_resource_set($uid, $type, $lang = '', $fields) { + global $user; + $node = content_profile_load($type, $uid, $lang); + + if ($node) { + // Apply field level content permissions + if (module_exists('content') && variable_get('services_use_content_permissions', FALSE)) { + $content_fields = content_fields(NULL, $node->type); + foreach ($content_fields as $field_name => $field_info) { + if (isset($fields->$field_name)) { + $access = module_invoke_all('field_access', 'update', $field_info, $user, $node); + if (in_array(FALSE, $access)) { + unset($fields->$field_name); + } + } + } + } + $node = (object) ($fields + (array) $node); + node_save($node); + + $node = node_load($node->nid); + $result = services_node_load($node); + } + else { + $result = services_error(t('Could not find the node.'), 404); + } + + return $result; +}