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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Get Contact Tags of a Tag Set - to present within a Template
Pages: [1]

Author Topic: Get Contact Tags of a Tag Set - to present within a Template  (Read 1770 times)

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Get Contact Tags of a Tag Set - to present within a Template
September 03, 2011, 05:53:29 pm
Hi,

we are in progress of reworking our Alumni system with CiviCRM. Right now I have the following problem:
I setup a Tag Set called "Field of Study". Our students add tags in their Profile/Summary Page like "Chemistry", "Economics" and so on which works great.

Now I want to list via the API within the summary page the child tags (Chemistry, Economics etc.) of the Parent Tag (Field of Study) that the specific student choose.

Unlike the call "GroupContact", I don't know how to tell the api to filter for a certain contact_id, so it just shows the tags of a contact.
Code: [Select]
$results=civicrm_api("TagContact","get", array ('version' =>'3', 'contact_id' =>'102'));
I would be very thankful if someone could show me a solution to get those Tags depending on the contact viewed.

Sincerely
Sondy

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Get Contact Tags of a Tag Set - to present within a Template
September 04, 2011, 02:02:52 am
Hi,

Not sure what you want to do. Get the list of tags a contact has? The entity to use it EntityTag:

http://drupal.demo.civicrm.org/civicrm/ajax/doc#/civicrm/ajax/rest?json=1&debug=1&version=3&entity=EntityTag&action=get&contact_id=1
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Re: Get Contact Tags of a Tag Set - to present within a Template
September 04, 2011, 04:15:39 am
Hey,

almost :-)

This query shows me all the tags a contact has. I just want those tags, that belong to the parent tag set "Field of Study".

I'll just explain what I did:
I went to: Administer -> Option Lists -> Tags (Categories)
and created a new Tag Set (Add Tag Set) which is called "Field of Study" which has the ID: 6.
Now Students go to their profile under the "Tags Tap" and add Tags to the Tag Set "Field of Study". This could be "Chemistry", "Economics", "Physics" and so on.
All those student entered tags show up now under [Administer -> Option Lists -> Tags (Categories)] with the information Parent ID -> "Field of Study (6)" next to it. For example:
chemistry - id: 7 - parent_id:6
economics - id: 8 - parent_id:6
physics - id: 9 - parent_id:6
(...)

What I want to do now is this:
Extend the area above the summary.tpl to show the following - Name and a list of the Subjects the Student studies:

John Doe
Field of Study: Economics, Chemistry <- where this has to be a query that pulls the tags (subjects the student studies) - pseudo code: show tags of contact_id=1 [if] tag has parent_id=6

We are very new to civicrm - its very hard to get through all the parameters and structure.

thank you
« Last Edit: September 04, 2011, 04:24:32 am by Alex Sondy »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Get Contact Tags of a Tag Set - to present within a Template
September 04, 2011, 06:21:27 am
Hi,

There isn't (yet) a way of filtering the tags by parent. This being said, seems like a useful feature, do you think you can submit a patch?

The function to modify is into api/v3/EntityTag.php. Might have to modify the BAO or add the feature you need directly in the _get function.

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

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Re: Get Contact Tags of a Tag Set - to present within a Template
September 04, 2011, 06:50:59 am
Oh, I'm very new to php, civicrm and the whole idea of a API etc. I'm an economics student just volunteering reassembling our alumni system.
For now I'm probably more the one that needs the support. But as soon I know my way around and can contribute, I surely will.

After a while I figured I could just combine the "EntityTag" call and the "Tag" call it to get what I wanted. Maybe its a little immature, but it works. One of my first php functions ^^

Funtion to create an array of tags of a contact id ($func_contactId) which tags belong to a certain parent tag id ($func_tag_parrent_id)
Code: [Select]
function pac_contact_child_tags($func_contactId, $func_tag_parrent_id) {
require_once 'api/api.php';
$func_entitytag=civicrm_api("EntityTag","get", array ('version' =>'3', 'contact_id' =>$func_contactId));
foreach ($func_entitytag["values"] as $func_entitytag_tag_id) {
$func_tag=civicrm_api("Tag","get", array ('version' =>'3', 'id' =>$func_entitytag_tag_id[tag_id]));
if ($func_tag["values"][$func_entitytag_tag_id[tag_id]]["parent_id"] == $func_tag_parrent_id) {
$func_tag_filtered[] = $func_tag["values"][$func_entitytag_tag_id[tag_id]]["name"];
}
}
return $func_tag_filtered;
}

To list the Tags of a Parent Tag in the summary template
Code: [Select]
{php}
$pac_contactId = $this->get_template_vars('contactId');
$i = 0;
foreach (pac_contact_child_tags($pac_contactId, 6) as $pac_tag) {
if ($i > 0) {
echo ", ";
}
echo $pac_tag;
$i++;
}
{/php}

Output
Code: [Select]
economics, chemistry

I would like to gather all the functions/classes outside of the template. Where should a put my "function_reposetory.php" in the cms structure so I can include it in the template when I need it?

Thank you for your answers. I'm open to criticism.

Sondy
« Last Edit: September 04, 2011, 06:55:14 am by Alex Sondy »

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: Get Contact Tags of a Tag Set - to present within a Template
September 04, 2011, 07:58:34 am

in drupal, you would package all the functions in a .module file

might want to check the docs on drupal.org which are quite nice

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Get Contact Tags of a Tag Set - to present within a Template

This forum was archived on 2017-11-26.