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) »
  • Basic report on wiki needs more code (I think)
Pages: [1]

Author Topic: Basic report on wiki needs more code (I think)  (Read 441 times)

krypto

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 5
  • IT guy for @bhahumanists. Running Civi on WP.
    • British Humanist Association
  • CiviCRM version: 4.5.8
  • CMS version: WordPress 4.x
  • MySQL version: 5.5.x
  • PHP version: 5.5.x
Basic report on wiki needs more code (I think)
February 19, 2014, 08:15:48 am
The wiki at http://wiki.civicrm.org/confluence/display/CRMDOC/CiviReport+Reference gives an example of a very simple report, but as it stands you can't save instances without extra code. I don't want to update the wiki without checking I'm making sense, though. I made:

Code: [Select]
<?php
class CRM_Report_Form_FindBob extends CRM_Report_Form {

function postProcess( ) {
        
$this->beginPostProcess( );
 
        
// note1: your query
        
$myQuery = "SELECT id from civicrm_contact where first_name like '%bob%'";
 
        
// note2: register columns you want displayed-
        
$this->_columnHeaders = array(
          
'id'  => array('type'=>0,'title'=>'ID')
    );
  
        
// note3: let report do the fetching of records for you
        
$this->buildRows ( $myQuery, $rows );
 
        
$this->formatDisplay($rows);
 
        
$this->doTemplateAssignment( $rows );
        
$this->endPostProcess( $rows );
     
     } 
// post process ends
 
} // class ends

which works as a report, but you can't save an instance. It tries to save it with a blank name - "" report has been successfully created" - and you get a smarty warning in the php error log: "missing 'var' parameter". The only way I could get it to work was to add a constructor with Contact Name in it:

Code: [Select]
  function __construct() {
    $this->_columns = array(
      'civicrm_contact' =>
      array(
        'dao' => 'CRM_Contact_DAO_Contact',
        'fields' =>
        array(
          'sort_name' =>
          array('title' => ts('Contact Name'),
            'required' => TRUE,
            'no_repeat' => TRUE,
          ),
        ),
      ),
    );
    parent::__construct();
  }

Does that seem like a sensible thing to do? Or is this a bug?

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Basic report on wiki needs more code (I think)
February 20, 2014, 01:18:49 pm
Yes, that seems like a useful improvement on the wiki documentation.

I think there is an obscure setting you should use if you don't define any fields - I can't quite recall the use case although I'm pretty sure I have used it

  protected $_noFields = TRUE;
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

krypto

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 5
  • IT guy for @bhahumanists. Running Civi on WP.
    • British Humanist Association
  • CiviCRM version: 4.5.8
  • CMS version: WordPress 4.x
  • MySQL version: 5.5.x
  • PHP version: 5.5.x
Re: Basic report on wiki needs more code (I think)
February 24, 2014, 10:05:54 am
Aha - that works. Thank you! Will update the wiki.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Basic report on wiki needs more code (I think)

This forum was archived on 2017-11-26.