? .svn
? modules
? pcp.module.323032.patch
Index: pcp.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pcp/pcp.install,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 pcp.install
--- pcp.install	17 Oct 2008 20:45:03 -0000	1.1.2.2
+++ pcp.install	8 Sep 2009 01:59:44 -0000
@@ -20,12 +20,36 @@ function pcp_install() {
 function pcp_schema() {
   $schema['profile_pcp'] = array(
     'fields' => array(
-      'fid' => array('type' => 'int', 'not null' => TRUE),
+      'fid' => array('type' => 'int'),
+      'fieldname' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE),
       ),
-    );
+  );
   return $schema;
 }
 
 function pcp_uninstall() {
   drupal_uninstall_schema('pcp');
-}
\ No newline at end of file
+}
+
+/**
+ * Integrates non-profile fields
+ */
+function pcp_update_6001() {
+  $ret = array();
+  // we will now use text instead of fid for field identification because cck
+  // fields are do not have fids. We keep the fid column for legacy purpose but
+  // will no longer be used in this module.
+  $ret[] = update_sql("ALTER TABLE {profile_pcp} ADD fieldname longtext NOT NULL");
+  $ret[] = update_sql("ALTER TABLE {profile_pcp} ADD fid int NULL");
+
+
+  // Adds the fieldnames that will be used from now on.
+  $result = db_query('SELECT f.fid, f.name FROM {profile_fields} f JOIN {profile_pcp} p ON f.fid=p.fid');
+
+  while ($field = db_fetch_object($result)) {
+    db_query('UPDATE {profile_pcp} SET fieldname="%s" WHERE fid=%d', $field->name, $field->fid);
+  }
+
+  return $ret;
+}
+
Index: pcp.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pcp/pcp.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 pcp.module
--- pcp.module	30 Jun 2009 17:25:03 -0000	1.1.2.3
+++ pcp.module	8 Sep 2009 01:59:44 -0000
@@ -4,7 +4,7 @@
 /**
  * @file
  * Allows users with valid permissions to tag profile fields created
- * from the profile module as required fields for a 
+ * from the profile module as required fields for a
  * users profile to be considered complete.
  */
 
