From 42a23dceb819ce700987d5afbf6410e1023c6fb7 Mon Sep 17 00:00:00 2001
From: Matthew Grasmick <madmatter23@gmail.com>
Date: Wed, 26 Sep 2012 10:58:12 -0400
Subject: [PATCH] fixing syntax to match changes in services api.

---
 flag_service.inc    |   84 +++++++++++++++++++++++++-------------------------
 flag_service.module |   22 ++++++++-----
 2 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/flag_service.inc b/flag_service.inc
index eeb8c1c..ec00d7d 100644
--- a/flag_service.inc
+++ b/flag_service.inc
@@ -19,31 +19,32 @@
  * @return
  *   TRUE if access is allowed.
  */
-function flag_service_flag_content_access($flag_name, $content_id, $action = 'flag', $uid = NULL) {
-  // Check action is valid.
-  if (!in_array($action, array('flag', 'unflag'))) {
-    return FALSE;
-  }
+ function flag_service_flag_content_access($data) {
 
-  $account = NULL;
-  if (!empty($uid)) {
-    $account = user_load($uid);
-  }
-  
-  $flag = flag_get_flag($flag_name);
+   // Check action is valid.
+   if (!in_array($data['action'], array('flag', 'unflag'))) {
+     return FALSE;
+   }
 
-  if (!$flag) {
-    // Flag does not exist.
-    return services_error(t('There is no file with flag with the name @flag_name', array('@flag_name' => $flag_name)), 406);
-  }
+   $account = NULL;
+   if (!empty($data['uid'])) {
+     $account = user_load($data['uid']);
+   }
 
-  if (!$flag->access($content_id, $action, $account)) {
-    // User has no permission to use this flag.
-    return FALSE;
-  }
+   $flag = flag_get_flag($data['flag_name']);
 
-  return TRUE;
-}
+   if (!$flag) {
+     // Flag does not exist.
+     return services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
+   }
+
+   if (!$flag->access($data['content_id'], $data['action'], $account)) {
+     // User has no permission to use this flag.
+     return FALSE;
+   }
+
+   return TRUE;
+ }
 
 /**
  * Service wrapper to flag a content.
@@ -59,18 +60,18 @@ function flag_service_flag_content_access($flag_name, $content_id, $action = 'fl
  * @return
  *   TRUE if content was flagged.
  */
-function flag_service_flag_content($flag_name, $content_id, $action = 'flag', $uid = NULL, $skip_permission_check = FALSE) {
-  global $user;
-  $account = empty($uid) ? $user : user_load($uid);
-  $flag = flag_get_flag($flag_name);
-  $skip_permission_check = (boolean) $skip_permission_check;
-  if (!$flag) {
-    watchdog('services', '<pre>' . print_r(debug_backtrace(), TRUE) . '</pre>');
-    // Flag does not exist.
-    return services_error(t('There is no file with flag with the name @flag_name', array('@flag_name' => $flag_name)), 406);
-  }
-  return $flag->flag($action, $content_id, $account, $skip_permission_check);
-}
+ function flag_service_flag_content($data) {
+   global $user;
+   $account = empty($data['uid']) ? $user : user_load($data['uid']);
+   $flag = flag_get_flag($data['flag_name']);
+   $skip_permission_check = (boolean) $data['skip_permission_check'];
+   if (!$flag) {
+     watchdog('services', '<pre>' . print_r(debug_backtrace(), TRUE) . '</pre>');
+     // Flag does not exist.
+     return services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
+   }
+   return $flag->flag($data['action'], $data['content_id'], $account, $data['skip_permission_check']);
+ }
 
 /**
  * Service wrapper to check if a content is flagged by a user.
@@ -84,14 +85,14 @@ function flag_service_flag_content($flag_name, $content_id, $action = 'flag', $u
  * @return
  *   TRUE if content was flagged.
  */
-function flag_service_is_flagged($flag_name, $content_id, $uid = NULL) {
-  $flag = flag_get_flag($flag_name);
-  if (!$flag) {
-    // Flag does not exist.
-    return services_error(t('There is no file with flag with the name @flag_name', array('@flag_name' => $flag_name)), 406);
-  }
-  return $flag->is_flagged($content_id, $uid);
-}
+ function flag_service_is_flagged($data) {
+   $flag = flag_get_flag($data['flag_name']);
+   if (!$flag) {
+     // Flag does not exist.
+     return services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
+   }
+   return $flag->is_flagged($data['content_id'], $data['uid']);
+ }
 
 /**
  * Service wrapper to count a flag on a content.
@@ -113,4 +114,3 @@ function flag_service_flag_countall($flag_name, $content_id) {
   $result = $query->execute()->fetchObject();
   return $result;                  
 }
-
diff --git a/flag_service.module b/flag_service.module
index 2b1ec89..10a3e32 100644
--- a/flag_service.module
+++ b/flag_service.module
@@ -20,22 +20,23 @@ function flag_service_services_resources() {
         'name' => 'flag_name',
         'type' => 'string',
         'description' => t('The name of the flag.'),
-        'source' => array('data' => 'flag_name'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
       array(
         'name' => 'content_id',
         'type' => 'int',
         'description' => t('The content ID.'),
-        'source' => array('data' => 'content_id'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
       array(
         'name' => 'uid',
         'type' => 'int',
         'description' => t('The user ID that might have flagged the content.'),
-        'source' => array('data' => 'uid'),
+        'source' => 'data',
         'optional' => TRUE,
+        'default value' => NULL,
       ),
     ),
   );
@@ -54,29 +55,31 @@ function flag_service_services_resources() {
         'name' => 'flag_name',
         'type' => 'string',
         'description' => t('The name of the flag.'),
-        'source' => array('data' => 'flag_name'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
       array(
         'name' => 'content_id',
         'type' => 'int',
         'description' => t('The content ID.'),
-        'source' => array('data' => 'content_id'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
       array(
         'name' => 'action',
         'type' => 'string',
         'description' => t('Optional; The action to perform, default is "flag". Should be "flag" or "unflag".'),
-        'source' => array('data' => 'action'),
+        'source' => 'data',
         'optional' => TRUE,
+        'default value' => 'flag',
       ),
       array(
         'name' => 'uid',
         'type' => 'int',
         'description' => t('The user ID for which to flag.'),
-        'source' => array('data' => 'uid'),
+        'source' => 'data',
         'optional' => TRUE,
+        'default value' => NULL,
       ),
       array(
         'name' => 'skip_permission_check',
@@ -84,6 +87,7 @@ function flag_service_services_resources() {
         'description' => t('Optional; Flag the content even if the user does not have permission to do so. FALSE by default'),
         'source' => 'data',
         'optional' => TRUE,
+        'default value' => FALSE,
       ),
     ),
   );
@@ -102,14 +106,14 @@ function flag_service_services_resources() {
         'name' => 'flag_name',
         'type' => 'string',
         'description' => t('The name of the flag.'),
-        'source' => array('data' => 'flag_name'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
       array(
         'name' => 'content_id',
         'type' => 'int',
         'description' => t('The content ID.'),
-        'source' => array('data' => 'content_id'),
+        'source' => 'data',
         'optional' => FALSE,
       ),
     ),
-- 
1.7.7.5 (Apple Git-26)

