From b677df0e963462a149f8f8a4888c64afe7ff2d3a Mon Sep 17 00:00:00 2001
From: Matthew Grasmick <madmatter23@gmail.com>
Date: Wed, 26 Sep 2012 11:14:55 -0400
Subject: [PATCH] fixing syntax to match changes in services api.

---
 flag_service.inc    |  102 ++++++++++++++++++++++++--------------------------
 flag_service.module |   22 ++++++----
 2 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/flag_service.inc b/flag_service.inc
index eeb8c1c..5505fdc 100644
--- a/flag_service.inc
+++ b/flag_service.inc
@@ -8,36 +8,36 @@
 /**
  * Access callback to check a user has access to a flag operation via Services.
  *
- * @param $flag_name
- *   The flag name.
- * @param $content_id
- *   The content ID that should be flagged.
- * @param $uid
- *   Optional. The user ID on behalf to flag the content.
- * @param $action
- *   Optional. The desired method - flag or unflag. Defaults to flag.
+ * @param $data
+ *   An associative array containing POSTed arguments.
+ *   - flag_name: The flag name.
+ *   - content_id: The content ID that should be flagged.
+ *   - uid: Optional. The user ID on behalf to flag the content.
+ *   - action: Optional. The desired method - flag or unflag. Defaults to flag.
+ *
  * @return
  *   TRUE if access is allowed.
  */
-function flag_service_flag_content_access($flag_name, $content_id, $action = 'flag', $uid = NULL) {
+function flag_service_flag_content_access($data) {
+
   // Check action is valid.
-  if (!in_array($action, array('flag', 'unflag'))) {
+  if (!in_array($data['action'], array('flag', 'unflag'))) {
     return FALSE;
   }
 
   $account = NULL;
-  if (!empty($uid)) {
-    $account = user_load($uid);
+  if (!empty($data['uid'])) {
+    $account = user_load($data['uid']);
   }
-  
-  $flag = flag_get_flag($flag_name);
+
+  $flag = flag_get_flag($data['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 services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
   }
 
-  if (!$flag->access($content_id, $action, $account)) {
+  if (!$flag->access($data['content_id'], $data['action'], $account)) {
     // User has no permission to use this flag.
     return FALSE;
   }
@@ -48,69 +48,65 @@ function flag_service_flag_content_access($flag_name, $content_id, $action = 'fl
 /**
  * Service wrapper to flag a content.
  *
- * @param $flag_name
- *   The flag name.
- * @param $content_id
- *   The content ID to check if it was flagged.
- * @param $uid
- *   The user ID to check if they flagged the content.
- * @param $action
- *   The action. Should be "flag" or "unflag".
+ * @param $data
+ *   An associative array containing POSTed arguments.
+ *   - flag_name: The flag name.
+ *   - content_id: The content ID that should be flagged.
+ *   - uid: Optional. The user ID on behalf to flag the content.
+ *   - action: Optional. The desired method - flag or unflag. Defaults to flag.
+ *
  * @return
  *   TRUE if content was flagged.
  */
-function flag_service_flag_content($flag_name, $content_id, $action = 'flag', $uid = NULL, $skip_permission_check = FALSE) {
+function flag_service_flag_content($data) {
   global $user;
-  $account = empty($uid) ? $user : user_load($uid);
-  $flag = flag_get_flag($flag_name);
-  $skip_permission_check = (boolean) $skip_permission_check;
+  $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 file with flag with the name @flag_name', array('@flag_name' => $flag_name)), 406);
+    return services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
   }
-  return $flag->flag($action, $content_id, $account, $skip_permission_check);
+  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.
  *
- * @param $flag_name
- *   The flag name.
- * @param $content_id
- *   The content ID to check if it was flagged.
- * @param $uid
- *   The user ID to check if they flagged the content.
+ * @param $data
+ *   An associative array containing POSTed arguments.
+ *   - flag_name: The flag name.
+ *   - content_id: The content ID that should be flagged.
+ *   - uid: Optional. The user ID on behalf to flag the content.
+ *
  * @return
  *   TRUE if content was flagged.
  */
-function flag_service_is_flagged($flag_name, $content_id, $uid = NULL) {
-  $flag = flag_get_flag($flag_name);
+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 file with flag with the name @flag_name', array('@flag_name' => $flag_name)), 406);
+    return services_error(t('There is no flag with the name @flag_name', array('@flag_name' => $data['flag_name'])), 406);
   }
-  return $flag->is_flagged($content_id, $uid);
+  return $flag->is_flagged($data['content_id'], $data['uid']);
 }
 
 /**
  * Service wrapper to count a flag on a content.
  *
- * @param $flag_name
- *   The flag name.
- * @param $content_id
- *   The content ID to check if it was flagged.
+ * @param $data
+ *   An associative array containing POSTed arguments.
+ *   - flag_name: The flag name.
+ *   - content_id: The content ID that should be flagged.
+ *
  * @return
  *   A object contain the number which shows how many users flagged a content.
  */
-
-function flag_service_flag_countall($flag_name, $content_id) {
+function flag_service_flag_countall($data) {
   $query = db_select('flag_counts', 'fc');
-  $query->join('flags', 'f','f.fid = fc.fid');
-  $query->fields('fc', array('count'))
-        ->condition('fc.content_id', $content_id)
-        ->condition('f.name', $flag_name);
+  $query->join('flags', 'f', 'f.fid = fc.fid');
+  $query->fields('fc', array('count'))->condition('fc.content_id', $data['content_id'])->condition('f.name', $data['flag_name']);
   $result = $query->execute()->fetchObject();
-  return $result;                  
-}
-
+  return $result;
+}
\ No newline at end of file
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)

