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 CiviReport (Moderator: Dave Greenberg) »
  • How to insert static value into each row?
Pages: [1]

Author Topic: How to insert static value into each row?  (Read 462 times)

allenthehusband

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • PHP version: 5.3
How to insert static value into each row?
September 07, 2014, 09:06:31 am
I have added a new column to our Pledge Summary report which will be used when we export to CSV.  We need each row of that column to be the same text value.  I added the new column header in the "function postProcess()" with the below example code:

Code: [Select]
$this->_columnHeaders['xyz'] = array(
'title' => 'X, Y & Z',
);

How would I then add a set text value to each row of that column? 

I could add a custom field to our pledges, fill that custom field with the same default value then add the custom field to our report, but I figured adding another field to our database wasn't the way to go if the value could be provided on just the exported report.
 
Thanks for the help!
« Last Edit: September 07, 2014, 09:11:22 am by allenthehusband »

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: How to insert static value into each row?
September 08, 2014, 01:00:39 am
There are several ways in which you can do this. What I generally do is copy the buildRows function from the parent class (CRM/Report/Form) and there add my values. The buildRows will be:
Code: [Select]
  function buildRows($sql, &$rows) {
    $dao = CRM_Core_DAO::executeQuery($sql);
    if (!is_array($rows)) {
      $rows = array();
    }

    // use this method to modify $this->_columnHeaders
    $this->modifyColumnHeaders();

    $unselectedSectionColumns = $this->unselectedSectionColumns();

    while ($dao->fetch()) {
      $row = array();
      foreach ($this->_columnHeaders as $key => $value) {
        if (property_exists($dao, $key)) {
          $row[$key] = $dao->$key;
        }
      }

      // section headers not selected for display need to be added to row
      foreach ($unselectedSectionColumns as $key => $values) {
        if (property_exists($dao, $key)) {
          $row[$key] = $dao->$key;
        }
      }

      $rows[] = $row;
    }
  }
so you could add you specific bit of code after the foreach loop, something like this:
Code: [Select]
$row['xyz'] = 'XYZ';
Does that help?

Alternative is to add your own function inside the postProcess function that is probably already in your report Class, just after the buildRows function has been executed.
[/code]
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

allenthehusband

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • PHP version: 5.3
Re: How to insert static value into each row?
September 08, 2014, 10:53:26 am
Erik, this is a huge help.  I'm still piecing together for myself how exactly the reports work; your explanation goes a long way in helping me understand!  Thank you!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • How to insert static value into each row?

This forum was archived on 2017-11-26.