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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Fatal error: Cannot access protected property
Pages: [1]

Author Topic: Fatal error: Cannot access protected property  (Read 5484 times)

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Fatal error: Cannot access protected property
February 09, 2011, 11:40:52 am
I am getting this error when working with trying to get a custom fields text.
Fatal error: Cannot access protected property CRM_Event_Form_Registration_Register::$_params in /home/wesley/public_html/civicustom/civicrmHooks.php on line 32

Joomla install civic 3.3

Here is the hooks file.
Code: [Select]
<?php

/*
 * When Contribution Confirm form is submitted
 * 
 * When the contribution page is submitted we want to check for 2nd and 3rd members 
 * and create contacts for them. 
 * Then we create a relationship with the organization identified.
 */

function joomla_civicrm_postProcess ( $class, &$form ) {

if ( ! 
is_a($form, 'CRM_Event_Form_Registration_Register') ) {
return;
}

//CRM_Core_Error::debug( $form );


require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

require_once 
"api/v2/Contact.php";
require_once 
"api/v2/Relationship.php";
require_once 
"api/v2/GroupContact.php";

// if selected "on behalf of organization" then get that org ID


// get contact of the submitter - it doesn't show up in the $form if it's an anon user
$indivParams = array ( 
'email' => $form->_params['email-5'],
'contact_type' => 'Individual',
);
$indivResult = civicrm_contact_search( $indivParams );

if ( 
civicrm_error ($indivResult )) { return $indivResult['error_message']; } 
else {

foreach ($indivResult as $indiv) {
foreach ($indiv as $ind) {
$submitterID = $indiv['contact_id'];
}
}
}



// create contacts for the 2nd member
$contactParams2 = array(
                    
'first_name'    => $form->_params['custom_4'],
                    
'last_name'     => $form->_params['custom_5'],
                    
'email'         => $form->_params['custom_6'],
                    
'contact_type'  => 'Individual',
                    
'dupe_check'    => True,
                    );
$contact2 = &civicrm_contact_create( $contactParams2 ); // returns contact id, is_error
if ( civicrm_error ( $contact2)) { return $contact2['error_message']; }




//CRM_Core_Error::debug($form);

if ($form->_params['is_online_registration'] == 0) {
$contactbID = $relatedOrgID;
$reltype = 4; // DOC company membership
} else {
// if no org was set we still want to create a relationship
$contactbID = $submitterID;
$reltype = 1; // colleague of 
}




// we want to set the default relationships for each contact as set above
add_relationship($contact2['contact_id'],$contactbID,$reltype);




// add submitter to the member group
add_to_group(1,$submitterID);

// add 2nd member to member group
add_to_group(2,$contact2['contact_id']);




} 
//end associated_members_civicrm_postProcess()

function add_to_group($groupID, $contactID) {

$groupParams = array(
                    
'contact_id' => $contactID,
                    
'group_id'     => $groupID
                    
);
$groupResult = civicrm_group_contact_add( $groupParams );
}

function 
add_relationship($contactaID,$contactbID,$relationshipType) {

$relationshipParams = array(
                    
'contact_id_a'         => $contactaID,
                    
'contact_id_b'         => $contactbID,
                    
'relationship_type_id' => $relationshipType,
                    
'is_active'            => 1
                    
);
$relationshipCreate = &civicrm_relationship_create( $relationshipParams );
if ( civicrm_error ( $relationshipCreate )) { 
return $relationshipCreate['error_message']; 
}
}
?>
« Last Edit: February 09, 2011, 12:12:46 pm by zesgar »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Fatal error: Cannot access protected property
February 09, 2011, 01:37:50 pm

use this code

Code: [Select]
$params =& $form->getVar( '_params' );
...
use $params in your code
.. if u change it, do
$form->setVar( '_params', $params );

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Fatal error: Cannot access protected property
February 09, 2011, 01:40:01 pm
Kinda fixed got past the params issue

but now it comes back with a fatal error.  it successfully adds the second user. But it then hangs up. I believe it is hanging up with the submitter contact id.. Could some one please look at that...
Thanks,

here is the backtrace:
Code: [Select]
backTrace

