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 »
  • CiviEvent Suggestions (Moderator: Michał Mach) »
  • Using Tags to Sort Event Participants
Pages: [1]

Author Topic: Using Tags to Sort Event Participants  (Read 5293 times)

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Using Tags to Sort Event Participants
March 11, 2010, 10:35:16 pm
A client of ours is wanting to be able to be able to use the Contacts' Tags as a way to sort Participants when managing an event. They are a theatre company and have thousands of contacts. I had suggested using Roles (to search/sort), as this is a pre-existing feature of CiviEvent, but this does not suit their requirements.

A couple of items of correspondence are below;

From my Project Manager
Quote
They want to be able to use one of the searches to send participants to an event - then once in the event they wish to be able to sort the participants according to who's department they belong to - so each department can see their own list more easily (you can imagine with many hundreds of participants, picking through them would be quite tedious and slower than their current method).

From one of the Client's Team Members
Quote
We need the roles to be used in a different way to assign not attendees (i.e ticket buyers) but performers, suppliers and other employees to an event. Plus it wouldn't allow us to categorise the roles by department either so we would not gain anything. Also it wouldn't allow us to categorise contacts at the point of entry into the database.

Without me hacking the CiviCRM code to the extent that we pull the project out of any chance of future upgrades, are their any suggestions on how this can be achieved?

If code changes are the only option, I think I'll need a few pointers to making the necessary modifications.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using Tags to Sort Event Participants
March 12, 2010, 12:28:37 am
Think that's a good idea.

Quote from: DirkHartog on March 11, 2010, 10:35:16 pm
Without me hacking the CiviCRM code to the extent that we pull the project out of any chance of future upgrades, are their any suggestions on how this can be achieved?
Financial contributions are a good way of increasing the odds of a feature to get implemented. Could you go down that road ?

Quote from: DirkHartog on March 11, 2010, 10:35:16 pm
If code changes are the only option, I think I'll need a few pointers to making the necessary modifications.


The easiest might be to develop a custom search, copy/reuse most of the interface and function from the participants' search and add a inner join on the tag table.

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

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 15, 2010, 09:05:01 pm
Okay, I've managed to find the template at /CRM/Event/Form/Selector.tpl and copy that to the appropriate place in my custom templates directory.

Next: What PHP files contain the code to gather the array of data which is used to fill the table in that template?

If I can find such a file(s), then I can (maybe) find where to insert the inner join to grab the tags as part of the contact data. And also, get that data put into the array  for the template.
« Last Edit: March 15, 2010, 10:04:08 pm by DirkHartog »

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 15, 2010, 11:43:39 pm
In my custom template at CRM/Event/Form/Selector.tpl I have inserted a row into the table;
Code: [Select]
    <td>{$row.tags}</td>

Now I've found CRM/Event/Selector/Search.php and in my custom copy I have added;

into the function &getColumnHeaders
Code: [Select]
array(
    'name'      => ts('Tags'),
    'sort'      => 'tags',
    'direction' => CRM_Utils_Sort::DONTCARE,
),

into the function &getRows at line 326
Code: [Select]
$row['tags'] = 'test' ;

And the result is a display of a column with the header 'Tags' and each cell containing 'test'. Woohoo  :D

The next part is trying to find how to get the tag data. What function in what file?  ???
« Last Edit: March 15, 2010, 11:51:55 pm by DirkHartog »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using Tags to Sort Event Participants
March 16, 2010, 12:09:28 am
isn't your code different than the initial goal ?

didn't you want to filter by tag rather than displaying them as an extra column ?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 17, 2010, 07:08:50 pm
Part of this is that they want a column in the search results form where they can sort by Tags.

So, from my previous post, is there any help that can be provided by indicating where I can get the tag data? What function in what file?

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: Using Tags to Sort Event Participants
March 17, 2010, 07:22:18 pm

i assume u r aware that tags are on a contact not on a participant.

To get the exisiting tags of a contact, you can use the api call:

civicrm_entity_tag_get

Check: http://svn.civicrm.org/civicrm/branches/v3.1/tests/phpunit/api/v2/EntityTagTest.php for an example of usage

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

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 17, 2010, 11:15:53 pm
Well, I now have the correct Tag names displayed in a column in the search results, via a bit of editing of the custom copies of;

CRM/Event/Form/Selector.tpl
and
CRM/Event/Selector/Search.php

What I'm wrestling with now is how to make the Search results able to be sorted via the Tags column header.

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: Using Tags to Sort Event Participants
March 18, 2010, 06:50:55 am

this is a bit harder since the query does not retrieve the tag information and hence u cant let mysql do the hard work of sorting

your best bet might be to do a PHP sort in CRM/Event/Selector/Search.php. You'll need to make sure you retrieve all the participants etc

