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) »
  • Tweak to CiviGrant report -- make plain text into url link
Pages: [1]

Author Topic: Tweak to CiviGrant report -- make plain text into url link  (Read 479 times)

kmitz

  • I post occasionally
  • **
  • Posts: 74
  • Karma: 2
Tweak to CiviGrant report -- make plain text into url link
February 09, 2014, 02:51:54 pm
I have a custom field called "grant title" that I can pull up in a built-in (but slightly modified by including custom profile data) "grant details" report. I'd like to make the title link to the actual grant.  It's OK if it links to the grant in every report, if that's what is necessary.  Is there an easy way to do this?  I looked at the template files and that didn't help.

Thanks.
« Last Edit: February 11, 2014, 05:42:20 pm by kmitz »

kmitz

  • I post occasionally
  • **
  • Posts: 74
  • Karma: 2
Re: Tweak to CiviGrant report
February 10, 2014, 06:27:19 pm
Found this: https://wiki.civicrm.org/confluence/display/CRMDOC/CiviReport+Reference

This article contains 2 links a little ways down the page, but this one specifically addresses my question.

http://artfulrobot.com/civicrm-custom-birthdays-report

Once on the page, search for the alterDisplay() function.  Therein lies the solution.
« Last Edit: February 11, 2014, 01:38:24 pm by kmitz »

kmitz

  • I post occasionally
  • **
  • Posts: 74
  • Karma: 2
Re: Tweak to CiviGrant report
February 11, 2014, 05:36:15 pm
I used CRM/Report/Form/Grant/Detail.php as a guide.  It contains a class called "CRM_Report_Form_Grant_Detail".

The __construct() method of this class creates a huge array with array indicies named "civicrm_<table>_<field>".  I'm using a table that was created by Civi for custom profile data called "civicrm_value_XXXX_grant_data_1".  The fields I'm using are "grant_title_1" (civicrm_value_XXXX_grant_data_1_grant_title_1) and "entity_id" (civicrm_value_XXXX_grant_data_1_entity_id), as well the the contact_id value from the civicrm_grant table ('civicrm_grant_contact_id').

Later, the alterDisplay() method changes plain data into a URL.  The section of the code that does that is listed below (line 348 as of v4.4.4).

The code checks for 3 pieces of data, and if they exist, creates the URL using a utility function.  It then assigns "link" and "hover" attributes.

Hope that helps.

kmitz

Code: [Select]
if (array_key_exists('civicrm_value_XXXX_grant_data_1_grant_title_1', $row) &&
        array_key_exists('civicrm_value_XXXX_grant_data_1_entity_id', $row) &&
        array_key_exists('civicrm_grant_contact_id', $row)
      ) {
        $url = CRM_Utils_System::url('civicrm/contact/view/grant',
          'action=view&reset=1&id=' . $row['civicrm_value_XXXX_grant_data_1_entity_id'] . '&cid=' . $row['civicrm_grant_contact_id'],
          $this->_absoluteUrl
        );
        $rows[$rowNum]['civicrm_value_XXXX_grant_data_1_grant_title_1_link'] = $url;
        $rows[$rowNum]['civicrm_value_XXXX_grant_data_1_grant_title_1_hover'] = ts("View grant details for this record.");
        $entryFound = TRUE;
}
« Last Edit: February 11, 2014, 05:41:01 pm by kmitz »

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Tweak to CiviGrant report -- make plain text into url link
March 07, 2014, 10:26:07 am
@kmitz: Thanks for posting this information. It is coming in quite handy.
My CiviCRM Extension Workshop: https://github.com/awasson

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Tweak to CiviGrant report -- make plain text into url link

This forum was archived on 2017-11-26.