/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/Error.php, backtrace, 254
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/DAO.php, fatal, 708
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Contact/BAO/Contact.php, getFieldValue, 890
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/api/v2/Relationship.php, getContactType, 323
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/api/v2/Relationship.php, _civicrm_relationship_format_params, 76
/home/wesley/public_html/civicustom/civicrmHooks.php, civicrm_relationship_create, 111
/home/wesley/public_html/civicustom/civicrmHooks.php, add_relationship, 78
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Utils/Hook.php, joomla_civicrm_postProcess, 446
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Utils/Hook/Joomla.php, invoke, 45
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Utils/Hook.php(144) : eval()'d code, invoke, 1
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Utils/Hook.php, eval, 144
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/Form.php, postProcess, 253
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php, mainProcess, 153
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/QuickForm/Action/Upload.php, realPerform, 130
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/packages/HTML/QuickForm/Controller.php, perform, 203
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/packages/HTML/QuickForm/Page.php, handle, 103
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/Controller.php, handle, 279
/home/wesley/public_html/administrator/components/com_civicrm/civicrm/CRM/Core/Invoke.php, run, 219
/home/wesley/public_html/components/com_civicrm/civicrm.php, invoke, 81
/home/wesley/public_html/components/com_civicrm/civicrm.php, civicrm_invoke, 24
/home/wesley/public_html/libraries/joomla/application/component/helper.php, require_once, 162
/home/wesley/public_html/includes/application.php, renderComponent, 124
/home/wesley/public_html/index.php, dispatch, 68

adding
Code: [Select]
$params = $form->controller->exportValues( $form->getName( ) );
now looks like
Code: [Select]
<?php

/*
 * When Contribution Confirm form is submitted
 * 
 * When the contribution page is submitted we want to check for 2nd and 3rd members 
 * and create contacts for them. 
 * Then we create a relationship with the organization identified.
 */

function joomla_civicrm_postProcess ( $class, &$form ) {

if ( ! 
is_a($form, 'CRM_Event_Form_Registration_Register') ) {
return;
}

//CRM_Core_Error::debug( $form );


require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

require_once 
"api/v2/Contact.php";
require_once 
"api/v2/Relationship.php";
require_once 
"api/v2/GroupContact.php";

// if selected "on behalf of organization" then get that org ID

$params = $form->controller->exportValues( $form->getName( ) );
// get contact of the submitter - it doesn't show up in the $form if it's an anon user
$indivParams = array ( 
'email' => $params['email-5'],
'contact_type' => 'Individual',
);
$indivResult = civicrm_contact_search( $indivParams );

if ( 
civicrm_error ($indivResult )) { return $indivResult['error_message']; } 
else {

foreach ($indivResult as $indiv) {
foreach ($indiv as $ind) {
$submitterID = $indiv['contact_id'];
}
}
}



// create contacts for the 2nd member
$contactParams2 = array(
                    
'first_name'    => $params['custom_4'],
                    
'last_name'     => $params['custom_5'],
                    
'email'         => $params['custom_6'],
                    
'contact_type'  => 'Individual',
                    
'dupe_check'    => True,
                    );
$contact2 = &civicrm_contact_create( $contactParams2 ); // returns contact id, is_error
if ( civicrm_error ( $contact2)) { return $contact2['error_message']; }




CRM_Core_Error::debug($form);

if (
$params['is_online_registration'] == 0) {
$contactbID = $relatedOrgID;
$reltype = 4; // DOC company membership
} else {
// if no org was set we still want to create a relationship
$contactbID = $submitterID;
$reltype = 1; // child
}




// we want to set the default relationships for each contact as set above
add_relationship($contact2['contact_id'],$contactbID,$reltype);




// add submitter to the member group
add_to_group(1,$submitterID);

// add 2nd member to member group
add_to_group(2,$contact2['contact_id']);




} 
//end associated_members_civicrm_postProcess()

function add_to_group($groupID, $contactID) {

$groupParams = array(
                    
'contact_id' => $contactID,
                    
'group_id'     => $groupID
                    
);
$groupResult = civicrm_group_contact_add( $groupParams );
}