Thinking about it a bit more, a better approach might be to use a custom search or report rather than hacking core

http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Search+Components
http://wiki.civicrm.org/confluence/display/CRMDOC/CiviReport+structure+and+customization

This is assuming your search criteria is not too complex

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

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 19, 2010, 12:33:19 am
After many hours of searching and attempting to make sense of the vast cobweb of code which is CiviCRM, I finally ended up with something which is probably a bit of a brutish approach, but it works. I created some custom files (PHP and Templates) which are slightly modified from the originals.


custom/templates/CRM/Event/Form/Selector.tpl
Line 40: insert
Code: [Select]
<!--Line 52: insert
Code: [Select]
-->
    <td>{$row.tags}</td>


custom/PHP/CRM/Event/Selector/Search.php
Line 88: append
Code: [Select]
, 'tags'Line 291: insert
Code: [Select]
require_once 'CRM/Core/PseudoConstant.php';Line 294: insert
Code: [Select]
$tagNames =& CRM_Core_PseudoConstant::tag( );Line 297: insert
Code: [Select]
$names = array() ;Line 328: insert
Code: [Select]
require_once 'CRM/Core/BAO/Tag.php';
require_once 'CRM/Core/BAO/EntityTag.php';
$tagIDs = CRM_Core_BAO_EntityTag::getTag($result->contact_id);
foreach ( $tagIDs as $id => $dontCare ) {
    if (array_key_exists($id, $tagNames)) {
         $names[] = $tagNames[$id];
     }
}
$row['tags'] = implode(', ', $names);
Comment out Lines 392-396
Line 399: insert
Code: [Select]
array(
    'name'      => ts('Tags'),
    'sort'      => 'tags',
    'direction' => CRM_Utils_Sort::DONTCARE,
    ),


custom/PHP/CRM/Contact/BAO/Query.php
Line 622: insert
Code: [Select]
if (!array_key_exists('tags', $this->_select)) {
    $this->_useGroupBy  = true;
    $this->_select['tags'              ] = "GROUP_CONCAT(DISTINCT(civicrm_tag.name)) AS tags";
    $this->_element['tags'             ] = 1;
    $this->_tables['civicrm_tag'       ] = 1;
    $this->_tables['civicrm_entity_tag'] = 1;
}

If there is a more elegant/refined approach (something more specific to the requirement) I'd like to know.

If this seems like a hack which people would like to see added to the general repository, then I'll come up with some diff files.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using Tags to Sort Event Participants
March 19, 2010, 02:50:57 am
First, well done, you have found your way around a part of code of civi that isn't that easy to visit ;)

I'd think that you tag on event part is a bit too specific, but  could you attach the patch to this forum post ? Will be proven handy if one wants to do something like you.

As for the CRM/Contact/BAO/Query.php I think it should go back in the core. That's a nice and logical addition (quite surprised it isn't in already actually, eg to handle the tag in a profile if used for a list).

Lobo, what do you think ?

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: Using Tags to Sort Event Participants
March 19, 2010, 08:12:42 am

hmm, i dont think we should add it to core, a few reasons:

1. Query should return only what its asked for. If tags has not been requested it should not be returned

2. GROUP_CONCAT has a limitation with regard to how many tags / length. We prefer not using it (we've been bitten a few times using that).

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using Tags to Sort Event Participants
March 20, 2010, 04:53:35 am
Code: [Select]
if (!array_key_exists('tags', $this->_select)) {

Doesn't it mean the tags are returned only if requested ?

Didn't know about group_concat, thx.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 21, 2010, 06:09:29 pm
After thinking about it over the weekend and reading your comments, I have been able to reduce the changes to custom/PHP/CRM/Event/Selector/Search.php as follows;

Line 88: append
Code: [Select]
, 'tags'
Line 325: insert
Code: [Select]
$row['tags'] = $result->tags ;
Comment out Lines 381-385

Line 386: insert
Code: [Select]
array(
    'name'      => ts('Tags'),
    'sort'      => 'tags',
    'direction' => CRM_Utils_Sort::DONTCARE,
    ),

This is due to selecting the Tags in the Query.php

The other two files remain as per my previous post.
« Last Edit: March 21, 2010, 06:18:31 pm by DirkHartog »

DirkHartog

  • I’m new here
  • *
  • Posts: 16
  • Karma: 1
Re: Using Tags to Sort Event Participants
March 21, 2010, 07:58:48 pm
Here we are,

attached is a text file containing the diff instructions for all three files to include the Tags Column in searching for Event Participants.

I can keep these as custom files for now, but I'd like to know if this makes it into future releases. Should I submit this in the Issue Tracker? If so, where should I put it?

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • CiviEvent Suggestions (Moderator: Michał Mach) »
  • Using Tags to Sort Event Participants

This forum was archived on 2017-11-26.