CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Sort Name for Org Records
Pages: [1] 2

Author Topic: Sort Name for Org Records  (Read 5005 times)

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Sort Name for Org Records
February 28, 2013, 02:13:20 pm
The sort name for organization records seems to be identical to the display name.  I think it would be helpful to strip any leading "the "s and also expose the sort name field.

I see that there was a fix for exposing this field, but that it was marked "not fixed". http://issues.civicrm.org/jira/browse/CRM-6333

Wondering why this wasn't adopted, and whether there would be any objection to having the sort name strip any leading "The "s.    I haven't looked yet, but I assume there is code that is run on insert/update of contacts that sets the sort name, and it should be a fairly easy thing to modify. 
« Last Edit: February 28, 2013, 02:18:39 pm by civicrmsav »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sort Name for Org Records
February 28, 2013, 04:41:42 pm

Might want to take a look at the patch and see if you can create a new patch for 4.3 from it

Not sure if there is any benefit from deleting the The, since in most cases we do a wild card search on sort name

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: Sort Name for Org Records
February 28, 2013, 06:30:09 pm
If you are open to that, I'll try to do it.   It's certainly a more complete way of doing in than just stripping the "the"s.  But right now we're using view to pull up a list of members on our website, and if I sort the view on sortname the "the"s all sort in the 't's instead of in their appropriate spot, which is why this is on my radar. 

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: Sort Name for Org Records
May 29, 2013, 06:59:46 pm
Finally coming back to this after a long hiatus.   

if I change line 163 of my 4.2 version

from this: 
$contact->display_name = $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
to this: 
        $contact->display_name = CRM_Utils_Array::value('organization_name', $params, '');
        $contact->sort_name = preg_replace('/^the /i', '', CRM_Utils_Array::value('organization_name', $params, ''));

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: Sort Name for Org Records
May 29, 2013, 07:15:28 pm
Must have hit save by accident somehow ...

The change above works well for my simple needs.  (Of course you need to do this: update civicrm_contact set sort_name = right(sort_name, length(sort_name) - 4) where sort_name like 'the %'; to correct existing organizations.)

Is this of interest as a patch?  I don't know when or if I'll ever get to tackling the larger question of exposing the sort name. Although that would clearly be a better solution.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Sort Name for Org Records
May 29, 2013, 09:01:57 pm
I think this would be an excellent patch!  I love that this is at the BAO level too...so in theory should fire on anything that resaves a record.

That also means that there's an alternative way to fix existing records that works for savvy end users who aren't up to playing with SQL - you can tell them to export just the contact IDs of the relevant records, then import a CSV of just the contact IDs.  The records will be resaved, the sort name should get fixed.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sort Name for Org Records
May 29, 2013, 09:30:44 pm

we'll need to figure out how to address this for other languages and probably other patterns.

maybe introduce a hook there with the default implementation, checking the language and  if en_* stripping 'the' out

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: Sort Name for Org Records
May 30, 2013, 10:14:20 am
Right, language checking. I thought of that just after posting.   Would you be open to this, so that at least the simple case could be solved in the code base? This fixes it for us english speakers without mucking it up for others.

It definitely should be more generic both in terms of language and pattterns, but I don't have tine to do that right now.

Code: [Select]
$contact->display_name = CRM_Utils_Array::value('organization_name', $params, '');
        global $tsLocale;
        if ($tsLocale = '' or $tsLocale = 'en_US') {
                $contact->sort_name = preg_replace('/^the /i', '', CRM_Utils_Array::value('organization_name', $params, ''));
             }
             else{
                   $contact->sort_name = CRM_Utils_Array::value('organization_name', $params, '');
             }

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Sort Name for Org Records
May 30, 2013, 03:12:53 pm
Hi,

en_GB might want to remove "the" too

I'd second lobo suggestion to have a new hook, and create your "remove the" as an extension that implements the hook. Gives a good example AND makes it more modular (eg. I have clients with a dutch interface but that deal with a lot of english org)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sort Name for Org Records
May 30, 2013, 04:04:42 pm

I dont think we should put language specific code directly in the code base. Would be good to design and implement this so it could apply to other languages as easily as english

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

BrightBold

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • MySQL version: Pantheon
  • PHP version: Pantheon
Re: Sort Name for Org Records
April 03, 2014, 06:39:16 pm
Agreed - I would really like this functionality. I posted a comment in CRM-6333 linking to this issue and asking if it was appropriate to reopen (which I don't appear to have the permissions to do), but I know in the Drupal issue queue, the maintainers will rarely ever see a comment on a closed issue, so I thought I should pipe up here as well.

One use case: I've used Eileen's entity module to expose CiviCRM data to Views, and I've created a list of auction donors that contains both individuals and organizations. But not everything is in the right order so it would be great to be able to control it.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Sort Name for Org Records
April 03, 2014, 07:19:59 pm
It sounds like the preferred approach is to use a hook + extension. I think you could use existing "post" hook against the contact record (in theory :-) ).
Protect your investment in CiviCRM by  becoming a Member!

BrightBold

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • MySQL version: Pantheon
  • PHP version: Pantheon
Re: Sort Name for Org Records
April 16, 2014, 07:53:23 am
Thanks Dave!

I'm new enough to this that although I have some experience with Drupal hooks, I have no idea (yet) what an "existing post hook against the contact record" would be, but hopefully I will figure all this out soon.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Sort Name for Org Records
April 16, 2014, 02:38:40 pm
There's good documentation for getting started with CiviCRM hooks / extensions on the wiki. Start from here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Develop
Protect your investment in CiviCRM by  becoming a Member!

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Re: Sort Name for Org Records
October 22, 2014, 12:01:11 pm
I've been discussing this with Dave recently as a client has been willing to sponsor (part) of this effort.  The cost would be relatively low, but no insignificant. 

If would could find a way to make Sort Name available for editing on Households and Organizations ...as well as import and batch update, would any of you be interested in contributing $ € £ ?

See here for more information on the plan:
http://wiki.civicrm.org/confluence/display/CRM/Sort+Name+as+a+Customizable+Field
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Sort Name for Org Records

This forum was archived on 2017-11-26.