--- profile.module.ini 2006-04-17 22:48:26.000000000 +0200 +++ profile.module 2006-06-08 00:14:30.000000000 +0200 @@ -30,6 +30,7 @@
  • freeform list
  • URL
  • date
  • +
  • related with
  • '); $output .= t('

    You can

    @@ -240,6 +241,14 @@ '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'), ); } + if ($type == 'related') { + $form['fields']['options'] = array('#type' => 'textfield', + '#title' => t('Related with node type'), + '#default_value' => $edit['options'], + '#description' => t('Content type name of the related node type, for instance: page, image, event, flexinode-1 (on flexinodes it will be something like flexinode-X where X is your flexinode id).'), + '#required' => TRUE, + ); + } $form['fields']['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], @@ -251,7 +260,7 @@ '#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' || $type == 'related') { $form['fields']['page'] = array('#type' => 'textfield', '#title' => t('Page title'), '#default_value' => $edit['page'], @@ -436,6 +445,11 @@ $query = "v.value LIKE '%%%s%%'"; $arguments[] = $value; break; + case 'related': + ////$query = 'v.value = 1'; + $query = "v.value LIKE '%%%s%%'"; + $arguments = explode("#",$value); + break; default: drupal_not_found(); return; @@ -452,7 +466,7 @@ } $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' || $field->type == 'related') { $title = strtr($field->page, array('%value' => theme('placeholder', $value))); } else { @@ -513,7 +527,10 @@ $edit[$field->name] = serialize($edit[$field->name]); } db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); - db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); + //if (is_array($edit[$field->name])) + // db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, serialize($edit[$field->name])); + //else + db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); // Mark field as handled (prevents saving to user->data). $edit[$field->name] = NULL; } @@ -551,6 +568,43 @@ 'H:i' => null, 'g:ia' => null); return strtr($format, $replace); + case 'related': +/* + $values=$value; + foreach ($values as $value) { + if ($value = trim($value)) { + $fields[] = $browse ? l($value, 'profile/'. $field->name .'/'. $value) : check_plain($value); + } + } + return implode(', ', $fields); +*/ + +/* + $output=""; + foreach ($value as $node_id) { + if ($node_id = trim($node_id)) { + $node=array( + 'nid' => $node_id, + 'type' => "page", + 'title' => "myTitle" + ); + $output = $field->required, ); break; + //MBR extension: + case 'related': + //Get nodes from the requested type: + //$result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight'); + $rows = db_query('SELECT {nid}, {title} FROM {node} WHERE {type} like "' .$field->options. '" ORDER BY title'); + + ////$rows=node_db_rewrite_sql($query, $table, $where); + + //$options = $field->required ? array() : array('none' => 'None'); + $options = ""; + while ($row = db_fetch_object($rows)) { + $nid = $row->nid; + $ntitle = $row->title; + if ($row = trim($row)) { + $options[$nid] = check_plain($ntitle); + } + } + $fields[$category][$field->name] = array('#type' => 'select', + '#title' => check_plain($field->title), + '#default_value' => $edit[$field->name], + '#multiple' => TRUE, + '#options' => $options, + '#description' => _profile_form_explanation($field) . " Utilitza [Shift + clic] per a indicar més d'uan opció i [Control + clic] per a desactivar una opció previament escollida.", + '#required' => $field->required, + ); + break; case 'date': $fields[$category][$field->name] = array('#type' => 'date', '#title' => check_plain($field->title), @@ -730,7 +810,7 @@ } function profile_categories() { - $result = db_query("SELECT DISTINCT(category) FROM {profile_fields}"); + $result = db_query("SELECT DISTINCT(category) FROM {profile_fields} ORDER BY {fid}"); //MBR: ORDER BY visibility // ORDER BY fid while ($category = db_fetch_object($result)) { $data[] = array('name' => check_plain($category->category), 'title' => $category->category, 'weight' => 3); } @@ -779,10 +859,11 @@ 'selection' => t('list selection'), 'list' => t('freeform list'), 'url' => t('URL'), + 'related' => t('related with'), 'date' => t('date')); return isset($type) ? $types[$type] : $types; } function _profile_field_serialize($type = NULL) { - return $type == 'date'; + return (($type == 'date') || $type == 'related'); }