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) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Custom Event Badge template questions
Pages: [1]

Author Topic: Custom Event Badge template questions  (Read 2528 times)

itowler

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.20
Custom Event Badge template questions
January 29, 2011, 10:50:45 am
Hi all,

I think that I have an easy one here, but its got me confused.  I am trying to modify the CRM_Event_Badge_Logo.php file so that I can create a custom name badge for our events.

I am following the instructions that lobo posted here:

http://civicrm.org/blogs/xavier/new-features-civievent-32-name-badges-and-place-cards

So far so good.  I was able to change the background logo with no issues.  I was able to create the new format using the admin function,....

but I can not figure out how to add some of our Custom data to the tag. 

I would like to replace the   $participant['current_employer'] with our custom field of National Title. 

I have tried replacing the current_employer code with this: $participant['national_title_5'], or this $participant['national_title'],
neither of which worked.

Any help would be great. Thanks in advance

That particular field is part of the event registration process, but I can not figure out the code to make it print in my custom tags.

CiviCRM 3.3.3
Drupal 6.20

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom Event Badge template questions
January 29, 2011, 11:12:26 am
Quote from: itowler on January 29, 2011, 10:50:45 am
I am following the instructions that lobo posted here:

http://civicrm.org/blogs/xavier/new-features-civievent-32-name-badges-and-place-cards

I have tried replacing the current_employer code with this: $participant['national_title_5'], or this $participant['national_title'],
neither of which worked.


First time I'm called lobo -and I don't even yet have the "I'm (like) lobo ;)" status on the forum ;)

The custom fields aren't fetched in the array of participants.

What you'll need to do is collect all the ids of participants, and do a big "select ... from the custom table where id in (list of ids)".

ie. a bit of custom coding and figure out what the table and columns are.

Otherwise, I would suggest that instead of modifying the existing format, you create a new one (will avoid problems with the upgrades).

X+

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

itowler

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.20
Re: Custom Event Badge template questions
January 29, 2011, 11:19:57 am
Xavier,

whoops sorry about that....  :-\

I am not actually editing the CRM_Event_Badge_Logo.php file, rather using it as a base to work from.  I have created a new file and have it "registered" in the event badge admin menu...

I am a little confused still about how I accomplish what you indicated...

Can you point my to an example of some code so that I can work my way through it.... I am not a coder at all, but I can fumble my way around if I have an example to work from.....

I tried working from the NameTitleOrg4x3 file in the wiki... and tired to use this code:
Code: [Select]
//retrieve national_title and add to $participant array
require_once 'api/v2/Participant.php';
require_once 'api/v2/Contact.php';
$params_participant = array(
'participant_id' => $participant['participant_id'],
);
$participant_full = & civicrm_participant_get( $params_participant );
$contact_id = $participant_full['contact_id'];
$params_contact = array(
'contact_id' => $contact_id,
);
$contact_full = civicrm_contact_get( $params_contact );
$participant['contact_id'] = $contact_id;
$participant['national_title_5'] = $contact_full[$contact_id]['national_title_5'];

But no dice.... 

So here is what my entire file looks like:
Code: [Select]
<?php
/**********************************************************************
Constructs participant name badges for NSSAR Leadership meetings with the following stats:
?"x?" badges
10 per page
?" top margin
?" left/right margin
?" bottom margin
?letter size page
      ? Avery badge template style
      
**********************************************************************/


/******** Start Layout portion ***************************************/
require_once 'CRM/Event/Badge.php';
require_once 
'CRM/Utils/Date.php';

