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 Joomla Extensions (Moderator: lcdweb) »
  • Plugins in 4.0.8
Pages: [1]

Author Topic: Plugins in 4.0.8  (Read 1370 times)

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Plugins in 4.0.8
March 14, 2012, 09:36:59 am
I am trying to get this contribution code to work in a plugin in 4.0.8  and can't get it to run
Code: [Select]
<?php

/**

 * @version

 * @package Civicrm

 * @subpackage Joomla Plugin

 * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.

 * @license GNU General Public License version 2 or later; see LICENSE.txt

 */



// No direct access

defined('_JEXEC') or die;



jimport('joomla.plugin.plugin');



class 
plgCiviCRMBase extends JPlugin

{



/**

 * Base Civicrm Plugin.

 *

 * @package Civicrm

 * @subpackage Joomla plugins

 * @since 1.6

 */



   public function 
civitoken_civicrm_tokens( &$tokens ) {
    
$tokens['civitoken'] = array( 'civitoken.contributionTotal',  'civitoken.contributionLast','civitoken.contributionList' );
}

function 
civitoken_civicrm_tokenValues( &$values, &$contactIDs, $jobID ) {

    
// we could be given an array of contact IDs or a string
    
require_once 'api/v2/Contact.php';
    require_once 
'api/v2/Contribute.php';
    if (isset(
$contactIDs[0])){
    
$params['contact_id'] = $contactIDs[0];
    }else{
        
$params['contact_id'] = $contactIDs['contact_id'];
    }


    if ( 
is_array( $contactIDs ) ) {
        foreach (
$contactIDs as $contactID){
          
$value =& $values[$contactID];
          
$value = get_contribution_details($contactID,$value);
          
$value = get_contribution_totals($contactID,$value);


        }

    } else {
          
$value =& $values;
          
$value = get_contribution_details($contactIDs,$value);
    }





    
//  $value['civitoken.contributionTotal'] = 'total amount from above functions' ;
    
}

function 
get_contribution_totals($cid, &$value){
        global 
$db_url;
        if (
$db_url['civicrm']){
          
db_set_active('civicrm');
        }
     
$query = "
SELECT sum( total_amount ) as total_amount,
       contact_id,
       max( receive_date ) as receive_date
FROM   civicrm_contribution
WHERE  contact_id = ( 
$cid )
AND    is_test = 0
GROUP BY contact_id
"
;
    
$dao = CRM_Core_DAO::executeQuery( $query );
        
//Switch back to the default connection when finished.
        
db_set_active('default');



    while ( 
$dao->fetch( ) ) {
        
$value['civitoken.contributionTotal'] = $dao->total_amount;
        
$value['civitoken.contributionLast'  ] =  CRM_Utils_Date::customFormat($dao->receive_date, null,array('M','d','Y')) ;
    }
    return 
$value;

}



function 
get_contribution_details($cid, &$value){

    require_once 
'api/v2/Contribute.php';
    
$params['sort']       = 'receive_date DESC';
    
$params['contact_id'] = $cid;
    
$params['limit'] = 5;
    
$contributions = civicrm_contribution_search($params);
    
//get field labels

    
$i = 0;
    
$value['civitoken.contributionList'] = "<table><tr><th>Amount</th><th>Date</th><th>Status</th><th>Type</th><th>Worker</th><th>Promo</th><th>Dept</th><th>Staff member</th></tr>";

    foreach(
$contributions as $contribution){
    if (
$i<5){
      
$value['civitoken.contributionList'] .= "<tr><td>$" . $contribution['total_amount'] . "</td>";
      
$value['civitoken.contributionList'] .= "<td>" . CRM_Utils_Date::customFormat($contribution['receive_date'], null,array('M','d','Y')) . "</td>";
      
$value['civitoken.contributionList'] .= "<td>" .$contribution['contribution_status_id']. "</td>";
      
$value['civitoken.contributionList'] .= "<td>" .$contribution['contribution_type']. "</td></tr>";
    
      

    }
    
$i++;
    }
        
$value['civitoken.contributionList'] .= "</table>";

    return 
$value;

}

}

I tried using the basic plugin rename contribution php code and it works just fine.  So my guess is something is wrong in this code... I borrowed if from http://forum.civicrm.org/index.php?topic=18952.0
I also tried adding hooks_ or joomla_ to the from of the first two functions and no go... any ideas?

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Plugins in 4.0.8
March 14, 2012, 10:08:22 am
I have made progress I took out changed the code on the first two functions to:
Code: [Select]
function civicrm_tokenValues    public function civicrm_tokens 
My problem now is it throws:

Fatal error: Call to undefined function get_contribution_details() in /home/wesley/public_html/plugins/civicrm/base/base.php on line 74

Any ideas?

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Plugins in 4.0.8
March 22, 2012, 08:44:29 am
Here is the solution add self before functions within the same file

Code: [Select]
$value = self::civicrm_get_contribution_details($contactID,$value);

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Joomla Extensions (Moderator: lcdweb) »
  • Plugins in 4.0.8

This forum was archived on 2017-11-26.