/** * Pre processing work done here. * * gets session variables for group or field id * * @return void */ public function preProcess() { // get the controller vars $this->_groupId = $this->get('groupId'); $this->_fieldId = $this->get('fieldId'); if ($this->_fieldId) { // field preview $defaults = array(); $params = array('id' => $this->_fieldId); $fieldDAO = new CRM_Core_DAO_CustomField(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); if (!empty($defaults['is_view'])) { CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.')); } elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) { CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.')); } $groupTree = array(); $groupTree[$this->_groupId]['id'] = 0; $groupTree[$this->_groupId]['fields'] = array(); $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults; $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this); $this->assign('preview_type', 'field'); } else { $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId); $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this); $this->assign('preview_type', 'group'); } }
/** * pre processing work done here. * * gets session variables for group or field id * * @param null * * @return void * @access public */ function preProcess() { // get the controller vars $groupId = $this->get('groupId'); $fieldId = $this->get('fieldId'); if ($fieldId) { // field preview $defaults = array(); $params = array('id' => $fieldId); $fieldDAO =& new CRM_Core_DAO_CustomField(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults); $this->_groupTree = array(); $this->_groupTree[0]['id'] = 0; $this->_groupTree[0]['fields'] = array(); $this->_groupTree[0]['fields'][$fieldId] = $defaults; $this->assign('preview_type', 'field'); } else { // group preview $this->_groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($groupId); $this->assign('preview_type', 'group'); } }
/** * add all the elements shared between contribute search and advnaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { //added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); //adding select option for curreny type -- CRM-4711 $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- select -')) + CRM_Core_PseudoConstant::currencySymbols('name')); $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage()); $status = array(); $statusValues = CRM_Core_OptionGroup::values("contribution_status"); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5']); unset($statusValues['6']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, NULL, $val); } $form->addGroup($status, 'contribution_status_id', ts('Contribution Status')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?')); //add fields for honor search $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of")); $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?')); $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?')); //add field for transaction ID search $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID")); $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?')); $form->addElement('checkbox', 'contribution_recurring_isnull', ts('Find Non Recurring Contributions?')); $form->addElement('text', 'contribution_check_number', ts('Check Number')); //add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?')); // add all the custom searchable fields $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution); if ($groupDetails) { $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id'); // add batch select $batches = CRM_Core_BAO_Batch::getBatches(); if (!empty($batches)) { $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- select -')) + $batches); } $form->assign('validCiviContribute', TRUE); }
function copyCustomValues($recurId, $targetContributionId) { if ($recurId && $targetContributionId) { // get the initial contribution id of recur id $sourceContributionId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id'); // if the same contribution is being proccessed then return if ($sourceContributionId == $targetContributionId) { return; } // check if proper recurring contribution record is being processed $targetConRecurId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $targetContributionId, 'contribution_recur_id'); if ($targetConRecurId != $recurId) { return; } // copy custom data $extends = array('Contribution'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $targetContributionId; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$sourceContributionId}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } } }
/** * Build the search form. * * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(); $form->add('select', 'membership_status_id', ts('Membership Status(s)'), $membershipStatus, FALSE, array('id' => 'membership_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->addEntityRef('membership_type_id', ts('Membership Type(s)'), array('entity' => 'MembershipType', 'multiple' => TRUE, 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0))); $form->addElement('text', 'member_source', ts('Source')); CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE); $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE); $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE); $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE); $form->addYesNo('member_is_override', ts('Membership Status Is Override?'), TRUE); // add all the custom searchable fields $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id'); $form->assign('validCiviMember', TRUE); $form->setDefaults(array('member_test' => 0)); }
/** * This function is to make a copy of a Event, including * all the fields in the event Wizard * * @param int $id the event id to copy * * @return void * @access public */ static function copy($id) { $defaults = $eventValues = array(); //get the require event values. $eventParams = array('id' => $id); $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id'); CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties); // since the location is sharable, lets use the same loc_block_id. $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues); $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' ')); if (!CRM_Utils_Array::value('is_show_location', $eventValues)) { $fieldsFix['prefix']['is_show_location'] = 0; } $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : null), $fieldsFix); $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); require_once "CRM/Core/BAO/OptionGroup.php"; //copy option Group and values $copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues)); //copy discounted fee levels require_once 'CRM/Core/BAO/Discount.php'; $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event'); if (!empty($discount)) { foreach ($discount as $discountOptionGroup) { $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup); $length = substr_compare($name, "civicrm_event.amount." . $id, 0); $discountSuffix = substr($name, $length * -1); $copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix); } } //copy custom data require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(null, null, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $copyEvent->id; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$id}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } $copyEvent->save(); require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::copy('Event', $copyEvent); return $copyEvent; }
/** * Function to test getGroupDetail() */ function testGetGroupDetail() { $customGrouptitle = 'My Custom Group'; $groupParams = array('title' => $customGrouptitle, 'name' => 'my_custom_group', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1); $customGroup = Custom::createGroup($groupParams); $customGroupId = $customGroup->id; $fieldParams = array('custom_group_id' => $customGroupId, 'label' => 'Test Custom Field', 'html_type' => 'Text', 'data_type' => 'String', 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1); $customField = Custom::createField($fieldParams); $customFieldId = $customField->id; require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId); $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.'); //check retieve values of custom group unset($groupParams['is_active']); $this->assertAttributesEquals($groupParams, $groupTree[$customGroupId]); //check retieve values of custom field unset($fieldParams['is_active']); unset($fieldParams['custom_group_id']); $this->assertAttributesEquals($fieldParams, $groupTree[$customGroupId]['fields'][$customFieldId]); //cleanup DB by deleting customGroup Custom::deleteField($customField); Custom::deleteGroup($customGroup); }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { // pledge related dates CRM_Core_Form_Date::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE); // pledge payment related dates CRM_Core_Form_Date::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('pledge_test', ts('Pledge is a Test?'), TRUE); $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); $statusValues = CRM_Contribute_PseudoConstant::contributionStatus(); // Remove status values that are only used for recurring contributions for now (Failed and In Progress). unset($statusValues['4']); $form->add('select', 'pledge_status_id', ts('Pledge Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); //unset in progress for payment unset($statusValues['5']); $form->add('select', 'pledge_payment_status_id', ts('Pledge Payment Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'pledge_financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), FALSE, array('class' => 'crm-select2')); $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2')); //add fields for pledge frequency $form->add('text', 'pledge_frequency_interval', ts('Every'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_frequency_interval', ts('Please enter valid Pledge Frequency Interval'), 'integer'); $frequencies = CRM_Core_OptionGroup::values('recur_frequency_units'); foreach ($frequencies as $val => $label) { $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', array(1 => $label)); } $form->add('select', 'pledge_frequency_unit', ts('Pledge Frequency'), array('' => ts('- any -')) + $freqUnitsDisplay); // add all the custom searchable fields $pledge = array('Pledge'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $pledge); if ($groupDetails) { $form->assign('pledgeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'pledge_campaign_id'); $form->assign('validCiviPledge', TRUE); $form->setDefaults(array('pledge_test' => 0)); }
/** * Generate the custom Data Fields based * on the is_searchable * * * @param $form * * @return void */ public static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; if ($field['data_type'] == 'Date' && $field['is_search_range']) { CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE); } else { CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } //TODO: validate for only one state if prox_distance isset }
/** * Generate the custom Data Fields based * on the is_searchable * * @access private * @return void */ static function custom(&$form) { $form->add('hidden', 'hidden_custom', 1); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); $form->assign('groupTree', $groupDetails); foreach ($groupDetails as $key => $group) { $_groupTitle[$key] = $group['name']; CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); $groupId = $group['id']; foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } }
/** * Browse the listing. * * @return void */ public function browse() { $dateFields = NULL; $cgcount = 0; $attributes = array(); $dateFieldsVals = NULL; if ($this->_pageViewType == 'profileDataView' && $this->_profileId) { $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT); $multiRecordFields = array(); $fieldIDs = NULL; $result = NULL; $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE); $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields)); $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id'); $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId); if (!$reached) { $this->assign('contactId', $this->_contactId); $this->assign('gid', $this->_profileId); } $this->assign('reachedMax', $reached); if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) { $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing); } } elseif ($this->_pageViewType == 'customDataView') { // require custom group id for _pageViewType of customDataView $customGroupId = $this->_customGroupId; $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId); if (!$reached) { $this->assign('contactId', $this->_contactId); $this->assign('customGroupId', $customGroupId); $this->assign('ctype', $this->_contactType); } $this->assign('reachedMax', $reached); // custom group info : this consists of the field title of group fields $groupDetail = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId, NULL, CRM_Core_DAO::$_nullObject, TRUE); // field ids of fields in_selector for the custom group id provided $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']); // field labels for headers $fieldLabels = $groupDetail[$customGroupId]['fields']; // from the above customGroupInfo we can get $this->_customGroupTitle $this->_customGroupTitle = $groupDetail[$customGroupId]['title']; } if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) { $options = array(); $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format', 'default_value', 'is_required'); foreach ($fieldIDs as $key => $fieldID) { $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID; $param = array('id' => $fieldIDs[$key]); $returnValues = array(); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities); if ($returnValues['data_type'] == 'Date') { $dateFields[$fieldIDs[$key]] = 1; $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats(); $dateFormat = (array) CRM_Utils_Array::value($returnValues['date_format'], $actualPHPFormats); $timeFormat = CRM_Utils_Array::value('time_format', $returnValues); } $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]); if (!empty($optionValuePairs)) { foreach ($optionValuePairs as $optionPairs) { $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label']; } } $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type']; $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type']; $options[$fieldIDs[$key]]['attributes']['is_required'] = !empty($returnValues['is_required']); $options[$fieldIDs[$key]]['attributes']['default_value'] = CRM_Utils_Array::value('default_value', $returnValues); $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues); $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues); } // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView) $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE); if ($this->_pageViewType == 'profileDataView') { if (!empty($fieldIDs)) { //get the group info of multi rec fields in listing view $fieldInput = $fieldIDs; $fieldIdInput = $fieldIDs[0]; } else { //if no listing fields exist, take the group title for display $nonListingFieldIds = array_keys($multiRecordFields); $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]); $fieldIdInput = $singleField; $singleField = array($singleField); $fieldInput = $singleField; } $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput); $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle']; } // $cgcount is defined before 'if' condition as enitiy may have no record // and $cgcount is used to build new record url $cgcount = 1; if ($result && !empty($result)) { $links = self::links(); if ($this->_pageViewType == 'profileDataView') { $pageCheckSum = $this->get('pageCheckSum'); if ($pageCheckSum) { foreach ($links as $key => $link) { $links[$key] = $link['qs'] . "&cs=%%cs%%"; } } } $linkAction = array_sum(array_keys($this->links())); if ($reached) { unset($links[CRM_Core_Action::COPY]); } $newCgCount = !$reached ? count($result) + 1 : NULL; foreach ($result as $recId => &$value) { foreach ($value as $fieldId => &$val) { if (is_numeric($fieldId)) { $customValue =& $val; if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) { // formated date capture value capture $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); //set date and time format switch ($timeFormat) { case 1: $dateFormat[1] = 'g:iA'; break; case 2: $dateFormat[1] = 'G:i'; break; default: // if time is not selected remove time from value $result[$recId][$fieldId] = substr($result[$recId][$fieldId], 0, 10); } $result[$recId][$fieldId] = CRM_Utils_Date::processDate($result[$recId][$fieldId], NULL, FALSE, implode(" ", $dateFormat)); } else { // assign to $result $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); } // FIXME: getDisplayValue should always return a string so why is this necessary? if (!$customValue && $customValue !== '0') { $customValue = ""; } // Set field attributes to support crmEditable // Note that $fieldAttributes[data-type] actually refers to the html type not the sql data type // TODO: Not all widget types and validation rules are supported by crmEditable so some fields will not be in-place editable $fieldAttributes = array('class' => "crmf-custom_{$fieldId}_{$recId}"); $editable = FALSE; if ($linkAction & CRM_Core_Action::UPDATE) { $spec = $options[$fieldId]['attributes']; switch ($spec['html_type']) { case 'Text': // Other data types like money would require some extra validation // FIXME: crmEditable currently does not support any validation rules :( $supportedDataTypes = array('Float', 'String', 'Int'); $editable = in_array($spec['data_type'], $supportedDataTypes); break; case 'TextArea': $editable = TRUE; $fieldAttributes['data-type'] = 'textarea'; break; case 'Radio': case 'Select': case 'Select Country': case 'Select State/Province': $editable = TRUE; $fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select'; if (!$spec['is_required']) { $fieldAttributes['data-empty-option'] = ts('- none -'); } break; } } if ($editable) { $fieldAttributes['class'] .= ' crm-editable'; } $attributes[$fieldId][$recId] = $fieldAttributes; $op = NULL; if ($this->_pageViewType == 'profileDataView') { $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId); $op = 'profile.multiValue.row'; } else { // different set of url params $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId; $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId; $actionParams['recId'] = $recId; $actionParams['type'] = $this->_contactType; $actionParams['cgcount'] = $cgcount; $actionParams['newCgCount'] = $newCgCount; // DELETE action links $deleteData = array('valueID' => $recId, 'groupID' => $this->_customGroupId, 'contactId' => $this->_contactId, 'key' => CRM_Core_Key::get('civicrm/ajax/customvalue')); $links[CRM_Core_Action::DELETE]['url'] = '#'; $links[CRM_Core_Action::DELETE]['extra'] = ' data-delete_params="' . htmlspecialchars(json_encode($deleteData)) . '"'; $links[CRM_Core_Action::DELETE]['class'] = 'delete-custom-row'; } if (!empty($pageCheckSum)) { $actionParams['cs'] = $pageCheckSum; } $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams, ts('more'), FALSE, $op, 'customValue', $fieldId); } } $cgcount++; } } } $headers = array(); if (!empty($fieldIDs)) { foreach ($fieldIDs as $fieldID) { $headers[$fieldID] = $this->_pageViewType == 'profileDataView' ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label']; } } $this->assign('dateFields', $dateFields); $this->assign('dateFieldsVals', $dateFieldsVals); $this->assign('cgcount', $cgcount); $this->assign('customGroupTitle', $this->_customGroupTitle); $this->assign('headers', $headers); $this->assign('records', $result); $this->assign('attributes', $attributes); }
public static function printCaseReport() { $caseID = CRM_Utils_Request::retrieve('caseID', 'Positive', CRM_Core_DAO::$_nullObject); $clientID = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject); $activitySetName = CRM_Utils_Request::retrieve('asn', 'String', CRM_Core_DAO::$_nullObject); $isRedact = CRM_Utils_Request::retrieve('redact', 'Boolean', CRM_Core_DAO::$_nullObject); $includeActivities = CRM_Utils_Request::retrieve('all', 'Positive', CRM_Core_DAO::$_nullObject); $params = $otherRelationships = $globalGroupInfo = array(); $report = new CRM_Case_XMLProcessor_Report($isRedact); if ($includeActivities) { $params['include_activities'] = 1; } if ($isRedact) { $params['is_redact'] = 1; $report->_redactionStringRules = array(); } $template = CRM_Core_Smarty::singleton(); //get case related relationships (Case Role) $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($clientID, $caseID); $caseType = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseType, 'CaseRoles'); foreach ($caseRelationships as $key => &$value) { if (!empty($caseRoles[$value['relation_type']])) { unset($caseRoles[$value['relation_type']]); } if ($isRedact) { if (!array_key_exists($value['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['name'] => 'name_' . rand(10000, 100000))); } $value['name'] = self::redact($value['name'], TRUE, $report->_redactionStringRules); if (!empty($value['email']) && !array_key_exists($value['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['email'] => 'email_' . rand(10000, 100000))); } $value['email'] = self::redact($value['email'], TRUE, $report->_redactionStringRules); if (!empty($value['phone']) && !array_key_exists($value['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($value['phone'] => 'phone_' . rand(10000, 100000))); } $value['phone'] = self::redact($value['phone'], TRUE, $report->_redactionStringRules); } } $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); if ($isRedact) { if (!array_key_exists($caseRoles['client']['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($caseRoles['client']['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$caseRoles['client']['display_name']] = $report->_redactionStringRules[$caseRoles['client']['sort_name']]; } $caseRoles['client']['sort_name'] = self::redact($caseRoles['client']['sort_name'], TRUE, $report->_redactionStringRules); if (!empty($caseRoles['client']['email']) && !array_key_exists($caseRoles['client']['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['email'] => 'email_' . rand(10000, 100000))); } $caseRoles['client']['email'] = self::redact($caseRoles['client']['email'], TRUE, $report->_redactionStringRules); if (!empty($caseRoles['client']['phone']) && !array_key_exists($caseRoles['client']['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($caseRoles['client']['phone'] => 'phone_' . rand(10000, 100000))); } $caseRoles['client']['phone'] = self::redact($caseRoles['client']['phone'], TRUE, $report->_redactionStringRules); } // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($clientID, CRM_Contact_BAO_Relationship::CURRENT, 0, 0, 0, NULL, NULL, FALSE); foreach ($relClient as $r) { if ($isRedact) { if (!array_key_exists($r['name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['name']]; } $r['name'] = self::redact($r['name'], TRUE, $report->_redactionStringRules); if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules); if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules); } if (!array_key_exists($r['id'], $caseRelationships)) { $otherRelationships[] = $r; } } // Now global contact list that appears on all cases. $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); foreach ($relGlobal as &$r) { if ($isRedact) { if (!array_key_exists($r['sort_name'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['sort_name'] => 'name_' . rand(10000, 100000))); } if (!array_key_exists($r['display_name'], $report->_redactionStringRules)) { $report->_redactionStringRules[$r['display_name']] = $report->_redactionStringRules[$r['sort_name']]; } $r['sort_name'] = self::redact($r['sort_name'], TRUE, $report->_redactionStringRules); if (!empty($r['phone']) && !array_key_exists($r['phone'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['phone'] => 'phone_' . rand(10000, 100000))); } $r['phone'] = self::redact($r['phone'], TRUE, $report->_redactionStringRules); if (!empty($r['email']) && !array_key_exists($r['email'], $report->_redactionStringRules)) { $report->_redactionStringRules = CRM_Utils_Array::crmArrayMerge($report->_redactionStringRules, array($r['email'] => 'email_' . rand(10000, 100000))); } $r['email'] = self::redact($r['email'], TRUE, $report->_redactionStringRules); } } // Retrieve custom values for cases. $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($caseID, 'Case'); $extends = array('case'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); $caseCustomFields = array(); while (list($gid, $group_values) = each($groupTree)) { while (list($id, $field_values) = each($group_values['fields'])) { if (array_key_exists($id, $customValues)) { $caseCustomFields[$gid]['title'] = $group_values['title']; $caseCustomFields[$gid]['values'][$id] = array('label' => $field_values['label'], 'value' => $customValues[$id]); } } } $template->assign('caseRelationships', $caseRelationships); $template->assign('caseRoles', $caseRoles); $template->assign('otherRelationships', $otherRelationships); $template->assign('globalRelationships', $relGlobal); $template->assign('globalGroupInfo', $globalGroupInfo); $template->assign('caseCustomFields', $caseCustomFields); $contents = self::getCaseReport($clientID, $caseID, $activitySetName, $params, $report); $printReport = CRM_Case_Audit_Audit::run($contents, $clientID, $caseID, TRUE); echo $printReport; CRM_Utils_System::civiExit(); }
static function buildSearchForm(&$form) { // pledge related dates $form->addDate('pledge_start_date_low', ts('Payments Start Date - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_start_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('pledge_end_date_low', ts('Payments Ended Date - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_end_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('pledge_create_date_low', ts('Pledge Made - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_create_date_high', ts('To'), false, array('formatType' => 'relative')); // pledge payment related dates $form->addDate('pledge_payment_date_low', ts('Payment Scheduled - From'), false, array('formatType' => 'relative')); $form->addDate('pledge_payment_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addElement('checkbox', 'pledge_test', ts('Find Test Pledges?')); require_once 'CRM/Utils/Money.php'; $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); require_once 'CRM/Contribute/PseudoConstant.php'; $statusValues = CRM_Contribute_PseudoConstant::contributionStatus(); // Remove status values that are only used for recurring contributions for now (Failed and In Progress). unset($statusValues['4']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($status, 'pledge_status_id', ts('Pledge Status')); //unset in progress for payment unset($statusValues['5']); foreach ($statusValues as $key => $val) { $paymentStatus[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status')); require_once 'CRM/Contribute/PseudoConstant.php'; $form->add('select', 'pledge_contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'pledge_contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); //add fields for honor search $form->addElement('text', 'pledge_in_honor_of', ts("In Honor Of")); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $pledge = array('Pledge'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $pledge); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('pledgeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviPledge', true); }
static function buildSearchForm(&$form) { $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event', "reset=1", false, null, false); $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType', "reset=1", false, null, false); $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", false, null, false); $form->assign('dataURLEvent', $dataURLEvent); $form->assign('dataURLEventType', $dataURLEventType); $form->assign('dataURLEventFee', $dataURLEventFee); $eventId =& $form->add('text', 'event_name', ts('Event Name')); $eventType =& $form->add('text', 'event_type', ts('Event Type')); $participantFee =& $form->add('text', 'participant_fee_level', ts('Fee Level')); //elements for assigning value operation $eventNameId =& $form->add('hidden', 'event_id', '', array('id' => 'event_id')); $eventTypeId =& $form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id')); $participantFeeId =& $form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id')); $form->addDate('event_start_date_low', ts('Event Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('event_end_date_high', ts('To'), false, array('formatType' => 'searchDate')); require_once 'CRM/Event/PseudoConstant.php'; $status = CRM_Event_PseudoConstant::participantStatus(null, null, 'label'); asort($status); foreach ($status as $id => $Name) { $form->_participantStatus =& $form->addElement('checkbox', "participant_status_id[{$id}]", null, $Name); } foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { $form->_participantRole =& $form->addElement('checkbox', "participant_role_id[{$rId}]", null, $rName); } $form->addElement('checkbox', 'participant_test', ts('Find Test Participants?')); $form->addElement('checkbox', 'participant_pay_later', ts('Find Pay Later Participants?')); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Participant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviEvent', true); }
static function buildSearchForm(&$form) { $dataURLEvent = CRM_Utils_System::url('civicrm/ajax/event', "reset=1", FALSE, NULL, FALSE); $dataURLEventType = CRM_Utils_System::url('civicrm/ajax/eventType', "reset=1", FALSE, NULL, FALSE); $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE); $form->assign('dataURLEvent', $dataURLEvent); $form->assign('dataURLEventType', $dataURLEventType); $form->assign('dataURLEventFee', $dataURLEventFee); $eventId =& $form->add('text', 'event_name', ts('Event Name')); $eventType =& $form->add('text', 'event_type', ts('Event Type')); $participantFee =& $form->add('text', 'participant_fee_level', ts('Fee Level')); //elements for assigning value operation $eventNameId =& $form->add('hidden', 'event_id', '', array('id' => 'event_id')); $eventTypeId =& $form->add('hidden', 'event_type_id', '', array('id' => 'event_type_id')); $participantFeeId =& $form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id')); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE, FALSE); $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); asort($status); foreach ($status as $id => $Name) { $form->_participantStatus =& $form->addElement('checkbox', "participant_status_id[{$id}]", NULL, $Name); } foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) { $form->_participantRole =& $form->addElement('checkbox', "participant_role_id[{$rId}]", NULL, $rName); } $form->addElement('checkbox', 'participant_test', ts('Find Test Participants?')); $form->addElement('checkbox', 'participant_pay_later', ts('Find Pay Later Participants?')); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields $extends = array('Participant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); $form->assign('validCiviEvent', TRUE); }
/** * add all the elements shared between grant search and advanaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { $grantType = CRM_Core_OptionGroup::values('grant_type'); $form->add('select', 'grant_type_id', ts('Grant Type'), array('' => ts('- any -')) + $grantType, FALSE, array('class' => 'crm-select2')); $grantStatus = CRM_Core_OptionGroup::values('grant_status'); $form->add('select', 'grant_status_id', ts('Grant Status'), array('' => ts('- any -')) + $grantStatus, FALSE, array('class' => 'crm-select2')); $form->addDate('grant_application_received_date_low', ts('App. Received Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_application_received_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_application_received_notset', ts(''), NULL); $form->addDate('grant_money_transfer_date_low', ts('Money Sent Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_money_transfer_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_money_transfer_date_notset', ts(''), NULL); $form->addDate('grant_due_date_low', ts('Report Due Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_due_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_due_date_notset', ts(''), NULL); $form->addDate('grant_decision_date_low', ts('Grant Decision Date - From'), FALSE, array('formatType' => 'searchDate')); $form->addDate('grant_decision_date_high', ts('To'), FALSE, array('formatType' => 'searchDate')); $form->addElement('checkbox', 'grant_decision_date_notset', ts(''), NULL); $form->addYesNo('grant_report_received', ts('Grant report received?'), TRUE); $form->add('text', 'grant_amount_low', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('grant_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'grant_amount_high', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('grant_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // add all the custom searchable fields $grant = array('Grant'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $grant); if ($groupDetails) { $form->assign('grantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->assign('validGrant', TRUE); }
/** * Add all the elements shared between case search and advanaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); $form->add('select', 'case_type_id', ts('Case Type'), CRM_Case_PseudoConstant::caseType('title', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'case_status_id', ts('Case Status'), CRM_Case_PseudoConstant::caseStatus('label', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); $form->assign('validCiviCase', TRUE); //give options when all cases are accessible. $accessAllCases = FALSE; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = TRUE; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); $caseTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE); if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } // add all the custom searchable fields $extends = array('Case'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('caseGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->setDefaults(array('case_owner' => 1)); }
/** * add all the elements shared between case activity search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(true, true, false, 'label', true); asort($activityOptions); foreach ($activityOptions as $activityID => $activity) { $form->_activityElement =& $form->addElement('checkbox', "activity_type_id[{$activityID}]", null, $activity, array('onClick' => 'showCustomData( this.id );')); } $form->addDate('activity_date_low', ts('Activity Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('activity_date_high', ts('To'), false, array('formatType' => 'searchDate')); $activityRoles = array(1 => ts('Created by'), 2 => ts('Assigned to')); $form->addRadio('activity_role', null, $activityRoles, null, '<br />'); $form->setDefaults(array('activity_role' => 1)); $form->addElement('text', 'activity_contact_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); foreach ($activityStatus as $activityStatusID => $activityStatusName) { $activity_status[] = HTML_QuickForm::createElement('checkbox', $activityStatusID, null, $activityStatusName); } $form->addGroup($activity_status, 'activity_status', ts('Activity Status')); $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1)); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addElement('checkbox', 'activity_test', ts('Find Test Activities?')); require_once 'CRM/Core/BAO/Tag.php'; $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", null, $tagName); } } require_once 'CRM/Campaign/BAO/Survey.php'; $surveys = array('' => ts('- none -')) + CRM_Campaign_BAO_Survey::getSurveyList(); $form->add('select', 'activity_survey_id', ts('Survey'), $surveys, false); require_once 'CRM/Core/BAO/CustomGroup.php'; $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { $this->set('context', 'advanced'); $this->_searchPane = CRM_Utils_Array::value('searchPane', $_GET); $this->_searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options'); if (!$this->_searchPane || $this->_searchPane == 'basic') { CRM_Contact_Form_Search_Criteria::basic($this); } $allPanes = array(); $paneNames = array(ts('Address Fields') => 'location', ts('Custom Fields') => 'custom', ts('Activities') => 'activity', ts('Relationships') => 'relationship', ts('Demographics') => 'demographics', ts('Notes') => 'notes', ts('Change Log') => 'changeLog'); //check if there are any custom data searchable fields $groupDetails = array(); $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), CRM_Contact_BAO_ContactType::subTypes()); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); // if no searchable fields unset panel if (empty($groupDetails)) { unset($paneNames[ts('Custom Fields')]); } foreach ($paneNames as $name => $type) { if (!$this->_searchOptions[$type]) { unset($paneNames[$name]); } } $components = CRM_Core_Component::getEnabledComponents(); $componentPanes = array(); foreach ($components as $name => $component) { if (in_array($name, array_keys($this->_searchOptions)) && $this->_searchOptions[$name] && CRM_Core_Permission::access($component->name)) { $componentPanes[$name] = $component->registerAdvancedSearchPane(); $componentPanes[$name]['name'] = $name; } } usort($componentPanes, array('CRM_Utils_Sort', 'cmpFunc')); foreach ($componentPanes as $name => $pane) { // FIXME: we should change the use of $name here to keyword $paneNames[$pane['title']] = $pane['name']; } $hookPanes = array(); CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes); $paneNames = array_merge($paneNames, $hookPanes); $this->_paneTemplatePath = array(); foreach ($paneNames as $name => $type) { if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) { continue; } $allPanes[$name] = array('url' => CRM_Utils_System::url('civicrm/contact/search/advanced', "snippet=1&searchPane={$type}&qfKey={$this->controller->_key}"), 'open' => 'false', 'id' => $type); // see if we need to include this paneName in the current form if ($this->_searchPane == $type || CRM_Utils_Array::value("hidden_{$type}", $_POST) || CRM_Utils_Array::value("hidden_{$type}", $this->_formValues)) { $allPanes[$name]['open'] = 'true'; if (CRM_Utils_Array::value($type, $components)) { $c = $components[$type]; $this->add('hidden', "hidden_{$type}", 1); $c->buildAdvancedSearchPaneForm($this); $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath(); } else { if (in_array($type, $hookPanes)) { CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type); CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type); } else { CRM_Contact_Form_Search_Criteria::$type($this); $template = ucfirst($type); $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl"; } } } } $this->assign('allPanes', $allPanes); if (!$this->_searchPane) { parent::buildQuickForm(); } else { $this->assign('suppressForm', TRUE); } }
/** * Add all the elements shared between case activity search and advanced search. * * * @param CRM_Core_Form $form * @return void */ public static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); $form->addSelect('activity_type_id', array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $followUpActivity = array(1 => ts('Yes'), 2 => ts('No')); $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $activityRoles = array(3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by')); $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); $form->setDefaults(array('activity_role' => 3)); $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); $form->addSelect('status_id', array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addYesNo('activity_test', ts('Activity is a Test?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), array('' => ts('- none -')) + $surveys, FALSE, array('class' => 'crm-select2')); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); $resultOptions = array(); foreach ($optionGroups as $gid => $name) { if ($name) { $value = array(); $value = CRM_Core_OptionGroup::values($name); if (!empty($value)) { while (list($k, $v) = each($value)) { $resultOptions[$v] = $v; } } } } // If no survey result options have been created, don't build // the field to avoid clutter. if (count($resultOptions) > 0) { $buildSurveyResult = TRUE; asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2')); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); }
/** * This function is to make a copy of a Event, including * all the fields in the event Wizard * * @param int $id the event id to copy * obj $newEvent object of CRM_Event_DAO_Event * boolean $afterCreate call to copy after the create function * @param null $newEvent * @param bool $afterCreate * * @return void * @access public */ static function copy($id, $newEvent = NULL, $afterCreate = FALSE) { $defaults = $eventValues = array(); //get the require event values. $eventParams = array('id' => $id); $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id', 'is_template'); CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties); // since the location is sharable, lets use the same loc_block_id. $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues); $fieldsFix = $afterCreate ? array() : array('prefix' => array('title' => ts('Copy of') . ' ')); if (empty($eventValues['is_show_location'])) { $fieldsFix['prefix']['is_show_location'] = 0; } if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) { $copyEvent = $newEvent; } if (!isset($copyEvent)) { $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix); } CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id); $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyPCP =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id), array('replace' => array('target_entity_id' => $copyEvent->id))); if ($eventValues['is_template']) { $field = 'event_template'; } else { $field = 'civicrm_event'; } $mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value'); $oldData = array('entity_value' => $id, 'mapping_id' => $mappingId); if ($copyEvent->is_template == 1) { $field = 'event_template'; } else { $field = 'civicrm_event'; } $copyMappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value'); $newData = array('entity_value' => $copyEvent->id, 'mapping_id' => $copyMappingId); $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', $oldData, $newData); if (!$afterCreate) { //copy custom data $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $copyEvent->id; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$id}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } } $copyEvent->save(); CRM_Utils_System::flushCache(); if (!$afterCreate) { CRM_Utils_Hook::copy('Event', $copyEvent); } return $copyEvent; }
/** * Test getGroupDetail(). */ public function testGetGroupDetail() { $customGroupTitle = 'My Custom Group'; $groupParams = array('title' => $customGroupTitle, 'name' => 'My_Custom_Group', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1); $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; $fieldParams = array('custom_group_id' => $customGroupId, 'label' => 'Test Custom Field', 'html_type' => 'Text', 'data_type' => 'String', 'is_required' => 1, 'is_searchable' => 0, 'is_active' => 1); $customField = $this->customFieldCreate($fieldParams); $customFieldId = $customField['id']; $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($customGroupId); $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.'); //check retieve values of custom group unset($groupParams['is_active']); unset($groupParams['title']); unset($groupParams['version']); $this->assertAttributesEquals($groupParams, $groupTree[$customGroupId]); //check retieve values of custom field unset($fieldParams['is_active']); unset($fieldParams['custom_group_id']); unset($fieldParams['version']); $this->assertAttributesEquals($fieldParams, $groupTree[$customGroupId]['fields'][$customFieldId], " in line " . __LINE__); $this->customFieldDelete($customField['id']); $this->customGroupDelete($customGroup['id']); }
/** * Add all the elements shared between contribute search and advnaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { // Added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // Adding select option for curreny type -- CRM-4711 $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- any -')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name')), FALSE, array('class' => 'crm-select2')); // CRM-13848 $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2')); $form->addSelect('payment_instrument_id', array('entity' => 'contribution', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::pcPage(), FALSE, array('class' => 'crm-select2')); $status = array(); $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status'); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5'], $statusValues['6']); $form->addSelect('contribution_status_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'label' => ts('Contribution Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); // Add fields for thank you and receipt $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE); $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?'), TRUE); $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?'), TRUE); $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE); // Recurring contribution fields foreach (self::getRecurringFields() as $key => $label) { CRM_Core_Form_Date::buildDateRange($form, $key, 1, '_low', '_high'); // If data has been entered for a recurring field, tell the tpl layer to open the pane if (!empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) { $form->assign('contribution_recur_pane_open', TRUE); } } $form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE); // Add field for transaction ID search $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID")); $form->addElement('text', 'contribution_check_number', ts('Check Number')); // Add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'), TRUE); // Soft credit related fields $options = array('only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), 'both_related' => ts('Soft Credits with related Hard Credit'), 'both' => ts('Both')); $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2")); $form->addSelect('contribution_soft_credit_type_id', array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'context' => 'search')); // Add all the custom searchable fields $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution); if ($groupDetails) { $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id'); // Add batch select $batches = CRM_Contribute_PseudoConstant::batch(); if (!empty($batches)) { $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- any -')) + $batches, FALSE, array('class' => 'crm-select2')); } $form->assign('validCiviContribute', TRUE); $form->setDefaults(array('contribution_test' => 0)); }
/** * add all the elements shared between this and advnaced search * * @access public * @return void * @static */ function buildQuickFormCommon(&$form) { // Date selects for date $form->add('date', 'contribution_date_from', ts('Contribution Dates - From'), CRM_Core_SelectValues::date('relative')); $form->addRule('contribution_date_from', ts('Select a valid date.'), 'qfDate'); $form->add('date', 'contribution_date_to', ts('To'), CRM_Core_SelectValues::date('relative')); $form->addRule('contribution_date_to', ts('Select a valid date.'), 'qfDate'); $form->add('text', 'contribution_min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_min_amount', ts('Please enter a valid money value (e.g. 9.99).'), 'money'); $form->add('text', 'contribution_max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_max_amount', ts('Please enter a valid money value (e.g. 99.99).'), 'money'); $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $status = array(); $status[] = $form->createElement('radio', null, null, ts('Valid'), 'Valid'); $status[] = $form->createElement('radio', null, null, ts('Cancelled'), 'Cancelled'); $status[] = $form->createElement('radio', null, null, ts('All'), 'All'); $form->addGroup($status, 'contribution_status', ts('Contribution Status')); $form->setDefaults(array('contribution_status' => 'All')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt date not set?')); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, array('Contribution')); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } }
/** * @param $form */ public static function recurringContribution(&$form) { // Recurring contribution fields foreach (self::getRecurringFields() as $key => $label) { if ($key == 'contribution_recur_payment_made' && !empty($form->_formValues) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($key, $form->_formValues))) { $form->assign('contribution_recur_pane_open', TRUE); break; } CRM_Core_Form_Date::buildDateRange($form, $key, 1, '_low', '_high'); // If data has been entered for a recurring field, tell the tpl layer to open the pane if (!empty($form->_formValues) && !empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) { $form->assign('contribution_recur_pane_open', TRUE); break; } } // Add field to check if payment is made for recurring contribution $recurringPaymentOptions = array(1 => ts('All recurring contributions'), 2 => ts('Recurring contributions with at least one payment')); $form->addRadio('contribution_recur_payment_made', NULL, $recurringPaymentOptions, array('allowClear' => TRUE)); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_start_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_end_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_modified_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_next_sched_contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_failure_retry_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_cancel_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); $form->addElement('text', 'contribution_recur_processor_id', ts('Processor ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'processor_id')); $form->addElement('text', 'contribution_recur_trxn_id', ts('Transaction ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'trxn_id')); $contributionRecur = array('ContributionRecur'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contributionRecur); if ($groupDetails) { $form->assign('contributeRecurGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); } } } }
/** * add all the elements shared between contribute search and advnaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { require_once 'CRM/Utils/Money.php'; //added contribution source $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source')); $form->addDate('contribution_date_low', ts('Contribution Dates - From'), false, array('formatType' => 'searchDate')); $form->addDate('contribution_date_high', ts('To'), false, array('formatType' => 'searchDate')); $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money'); $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); require_once 'CRM/Contribute/PseudoConstant.php'; $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $form->add('select', 'contribution_page_id', ts('Contribution Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage()); $form->add('select', 'contribution_payment_instrument_id', ts('Payment Instrument'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument()); $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::pcPage()); $status = array(); require_once "CRM/Core/OptionGroup.php"; $statusValues = CRM_Core_OptionGroup::values("contribution_status"); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5']); unset($statusValues['6']); foreach ($statusValues as $key => $val) { $status[] = $form->createElement('advcheckbox', $key, null, $val); } $form->addGroup($status, 'contribution_status_id', ts('Contribution Status')); // add null checkboxes for thank you and receipt $form->addElement('checkbox', 'contribution_thankyou_date_isnull', ts('Thank-you date not set?')); $form->addElement('checkbox', 'contribution_receipt_date_isnull', ts('Receipt not sent?')); //add fields for honor search $form->addElement('text', 'contribution_in_honor_of', ts("In Honor Of")); $form->addElement('checkbox', 'contribution_test', ts('Find Test Contributions?')); $form->addElement('checkbox', 'contribution_pay_later', ts('Find Pay Later Contributions?')); //add field for transaction ID search $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID")); $form->addElement('checkbox', 'contribution_recurring', ts('Find Recurring Contributions?')); $form->addElement('text', 'contribution_check_number', ts('Check Number')); //add field for pcp display in roll search $form->addYesNo('contribution_pcp_display_in_roll', ts('Display In Roll ?')); // add all the custom searchable fields require_once 'CRM/Core/BAO/CustomGroup.php'; $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $contribution); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('contributeGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviContribute', true); }
/** * Function perform two task. * 1. Merge two duplicate contacts cases - follow CRM-5758 rules. * 2. Merge two cases of same contact - follow CRM-5598 rules. * * @param int $mainContactId contact id of main contact record. * @param int $mainCaseId case id of main case record. * @param int $otherContactId contact id of record which is going to merge. * @param int $otherCaseId case id of record which is going to merge. * * @param bool $changeClient * * @return integer|NULL * @static */ static function mergeCases($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) { $moveToTrash = TRUE; $duplicateContacts = FALSE; if ($mainContactId && $otherContactId && $mainContactId != $otherContactId) { $duplicateContacts = TRUE; } $duplicateCases = FALSE; if ($mainCaseId && $otherCaseId && $mainCaseId != $otherCaseId) { $duplicateCases = TRUE; } $mainCaseIds = array(); if (!$duplicateContacts && !$duplicateCases) { return $mainCaseIds; } $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); $activityStatuses = CRM_Core_PseudoConstant::activityStatus('name'); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $processCaseIds = array($otherCaseId); if ($duplicateContacts && !$duplicateCases) { if ($changeClient) { $processCaseIds = array($mainCaseId); } else { //get all case ids for other contact. $processCaseIds = self::retrieveCaseIdsByContactId($otherContactId, TRUE); } if (!is_array($processCaseIds)) { return; } } $session = CRM_Core_Session::singleton(); $currentUserId = $session->get('userID'); CRM_Utils_Hook::pre_case_merge($mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient); // copy all cases and connect to main contact id. foreach ($processCaseIds as $otherCaseId) { if ($duplicateContacts) { $mainCase = CRM_Core_DAO::copyGeneric('CRM_Case_DAO_Case', array('id' => $otherCaseId)); $mainCaseId = $mainCase->id; if (!$mainCaseId) { continue; } // CRM-11662 Copy Case custom data $extends = array('case'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $mainCaseId; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$otherCaseId}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } $mainCase->free(); $mainCaseIds[] = $mainCaseId; //insert record for case contact. $otherCaseContact = new CRM_Case_DAO_CaseContact(); $otherCaseContact->case_id = $otherCaseId; $otherCaseContact->find(); while ($otherCaseContact->fetch()) { $mainCaseContact = new CRM_Case_DAO_CaseContact(); $mainCaseContact->case_id = $mainCaseId; $mainCaseContact->contact_id = $otherCaseContact->contact_id; if ($mainCaseContact->contact_id == $otherContactId) { $mainCaseContact->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainCaseContact->find(TRUE)) { $mainCaseContact->save(); } $mainCaseContact->free(); } $otherCaseContact->free(); } elseif (!$otherContactId) { $otherContactId = $mainContactId; } if (!$mainCaseId || !$otherCaseId || !$mainContactId || !$otherContactId) { continue; } // get all activities for other case. $otherCaseActivities = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Case_DAO_CaseActivity', 'case_id', $otherCaseId, $otherCaseActivities); //for duplicate cases do not process singleton activities. $otherActivityIds = $singletonActivityIds = array(); foreach ($otherCaseActivities as $caseActivityId => $otherIds) { $otherActId = CRM_Utils_Array::value('activity_id', $otherIds); if (!$otherActId || in_array($otherActId, $otherActivityIds)) { continue; } $otherActivityIds[] = $otherActId; } if ($duplicateCases) { if ($openCaseType = array_search('Open Case', $activityTypes)) { $sql = "\nSELECT id\n FROM civicrm_activity\n WHERE activity_type_id = {$openCaseType}\n AND id IN ( " . implode(',', array_values($otherActivityIds)) . ');'; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $singletonActivityIds[] = $dao->id; } $dao->free(); } } // migrate all activities and connect to main contact. $copiedActivityIds = $activityMappingIds = array(); sort($otherActivityIds); foreach ($otherActivityIds as $otherActivityId) { //for duplicate cases - //do not migrate singleton activities. if (!$otherActivityId || in_array($otherActivityId, $singletonActivityIds)) { continue; } //migrate activity record. $otherActivity = new CRM_Activity_DAO_Activity(); $otherActivity->id = $otherActivityId; if (!$otherActivity->find(TRUE)) { continue; } $mainActVals = array(); $mainActivity = new CRM_Activity_DAO_Activity(); CRM_Core_DAO::storeValues($otherActivity, $mainActVals); $mainActivity->copyValues($mainActVals); $mainActivity->id = NULL; $mainActivity->activity_date_time = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time); $mainActivity->source_record_id = CRM_Utils_Array::value($mainActivity->source_record_id, $activityMappingIds); $mainActivity->original_id = CRM_Utils_Array::value($mainActivity->original_id, $activityMappingIds); $mainActivity->parent_id = CRM_Utils_Array::value($mainActivity->parent_id, $activityMappingIds); $mainActivity->save(); $mainActivityId = $mainActivity->id; if (!$mainActivityId) { continue; } $activityMappingIds[$otherActivityId] = $mainActivityId; // insert log of all activities CRM_Activity_BAO_Activity::logActivityAction($mainActivity); $otherActivity->free(); $mainActivity->free(); $copiedActivityIds[] = $otherActivityId; //create case activity record. $mainCaseActivity = new CRM_Case_DAO_CaseActivity(); $mainCaseActivity->case_id = $mainCaseId; $mainCaseActivity->activity_id = $mainActivityId; $mainCaseActivity->save(); $mainCaseActivity->free(); //migrate source activity. $otherSourceActivity = new CRM_Activity_DAO_ActivityContact(); $otherSourceActivity->activity_id = $otherActivityId; $otherSourceActivity->record_type_id = $sourceID; $otherSourceActivity->find(); while ($otherSourceActivity->fetch()) { $mainActivitySource = new CRM_Activity_DAO_ActivityContact(); $mainActivitySource->record_type_id = $sourceID; $mainActivitySource->activity_id = $mainActivityId; $mainActivitySource->contact_id = $otherSourceActivity->contact_id; if ($mainActivitySource->contact_id == $otherContactId) { $mainActivitySource->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainActivitySource->find(TRUE)) { $mainActivitySource->save(); } $mainActivitySource->free(); } $otherSourceActivity->free(); //migrate target activities. $otherTargetActivity = new CRM_Activity_DAO_ActivityContact(); $otherTargetActivity->activity_id = $otherActivityId; $otherTargetActivity->record_type_id = $targetID; $otherTargetActivity->find(); while ($otherTargetActivity->fetch()) { $mainActivityTarget = new CRM_Activity_DAO_ActivityContact(); $mainActivityTarget->record_type_id = $targetID; $mainActivityTarget->activity_id = $mainActivityId; $mainActivityTarget->contact_id = $otherTargetActivity->contact_id; if ($mainActivityTarget->contact_id == $otherContactId) { $mainActivityTarget->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainActivityTarget->find(TRUE)) { $mainActivityTarget->save(); } $mainActivityTarget->free(); } $otherTargetActivity->free(); //migrate assignee activities. $otherAssigneeActivity = new CRM_Activity_DAO_ActivityContact(); $otherAssigneeActivity->activity_id = $otherActivityId; $otherAssigneeActivity->record_type_id = $assigneeID; $otherAssigneeActivity->find(); while ($otherAssigneeActivity->fetch()) { $mainAssigneeActivity = new CRM_Activity_DAO_ActivityContact(); $mainAssigneeActivity->activity_id = $mainActivityId; $mainAssigneeActivity->record_type_id = $assigneeID; $mainAssigneeActivity->contact_id = $otherAssigneeActivity->contact_id; if ($mainAssigneeActivity->contact_id == $otherContactId) { $mainAssigneeActivity->contact_id = $mainContactId; } //avoid duplicate object. if (!$mainAssigneeActivity->find(TRUE)) { $mainAssigneeActivity->save(); } $mainAssigneeActivity->free(); } $otherAssigneeActivity->free(); // copy custom fields and attachments $aparams = array('activityID' => $otherActivityId, 'mainActivityId' => $mainActivityId); CRM_Activity_BAO_Activity::copyExtendedActivityData($aparams); } //copy case relationship. if ($duplicateContacts) { //migrate relationship records. $otherRelationship = new CRM_Contact_DAO_Relationship(); $otherRelationship->case_id = $otherCaseId; $otherRelationship->find(); $otherRelationshipIds = array(); while ($otherRelationship->fetch()) { $otherRelVals = array(); $updateOtherRel = FALSE; CRM_Core_DAO::storeValues($otherRelationship, $otherRelVals); $mainRelationship = new CRM_Contact_DAO_Relationship(); $mainRelationship->copyValues($otherRelVals); $mainRelationship->id = NULL; $mainRelationship->case_id = $mainCaseId; if ($mainRelationship->contact_id_a == $otherContactId) { $updateOtherRel = TRUE; $mainRelationship->contact_id_a = $mainContactId; } //case creator change only when we merge user contact. if ($mainRelationship->contact_id_b == $otherContactId) { //do not change creator for change client. if (!$changeClient) { $updateOtherRel = TRUE; $mainRelationship->contact_id_b = $currentUserId ? $currentUserId : $mainContactId; } } $mainRelationship->end_date = CRM_Utils_Date::isoToMysql($otherRelationship->end_date); $mainRelationship->start_date = CRM_Utils_Date::isoToMysql($otherRelationship->start_date); //avoid duplicate object. if (!$mainRelationship->find(TRUE)) { $mainRelationship->save(); } $mainRelationship->free(); //get the other relationship ids to update end date. if ($updateOtherRel) { $otherRelationshipIds[$otherRelationship->id] = $otherRelationship->id; } } $otherRelationship->free(); //update other relationships end dates if (!empty($otherRelationshipIds)) { $sql = 'UPDATE civicrm_relationship SET end_date = CURDATE() WHERE id IN ( ' . implode(',', $otherRelationshipIds) . ')'; CRM_Core_DAO::executeQuery($sql); } } //move other case to trash. $mergeCase = self::deleteCase($otherCaseId, $moveToTrash); if (!$mergeCase) { continue; } $mergeActSubject = $mergeActSubjectDetails = $mergeActType = ''; if ($changeClient) { $mainContactDisplayName = CRM_Contact_BAO_Contact::displayName($mainContactId); $otherContactDisplayName = CRM_Contact_BAO_Contact::displayName($otherContactId); $mergeActType = array_search('Reassigned Case', $activityTypes); $mergeActSubject = ts("Case %1 reassigned client from %2 to %3. New Case ID is %4.", array(1 => $otherCaseId, 2 => $otherContactDisplayName, 3 => $mainContactDisplayName, 4 => $mainCaseId)); } elseif ($duplicateContacts) { $mergeActType = array_search('Merge Case', $activityTypes); $mergeActSubject = ts("Case %1 copied from contact id %2 to contact id %3 via merge. New Case ID is %4.", array(1 => $otherCaseId, 2 => $otherContactId, 3 => $mainContactId, 4 => $mainCaseId)); } else { $mergeActType = array_search('Merge Case', $activityTypes); $mergeActSubject = ts("Case %1 merged into case %2", array(1 => $otherCaseId, 2 => $mainCaseId)); if (!empty($copiedActivityIds)) { $sql = ' SELECT id, subject, activity_date_time, activity_type_id FROM civicrm_activity WHERE id IN (' . implode(',', $copiedActivityIds) . ')'; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $mergeActSubjectDetails .= "{$dao->activity_date_time} :: {$activityTypes[$dao->activity_type_id]}"; if ($dao->subject) { $mergeActSubjectDetails .= " :: {$dao->subject}"; } $mergeActSubjectDetails .= "<br />"; } } } //create merge activity record. $activityParams = array('subject' => $mergeActSubject, 'details' => $mergeActSubjectDetails, 'status_id' => array_search('Completed', $activityStatuses), 'activity_type_id' => $mergeActType, 'source_contact_id' => $mainContactId, 'activity_date_time' => date('YmdHis')); $mergeActivity = CRM_Activity_BAO_Activity::create($activityParams); $mergeActivityId = $mergeActivity->id; if (!$mergeActivityId) { continue; } $mergeActivity->free(); //connect merge activity to case. $mergeCaseAct = array('case_id' => $mainCaseId, 'activity_id' => $mergeActivityId); self::processCaseActivity($mergeCaseAct); } CRM_Utils_Hook::post_case_merge($mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient); return $mainCaseIds; }
static function buildSearchForm(&$form) { require_once 'CRM/Member/PseudoConstant.php'; foreach (CRM_Member_PseudoConstant::membershipType() as $id => $Name) { $form->_membershipType =& $form->addElement('checkbox', "member_membership_type_id[{$id}]", null, $Name); } // Option to include / exclude inherited memberships from search results (e.g. rows where owner_membership_id is NOT NULL) $primaryValues = array(1 => ts('All Members'), 2 => ts('Primary Members Only'), 3 => ts('Related Members Only')); $form->addRadio('member_is_primary', '', $primaryValues); $form->setDefaults(array('member_is_primary' => 1)); foreach (CRM_Member_PseudoConstant::membershipStatus() as $sId => $sName) { $form->_membershipStatus =& $form->addElement('checkbox', "member_status_id[{$sId}]", null, $sName); } $form->addElement('text', 'member_source', ts('Source')); $form->addDate('member_join_date_low', ts('Join Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_join_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('member_start_date_low', ts('Start Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_start_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addDate('member_end_date_low', ts('End Date - From'), false, array('formatType' => 'relative')); $form->addDate('member_end_date_high', ts('To'), false, array('formatType' => 'relative')); $form->addElement('checkbox', 'member_test', ts('Find Test Memberships?')); $form->addElement('checkbox', 'member_pay_later', ts('Find Pay Later Memberships?')); // add all the custom searchable fields require_once 'CRM/Custom/Form/CustomData.php'; $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(null, true, $extends); if ($groupDetails) { require_once 'CRM/Core/BAO/CustomField.php'; $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, false, false, true); } } } $form->assign('validCiviMember', true); }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE); $form->assign('dataURLEventFee', $dataURLEventFee); $form->addEntityRef('event_id', ts('Event Name'), array('entity' => 'event', 'placeholder' => ts('- any -'), 'multiple' => 1, 'select' => array('minimumInputLength' => 0))); $form->addEntityRef('event_type_id', ts('Event Type'), array('entity' => 'option_value', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0), 'api' => array('params' => array('option_group_id' => 'event_type')))); $obj = new CRM_Report_Form_Event_ParticipantListing(); $form->add('select', 'participant_fee_id', ts('Fee Level'), $obj->getPriceLevels(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE); $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>'))); $form->addSelect('participant_status_id', array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addSelect('participant_role_id', array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money'); $form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money'); // add all the custom searchable fields $extends = array('Participant', 'Event'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('participantGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id'); $form->assign('validCiviEvent', TRUE); $form->setDefaults(array('participant_test' => 0)); }
/** * @param $form */ static function buildSearchForm(&$form) { foreach (CRM_Member_PseudoConstant::membershipType() as $id => $Name) { $form->_membershipType =& $form->addElement('checkbox', "member_membership_type_id[{$id}]", NULL, $Name); } foreach (CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label') as $sId => $sName) { $form->_membershipStatus =& $form->addElement('checkbox', "member_status_id[{$sId}]", NULL, $sName); } $form->addElement('text', 'member_source', ts('Source')); CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE); $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE); $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE); $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE); // add all the custom searchable fields $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id'); $form->assign('validCiviMember', TRUE); $form->setDefaults(array('member_test' => 0)); }