Community & Support

Location Module - Two Locations per User - How to distinguish?

I'm using the Location Module to store one or two locations for each user - one for current location (required), and another for their home place (optional).

I've allowed two locations to be shown on the profile edit (and registration) pages. However, the Location Module doesn't keep them in the same order that they were entered. I can't figure out its logic for this either - it's not by location id (lid) - coz 14 was followed by 13 - and not alphabetical coz "A.." came after "H..".

Also, if someone can help me sort out *this* issue, there's another one... How will I be able to get the location(s) I need from the database. For example, if I need current location for a user, how do I know which of the two records in the location_instance table is the one I need (for that user)?

Comments

Did you find a solution ?

Hi,

It seems I will face the same need you had (storing multiple location for a user, being able to distinguish one from the other). Did you find a solution ?

Best regards,
Simon

Not yet...

@Simon... No solution yet. And, as you can see, so far you are the only respondent to my post. If you figure something out before we get an answer here, please post back, ok? And I'll certainly do the same.

Cheers.

_

afaik, it supposed to be alphabetical. That's how it works on my dev site.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Doesn't seem very useful...

So how would I use it for a current location and a home location?

If I can't count on the order of the locations - or distinguish one from the other - I won't be able to know which is which, true?

_

I'm not sure I understand -- "current location" will always come before "home location" (c before h).

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

That's not what I meant...

I'm talking about the field values. I was just referring to them as the purpose for which they are intended to be used in my site (current vs. home).

So, using hook_form_alter, I was able to make the fieldset groupings have the correct wording I wanted. The "top" location on my form was "Current Location", the second location was "Home Location".

But if I enter "Los Angeles" in Current and "Austin" in Home, when the form is redisplayed, Austin is now first (labeled "Current") and Los Angeles is second (labeled "Home") - just the reverse of what I entered.

I just don't see how multiple locations would be useful at all the way this module works. I mean, how can anyone be in more than one location at a time? Unless this is just meant for business profiles that have multiple branches - and, even then, it seems like the business would want their main branch (corporate HQ) to be shown first, even it it wasn't first alphabetically.

_

I don't have access to the site atm, but I'm fairly certain I hook_form_altered the location field names for location 0 to be "Home" and location 1 to be "Work" and then just disabled and hid them. For user locations at any rate.

For node based locations you can just create separate location cck fields. To extend that to users you could use the content_profile module.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

_

Found my code, this is what I did:

<?php
function custom_form_alter(&$form, $form_state, $form_id) {
  switch (
$form_id) {
    case
'user_profile_form':
     
$form['locations'][0]['#title'] = "Home";
     
$form['locations'][0]['#default_value']['name'] = "Home";
     
$form['locations'][1]['#title'] = "Work";
     
$form['locations'][1]['#default_value']['name'] = "Work"
     
break;
  }
}
?>

And then I just hid the form elements themselves with css:

#edit-locations-0-name-wrapper,
#edit-locations-1-name-wrapper,
#edit-locations-0-delete-location-wrapper,
#edit-locations-1-delete-location-wrapper {
  display: none;
}

A bit ugly, but it works.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

More questions...

Ok, I see what your doing with the names (Home and Work), but I don't understand the reason for hiding with CSS.

And, does this really keep the values with the appropriate "classifications". In my code, I had already changed the "field names" that the user sees to say "Current" and "Home" (similar to your "Home" and "Work"). But when I entered "Houston" in the first field (labeled "Current") and "Austin" in the second (labeled "Home"), then re-displayed the user edit form, they were reversed because of being re-ordered in the table used by the Location module. So in my example, Austin was shown as "Current" and Houston as "Home".

My point is... it's the way the Location module stores and retrieves the data that is the issue, not the arbitrary naming (or labeling) of fields on the page. Seems like it should store the values entered for location "0" as location "0", and "1" as "1", and so on. And always retrieve them in the same fashion.

__

I didn't want users to be able to change the location name so I hid it with css ( i never did figure out how to disable that one part of the field).

You've totally lost me with what your problem is. But the location field is an array and can be referenced with 0 and 1 (as I do right in my code). And they don't ever get reversed or changed. Whatever is entered in locations[0] and locations[1] will always be there (unless manually changed by the user).

Sorry, I just don't get what your issue is.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

It just didn't work that way for me...

@WorldFallz... first, thanks ever so much for hanging in there with me on this.

My issue is that it didn't work for me the way you are describing. On my form, I had location 0 set with the label of "Current" and location 1 with "Home". I entered "Austin" as current (location 0) and "Houston" as home (location 1). I re-displayed the user-edit page and "Houston" was shown first (location 0) and "Austin" second (location 1). That's why, in my original post, I said it didn't even seem to be alphabetical, coz Houston came before Austin.

Also, beyond the cosmetics of showing it on the page, I couldn't see a way that I could tell which record in the {location_instance} table is "location 0" ("Current" in my site) or "location 1" ("Home" in my site). So if, for example, I want to show the user's current location on their profile page (or wherever their username and profile photo thumbnail appears), how would my code know which is which?

However, as you can see above, my original post was back in October, and I haven't had time to get back to that code during our latest exchange in this thread. Perhaps I can let you off the hook for now until I finish my current project and can take another look at that page.

Thanks again.