function 
add_relationship($contactaID,$contactbID,$relationshipType) {

$relationshipParams = array(
                    
'contact_id_a'         => $contactaID,
                    
'contact_id_b'         => $contactbID,
                    
'relationship_type_id' => $relationshipType,
                    
'is_active'            => 1
                    
);
$relationshipCreate = &civicrm_relationship_create( $relationshipParams );
if ( civicrm_error ( $relationshipCreate )) { 
return $relationshipCreate['error_message']; 
}
}
?>

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Fatal error: Cannot access protected property
February 10, 2011, 02:46:47 pm
if i manually put in a number here it works fine
add_to_group(2,$contact2['contact_id']);  -->   add_to_group(2,44);

if i print these above they return the correct values;
print_r($contact2['contact_id']);
   print_r($submitterID);

but when called here they do not pass????


// add 2nd member to member group
add_to_group(2,$contact2['contact_id']);


// add submitter to the member group
add_to_group(1,$submitterID);
???

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Re: Fatal error: Cannot access protected property
February 10, 2011, 05:02:31 pm
got it to work here it is
Code: [Select]
<?php

/*
 * When Contribution Confirm form is submitted
 * 
 * When the contribution page is submitted we want to check for 2nd and 3rd members 
 * and create contacts for them. 
 * Then we create a relationship with the organization identified.
 */

function joomla_civicrm_postProcess ( $class, &$form ) {

if ( ! 
is_a($form, 'CRM_Event_Form_Registration_Register') ) {
return;
}

//CRM_Core_Error::debug( $form );


require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

require_once 
"api/v2/Contact.php";
require_once 
"api/v2/Relationship.php";
require_once 
"api/v2/GroupContact.php";

// if selected "on behalf of organization" then get that org ID


$params = $form->controller->exportValues( $form->getName( ) );
// get contact of the submitter - it doesn't show up in the $form if it's an anon user
$indivParams = array ( 
'email' => $params['email-5'],
'contact_type' => 'Individual',
);
$indivResult = civicrm_contact_search( $indivParams );

if ( 
civicrm_error ($indivResult )) { return $indivResult['error_message']; } 
else {

foreach ($indivResult as $indiv) {
foreach ($indiv as $ind) {
$submitterID = $indiv['contact_id'];
}
}
}



// create contacts for the 2nd member
$contactParams2 = array(
                    
'first_name'    => $params['custom_4'],
                    
'last_name'     => $params['custom_5'],
                    
'email'         => $params['custom_6'],
                    
'contact_type'  => 'Individual',
                    
'dupe_check'    => True,
                    );
$contact2 = &civicrm_contact_create( $contactParams2 ); // returns contact id, is_error
print_r($contact2['contact_id']);
print_r($submitterID);
if ( civicrm_error ( $contact2)) { return $contact2['error_message']; }


// add 2nd member to member group
add_to_group(2,$contact2['contact_id']);


// add submitter to the member group
add_to_group(1,$submitterID);

//CRM_Core_Error::debug($form);

if ($params['is_online_registration'] == 0) {
$contactbID = $relatedOrgID;
$reltype = 4; // DOC company membership
} else {
// if no org was set we still want to create a relationship
$contactbID = $submitterID;
$reltype = 1; // child
}







// we want to set the default relationships for each contact as set above
add_relationship($submitterID,$contact2['contact_id'],1);








} 
//end associated_members_civicrm_postProcess()

function add_to_group($groupID, $contactID) {

$groupParams = array(
                    
'contact_id' => $contactID,
                    
'group_id'     => $groupID
                    
);
$groupResult = civicrm_group_contact_add( $groupParams );
print_r($groupResult);
print_r($groupID);
print_r($contactID);
}

function 
add_relationship($contactaID,$contactbID,$relationshipType) {

$relationshipParams = array(
                    
'contact_id_a'         => $contactaID,
                    
'contact_id_b'         => $contactbID,
                    
'relationship_type_id' => $relationshipType,
                    
'is_active'            => 1
                    
);
$relationshipCreate = &civicrm_relationship_create( $relationshipParams );
if ( civicrm_error ( $relationshipCreate )) { 
return $relationshipCreate['error_message']; 
}
}
?>

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Fatal error: Cannot access protected property

This forum was archived on 2017-11-26.