Exemplo n.º 1
0
 /**
  * Function to process price set and line items.
  * @param int $contributionId contribution id
  * @param array $lineItem line item array
  * @param object $contributionDetails
  * @param decimal $initAmount amount
  * @param string $entityTable entity table
  *
  * @access public
  * @return void
  * @static
  */
 static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
 {
     if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             $line['entity_id'] = $entityId;
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (CRM_Utils_Array::value('price_field_value_id', $line) && !CRM_Utils_Array::value('financial_type_id', $line)) {
                 $line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
             }
             $lineItems = CRM_Price_BAO_LineItem::create($line);
             if (!$update && $contributionDetails) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Process price set and line items.
  *
  * @param int $entityId
  * @param array $lineItem
  *   Line item array.
  * @param object $contributionDetails
  * @param string $entityTable
  *   Entity table.
  *
  * @param bool $update
  *
  * @return void
  */
 public static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
 {
     if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             if (empty($line['entity_id'])) {
                 $line['entity_id'] = $entityId;
             }
             if (!empty($line['membership_type_id'])) {
                 $line['entity_table'] = 'civicrm_membership';
             }
             if (!empty($contributionDetails->id)) {
                 $line['contribution_id'] = $contributionDetails->id;
                 if ($line['entity_table'] == 'civicrm_contribution') {
                     $line['entity_id'] = $contributionDetails->id;
                 }
             }
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (!empty($line['price_field_value_id']) && empty($line['financial_type_id'])) {
                 $line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
             }
             $lineItems = CRM_Price_BAO_LineItem::create($line);
             if (!$update && $contributionDetails) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
                 if (isset($line['tax_amount'])) {
                     CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /** 
  * Function to process price set and line items. 
  * 
  * @access public 
  * @return None 
  */
 function processPriceSet($contributionId, $lineItem)
 {
     if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     require_once 'CRM/Price/BAO/Set.php';
     require_once 'CRM/Price/BAO/LineItem.php';
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = 'civicrm_contribution';
             $line['entity_id'] = $contributionId;
             CRM_Price_BAO_LineItem::create($line);
         }
         CRM_Price_BAO_Set::addTo('civicrm_contribution', $contributionId, $priceSetId);
     }
 }
Exemplo n.º 4
0
 /**
  * Function returns formatted groupTree, sothat form can be easily build in template
  *
  * @param array  $groupTree associated array
  * @param int    $groupCount group count by default 1, but can varry for multiple value custom data 
  * @param object form object 
  *
  * @return array $formattedGroupTree
  */
 static function formatGroupTree(&$groupTree, $groupCount = 1, &$form)
 {
     $formattedGroupTree = array();
     $uploadNames = array();
     foreach ($groupTree as $key => $value) {
         if ($key === 'info') {
             continue;
         }
         // add group information
         $formattedGroupTree[$key]['name'] = CRM_Utils_Array::value('name', $value);
         $formattedGroupTree[$key]['title'] = CRM_Utils_Array::value('title', $value);
         $formattedGroupTree[$key]['help_pre'] = CRM_Utils_Array::value('help_pre', $value);
         $formattedGroupTree[$key]['help_post'] = CRM_Utils_Array::value('help_post', $value);
         $formattedGroupTree[$key]['collapse_display'] = CRM_Utils_Array::value('collapse_display', $value);
         $formattedGroupTree[$key]['collapse_adv_display'] = CRM_Utils_Array::value('collapse_adv_display', $value);
         // this params needed of bulding multiple values
         $formattedGroupTree[$key]['is_multiple'] = CRM_Utils_Array::value('is_multiple', $value);
         $formattedGroupTree[$key]['extends'] = CRM_Utils_Array::value('extends', $value);
         $formattedGroupTree[$key]['extends_entity_column_id'] = CRM_Utils_Array::value('extends_entity_column_id', $value);
         $formattedGroupTree[$key]['extends_entity_column_value'] = CRM_Utils_Array::value('extends_entity_column_value', $value);
         $formattedGroupTree[$key]['subtype'] = CRM_Utils_Array::value('subtype', $value);
         $formattedGroupTree[$key]['max_multiple'] = CRM_Utils_Array::value('max_multiple', $value);
         // add field information
         foreach ($value['fields'] as $k => $properties) {
             $properties['element_name'] = "custom_{$k}_-{$groupCount}";
             if (isset($properties['customValue']) && !CRM_Utils_system::isNull($properties['customValue'])) {
                 if (isset($properties['customValue'][$groupCount])) {
                     $properties['element_name'] = "custom_{$k}_{$properties['customValue'][$groupCount]['id']}";
                     if ($properties['data_type'] == 'File') {
                         $properties['element_value'] = $properties['customValue'][$groupCount];
                         $uploadNames[] = $properties['element_name'];
                     } else {
                         $properties['element_value'] = $properties['customValue'][$groupCount]['data'];
                     }
                 }
             }
             unset($properties['customValue']);
             $formattedGroupTree[$key]['fields'][$k] = $properties;
         }
     }
     if ($form) {
         // hack for field type File
         $formUploadNames = $form->get('uploadNames');
         if (is_array($formUploadNames)) {
             $uploadNames = array_unique(array_merge($formUploadNames, $uploadNames));
         }
         $form->set('uploadNames', $uploadNames);
     }
     return $formattedGroupTree;
 }
 /**
  * Function to process price set and line items.
  *
  * @access public
  *
  * @return None
  */
 function processPriceSet($contributionId, $lineItem, $entityTable = 'civicrm_contribution')
 {
     if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = $entityTable;
             $line['entity_id'] = $contributionId;
             CRM_Price_BAO_LineItem::create($line);
         }
     }
 }
 /**
  * function to set default values for address block
  *
  * @param array  $defaults  defaults associated array
  * @param object $form     form object
  *
  * @static
  * @access public
  */
 static function setDefaultValues(&$defaults, &$form)
 {
     $addressValues = array();
     if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
         // start of contact shared adddress defaults
         $sharedAddresses = array();
         $masterAddress = array();
         // get contact name of shared contact names
         $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
         foreach ($defaults['address'] as $key => $addressValue) {
             if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
                 $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
             } else {
                 $defaults['address'][$key]['use_shared_address'] = 0;
             }
             //check if any address is shared by any other contacts
             $masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
         }
         $form->assign('sharedAddresses', $sharedAddresses);
         $form->assign('masterAddress', $masterAddress);
         // end of shared address defaults
         // start of parse address functionality
         // build street address, CRM-5450.
         if ($form->_parseStreetAddress) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = NULL;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 if (isset($address['street_number'])) {
                     $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 }
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
             $form->assign('allAddressFieldValues', json_encode($addressValues));
             //hack to handle show/hide address fields.
             $parsedAddress = array();
             if ($form->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
                 foreach ($_POST['address'] as $cnt => $values) {
                     $showField = 'streetAddress';
                     foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                         if (CRM_Utils_Array::value($fld, $values)) {
                             $showField = 'addressElements';
                             break;
                         }
                     }
                     $parsedAddress[$cnt] = $showField;
                 }
             }
             $form->assign('showHideAddressFields', $parsedAddress);
             $form->assign('loadShowHideAddressFields', empty($parsedAddress) ? FALSE : TRUE);
         }
         // end of parse address functionality
     }
 }
 /**
  * Function to process price set and line items.
  *
  * @access public
  *
  * @return None
  */
 function processPriceSet($membershipId, $lineItem)
 {
     if (!$membershipId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => $values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as $line) {
             $line['entity_table'] = 'civicrm_membership';
             $line['entity_id'] = $membershipId;
             CRM_Price_BAO_LineItem::create($line);
         }
     }
 }
