/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public * @static */ static function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } $fields = CRM_Pledge_DAO_Pledge::export(); $fields = array_merge($fields, CRM_Pledge_DAO_PledgePayment::export()); //set title to calculated fields $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')), 'pledge_balance_amount' => array('title' => ts('Balance Amount')), 'pledge_next_pay_date' => array('title' => ts('Next Payment Date')), 'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')), 'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')), 'pledge_payment_paid_date' => array('title' => ts('Paid Date')), 'pledge_payment_status' => array('title' => ts('Pledge Payment Status'), 'name' => 'pledge_payment_status', 'data_type' => CRM_Utils_Type::T_STRING)); $pledgeFields = array('pledge_status' => array('title' => 'Pledge Status', 'name' => 'pledge_status', 'data_type' => CRM_Utils_Type::T_STRING), 'pledge_frequency_unit' => array('title' => 'Pledge Frequency Unit', 'name' => 'pledge_frequency_unit', 'data_type' => CRM_Utils_Type::T_ENUM), 'pledge_frequency_interval' => array('title' => 'Pledge Frequency Interval', 'name' => 'pledge_frequency_interval', 'data_type' => CRM_Utils_Type::T_INT), 'pledge_contribution_page_id' => array('title' => 'Pledge Contribution Page Id', 'name' => 'pledge_contribution_page_id', 'data_type' => CRM_Utils_Type::T_INT)); $fields = array_merge($fields, $pledgeFields, $calculatedFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Pledge')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * adds $value['foo_display'] for each $value['foo'] enum from civicrm_pledge * * @param array $values (reference) the array up for enhancing * @return void */ static function addDisplayEnums(&$values) { $enumFields =& CRM_Pledge_DAO_Pledge::getEnums(); foreach ($enumFields as $enum) { if (isset($values[$enum])) { $values[$enum . '_display'] = CRM_Pledge_DAO_Pledge::tsEnum($enum, $values[$enum]); } } }
/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public */ function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } require_once 'CRM/Pledge/DAO/Pledge.php'; $fields = CRM_Pledge_DAO_Pledge::export(); require_once 'CRM/Pledge/DAO/Payment.php'; $fields = array_merge($fields, CRM_Pledge_DAO_Payment::export()); //set title to calculated fields $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')), 'pledge_balance_amount' => array('title' => ts('Balance Amount')), 'pledge_next_pay_date' => array('title' => ts('Next Payment Date')), 'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')), 'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')), 'pledge_payment_paid_date' => array('title' => ts('Paid Date'))); $fields = array_merge($fields, $calculatedFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Pledge')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * take the input parameter list as specified in the data model and * convert it into the same format that we use in QF and BAO object * * @param array $params Associative array of property name/value * pairs to insert in new contact. * @param array $values The reformatted properties that we can use internally * ' * * @return array|CRM_Error * @access public */ function _civicrm_pledge_format_params(&$params, &$values, $create = FALSE) { // based on contribution apis - copy all the pledge fields - this function filters out non -valid fields but unfortunately // means we have to put them back where there are 2 names for the field (name in table & unique name) // since there is no clear std to use one or the other. Generally either works ? but not for create date // perhaps we should just copy $params across rather than run it through the 'filter'? // but at least the filter forces anomalies into the open. In several cases it turned out the unique names wouldn't work // even though they are 'generally' what is returned in the GET - implying they should $fields = CRM_Pledge_DAO_Pledge::fields(); _civicrm_store_values($fields, $params, $values); //add back the fields we know of that got dropped by the previous function if ($params['pledge_create_date']) { //pledge_create_date will not be formatted by the format params function so change back to create_date $values['create_date'] = $params['pledge_create_date']; } if ($params['create_date']) { //create_date may have been dropped by the $fields function so retrieve it $values['create_date'] = $params['create_date']; } if (array_key_exists('installment_amount', $params)) { //field has been renamed - don't lose it! Note that this must be called // installment amount not pledge_installment_amount, pledge_original_installment_amount // or original_installment_amount to avoid error // Division by zero in CRM\Pledge\BAO\PledgePayment.php:162 // but we should accept the variant because they are all 'logical assumptions' based on the // 'standards' $values['installment_amount'] = $params['installment_amount']; } if (array_key_exists('original_installment_amount', $params)) { $values['installment_amount'] = $params['original_installment_amount']; } if (array_key_exists('pledge_original_installment_amount', $params)) { $values['installment_amount'] = $params['pledge_original_installment_amount']; } if (array_key_exists('status_id', $params)) { $values['pledge_status_id'] = $params['status_id']; } if ($params['contact_id']) { //this is validity checked further down to make sure the contact exists $values['pledge_contact_id'] = $params['contact_id']; } if (array_key_exists('id', $params)) { //retrieve the id key dropped from params. Note we can't use pledge_id because it //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302 $values['id'] = $params['id']; } if (array_key_exists('pledge_id', $params)) { //retrieve the id key dropped from params. Note we can't use pledge_id because it //causes an error in CRM_Pledge_BAO_PledgePayment - approx line 302 $values['id'] = $params['pledge_id']; unset($values['pledge_id']); } if (array_key_exists('status_id', $params)) { $values['pledge_status_id'] = $params['status_id']; } if (empty($values['id'])) { //at this point both should be the same so unset both if not set - passing in empty //value causes crash rather creating new - do it before next section as null values ignored in 'switch' unset($values['id']); } if (!empty($params['scheduled_date'])) { //scheduled date is required to set next payment date - defaults to start date $values['scheduled_date'] = $params['scheduled_date']; } elseif (array_key_exists('start_date', $params)) { $values['scheduled_date'] = $params['start_date']; } if (CRM_Utils_Array::value('contribution_type_id', $params)) { $values['contribution_type_id'] = $params['contribution_type_id']; } foreach ($values as $key => $value) { // ignore empty values or empty arrays etc if (CRM_Utils_System::isNull($value)) { continue; } switch ($key) { case 'pledge_contact_id': if (!CRM_Utils_Rule::integer($value)) { return civicrm_create_error("contact_id not valid: {$value}"); } $dao = new CRM_Core_DAO(); $qParams = array(); $svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams); if (!$svq) { return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}."); } $values['contact_id'] = $values['pledge_contact_id']; unset($values['pledge_contact_id']); break; case 'pledge_id': if (!CRM_Utils_Rule::integer($value)) { return civicrm_create_error("contact_id not valid: {$value}"); } $dao = new CRM_Core_DAO(); $qParams = array(); $svq = $dao->singleValueQuery("SELECT id FROM civicrm_pledge WHERE id = {$value}", $qParams); if (!$svq) { return civicrm_create_error("Invalid Contact ID: There is no contact record with contact_id = {$value}."); } break; case 'create_date': case 'scheduled_date': case 'start_date': if (!CRM_Utils_Rule::datetime($value)) { return civicrm_create_error("{$key} not a valid date: {$value}"); } break; case 'installment_amount': case 'amount': if (!CRM_Utils_Rule::money($value)) { return civicrm_create_error("{$key} not a valid amount: {$value}"); } break; case 'currency': if (!CRM_Utils_Rule::currencyCode($value)) { return civicrm_create_error("currency not a valid code: {$value}"); } break; case 'contribution_type_id': require_once 'CRM/Contribute/PseudoConstant.php'; $typeId = CRM_Contribute_PseudoConstant::contributionType($value); if (!CRM_Utils_Rule::integer($value) || !$typeId) { return civicrm_create_error("contribution type id is not valid: {$value}"); } default: break; } } //format the parameters _civicrm_custom_format_params($params, $values, 'Pledge'); return array(); }
/** * Override buildOptions to hack out some statuses. * * @todo instead of using & hacking the shared optionGroup contribution_status use a separate one. * * @param string $fieldName * @param string $context * @param array $props * * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { $result = parent::buildOptions($fieldName, $context, $props); if ($fieldName == 'status_id') { $result = array_diff($result, array('Failed')); } return $result; }
function civicrm_pledge_payment_interogate($params) { $fields = CRM_Pledge_DAO_Pledge::fields(); $fields['installment_amount'] = array('name' => 'installment_amount', 'title' => ts('Installment Amount')); unset($fields['amount']); return $fields; }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['pledge'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }