--- database/database.mysql.orig 2005-03-16 23:06:37.000000000 +0100 +++ database/database.mysql 2005-03-16 23:08:11.000000000 +0100 @@ -466,6 +466,15 @@ KEY fid (fid) ); +-- +-- Table structure for table `profile_values_term` +-- + +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' +); -- -- Table structure for table 'url_alias' --- modules/profile.module.orig 2005-03-16 23:05:47.000000000 +0100 +++ modules/profile.module 2005-03-16 23:00:28.000000000 +0100 @@ -161,6 +161,13 @@ // We use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues. } while ($field = db_fetch_object($result)) { + if ($field->type == 'taxonomy') { + /* do this before serialize */ + db_query("DELETE FROM {profile_values_term} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); + foreach ($edit[$field->name] as $index => $term_id) { + db_query("INSERT INTO {profile_values_term} (fid, uid, tid) VALUES (%d, %d, %d)", $field->fid, $user->uid, $term_id[0]); + } + } if (_profile_field_serialize($field->type)) { $edit[$field->name] = serialize($edit[$field->name]); } @@ -289,6 +296,9 @@ case 'date': $fields[$category] .= _profile_date_field($field, $edit); break; + case 'taxonomy': + $fields[$category] .= _profile_taxonomy_field($field, $edit); + break; } } @@ -348,6 +358,23 @@ return format_date(gmmktime(0, 0, 0, $month, 2, 1970), 'custom', 'M', 0); } + +/** + * Helper function to select one or more types of taxonomy. + * This is basically the function taxonomy_form() with vocabulary->multiple + * forced to true. + */ +function _profile_taxonomy_field($field, $edit) { + $vid = $field->options; + $vocabulary = taxonomy_get_vocabulary($vid); + $data = array(); + foreach ($edit[$field->name] as $index => $termid) { + $data[] = $termid[0]; + } + return _taxonomy_term_select($vocabulary->name, $field->name, + $data, $vid, $vocabulary->help, 1, 0); +} + function profile_validate_profile($edit, $category) { if (($_GET['q'] == 'user/register') ? 1 : 0) { @@ -514,6 +541,15 @@ if ($type == 'selection') { $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, 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; + // print "key $key ---> $value->name
\n"; + } + $group .= form_select(t('Vocabulary'), 'options', $edit['options'], $taxopt, t('Select the vocabulary you want to use'), '', FALSE, TRUE); + } $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.')); $group .= form_radios(t('Visibility'), 'visibility', $edit['visibility'], array(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') { @@ -582,12 +618,13 @@ 'selection' => t('list selection'), 'list' => t('freeform list'), 'url' => t('URL'), - 'date' => t('date')); + 'date' => t('date'), + 'taxonomy' => t('taxonomy')); return isset($type) ? $types[$type] : $types; } function _profile_field_serialize($type = NULL) { - return $type == 'date'; + return $type == 'date' or $type == 'taxonomy'; } ?>