Exemplo n.º 8
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     $params = array();
     if ($this->_action & CRM_Core_Action::ADD) {
         if (array_key_exists('TagsAndGroups', $this->_editOptions)) {
             // set group and tag defaults if any
             if ($this->_gid) {
                 $defaults['group'][$this->_gid] = 1;
             }
             if ($this->_tid) {
                 $defaults['tag'][$this->_tid] = 1;
             }
         }
         if ($this->_contactSubType) {
             $defaults['contact_sub_type'] = $this->_contactSubType;
         }
     } else {
         require_once 'CRM/Contact/BAO/Relationship.php';
         $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
         $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
         $this->assign('currentEmployer', $defaults['current_employer_id']);
         foreach ($defaults['email'] as $dontCare => &$val) {
             if (isset($val['signature_text'])) {
                 $val['signature_text_hidden'] = $val['signature_text'];
             }
             if (isset($val['signature_html'])) {
                 $val['signature_html_hidden'] = $val['signature_html'];
             }
         }
     }
     // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
     foreach ($this->_editOptions as $name => $label) {
         if (!in_array($name, array('Address', 'Notes'))) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_Edit_" . $name) . ".php";
             eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );');
         }
     }
     $addressValues = array();
     if (isset($defaults['address']) && is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
         // start of contact shared adddress defaults
         $sharedAddresses = array();
         $masterAddress = array();
         // get contact name of shared contact names
         $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']);
         foreach ($defaults['address'] as $key => $addressValue) {
             if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) {
                 $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']);
             } else {
                 $defaults['address'][$key]['use_shared_address'] = 0;
             }
             //check if any address is shared by any other contacts
             $masterAddress[$key] = CRM_Core_BAO_Address::checkContactSharedAddress($addressValue['id']);
         }
         $this->assign('sharedAddresses', $sharedAddresses);
         $this->assign('masterAddress', $masterAddress);
         // end of shared address defaults
         // start of parse address functionality
         // build street address, CRM-5450.
         if ($this->_parseStreetAddress) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = null;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
             $this->assign('allAddressFieldValues', json_encode($addressValues));
             //hack to handle show/hide address fields.
             $parsedAddress = array();
             if ($this->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
                 foreach ($_POST['address'] as $cnt => $values) {
                     $showField = 'streetAddress';
                     foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                         if (CRM_Utils_Array::value($fld, $values)) {
                             $showField = 'addressElements';
                             break;
                         }
                     }
                     $parsedAddress[$cnt] = $showField;
                 }
             }
             $this->assign('showHideAddressFields', $parsedAddress);
             $this->assign('loadShowHideAddressFields', empty($parsedAddress) ? false : true);
         }
         // end of parse address functionality
     }
     if (CRM_Utils_Array::value('image_URL', $defaults)) {
         list($imageWidth, $imageHeight) = getimagesize($defaults['image_URL']);
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $defaults['image_URL']);
     }
     //set location type and country to default for each block
     $this->blockSetDefaults($defaults);
     return $defaults;
 }
Exemplo n.º 9
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = $this->_values;
     $params = array();
     if ($this->_action & CRM_Core_Action::ADD) {
         if (array_key_exists('TagsAndGroups', $this->_editOptions)) {
             // set group and tag defaults if any
             if ($this->_gid) {
                 $defaults['group'][$this->_gid] = 1;
             }
             if ($this->_tid) {
                 $defaults['tag'][$this->_tid] = 1;
             }
         }
         if ($this->_contactSubType) {
             $defaults['contact_sub_type'] = $this->_contactSubType;
         }
     } else {
         if (isset($this->_elementIndex["shared_household"])) {
             $sharedHousehold = $this->getElementValue("shared_household");
             if ($sharedHousehold) {
                 $this->assign('defaultSharedHousehold', $sharedHousehold);
             } elseif (CRM_Utils_Array::value('mail_to_household_id', $defaults)) {
                 $defaults['use_household_address'] = true;
                 $this->assign('defaultSharedHousehold', $defaults['mail_to_household_id']);
             }
             $defaults['shared_household_id'] = CRM_Utils_Array::value('mail_to_household_id', $defaults);
             if (array_key_exists(1, $defaults['address'])) {
                 $this->assign('sharedHouseholdAddress', $defaults['address'][1]['display']);
             }
         }
         require_once 'CRM/Contact/BAO/Relationship.php';
         $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
         $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
         $this->assign('currentEmployer', $defaults['current_employer_id']);
     }
     // set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
     foreach ($this->_editOptions as $name => $label) {
         if (!in_array($name, array('Address', 'Notes'))) {
             require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_Form_Edit_" . $name) . ".php";
             eval('CRM_Contact_Form_Edit_' . $name . '::setDefaultValues( $this, $defaults );');
         }
     }
     // build street address, CRM-5450.
     $addressValues = array();
     if ($this->_parseStreetAddress) {
         if (is_array($defaults['address']) && !CRM_Utils_system::isNull($defaults['address'])) {
             $parseFields = array('street_address', 'street_number', 'street_name', 'street_unit');
             foreach ($defaults['address'] as $cnt => &$address) {
                 $streetAddress = null;
                 foreach (array('street_number', 'street_number_suffix', 'street_name', 'street_unit') as $fld) {
                     if (in_array($fld, array('street_name', 'street_unit'))) {
                         $streetAddress .= ' ';
                     }
                     $streetAddress .= CRM_Utils_Array::value($fld, $address);
                 }
                 $streetAddress = trim($streetAddress);
                 if (!empty($streetAddress)) {
                     $address['street_address'] = $streetAddress;
                 }
                 $address['street_number'] .= CRM_Utils_Array::value('street_number_suffix', $address);
                 // build array for set default.
                 foreach ($parseFields as $field) {
                     $addressValues["{$field}_{$cnt}"] = CRM_Utils_Array::value($field, $address);
                 }
                 // don't load fields, use js to populate.
                 foreach (array('street_number', 'street_name', 'street_unit') as $f) {
                     if (isset($address[$f])) {
                         unset($address[$f]);
                     }
                 }
             }
         }
         $this->assign('allAddressFieldValues', json_encode($addressValues));
         //hack to handle show/hide address fields.
         $parsedAddress = array();
         if ($this->_contactId && CRM_Utils_Array::value('address', $_POST) && is_array($_POST['address'])) {
             foreach ($_POST['address'] as $cnt => $values) {
                 $showField = 'streetAddress';
                 foreach (array('street_number', 'street_name', 'street_unit') as $fld) {
                     if (CRM_Utils_Array::value($fld, $values)) {
                         $showField = 'addressElements';
                         break;
                     }
                 }
                 $parsedAddress[$cnt] = $showField;
             }
         }
         $this->assign('showHideAddressFields', $parsedAddress);
         $this->assign('loadShowHideAddressFields', empty($parsedAddress) ? false : true);
     }
     //set location type and country to default for each block
     $this->blockSetDefaults($defaults);
     return $defaults;
 }