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 (Moderator: Donald Lobo) »
  • Trying to print CiviCRM_Address fields for Contact Refernce Via a NODE
Pages: 1 [2]

Author Topic: Trying to print CiviCRM_Address fields for Contact Refernce Via a NODE  (Read 3809 times)

miko

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 2
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.77
  • PHP version: 5.2.11
Re: Trying to print CiviCRM_Address fields for Contact Refernce Via a NODE
April 24, 2011, 07:21:55 pm
Finally, here is the complete code I needed in Contemplate (Content Template, in the Body), to:

A.  Pull in CiviCRM address info for contacts
B.  Remove the node links to CiviCRM to prevent anonymous users from clicking over there
C.  ALSO get the State information from "Constant"

<?php

if ( ! civicrm_initialize( ) ) {
 
       return;
}

require_once 'api/api.php';

$xcoach_id = $node->field_headcoach[0]['contact_id'];
$xcoach = civicrm_api("Contact","get", array ('version' =>'3', 'contact_id' => $xcoach_id));

?>

<div class="field field-type-nodereference field-field-prac-sport">
   <h3 class="field-label" style="margin-bottom:0px; padding-bottom: 0px;">
      Sport</h3>
   <div class="field-items">
      <div class="field-item style="font-size: 13px;">
         <?php print $node->field_prac_sport[0]['view'] ?></div>
   </div>
</div>
<div class="field">
   <h3 class="field-label" style="margin-bottom:0px; padding-bottom: 0px;">
      Head Coach</h3>
   <div class="field-items">
      <div class="field-item style="font-size: 13px;">
         <?php print $xcoach['values'][$xcoach_id]['display_name']; ?></div>
   </div>
</div>
<div class="field">
   <h3 class="field-label" style="margin-bottom:0px; padding-bottom: 0px;">
      Practice Location</h3>
   <div class="field-items">
      
<div class="field-item style="font-size: 13px;">

<?php

$contid = $node->field_prac_location[0]['contact_id'];

$xloc_contact = civicrm_api("Contact","get", array ('version' =>'3', 'contact_id' => $contid));

print $xloc_contact['values'][$contid]['display_name'];
?>

<br>

<?php

$results=civicrm_api("Address","get", array ('version' =>'3', 'contact_id' => $contid));

$temp_id=$results['id'];

$tmp_state = civicrm_api('constant','get', array('version' => '3', 'name' => 'stateProvinceAbbreviation'));

$xstate_abbrev = $tmp_state['values'][$results['values'][$temp_id]['state_province_id']];

print $results['values'][$temp_id]['street_address']."\n";

if ($results['values'][$temp_id]['supplemental_address_1']) { print $results['values'][$temp_id]['supplemental_address_1'];};

?>
<br />
<?php print $results['values'][$temp_id]['city'].", ".$xstate_abbrev." ".$results['values'][$temp_id]['postal_code']."\n"; ?>
</div>
   </div>
</div>

<div class="field field-type-date field-field-prac-dates">
   <h3 class="field-label style="margin-bottom:0px; padding-bottom: 0px;">
      Dates</h3>
   <div class="field-items">
      <?php
                   
                  foreach ((array)$node->field_prac_dates as $item) {
?>

<div class="field-item">

<?php print $item['view'] ?></div>

<?php } ?>
      </div>
      
</div>

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to print CiviCRM_Address fields for Contact Refernce Via a NODE
April 24, 2011, 10:47:44 pm
oh yeah - that's right the values is first - it was just off the top of my head
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Trying to print CiviCRM_Address fields for Contact Refernce Via a NODE

This forum was archived on 2017-11-26.