--- modules/profile.module.head 2005-09-14 17:22:23.467334400 +0100
+++ modules/taxonomyprofile.module 2005-09-14 17:36:52.174270872 +0100
@@ -144,15 +144,21 @@
}
// Determine what query to use:
+ $qsql = 'v.value =';
switch ($field->type) {
case 'checkbox':
- $query = 'v.value = 1';
+ $query = '1';
break;
case 'selection':
- $query = "v.value = '". db_escape_string($value) ."'";
+ $query = db_escape_string($value);
break;
case 'list':
- $query = "v.value LIKE '%%". db_escape_string($value) ."%%'";
+ $qsql = 'v.value LIKE';
+ $query = "%%". db_escape_string($value) ."%%";
+ break;
+ case 'taxonomy':
+ $terms = taxonomy_get_term_by_name($value);
+ $query = serialize(array($terms[0]->tid));
break;
default:
drupal_not_found();
@@ -160,7 +166,7 @@
}
// Extract the affected users:
- $result = pager_query("SELECT u.uid FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND $query ORDER BY u.access DESC", 20, 0, NULL, $field->fid);
+ $result = pager_query("SELECT u.uid FROM {users} u INNER JOIN {profile_values} v ON u.uid = v.uid WHERE v.fid = %d AND %s '%s' ORDER BY u.access DESC", 20, 0, NULL, $field->fid, $qsql, $query);
$output = '
';
while ($account = db_fetch_object($result)) {
@@ -170,7 +176,7 @@
}
$output .= theme('pager', NULL, 20);
- if ($field->type == 'selection' || $field->type == 'list') {
+ if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'taxonomy') {
$title = strtr($field->page, array('%value' => theme('placeholder', $value)));
}
else {
@@ -277,7 +283,14 @@
}
}
return implode(', ', $fields);
- }
+ case 'taxonomy':
+ $fields = array();
+ foreach($value as $tid) {
+ $term = taxonomy_get_term($tid);
+ $fields[] = $browse ? l($term->name, "profile/". urlencode($field->name) ."/". urlencode($term->name)) : check_plain($term->name);
+ }
+ return implode(', ', $fields);
+ }
}
}
@@ -359,6 +372,8 @@
case 'date':
$fields[$category] .= _profile_date_field($field, $edit);
break;
+ case 'taxonomy':
+ $fields[$category] .= _profile_taxonomy_field($field, $edit);
}
}
@@ -429,6 +444,22 @@
return format_date(gmmktime(0, 0, 0, $month, 2, 1970), 'custom', 'M', 0);
}
+/**
+ * Helper function to select one or more types of taxonomy.
+ */
+function _profile_taxonomy_field($field, $edit) {
+ $vid = $field->options;
+ $vocabulary = taxonomy_get_vocabulary($vid);
+ $data = array();
+ if($edit[$field->name]) {
+ foreach ($edit[$field->name] as $index => $termid) {
+ $data[$termid] = $termid;
+ }
+ }
+
+ return taxonomy_form($vid, $data, $vocabulary->help, $field->name);
+}
+
function profile_validate_profile($edit, $category) {
if ($_GET['q'] == 'user/register' || $_GET['q'] == 'admin/user/create') {
@@ -603,6 +634,13 @@
if ($type == 'selection') {
$group .= form_textarea(t('Selection options'), 'options', $edit['options'], 60, 5, 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;
+ $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_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') {
@@ -684,11 +722,12 @@
'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';
}
?>