@@ -22,7 +22,7 @@ function pcp_perm() {
  */
 function pcp_menu() {
   $items = array();
-  
+
   $items['admin/user/pcp'] = array(
     'title' => 'Profile Complete Percentages',
     'description' => 'Tag profile fields as required for percent complete handling.',
@@ -68,8 +68,8 @@ function pcp_form_alter(&$form, $form_st
     $fid = $form['fid']['#value'];
     $tag = TRUE;
     if ($fid) {
-      $field_data = pcp_get_tagged_profile_fields($fid);
-      if (!$field_data[0]['fid']) {
+      $field_data = pcp_pcp_get_tagged_profile_fields($fid);
+      if (!$field_data[0]) {
         $tag = FALSE;
       }
     }
@@ -86,19 +86,19 @@ function pcp_form_alter(&$form, $form_st
       );
     $form['#submit'][] = 'pcp_profile_field_form_submit';
   }
-  
+
   if ($form_id == 'user_profile_form' && arg(3) != '' && $_GET['fieldname'] != '') {
     $fieldname = 'edit-'. preg_replace("/_/", "-", $_GET['fieldname']);
     drupal_add_js("
       $('#". $fieldname ."').css({
-        'border' : '2px solid red' 
+        'border' : '2px solid red'
         });
     ", 'inline', 'footer');
   }
 }
 
 /**
- * Called when a user submits a profile field form from the 
+ * Called when a user submits a profile field form from the
  * profile module (when adding or editing a profile field).
  */
 function pcp_profile_field_form_submit($form, &$form_state) {
@@ -112,7 +112,7 @@ function pcp_profile_field_form_submit($
 /**
  * Menu Callback Function
  *  Build output of the pcp module settings which allows the
- *  administrator to tag specific profile fields which will be 
+ *  administrator to tag specific profile fields which will be
  *  used to determine the completion of a users profile.
  */
 function pcp_admin_settings() {
@@ -146,9 +146,9 @@ function pcp_admin_settings_form() {
 function pcp_admin_settings_form_submit($form, &$form_state) {
   if (is_array($form_state['values']['profile_fields']) && !empty($form_state['values']['profile_fields'])) {
     db_query("DELETE FROM {profile_pcp}");
-    foreach ($form_state['values']['profile_fields'] as $fid) {
-      if ($fid) {
-        db_query("INSERT INTO {profile_pcp} VALUES (%d)", $fid);
+    foreach ($form_state['values']['profile_fields'] as $fieldname) {
+      if ($fieldname) {
+        db_query('INSERT INTO {profile_pcp} (fieldname) VALUES ("%s")', $fieldname);
       }
     }
     drupal_set_message("Your settings have been saved.");
@@ -156,34 +156,30 @@ function pcp_admin_settings_form_submit(
 }
 
 /**
- * Function that sets up parameters to be used 
+ * Function that sets up parameters to be used
  * when the pcp_admin_settings_form() function
- * is executed. 
+ * is executed.
  *
  * @return - assoc array
- *  ['profile_fields_options'] 
+ *  ['profile_fields_options']
  *    - An associative array of all fields created from the profile module.
  *  ['default_values']
  *    - An indexed array of all (if any) default values for the form.
  */
 function pcp_admin_settings_form_data() {
-  $profile_fields_options = array();
-  $default_values = array();
-  $profile_fields = pcp_get_profile_fields();
-  foreach ($profile_fields as $key => $value) {
-    $profile_fields_options[$value['fid']] = $value['title'];
-  }
-  $tagged_profile_fields = pcp_get_tagged_profile_fields();
-  foreach ($tagged_profile_fields as $key => $value) {
-    $default_values[] = $value['fid'];
-  }
   $options = array();
-  $options['profile_fields_options'] = $profile_fields_options;
-  $options['default_values'] = $default_values;
+
+  // allows other modules to define fields to be considered in the profile
+  // completedness
+  $options['profile_fields_options'] = module_invoke_all('pcp_get_profile_fields');
+  $options['default_values'] = module_invoke_all('pcp_get_tagged_profile_fields');
+
   return $options;
 }
 
 /**
+ * Implementation of hook_pcp_get_user_profile_values().
+ *
  * Return a users profile field values that have been saved
  * for a given user.
  *
@@ -191,49 +187,53 @@ function pcp_admin_settings_form_data() 
  *
  * @return assoc array of all profile fields for the user.
  */
-function pcp_get_user_profile_values($uid) {
+function pcp_pcp_get_user_profile_values($uid) {
   $values = array();
   if ($uid) {
-    $query = db_query("SELECT * FROM {profile_values} WHERE uid = %d", $uid);
+    $query = db_query("SELECT f.name, f.title, f.category, v.value
+                       FROM {profile_fields} f JOIN {profile_values} v
+                       ON f.fid=v.fid WHERE v.uid = %d", $uid);
     while ($result = db_fetch_array($query)) {
-      $values[$result['fid']] = $result['value'];
+      $values[$result['name']]['title'] = $result['title'];
+      $values[$result['name']]['category'] = $result['category'];
+      $values[$result['name']]['value'] = $result['value'];
     }
   }
+
   return $values;
 }
 
 /**
  * Get the profile complete percentage data for a given user.
  *
- * @param obj $user 
+ * @param obj $user
 *  - The user object to get data for.
- *  
+ *
  * @return assoc array of all values needed at the theme layer.
  *  - Refer to comments in theme_pcp_profile_percent_complete() for specific values.
  */
 function pcp_get_complete_percentage_data($user) {
-  $fields = pcp_get_tagged_profile_fields();
-  $user_values = pcp_get_user_profile_values($user->uid);
+  $fields = module_invoke_all('pcp_get_tagged_profile_fields');
+  $values = module_invoke_all('pcp_get_user_profile_values', $user->uid);
+
   $percent = 0;
   $complete = 0;
   $nextfield_set = FALSE;
-  
+
   if (is_array($fields) && !empty($fields)) {
     foreach ($fields as $key => $value) {
-      if ($user_values[$value['fid']] == '') {
+      if ($values[$value]['value'] == '') {
         if ($nextfield_set === FALSE) {
           $nextfield_set = TRUE;
-          $fid = $value['fid'];
-          $nextdata = db_fetch_array(db_query("SELECT title, name, category FROM {profile_fields} WHERE fid = %d", $fid));
-          $nextfield = $nextdata['title'];
-          $nextcategory = $nextdata['category'];
-          $nextname = $nextdata['name'];
+          $nextfield = $values[$value]['title'];
+          $nextcategory = $values[$value]['category'];
+          $nextname = $fields[$key];
         }
         continue;
       }
       $complete++;
     }
-    
+
     $dec = number_format(($complete / count($fields)), 2);
     $percent = $dec * 100;
     if ($nextfield_set) {
@@ -251,11 +251,13 @@ function pcp_get_complete_percentage_dat
   $complete_data['nextpercent'] = $nextpercent;
   $complete_data['nextcategory'] = $nextcategory;
   $complete_data['nextname'] = $nextname;
-  
+
   return $complete_data;
 }
 
 /**
+ * Implementation of hook_pcp_get_tagged_profile_fields().
+ *
  * Get all the profile fields that have been tagged.
  * If an $fid is passed in, only the data for that field will be returned.
  *
@@ -263,32 +265,37 @@ function pcp_get_complete_percentage_dat
  *
  * @return indexed array - All fields and their information returned from the query.
  */
-function pcp_get_tagged_profile_fields($fid = 0) {
-  $where = '';
-  $args = '';
-  
+function pcp_pcp_get_tagged_profile_fields($fid = 0) {
   if ($fid > 0) {
-    $where = " WHERE fid = %d";
-    $args = array($fid);
+    $add = ' JOIN {profile_fields} f ON f.name=p.fieldname WHERE f.fid = '. $fid;
   }
-  $query = db_query("SELECT * FROM {profile_pcp} LEFT JOIN {profile_fields} USING(fid) $where", $args);
-  $fields = array();
-  while ($result = db_fetch_array($query)) {
-    $fields[] = $result;
+
+  $query = 'SELECT p.fieldname FROM {profile_pcp} p'. $add;
+
+  $result = db_query($query);
+  $default_values = array();
+
+  while ($value = db_fetch_array($result)) {
+    $default_values[] = $value['fieldname'];
   }
-  return $fields;
+
+  return $default_values;
 }
 
 /**
+ * Implementation of hook_pcp_get_profile_fields().
+ *
  * Get all the profile fields stored in the system, tagged or not tagged.
  */
-function pcp_get_profile_fields() {
-  $query = db_query("SELECT * FROM {profile_fields}");
-  $fields = array();
-  while ($result = db_fetch_array($query)) {
-    $fields[] = $result;
+function pcp_pcp_get_profile_fields() {
+  $fields = $options = array();
+  $result = db_query("SELECT * FROM {profile_fields}");
+
+  while ($value = db_fetch_array($result)) {
+    $options[$value['name']] = $value['title'];
   }
-  return $fields;
+
+  return $options;
 }
 
 
@@ -321,24 +328,24 @@ function theme_pcp_profile_percent_compl
   $output .= '#pcp-percent-bar-wrapper {width: 100%; border: 1px solid #000; padding: 1px;}';
   $output .= '#pcp-percent-bar { width: '. $complete_data['percent'] .'%; height: 10px; background-color: #777777;}';
   $output .= '</style>';
-  
+
   $output .= '<div id="pcp-wrapper">';
   $output .= t('!complete% Complete', array('!complete' => $complete_data['percent']));
   $output .= '<div id="pcp-percent-bar-wrapper">';
   $output .= '<div id="pcp-percent-bar"></div>';
   $output .= '</div>';
   $output .= '</div>';
-  
+
   if ($complete_data['nextfield'] && $complete_data['nextpercent']) {
     $output .= t('Filling out ') . '<i> ' . l($complete_data['nextfield'], 'user/'. $complete_data['uid'] .'/edit/'. $complete_data['nextcategory'], array('query' => 'fieldname='. $complete_data['nextname'])) .'</i> ' . t('will bring your profile to') . ' ' . t('!complete% Complete', array('!complete' => $complete_data['nextpercent']));
   }
-    
+
   return $output;
 }
 
 /**
  * Implementation of hook_rules_condition_info().
- * 
+ *
  * @ingroup rules
  * @see content_complete_completeness_percentage_form
  */
@@ -357,7 +364,7 @@ function pcp_rules_condition_info() {
 
 /**
  * Rules Condition form configuration - select the profile fields to check
- * 
+ *
  * @see pcp_rules_condition_info
  */
 function pcp_condition_check_profile_fields_completeness_form($settings = array(), &$form) {
@@ -374,29 +381,29 @@ function pcp_condition_check_profile_fie
 
 /**
  * Rules Condition - Are the selected user profile fields filed in?
- * 
- * @param $user 
+ *
+ * @param $user
  *   The user for which the condition is checked.
  * @param $settings
  *   The configured settings of the rule condition
- * 
+ *
  * @see pcp_condition_check_profile_fields_completeness_form
  * @see pcp_rules_condition_info
- * 
+ *
  * @return TRUE or FALSE
  */
 function pcp_condition_check_profile_fields_completeness($user, $settings) {
-	
+
 	$edit_categories = array();
 	profile_load_profile($user);
 	if ($settings['profile_fields']) {
 		$result = db_query("SELECT fid, title, name, category FROM {profile_fields} WHERE fid IN (%s)", implode(', ', $settings['profile_fields']));
 		while ($field = db_fetch_object($result)) {
 			if (!$user->{$field->name}) {
-				return FALSE;		
+				return FALSE;
 			}
 		}
-	} 
+	}
 	return TRUE;
 }
 
@@ -417,14 +424,14 @@ function pcp_rules_action_info() {
 
 /**
  * Rules Action - Redirect the user to his profile edit page
- * 
- * @param $user 
+ *
+ * @param $user
  *   The user for which the action is performed.
  * @param $settings
  *   The configured settings of the rule action
- * 
+ *
  * @see pcp_rules_action_info
- * 
+ *
  * @return Perform the redirection
  */
 function pcp_action_redirect_user_to_editform($user, $settings) {
@@ -443,7 +450,7 @@ function pcp_action_redirect_user_to_edi
 				drupal_goto('user/'.$user->uid.'/edit/'.$field->category);
 			}
 		}
-	} 
+	}
 }
 
 /**
