Hi,

Firstly can I say thank you for such a great module, it really works great :) One request I would like to make is for it to suport the realname module, when creating a new task. http://drupal.org/project/realname

Instead of listing the available users by their username, it would be very helpfull if the module could list users by their Name & Suranames as specificed in the core profile.

Is this something that could be implemented ?

thanks
Charles

Comments

charles.holtzkampf’s picture

I have found the below that might be helpfull to add realname support.

http://drupal.org/project/author_smart_name

Allows the autocomplete field in "authoring information" to use values other than usernames.

I have tried to install the module, but I am getting an error. I have contacted the author for assistance. Once I have it installed I will try and change the form settings to match the to_do module:
$form['assignment']['assigned_users']

To see whether it works.

Charles

AlexisWilke’s picture

With real names being defined in the Core profile, it would certainly be feasible. We'd need to have a way to indicate whether a profile field represents a name we want to show whenever entered and possibly a way to hide the default username support.

The code is in this file:

to_do.users.autocomplete.inc

for the auto-complete.

And on clicking Save, the validation and submit function also need updates. That would be in this file:

to_do.pages.inc

Also, the auto-complete should probably transform the real name in a user identifier in the box, that way the validation and submit would work just fine.

Thank you.
Alexis Wilke

charles.holtzkampf’s picture

Hi Alexis,

thanks for the reply, im afraid im not a programmer, so I would not have a clue to do any of that. I was searching around for a solution and came across the above implementation.

I have tried changing the above mentioned modules code, to reflect the forms I think should be called, but again I am kind of guessing here. I did not work im afraid.

I changed the following

if ($form['assignment']['assigned_users']['#autocomplete_path']) {
   		$form['assignment']['assigned_users']['#autocomplete_path'] = 'smart/user_autocomplete';

Below is the actual module if that might help

<?php

/* 
 * Implementation of hook_menu()
 */
function author_smart_name_menu() {
  $items = array();
  
  $items['admin/settings/author_smart_name'] = array(
    'title' => 'Author Smart Name',
    'description' => 'Choose where your author name comes from',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('author_smart_name_settings'),
    'access arguments' => array('administer site configuration'),
    'file' => 'author_smart_name.admin.inc',
   );
  
  if (variable_get('author_smart_name_source', 0) != 0){
    $items['smart/user_autocomplete'] = array(
      'title' => 'User autocomplete',
      'page callback' => 'author_smart_name_autocomplete',
      'access callback' => 'user_access',
      'access arguments' => array('access user profiles'),
      'type' => MENU_CALLBACK,
     ); 
  }
  
  return $items;
}

/* 
 * Implementation of hook_menu()
 */
function author_smart_name_form_alter(&$form, $form_state, $form_id){
  if (variable_get('author_smart_name_source', 0) != 0){
    // Changing the authoring information in order to call another ajax function instead of core
    if ($form['assignment']['assigned_users']['#autocomplete_path']) {
   		$form['assignment']['assigned_users']['#autocomplete_path'] = 'smart/user_autocomplete';

      // Attach validation function to strip the real name off the submitted value.
      if (!in_array('_author_smart_name_validate', $form['#validate'])) {
        array_unshift($form['#validate'], '_author_smart_name_validate');
      }
   	}
  }
}

function author_smart_name_autocomplete($string = '') {
  $matches = array();
  
  if ($string) {
    
    $source = variable_get('author_smart_name_source', 0);
  
    switch ($source){
      // Core Profile module = 1
      case '1': 
        $result = db_query_range("SELECT CONCAT(u.name, ': ', pv.value) AS name, pv.value FROM {users} u, {profile_values} pv WHERE pv.fid = %d AND pv.uid = u.uid AND LOWER(pv.value) LIKE LOWER('%s%%')", 1, $string, 0, 10);
        while ($user = db_fetch_object($result)) {
          $matches[$user->name] = check_plain($user->value);
        }
      break;
      
      // Content Profile Modile = 2
      case '2':
        $field = variable_get('author_smart_name_profile_field', 'title');
        $type = variable_get('author_smart_name_profile_type', 'profile');
        if ($field == 'title'){
          $result = db_query_range("SELECT CONCAT(u.name, ': ', n.title) AS name, n.title FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = '%s' AND LOWER(n.title) LIKE LOWER('%s%%')", $type, $string, 0, 10);
          while ($author = db_fetch_object($result)) {
            $matches[$author->name] = check_plain($author->title);
          }
        }
        else {
          // TODO other fields on the node?
        }
      break;
    }  
  }
  drupal_json($matches);
}

/**
 * Detects names of the form 'username: smart name' and converts them to 'username', prior to node_validate() being run.
 */
function _author_smart_name_validate($form, &$form_state) {
  // Use limit=2 in the event that real names contain ':'.
  $name = explode(':', $form_state['values']['name'], 2);
  $username = $name[0];
  if ($author = user_load(array('name' => $username))) {
    $form_state['values']['name'] = $author->name;
  }
}

Anyways I hope this can be implemented would be such a great add on to, the to do list module.

AlexisWilke’s picture

I may look into it. You're the 2nd person to ask for such a feature, although the other person did not use a the Core Profile module.

Thank you.
Alexis

charles.holtzkampf’s picture

thanks much appreciated.