diff -urp profile/profile.admin.inc profile/profile.admin.inc --- profile/profile.admin.inc 2008-01-21 20:50:43.000000000 +0530 +++ profile/profile.admin.inc 2008-08-23 11:49:49.000000000 +0530 @@ -18,6 +18,18 @@ function profile_admin_overview() { $form = array(); $categories = array(); while ($field = db_fetch_object($result)) { + if ($field->type == 'taxonomy') { + db_query("DELETE FROM {profile_values_term} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); + settype($edit[$field->name] , "array"); + // Remove the term "" if exists (corresponds to ) + unset($edit[$field->name]['']); + foreach ($edit[$field->name] as $index => $term_id) { + if ($term_id) { + db_query("INSERT INTO {profile_values_term} (fid, uid, tid) VALUES (%d, %d, %d)", $field->fid, $user->uid, $term_id); + } + } + } + // Collect all category information $categories[] = $field->category; @@ -242,12 +254,37 @@ Unless you know what you are doing, it i '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'), ); } + if ($type == 'taxonomy') { + $tax_options = taxonomy_get_vocabularies(); + $taxopt = array(); + foreach ($tax_options as $key => $value) { + $taxopt[$key] = $value->name; + } + $form['fields']['options'] = array('#type' => 'select', + '#title' => t('Vocabulary'), + '#description' => t('Select the vocabulary you want to use'), + '#default_value' => $edit['options'], + '#options' => $taxopt + ); + } $form['fields']['visibility'] = array('#type' => 'radios', '#title' => t('Visibility'), '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC, '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')), ); - if ($type == 'selection' || $type == 'list' || $type == 'textfield') { +// if ($type == 'selection' || $type == 'list' || $type == 'textfield') { + $form['fields']['weight'] = array('#type' => 'weight', + '#title' => t('Weight'), + '#default_value' => $edit['weight'], + '#delta' => 5, + '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'), + ); + $form['fields']['visibility'] = array('#type' => 'radios', + '#title' => t('Visibility'), + '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC, + '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')), + ); + if ($type == 'selection' || $type == 'list' || $type == 'textfield' || $type == 'taxonomy' ) { $form['fields']['page'] = array('#type' => 'textfield', '#title' => t('Page title'), '#default_value' => $edit['page'], @@ -266,14 +303,24 @@ Unless you know what you are doing, it i '#default_value' => $edit['weight'], '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'), ); - $form['fields']['autocomplete'] = array('#type' => 'checkbox', + /* $form['fields']['autocomplete'] = array('#type' => 'checkbox', '#title' => t('Form will auto-complete while user is typing.'), '#default_value' => $edit['autocomplete'], ); $form['fields']['required'] = array('#type' => 'checkbox', '#title' => t('The user must enter a value.'), '#default_value' => $edit['required'], - ); + );*/ + if ($type != 'taxonomy' ) { + $form['fields']['autocomplete'] = array('#type' => 'checkbox', + '#title' => t('Form will auto-complete while user is typing.'), + '#default_value' => $edit['autocomplete'], + ); + $form['fields']['required'] = array('#type' => 'checkbox', + '#title' => t('The user must enter a value.'), + '#default_value' => $edit['required'], + ); + } $form['fields']['register'] = array('#type' => 'checkbox', '#title' => t('Visible in user registration form.'), '#default_value' => $edit['register'], @@ -380,7 +427,7 @@ function profile_field_delete(&$form_sta function profile_field_delete_submit($form, &$form_state) { db_query('DELETE FROM {profile_fields} WHERE fid = %d', $form_state['values']['fid']); db_query('DELETE FROM {profile_values} WHERE fid = %d', $form_state['values']['fid']); - + db_query('DELETE FROM {profile_values_term} WHERE fid = %d', $form_state['values']['fid']); cache_clear_all(); drupal_set_message(t('The field %field has been deleted.', array('%field' => $form_state['values']['title']))); diff -urp profile/profile.install profile/profile.install --- profile/profile.install 2007-12-18 18:29:22.000000000 +0530 +++ profile/profile.install 2008-08-23 12:40:45.000000000 +0530 @@ -142,6 +142,67 @@ function profile_schema() { ), ); + $schema['profile_values_term'] = array( + 'description' => t('Stores values for profile fields.'), + 'fields' => array( + 'fid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The {profile_fields}.fid of the field.'), + ), + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The {users}.uid of the profile user.'), + ), + 'tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The {users}.uid of the profile user.'), + ), + ), +// 'primary key' => array('uid', 'fid'), + 'indexes' => array( + 'fidtid' => array('fid','tid'), + ), + ); + return $schema; } +function profile_update_1() { + $items = array(); + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + $items[] = update_sql("CREATE TABLE {profile_values_term} ( + fid int(11) NOT NULL default '0', + uid int(11) NOT NULL default '0', + tid int(11) NOT NULL default '0', + KEY fidtid (fid, tid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); + break; + case 'pgsql': + $items[] = update_sql("CREATE TABLE {profile_values_term} ( + fid int(11) NOT NULL default '0', + uid int(11) NOT NULL default '0', + tid int(11) NOT NULL default '0' + )"); + $items[] = update_sql("CREATE INDEX fidtid ON profile_values_term(fid, tid)"); + } + return $items; +} + +/*+ db_query("CREATE TABLE if not exists {profile_values_term} ( ++ fid int(11) NOT NULL default '0', ++ uid int(11) NOT NULL default '0', ++ tid int(11) NOT NULL default '0', ++ KEY fidtid (fid, tid) ++ ) /*!40100 DEFAULT CHARACTER SET UTF8 */ /*"); ++ */ diff -urp profile/profile.module profile/profile.module --- profile/profile.module 2008-04-10 02:41:49.000000000 +0530 +++ profile/profile.module 2008-08-23 18:34:02.000000000 +0530 @@ -40,7 +40,8 @@ function profile_help($path, $arg) { $output .= '
  • '. t('list selection') .'
  • '; $output .= '
  • '. t('freeform list') .'
  • '; $output .= '
  • '. t('URL') .'
  • '; - $output .= '
  • '. t('date') .'
  • '; + $output .= '
  • '. t('date') .'
  • '; + $output .= '
  • '.t('taxonomy').'
  • '; $output .= '

    '. t('For more information, see the online handbook entry for Profile module.', array('@profile' => 'http://drupal.org/handbook/modules/profile/')) .'

    '; return $output; case 'admin/user/profile': @@ -237,6 +238,17 @@ function profile_load_profile(&$user) { function profile_save_profile(&$edit, &$user, $category, $register = FALSE) { $result = _profile_get_fields($category, $register); while ($field = db_fetch_object($result)) { + if ($field->type == 'taxonomy') { + db_query("DELETE FROM {profile_values_term} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); + settype($edit[$field->name] , "array"); + // Remove the term "" if exists (corresponds to ) + unset($edit[$field->name]['']); + foreach ($edit[$field->name] as $index => $term_id) { + if ($term_id) { + db_query("INSERT INTO {profile_values_term} (fid, uid, tid) VALUES (%d, %d, %d)", $field->fid, $user->uid, $term_id); + } + } + } if (_profile_field_serialize($field->type)) { $edit[$field->name] = serialize($edit[$field->name]); } @@ -290,6 +302,13 @@ function profile_view_field($user, $fiel } } return implode(', ', $fields); + case 'taxonomy': + $fields = array(); + foreach((array)$value as $tid) { + $term = taxonomy_get_term($tid); + $fields[] = $browse ? l($term->name, "profile/". drupal_urlencode($field->name) ."/". drupal_urlencode($term->name)) : check_plain($term->name); + } + return implode(', ', $fields); } } } @@ -415,6 +434,15 @@ function profile_form_profile($edit, $us '#required' => $field->required, ); break; + case 'taxonomy': + $vid = $field->options; + $form_element = taxonomy_form($vid, $edit[$field->name], _profile_form_explanation($field)); + // Override default weight added by taxonomy module + $form_element['#weight'] = NULL; + // Override default title added by taxonomy module + $form_element['#title'] = check_plain($field->title); + $fields[$category][$field->name] = $form_element; + break; } } return $fields; @@ -548,12 +576,16 @@ function _profile_field_types($type = NU 'selection' => t('list selection'), 'list' => t('freeform list'), 'url' => t('URL'), - 'date' => t('date')); +// 'date' => t('date')); + 'date' => t('date'), + 'taxonomy' => t('taxonomy select'), + ); return isset($type) ? $types[$type] : $types; } function _profile_field_serialize($type = NULL) { - return $type == 'date'; +// return $type == 'date'; + return ($type == 'date' | $type == 'taxonomy'); } function _profile_get_fields($category, $register = FALSE) { diff -urp profile/profile.pages.inc profile/profile.pages.inc --- profile/profile.pages.inc 2007-12-08 19:36:22.000000000 +0530 +++ profile/profile.pages.inc 2008-08-23 11:48:46.000000000 +0530 @@ -36,6 +36,7 @@ function profile_browse() { // Determine what query to use: $arguments = array($field->fid); + $table = '{profile_values}'; // Barinder Patch 19014 switch ($field->type) { case 'checkbox': $query = 'v.value = 1'; @@ -49,14 +50,21 @@ function profile_browse() { $query = "v.value LIKE '%%%s%%'"; $arguments[] = $value; break; + case 'taxonomy': + $table = '{profile_values_term}'; + $query = "v.tid = '%s'"; + $terms = taxonomy_get_term_by_name($value); + $arguments[] = $terms[0]->tid; + break; default: drupal_not_found(); return; } // Extract the affected users: - $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); +// $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); + $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN $table v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); $content = ''; while ($account = db_fetch_object($result)) { $account = user_load(array('uid' => $account->uid)); @@ -66,7 +74,8 @@ function profile_browse() { $output = theme('profile_wrapper', $content); $output .= theme('pager', NULL, 20); - if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') { +// if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') { + if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield' || $field->type == 'taxonomy') { $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value))); } else {