class 
CRM_Event_Badge_Leadership extends CRM_Event_Badge {
    
    function 
__construct() {
        
parent::__construct();
        
$pw=210; $ph=297;// A4
        
$h=50; $w=75;
        
$this->format = array( 'name' => 'Sigel 3C', 'paper-size' => 'A4', 'metric' => 'mm', 'lMargin' => ($pw-$w*2)/2,
                              
'tMargin' => ($ph-$h*5)/2, 'NX' => 2, 'NY' => 5, 'SpaceX' => 0, 'SpaceY' => 0,
                              
'width' => $w, 'height' => $h, 'font-size' => 12 );
        
$this->lMarginLogo = 20;
        
$this->tMarginName = 20;
        
//      $this->setDebug ();
    
}
/*********** End Layout Function *************************************/



/*********** Start data population function **************************/    
    
public function generateLabel( $participant ) {

//retrieve national_title and add to $participant array
require_once 'api/v2/Participant.php';
require_once 'api/v2/Contact.php';
$params_participant = array(
'participant_id' => $participant['participant_id'],
);
$participant_full = & civicrm_participant_get( $params_participant );
$contact_id = $participant_full['contact_id'];
$params_contact = array(
'contact_id' => $contact_id,
);
$contact_full = civicrm_contact_get( $params_contact ); 
$participant['contact_id'] = $contact_id;
$participant['national_title_5'] = $contact_full[$contact_id]['national_title_5'];

//retrieve State Society and add to $participant array
require_once 'api/v2/Participant.php';
require_once 'api/v2/Contact.php';
$params_participant = array(
'participant_id' => $participant['participant_id'],
);
$participant_full = & civicrm_participant_get( $params_participant );
$contact_id = $participant_full['contact_id'];
$params_contact = array(
'contact_id' => $contact_id,
);
$contact_full = civicrm_contact_get( $params_contact ); 
$participant['contact_id'] = $contact_id;
$participant['state_society'] = $contact_full[$contact_id]['state_society'];


        
$x = $this->pdf->GetAbsX();
        
$y = $this->pdf->GetY();
        
$this->printBackground (true);
        
$this->pdf->SetLineStyle( array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200 ) ) );
        
        
$this->pdf->SetFontSize(8);
        
$this->pdf->MultiCell ( $this->pdf->width-$this->lMarginLogo, 0, $participant['event_title'], $this->border, "L", 0, 1, $x+$this->lMarginLogo, $y );
        
        
$this->pdf->SetXY( $x, $y+$this->pdf->height-5 );
        
$date = CRM_Utils_Date::customFormat( $participant['event_start_date'], "%e %b" );
        
$this->pdf->Cell ( $this->pdf->width, 0, $date ,$this->border, 2, "R" );
        
        
$this->pdf->SetFontSize(15);
        
$this->pdf->MultiCell ( $this->pdf->width, 10, $participant['first_name']. " ".$participant['last_name'], $this->border, "C", 0, 1, $x, $y+$this->tMarginName );
        
$this->pdf->SetFontSize(10);
        
$this->pdf->MultiCell ( $this->pdf->width, 0, $participant['national_title_5'], $this->border, "C", 0, 1, $x, $this->pdf->getY() );
    }
    
}

/************ End Data population portion ****************************/

Again, sorry.... about the mixup... I was just looking at the big picture that has a guy with a name tag on it that said lobo...
« Last Edit: January 29, 2011, 01:13:42 pm by itowler »

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: Custom Event Badge template questions
January 29, 2011, 04:50:54 pm
You can pull in custom data using the api: See [How To Retrieve Custom Fields] at http://wiki.civicrm.org/confluence/display/CRMDOC33/Contact+APIs#ContactAPIs-civicrmcontactget%28%26%24params%29
Lead Developer, C3 Design.
Twitter: @FatherShawn

itowler

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 3.3.3
  • CMS version: Drupal 6.20
Re: Custom Event Badge template questions
January 29, 2011, 08:23:24 pm
Father Shawn,

Thanks for pointing me to that, i am getting closer I think..

I have identified the field ID, but I am still unsure about how to make it all come together....

So my custom data has a field ID of 16 and the other is 5. 

Code: [Select]
//retrieve State Society and National Title add to $participant array
require_once 'api/v2/Participant.php';
require_once 'api/v2/Contact.php';
$params_participant = array(
'participant_id' => $participant['participant_id'],
);
$participant_full = & civicrm_participant_get( $params_participant );
$contact_id = $participant_full['contact_id'];
$params_contact = array(
'contact_id' => $contact_id,
);

$params    = array(
                   'contact_id' => $contact_id,
                   'return_custom_16' => $state_society
                   'return_custom_5' => $national_title
                   );
