? 319224-flag-flaggings-11.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 4 May 2009 06:59:43 -0000 @@ -33,6 +33,12 @@ function flag_flag_definitions() { 'description' => t('Users who have created accounts on your site.'), 'handler' => 'flag_user', ), + 'flagging' => array( + 'title' => t('Flaggings'), + 'description' => t('Flagging are flags that were flagged.'), + // flag_flag is already taken by the system as the flag abstract class. + 'handler' => 'flag_flagging', + ), ); } @@ -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,59 @@ class flag_user extends flag_flag { } /** + * Implements a flag flaggging (i.e. a flag that was flagged). + */ +class flag_flagging 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 type that this flag may be used to flag its flaggings. A flagging is a flag that was flagged. You must check at least one flag.'), + '#required' => TRUE, + '#default_value' => $this->types, + ); + } + + function _load_content($content_id) { + // The content_id is the fcid column in the flag_content table. + return db_fetch_object(db_query("SELECT * FROM {flag_content} WHERE fcid = %d", $content_id)); + } + + function applies_to_content_object($flagging) { + if (!empty($flagging->fid)) { + // Load the flag according to the flag ID in the flagging object. + $flag = flag_get_flag(NULL, $flag->fid); + if (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 +1285,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