? 319224-flag-flaggings-7.patch
Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.30
diff -u -p -r1.1.2.30 flag.inc
--- flag.inc	14 Mar 2009 06:13:54 -0000	1.1.2.30
+++ flag.inc	3 May 2009 13:44:14 -0000
@@ -33,6 +33,12 @@ function flag_flag_definitions() {
       'description' => t('Users who have created accounts on your site.'),
       'handler' => 'flag_user',
     ),
+    'flag' => array(
+      'title' => t('Flags'),
+      'description' => t('Flags are an object created by the flag module.'),
+    // flag_flag is already taken by the system as the flag abstract class.
+      'handler' => 'flag_flags',
+    ),
   );
 }
 
@@ -634,14 +640,14 @@ class flag_flag {
   function rules_get_event_arguments_definition() {
     return array();
   }
-  
+
   /**
    * Defines the Rules argument for flag actions or conditions
    */
   function rules_get_element_argument_definition() {
     return array();
   }
-  
+
   /**
    * @} End of "defgroup rules".
    */
@@ -941,7 +947,7 @@ class flag_node extends flag_flag {
       ),
     );
   }
-  
+
   function rules_get_element_argument_definition() {
     return array('type' => 'node', 'label' => t('Flagged content'));
   }
@@ -1056,7 +1062,7 @@ class flag_comment extends flag_flag  {
       ),
     );
   }
-  
+
   function rules_get_element_argument_definition() {
     return array('type' => 'comment', 'label' => t('Flagged comment'));
   }
@@ -1170,7 +1176,7 @@ class flag_user extends flag_flag {
       ),
     );
   }
-  
+
   function rules_get_element_argument_definition() {
     return array('type' => 'user', 'label' => t('Flagged user'));
   }
@@ -1202,6 +1208,55 @@ class flag_user extends flag_flag {
 }
 
 /**
+ * Implements a flag flag (i.e. flag flaggings).
+ */
+class flag_flags extends flag_flag {
+
+  function options_form(&$form) {
+    parent::options_form($form);
+    $options = array();
+    $types = flag_fetch_definition();
+    // Prepare the flag types.
+    $flag_types = array();
+    foreach ($types as $type) {
+      $flag_types[$type['handler']] = $type['title'];
+    }
+    // Get all the flags and sort them by type.
+    $flags = flag_get_flags();
+    foreach($flags as $flag) {
+      $options[$flag_types[get_class($flag)]][$flag->name] = $flag->title;
+    }
+    $form['types'] = array(
+      '#title' => t('What flags this flag may be used on'),
+      // Using select allows showing nested options.
+      '#type' => 'select',
+      '#multiple' => TRUE,
+      '#options' => $options,
+      '#description' => t('Check any flags that this flag may be used on. You must check at least one flag.'),
+      '#required' => TRUE,
+      '#default_value' => $this->types,
+    );
+  }
+
+  function _load_content($content_id) {
+    return flag_load_flag_content($content_id);
+  }
+
+  function applies_to_content_object($flag) {
+    // Make sure the flag has already a flag ID.
+  if (!empty($flag->fid) && in_array($flag->name, $this->types)) {
+      return TRUE;
+    }
+  return FALSE;
+  }
+
+  function get_content_id($flag) {
+    return $flag->fcid;
+  }
+}
+
+
+/**
  * A dummy flag to be used where the real implementation can't be found.
  */
 class flag_broken extends flag_flag {
@@ -1226,5 +1281,4 @@ function _flag_url($path, $fragment = NU
   return _flag_is_drupal_5()
     ? url($path, NULL, $fragment, $absolute)
     : url($path, array('absolute' => TRUE, 'fragment' => $fragment));
-}
-
+}
\ No newline at end of file
Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.70
diff -u -p -r1.11.2.70 flag.module
--- flag.module	17 Mar 2009 02:07:34 -0000	1.11.2.70
+++ flag.module	3 May 2009 13:44:15 -0000
@@ -1011,6 +1011,25 @@ function flag_get_content_flags($content
 }
 
 /**
+ * Load a flag content. Flag content is defined as fcid in flag_content table.
+ * 
+ * This can be used to flag flaggings.
+ * 
+ * @param $fcid
+ *   The flag content ID.
+ * @return
+ *   An object with the flag object and the flaged content ID.
+ */
+function flag_load_flag_content($fcid = 0) {
+  $flag = array();
+  $fid = db_fetch_object(db_query("SELECT fid FROM {flag_content} WHERE fcid = %d ", $fcid));
+  if (!empty($fid->fid) && $flag = flag_get_flag(NULL, $fid->fid)) {
+   $flag->fcid = $fcid;    
+  }
+  return $flag;
+}
+
+/**
  * A utility function for outputting a flag link.
  *
  * You should call this function from your template when you want to put the