$contact_full = civicrm_contact_get( $params_contact );
$participant['contact_id'] = $contact_id;
$participant['national_title'] = $contact_full[$contact_id]['national_title'];
$participant['state_society'] = $contact_full[$contact_id]['state_society'];


But that just leaves me with a white screen of death....

what am I missing...

Thanks for the help thus far...

Here is the file I have thus far:
Code: [Select]
<?php
/**********************************************************************
Constructs participant name badges for NSSAR Leadership meetings with the following stats:
?"x?" badges
10 per page
?" top margin
?" left/right margin
?" bottom margin
?letter size page
      ? Avery badge template style
      
**********************************************************************/


/******** Start Layout portion ***************************************/
require_once 'CRM/Event/Badge.php';
require_once 
'CRM/Utils/Date.php';

class 
CRM_Event_Badge_Leadership extends CRM_Event_Badge {
    
    function 
__construct() {
        
parent::__construct();
        
$pw=210; $ph=297;// A4
        
$h=50; $w=75;
        
$this->format = array( 'name' => 'Sigel 3C', 'paper-size' => 'A4', 'metric' => 'mm', 'lMargin' => ($pw-$w*2)/2,
                              
'tMargin' => ($ph-$h*5)/2, 'NX' => 2, 'NY' => 5, 'SpaceX' => 0, 'SpaceY' => 0,
                              
'width' => $w, 'height' => $h, 'font-size' => 12 );
        
$this->lMarginLogo = 20;
        
$this->tMarginName = 20;
        
$this->setDebug ();
//  remeber to re-comment out the setDebug option
    
}
/*********** End Layout Function *************************************/



/*********** Start data population function **************************/    
    
public function generateLabel( $participant ) {

//retrieve State Society and National Title add to $participant array
require_once 'api/v2/Participant.php';
require_once 'api/v2/Contact.php';
$params_participant = array(
'participant_id' => $participant['participant_id'],
);
$participant_full = & civicrm_participant_get( $params_participant );
$contact_id = $participant_full['contact_id'];
$params_contact = array(
'contact_id' => $contact_id,
);

$params    = array(
                   
'contact_id' => $contact_id,
                   
'return_custom_16' => $state_society
                   
'return_custom_5' => $national_title
                   
);
$contact_full = civicrm_contact_get( $params_contact ); 
$participant['contact_id'] = $contact_id;
$participant['national_title'] = $contact_full[$contact_id]['national_title'];
$participant['state_society'] = $contact_full[$contact_id]['state_society'];


        
$x = $this->pdf->GetAbsX();
        
$y = $this->pdf->GetY();
        
$this->printBackground (true);
        
$this->pdf->SetLineStyle( array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200 ) ) );
        
        
$this->pdf->SetFontSize(8);
        
$this->pdf->MultiCell ( $this->pdf->width-$this->lMarginLogo, 0, $participant['event_title'], $this->border, "L", 0, 1, $x+$this->lMarginLogo, $y );
        
        
$this->pdf->SetXY( $x, $y+$this->pdf->height-5 );
        
$date = CRM_Utils_Date::customFormat( $participant['event_start_date'], "%e %b" );
        
$this->pdf->Cell ( $this->pdf->width, 0, $date ,$this->border, 2, "R" );
        
        
$this->pdf->SetFontSize(15);
        
$this->pdf->MultiCell ( $this->pdf->width, 10, $participant['first_name']. " ".$participant['last_name'], $this->border, "C", 0, 1, $x, $y+$this->tMarginName );
        
$this->pdf->SetFontSize(10);
        
$this->pdf->MultiCell ( $this->pdf->width, 0, $participant['national_title_5'], $this->border, "C", 0, 1, $x, $this->pdf->getY() );
    }
    
}

/************ End Data population portion ****************************/

Thanks in advance for any help...

ian

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Custom Event Badge template questions
May 10, 2013, 02:20:36 pm
Upcoming MIH for CiviCRM 4.4

http://civicrm.org/make-it-happen#Self service view, update and cancel for CiviEvent and better event badges
 
Make it Happen (MIH) campaigns are the best way to get the new features you are looking for into CiviCRM. Please consider contributing to make this happen.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Custom Event Badge template questions

This forum was archived on 2017-11-26.