/** * Create a new batch * * @return batch array * @access public */ static function create(&$params) { if (!CRM_Utils_Array::value('id', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } $batch = new CRM_Core_DAO_Batch(); $batch->copyValues($params); $batch->save(); return $batch; }
/** * Create a new batch. * * @param array $params * @param array $ids * Associated array of ids. * @param string $context * String. * * @return object * $batch batch object */ public static function create(&$params, $ids = NULL, $context = NULL) { if (empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } $batch = new CRM_Batch_DAO_Batch(); $batch->copyValues($params); if ($context == 'financialBatch' && !empty($ids['batchID'])) { $batch->id = $ids['batchID']; } $batch->save(); return $batch; }
/** * Takes an associative array and creates a campaign object. * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Campaign_DAO_Campaign */ public static function create(&$params) { if (empty($params)) { return NULL; } if (!CRM_Utils_Array::value('id', $params)) { if (!CRM_Utils_Array::value('created_id', $params)) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } if (!CRM_Utils_Array::value('created_date', $params)) { $params['created_date'] = date('YmdHis'); } if (!CRM_Utils_Array::value('name', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64); } CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params); } else { CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params); } $campaign = new CRM_Campaign_DAO_Campaign(); $campaign->copyValues($params); $campaign->save(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign); } else { CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign); } /* Create the campaign group record */ $groupTableName = CRM_Contact_BAO_Group::getTableName(); if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) { foreach ($params['groups']['include'] as $entityId) { $dao = new CRM_Campaign_DAO_CampaignGroup(); $dao->campaign_id = $campaign->id; $dao->entity_table = $groupTableName; $dao->entity_id = $entityId; $dao->group_type = 'Include'; $dao->save(); $dao->free(); } } //store custom data if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id); } return $campaign; }
/** * Takes an associative array and creates a Case Type object. * * the function extract all the params it needs to initialize the create a * case type object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @throws CRM_Core_Exception * * @return CRM_Case_BAO_CaseType */ public static function add(&$params) { $caseTypeDAO = new CRM_Case_DAO_CaseType(); // form the name only if missing: CRM-627 $nameParam = CRM_Utils_Array::value('name', $params, NULL); if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // Old case-types (pre-4.5) may keep their ucky names, but new case-types must satisfy isValidName() if (empty($params['id']) && !empty($params['name']) && !CRM_Case_BAO_CaseType::isValidName($params['name'])) { throw new CRM_Core_Exception("Cannot create new case-type with malformed name [{$params['name']}]"); } $caseTypeName = isset($params['name']) ? $params['name'] : CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $params['id'], 'name', 'id', TRUE); // function to format definition column if (isset($params['definition']) && is_array($params['definition'])) { $params['definition'] = self::convertDefinitionToXML($caseTypeName, $params['definition']); CRM_Core_ManagedEntities::scheduleReconciliation(); } $caseTypeDAO->copyValues($params); return $caseTypeDAO->save(); }
/** * helper function to record participant with paid contribution. * @param $feeTotal * @param $actualPaidAmt * * @return array * @throws Exception */ public function _addParticipantWithPayment($feeTotal, $actualPaidAmt) { // creating price set, price field $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); $paramsSet['is_active'] = FALSE; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceset->id); $priceSetId = $priceset->id; //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => $feeTotal, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => $feeTotal), 'option_name' => array('1' => $feeTotal), 'option_weight' => array('1' => 1), 'option_amount' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1); $ids = array(); $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield'); // create participant record $eventId = $this->_eventId; $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 14, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55'); $participant = $this->callAPISuccess('participant', 'create', $participantParams); $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); // create participant contribution with partial payment $contributionParams = array('total_amount' => $actualPaidAmt, 'source' => 'Fall Fundraiser Dinner: Offline registration', 'currency' => 'USD', 'non_deductible_amount' => 'null', 'receipt_date' => date('Y-m-d') . " 00:00:00", 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Y-m-d') . " 00:00:00", 'skipLineItem' => 1, 'partial_payment_total' => $feeTotal, 'partial_amount_pay' => $actualPaidAmt); $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams); $contributionId = $contribution->id; $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); // add participant payment entry $this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contributionId)); // -- processing priceSet using the BAO $lineItem = array(); $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE); $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); $feeBlock = CRM_Utils_Array::value('fields', $priceSet); $params['price_2'] = $feeTotal; CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItem); $lineItemVal[$priceSetId] = $lineItem; CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant'); return array($participant, $contribution); }
/** * takes an associative array and creates a campaign object * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Campaign_DAO_Campaign object * @access public * @static */ static function create(&$params) { if (empty($params)) { return; } if (!CRM_Utils_Array::value('id', $params)) { if (!CRM_Utils_Array::value('created_id', $params)) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } if (!CRM_Utils_Array::value('created_date', $params)) { $params['created_date'] = date('YmdHis'); } if (!CRM_Utils_Array::value('name', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title'], 64); } } $campaign = new CRM_Campaign_DAO_Campaign(); $campaign->copyValues($params); $campaign->save(); /* Create the campaign group record */ $groupTableName = CRM_Contact_BAO_Group::getTableName(); require_once 'CRM/Campaign/DAO/CampaignGroup.php'; $dao = new CRM_Campaign_DAO_CampaignGroup(); if (CRM_Utils_Array::value('include', $params['groups']) && is_array($params['groups']['include'])) { foreach ($params['groups']['include'] as $entityId) { $dao->reset(); $dao->campaign_id = $campaign->id; $dao->entity_table = $groupTableName; $dao->entity_id = $entityId; $dao->group_type = 'include'; $dao->save(); } } return $campaign; }
/** * Add participant with contribution * * @return array */ protected function addParticipantWithContribution() { // creating price set, price field require_once 'CiviTest/Event.php'; $this->_contactId = Contact::createIndividual(); $this->_eventId = Event::create($this->_contactId); $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4); $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); $paramsSet['is_active'] = TRUE; $paramsSet['financial_type_id'] = 4; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); $priceSetId = $priceset->id; //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name')); $priceField = CRM_Price_BAO_PriceField::create($paramsField); $eventParams = array('id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1); CRM_Event_BAO_Event::create($eventParams); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId); $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); $participantParams = array('financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', 'contact_id' => $this->_contactId); $participant = CRM_Event_BAO_Participant::add($participantParams); $contributionParams = array('total_amount' => 150, 'currency' => 'USD', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'contribution_status_id' => 1, 'partial_payment_total' => 300.0, 'partial_amount_pay' => 150, 'contribution_mode' => 'participant', 'participant_id' => $participant->id); foreach ($priceFields['values'] as $key => $priceField) { $lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']); } $contributionParams['line_item'] = $lineItems; $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams); $paymentParticipant = array('participant_id' => $participant->id, 'contribution_id' => $contributions->id); $ids = array(); CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids); return array($lineItems, $contributions); }
/** * Create a new group. * * @param array $params * * @return CRM_Contact_BAO_Group|NULL * The new group BAO (if created) */ public static function &create(&$params) { if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', NULL, $params); } // form the name only if missing: CRM-627 $nameParam = CRM_Utils_Array::value('name', $params, NULL); if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $session = CRM_Core_Session::singleton(); $cid = $session->get('userID'); // this action is add if ($cid && empty($params['id'])) { $params['created_id'] = $cid; } // this action is update if ($cid && !empty($params['id'])) { $params['modified_id'] = $cid; } $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn // use metadata to translate the array to the appropriate DB type or altering the param in the api layer, // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down // we need the $params one to be in it's original form & we are not sure what test coverage we have on that if (isset($group->parents) && is_array($group->parents)) { $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR; } if (empty($params['id']) && !$nameParam) { $group->name .= "_tmp"; } $group->save(); if (!$group->id) { return NULL; } if (empty($params['id']) && !$nameParam) { $group->name = substr($group->name, 0, -4) . "_{$group->id}"; } $group->buildClause(); $group->save(); // add custom field values if (!empty($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } } // clear any descendant groups cache if exists $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (!empty($params['organization_id'])) { $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } $recentOther = array(); if (CRM_Core_Permission::check('edit groups')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id); // currently same permission we are using for delete a group $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id); } // add the recently added group (unless hidden: CRM-6432) if (!$group->is_hidden) { CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther); } return $group; }
/** * Process the form. */ public function postProcess() { // store the submitted values in an array $status = ''; $params = $this->controller->exportValues($this->_name); $params['id'] = $this->_surveyId; $updateResultSet = FALSE; $resultSetOptGrpId = NULL; if (CRM_Utils_Array::value('option_type', $params) == 2 && !empty($params['option_group_id'])) { $updateResultSet = TRUE; $resultSetOptGrpId = $params['option_group_id']; } $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $resultSetOptGrpId; $optionValue->delete(); $params['result_id'] = $resultSetOptGrpId; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->title = $this->_values['title'] . ' Result Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (!empty($params['default_option']) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); // using is_numeric since 0 is a valid value for option_interval if (is_numeric($params['option_interval'][$k])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $survey = CRM_Campaign_BAO_Survey::create($params); // create report if required. if (!$this->_reportId && $survey->id && !empty($params['create_report'])) { $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $activityStatus = array_flip($activityStatus); $this->_params = array('name' => "survey_{$survey->id}", 'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'], 'status_id_op' => 'eq', 'status_id_value' => $activityStatus['Scheduled'], 'survey_id_value' => array($survey->id), 'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.')); //Default value of order by $this->_params['order_bys'] = array(1 => array('column' => 'sort_name', 'order' => 'ASC')); // for WalkList or default $displayFields = array('id', 'sort_name', 'result', 'street_number', 'street_name', 'street_unit', 'survey_response'); if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_values['activity_type_id']) { $this->_params['order_bys'] = array(1 => array('column' => 'street_name', 'order' => 'ASC'), 2 => array('column' => 'street_number_odd_even', 'order' => 'ASC'), 3 => array('column' => 'street_number', 'order' => 'ASC'), 4 => array('column' => 'sort_name', 'order' => 'ASC')); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') == $this->_values['activity_type_id']) { array_push($displayFields, 'phone'); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'Survey') == $this->_values['activity_type_id'] || CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') == $this->_values['activity_type_id']) { array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email'); } foreach ($displayFields as $key) { $this->_params['fields'][$key] = 1; } $this->_createNew = TRUE; $this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail'); CRM_Report_Form_Instance::postProcess($this, FALSE); $query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1"; $reportID = CRM_Core_DAO::singleValueQuery($query, array(1 => array("survey_{$survey->id}", 'String'))); if ($reportID) { $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1'); $status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.", array(1 => $url, 2 => $this->_params['title'])); } } if ($status) { // reset status as we don't want status set by Instance::postProcess $session = CRM_Core_Session::singleton(); $session->getStatus(TRUE); // set new status CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); } parent::endPostProcess(); }
/** * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method */ public function testfixEventLevel() { $paramsSet['title'] = 'Price Set'; $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); $paramsSet['is_active'] = FALSE; $paramsSet['extends'] = 1; $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'option_name' => array('1' => 10), 'option_weight' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1); $ids = array(); $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield'); $eventId = $this->_eventId; $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55'); $participant = CRM_Event_BAO_Participant::add($participantParams); //Checking for participant added in the table. $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant'); $values = array(); $ids = array(); $params = array('id' => $participant->id); CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNotEquals(count($values), 0, 'Checking for empty array.'); CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]); if ($values[$participant->id]['fee_level']) { CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']); } $deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id); $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.'); $deletePriceset = CRM_Price_BAO_PriceSet::deleteSet($priceset->id); $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.'); Participant::delete($participant->id); Contact::delete($this->_contactId); Event::delete($eventId); }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @param $files * @param $self * * @return array list of errors to be posted back to the form * @static * @access public */ static function formRule($fields, $files, $self) { $errors = array(); $invalidTagName = $invalidGroupName = FALSE; if (!empty($fields['newTagName'])) { if (!CRM_Utils_Rule::objectExists(trim($fields['newTagName']), array('CRM_Core_DAO_Tag'))) { $errors['newTagName'] = ts('Tag \'%1\' already exists.', array(1 => $fields['newTagName'])); $invalidTagName = TRUE; } } if (!empty($fields['newGroupName'])) { $title = trim($fields['newGroupName']); $name = CRM_Utils_String::titleToVar($title); $query = 'select count(*) from civicrm_group where name like %1 OR title like %2'; $grpCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), 2 => array($title, 'String'))); if ($grpCnt) { $invalidGroupName = TRUE; $errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName'])); } } $self->assign('invalidTagName', $invalidTagName); $self->assign('invalidGroupName', $invalidGroupName); return empty($errors) ? TRUE : $errors; }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues('Option'); // set values for custom field properties and save require_once 'CRM/Core/DAO/OptionValue.php'; require_once 'CRM/Utils/String.php'; $customOption =& new CRM_Core_DAO_OptionValue(); $customOption->label = $params['label']; $customOption->name = CRM_Utils_String::titleToVar($params['label']); $customOption->weight = $params['weight']; $customOption->value = $params['value']; $customOption->is_active = CRM_Utils_Array::value('is_active', $params, false); if ($this->_action == CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_optionGroupID); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); CRM_Core_BAO_CustomOption::del($this->_id); CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted', array(1 => $customOption->label))); return; } if ($this->_action & CRM_Core_Action::UPDATE) { $customOption->id = $this->_id; CRM_Core_BAO_CustomOption::updateCustomValues($params); } if ($this->_id) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id'); } $fieldValues = array('option_group_id' => $this->_optionGroupID); $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues); $customOption->option_group_id = $this->_optionGroupID; $customField =& new CRM_Core_DAO_CustomField(); $customField->id = $this->_fid; if ($customField->find(true) && ($customField->html_type == 'CheckBox' || $customField->html_type == 'AdvMulti-Select' || $customField->html_type == 'Multi-Select')) { $defVal = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($customField->default_value, 1, -1)); if (CRM_Utils_Array::value('default_value', $params)) { if (!in_array($customOption->value, $defVal)) { if (empty($defVal[0])) { $defVal = array($customOption->value); } else { $defVal[] = $customOption->value; } $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $customField->save(); } } else { if (in_array($customOption->value, $defVal)) { $tempVal = array(); foreach ($defVal as $v) { if ($v != $customOption->value) { $tempVal[] = $v; } } $customField->default_value = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $tempVal) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; $customField->save(); } } } else { switch ($customField->data_type) { case 'Money': require_once 'CRM/Utils/Rule.php'; $customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value); break; case 'Int': $customOption->value = intval($customOption->value); break; case 'Float': $customOption->value = floatval($customOption->value); break; } if (CRM_Utils_Array::value('default_value', $params)) { $customField->default_value = $customOption->value; $customField->save(); } else { if ($customField->find(true) && $customField->default_value == $customOption->value) { // this is the case where this option is the current default value and we have been reset $customField->default_value = 'null'; $customField->save(); } } } $customOption->save(); CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label))); $buttonName = $this->controller->getButtonName(); $session =& CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another option.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option', 'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid)); } }
/** * Create a new group * * @param array $params Associative array of parameters * @return object|null The new group BAO (if created) * @access public * @static */ public static function &create(&$params) { require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', null, $params); } // form the name only if missing: CRM-627 if (!CRM_Utils_Array::value('name', $params)) { require_once 'CRM/Utils/String.php'; $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $group =& new CRM_Contact_BAO_Group(); $group->copyValues($params); $group->save(); if (!$group->id) { return null; } $group->buildClause(); $group->save(); // add custom field values if (CRM_Utils_Array::value('custom', $params)) { require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. require_once 'CRM/Contact/BAO/GroupContactCache.php'; require_once 'CRM/Core/BAO/Domain.php'; require_once 'CRM/Contact/BAO/GroupNesting.php'; $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && empty($params['parents']) && $domainGroupID != $group->id && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } else { if (!is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } } foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } // clear any descendant groups cache if exists require_once 'CRM/Core/BAO/Cache.php'; $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed require_once 'CRM/Contact/BAO/GroupNestingCache.php'; CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (CRM_Utils_Array::value('organization_id', $params)) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } return $group; }
/** * takes an associative array and creates a custom group object * * This function is invoked from within the web form layer and also from the api layer * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Core_DAO_CustomGroup object * @access public * @static */ static function create(&$params) { // create custom group dao, populate fields and then save. $group = new CRM_Core_DAO_CustomGroup(); $group->title = $params['title']; require_once 'CRM/Utils/String.php'; if (isset($params['name'])) { $group->name = $params['name']; } else { $maxLength = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'name'); $group->name = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $maxLength)); } if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) { $group->extends = 'Participant'; } else { $group->extends = $params['extends'][0]; } $group->extends_entity_column_id = null; if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') { $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name'); } //this is format when form get submit. $extendsChildType = CRM_Utils_Array::value(1, $params['extends']); //lets allow user to pass direct child type value, CRM-6893 if (CRM_Utils_Array::value('extends_entity_column_value', $params)) { $extendsChildType = $params['extends_entity_column_value']; } if (!CRM_Utils_System::isNull($extendsChildType)) { $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType); if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') { $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType); } if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) { $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $extendsChildType = 'null'; } $group->extends_entity_column_value = $extendsChildType; if (isset($params['id'])) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id'); } else { $oldWeight = 0; } require_once 'CRM/Utils/Weight.php'; $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, false)); $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple'); foreach ($fields as $field) { $group->{$field} = CRM_Utils_Array::value($field, $params, false); } $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null'; $tableName = null; if (isset($params['id'])) { $group->id = $params['id']; //check whether custom group was changed from single-valued to multiple-valued $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple'); if ($params['is_multiple'] != $isMultiple && (CRM_Utils_Array::value('is_multiple', $params) || $isMultiple)) { $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name'); } } else { $group->created_id = CRM_Utils_Array::value('created_id', $params); $group->created_date = CRM_Utils_Array::value('created_date', $params); require_once 'CRM/Utils/String.php'; // lets create the table associated with the group and save it $tableName = $group->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group->title, '_', 32)); // we do this only once, so name never changes $group->name = CRM_Utils_String::munge($params['title'], '_', 64); } // enclose the below in a transaction require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $group->save(); if ($tableName) { // now append group id to table name, this prevent any name conflicts // like CRM-2742 $tableName .= "_{$group->id}"; $group->table_name = $tableName; CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName); // now create the table associated with this group self::createTable($group); } elseif ($oldTableName) { require_once 'CRM/Core/BAO/SchemaHandler.php'; CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params)); } if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) { $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name'); require_once 'CRM/Core/BAO/SchemaHandler.php'; CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0])); } $transaction->commit(); // reset the cache require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); require_once 'CRM/Utils/Hook.php'; if ($tableName) { CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group); } else { CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group); } return $group; }
/** * Process the form submission. * * * @return void */ public function postProcess() { $values = $this->exportValues(); //FIXME: Handle logic to replace is_default column by usage // reset used column to General (since there can only // be one 'Supervised' or 'Unsupervised' rule) if ($values['used'] != 'General') { $query = "\nUPDATE civicrm_dedupe_rule_group\n SET used = 'General'\n WHERE contact_type = %1\n AND used = %2"; $queryParams = array(1 => array($this->_contactType, 'String'), 2 => array($values['used'], 'String')); CRM_Core_DAO::executeQuery($query, $queryParams); } $rgDao = new CRM_Dedupe_DAO_RuleGroup(); if ($this->_action & CRM_Core_Action::UPDATE) { $rgDao->id = $this->_rgid; } $rgDao->title = $values['title']; $rgDao->is_reserved = CRM_Utils_Array::value('is_reserved', $values, FALSE); $rgDao->used = $values['used']; $rgDao->contact_type = $this->_contactType; $rgDao->threshold = $values['threshold']; $rgDao->save(); // make sure name is set only during insert if ($this->_action & CRM_Core_Action::ADD) { // generate name based on title $rgDao->name = CRM_Utils_String::titleToVar($values['title']) . "_{$rgDao->id}"; $rgDao->save(); } // lets skip updating of fields for reserved dedupe group if ($rgDao->is_reserved) { CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success'); return; } $ruleDao = new CRM_Dedupe_DAO_Rule(); $ruleDao->dedupe_rule_group_id = $rgDao->id; $ruleDao->delete(); $ruleDao->free(); $substrLenghts = array(); $tables = array(); $daoObj = new CRM_Core_DAO(); $database = $daoObj->database(); for ($count = 0; $count < self::RULES_COUNT; $count++) { if (empty($values["where_{$count}"])) { continue; } list($table, $field) = explode('.', CRM_Utils_Array::value("where_{$count}", $values)); $length = !empty($values["length_{$count}"]) ? CRM_Utils_Array::value("length_{$count}", $values) : NULL; $weight = $values["weight_{$count}"]; if ($table and $field) { $ruleDao = new CRM_Dedupe_DAO_Rule(); $ruleDao->dedupe_rule_group_id = $rgDao->id; $ruleDao->rule_table = $table; $ruleDao->rule_field = $field; $ruleDao->rule_length = $length; $ruleDao->rule_weight = $weight; $ruleDao->save(); $ruleDao->free(); if (!array_key_exists($table, $tables)) { $tables[$table] = array(); } $tables[$table][] = $field; } // CRM-6245: we must pass table/field/length triples to the createIndexes() call below if ($length) { if (!isset($substrLenghts[$table])) { $substrLenghts[$table] = array(); } //CRM-13417 to avoid fatal error "Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys, 1089" $schemaQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_SCHEMA = '{$database}' AND\n TABLE_NAME = '{$table}' AND COLUMN_NAME = '{$field}';"; $dao = CRM_Core_DAO::executeQuery($schemaQuery); if ($dao->fetch()) { // set the length to null for all the fields where prefix length is not supported. eg. int,tinyint,date,enum etc dataTypes. if ($dao->COLUMN_NAME == $field && !in_array($dao->DATA_TYPE, array('char', 'varchar', 'binary', 'varbinary', 'text', 'blob'))) { $length = NULL; } elseif ($dao->COLUMN_NAME == $field && !empty($dao->CHARACTER_MAXIMUM_LENGTH) && $length > $dao->CHARACTER_MAXIMUM_LENGTH) { //set the length to CHARACTER_MAXIMUM_LENGTH in case the length provided by the user is greater than the limit $length = $dao->CHARACTER_MAXIMUM_LENGTH; } } $substrLenghts[$table][$field] = $length; } } // also create an index for this dedupe rule // CRM-3837 CRM_Utils_Hook::dupeQuery($ruleDao, 'dedupeIndexes', $tables); CRM_Core_BAO_SchemaHandler::createIndexes($tables, 'dedupe_index', $substrLenghts); //need to clear cache of deduped contacts //based on the previous rule $cacheKey = "merge {$this->_contactType}_{$this->_rgid}_%"; CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey); CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success'); }
/** * Create price set * * @param string $component * @param int $componentId * * @return array */ protected function createPriceSet($component = 'contribution_page', $componentId = NULL) { $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 7); $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']); $paramsSet['is_active'] = TRUE; $paramsSet['financial_type_id'] = 4; $paramsSet['extends'] = 1; $priceSet = $this->callAPISuccess('price_set', 'create', $paramsSet); $priceSetId = $priceSet['id']; //Checking for priceset added in the table. $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset'); $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceSet['id'], 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee')); $priceField = CRM_Price_BAO_PriceField::create($paramsField); if ($componentId) { CRM_Price_BAO_PriceSet::addTo('civicrm_' . $component, $componentId, $priceSetId); } return $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id)); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues('Field'); $params['name'] = CRM_Utils_String::titleToVar($params['label']); $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, false); $params['is_required'] = CRM_Utils_Array::value('is_required', $params, false); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $params['active_on'] = CRM_Utils_Date::format(CRM_Utils_Array::value('active_on', $params)); $params['expire_on'] = CRM_Utils_Date::format(CRM_Utils_Array::value('expire_on', $params)); // need the FKEY - price set id $params['price_set_id'] = $this->_sid; require_once 'CRM/Utils/Weight.php'; if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $fieldValues = array('price_set_id' => $this->_sid); $oldWeight = null; if ($this->_fid) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'weight', 'id'); } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', $oldWeight, $params['weight'], $fieldValues); } // make value <=> name consistency. if (isset($params['option_name'])) { $params['option_value'] = $params['option_name']; } $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, false); if ($params['html_type'] == 'Text') { // if html type is Text, force is_enter_qty on $params['is_enter_qty'] = 1; // modify params values as per the option group and option // value $params['option_value'] = array(1 => $params['price']); $params['option_name'] = array(1 => $params['price']); $params['option_label'] = array(1 => $params['label']); $params['option_weight'] = array(1 => $params['weight']); $params['is_active'] = array(1 => 1); } $ids = array(); if ($this->_fid) { $ids['id'] = $this->_fid; } $priceField = CRM_Price_BAO_Field::create($params, $ids); if (!is_a($priceField, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label))); } $buttonName = $this->controller->getButtonName(); $session =& CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another price set field.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid)); } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Core/BAO/OptionGroup.php'; $updateResultSet = false; if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) { if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) { $updateResultSet = true; } } if ($this->_surveyId) { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Campaign_BAO_Survey::del($this->_surveyId); CRM_Core_Session::setStatus(ts(' Survey has been deleted.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); return; } $params['id'] = $this->_surveyId; } else { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $this->_values['result_id']; $optionValue->delete(); $params['result_id'] = $this->_values['result_id']; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->label = $params['title'] . ' Response Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); if (CRM_Utils_Array::value($k, $params['option_interval'])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $surveyId = CRM_Campaign_BAO_Survey::create($params); if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) { $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1"; $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer'))); // delete option group if no any survey is using it. if (!($countSurvey >= 1)) { CRM_Core_BAO_OptionGroup::del($this->_values['result_id']); } } require_once 'CRM/Core/BAO/UFJoin.php'; // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id); // first delete all past entries if ($this->_surveyId) { CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); } if (CRM_Utils_Array::value('profile_id', $params)) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['profile_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } if (!is_a($surveyId, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title']))); } if ($this->_context == 'dialog') { $returnArray = array('returnSuccess' => true); echo json_encode($returnArray); CRM_Utils_System::civiExit(); } $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another Survey.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); } }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues(); $batchParams = array(); $batchParams['label'] = $params['title']; $batchParams['name'] = CRM_Utils_String::titleToVar($params['title'], 63); $batchParams['description'] = $params['description']; $batchParams['batch_type'] = "Gift Aid"; $session =& CRM_Core_Session::singleton(); $batchParams['created_id'] = $session->get('userID'); $batchParams['created_date'] = date("YmdHis"); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Core/BAO/Batch.php'; $createdBatch =& CRM_Core_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; $batchLabel = $batchParams['label']; if ($_POST['contributionRejections']) { $rejectionsCount = @count($_POST['contributionRejections']); $contribution_rejections = @implode(',', $_POST['contributionRejections']); if (!empty($contribution_rejections)) { $sql = "UPDATE civicrm_entity_batch SET batch_id = {$batchID} WHERE entity_id IN ({$contribution_rejections})"; $dao = CRM_Core_DAO::executeQuery($sql); } } $this->_contributionIds = $this->getContributionsList(); require_once 'DirectDebit/Utils/Contribution.php'; list($total, $added, $notAdded) = DirectDebit_Utils_Contribution::addContributionToBatch($this->_contributionIds, $batchID); if ($added <= 0) { // rollback since there were no contributions added, and we might not want to keep an empty batch $transaction->rollback(); $status = ts('Could not create batch "%1", as there were no valid contribution(s) to be added.', array(1 => $batchLabel)); } else { $status = array(ts('Added Contribution(s) to %1', array(1 => $batchLabel)), ts('Total Selected Contribution(s): %1', array(1 => $total))); if ($added) { $status[] = ts('Total Contribution(s) added to batch: %1', array(1 => $added)); } if ($notAdded) { $status[] = ts('Total Contribution(s) already in batch or not valid: %1', array(1 => $notAdded)); } if ($rejectionsCount) { $status[] = ts('Total rejected Contribution(s) moved to batch: %1', array(1 => $rejectionsCount)); } $status = implode('<br/>', $status); } $transaction->commit(); CRM_Core_Session::setStatus($status); $url_array = @explode('&', CIVICRM_DIRECT_DEBIT_BATCH_REPORT_URL); drupal_goto($url_array[0], $url_array[1]); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues('Field'); $params['name'] = CRM_Utils_String::titleToVar($params['label']); $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE); $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, false); if (isset($params['active_on'])) { $params['active_on'] = CRM_Utils_Date::processDate($params['active_on'], CRM_Utils_Array::value('active_on_time', $params), TRUE); } if (isset($params['expire_on'])) { $params['expire_on'] = CRM_Utils_Date::processDate($params['expire_on'], CRM_Utils_Array::value('expire_on_time', $params), TRUE); } $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE); $params['count'] = CRM_Utils_Array::value('count', $params, FALSE); // need the FKEY - price set id $params['price_set_id'] = $this->_sid; if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $fieldValues = array('price_set_id' => $this->_sid); $oldWeight = NULL; if ($this->_fid) { $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id'); } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', $oldWeight, $params['weight'], $fieldValues); } // make value <=> name consistency. if (isset($params['option_name'])) { $params['option_value'] = $params['option_name']; } $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE); if ($params['html_type'] == 'Text') { // if html type is Text, force is_enter_qty on $params['is_enter_qty'] = 1; // modify params values as per the option group and option // value $params['option_amount'] = array(1 => $params['price']); $params['option_label'] = array(1 => $params['label']); $params['option_count'] = array(1 => $params['count']); $params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params)); //$params['option_description'] = array( 1 => $params['description'] ); $params['option_weight'] = array(1 => $params['weight']); $params['option_financial_type_id'] = array(1 => $params['financial_type_id']); $params['is_active'] = array(1 => 1); } if ($this->_fid) { $params['id'] = $this->_fid; } $params['membership_num_terms'] = !empty($params['membership_type_id']) ? CRM_Utils_Array::value('membership_num_terms', $params, 1) : NULL; $priceField = CRM_Price_BAO_PriceField::create($params); if (!is_a($priceField, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)), ts('Saved'), 'success'); } $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another price set field.'), '', 'info'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid)); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid)); } }
/** * Create a new group * * @param array $params Associative array of parameters * * @return object|null The new group BAO (if created) * @access public * @static */ public static function &create(&$params) { if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', NULL, $params); } // form the name only if missing: CRM-627 if (!CRM_Utils_Array::value('name', $params) && !CRM_Utils_Array::value('id', $params)) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); if (!CRM_Utils_Array::value('id', $params)) { $group->name .= "_tmp"; } $group->save(); if (!$group->id) { return NULL; } if (!CRM_Utils_Array::value('id', $params)) { $group->name = substr($group->name, 0, -4) . "_{$group->id}"; } $group->buildClause(); $group->save(); // add custom field values if (CRM_Utils_Array::value('custom', $params)) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } } // clear any descendant groups cache if exists $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (CRM_Utils_Array::value('organization_id', $params)) { $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } $recentOther = array(); if (CRM_Core_Permission::check('edit groups')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id); // currently same permission we are using for delete a group $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id); } // add the recently added group (unless hidden: CRM-6432) if (!$group->is_hidden) { CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther); } return $group; }
/** * Takes an associative array and creates a custom field object. * * This function is invoked from within the web form layer and also from the api layer * * @param array $params * (reference) an assoc array of name/value pairs. * * @return CRM_Core_DAO_CustomField */ public static function create(&$params) { $origParams = array_merge(array(), $params); if (!isset($params['id'])) { if (!isset($params['column_name'])) { // if add mode & column_name not present, calculate it. $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32)); } if (!isset($params['name'])) { $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64); } } else { $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name'); } $columnName = $params['column_name']; $indexExist = FALSE; //as during create if field is_searchable we had created index. if (!empty($params['id'])) { $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); } switch (CRM_Utils_Array::value('html_type', $params)) { case 'Select Date': if (empty($params['date_format'])) { $config = CRM_Core_Config::singleton(); $params['date_format'] = $config->dateInputFormat; } break; case 'CheckBox': case 'AdvMulti-Select': case 'Multi-Select': if (isset($params['default_checkbox_option'])) { $tempArray = array_keys($params['default_checkbox_option']); $defaultArray = array(); foreach ($tempArray as $k => $v) { if ($params['option_value'][$v]) { $defaultArray[] = $params['option_value'][$v]; } } if (!empty($defaultArray)) { // also add the separator before and after the value per new convention (CRM-1604) $params['default_value'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultArray) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']])) { $params['default_value'] = $params['option_value'][$params['default_option']]; } } break; } $transaction = new CRM_Core_Transaction(); // create any option group & values if required if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money'))) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name'); //CRM-16659: if option_value then create an option group for this custom field. if ($params['option_type'] == 1 && (empty($params['option_group_id']) || !empty($params['option_value']))) { // first create an option group for this custom group $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = "{$columnName}_" . date('YmdHis'); $optionGroup->title = $params['label']; $optionGroup->is_active = 1; $optionGroup->save(); $params['option_group_id'] = $optionGroup->id; if (!empty($params['option_value']) && is_array($params['option_value'])) { foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $optionGroup->id; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); switch ($params['data_type']) { case 'Money': $optionValue->value = CRM_Utils_Rule::cleanMoney($v); break; case 'Int': $optionValue->value = intval($v); break; case 'Float': $optionValue->value = floatval($v); break; default: $optionValue->value = trim($v); } $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], FALSE); $optionValue->save(); } } } } } // check for orphan option groups if (!empty($params['option_group_id'])) { if (!empty($params['id'])) { self::fixOptionGroups($params['id'], $params['option_group_id']); } // if we do not have a default value // retrieve it from one of the other custom fields which use this option group if (empty($params['default_value'])) { //don't insert only value separator as default value, CRM-4579 $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']); if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultValue))) { $params['default_value'] = $defaultValue; } } } // since we need to save option group id :) if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') { $params['attributes'] = 'rows=4, cols=60'; } $customField = new CRM_Core_DAO_CustomField(); $customField->copyValues($params); $customField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE); $customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE); $customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE); $customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE); //CRM-15792 - Custom field gets disabled if is_active not set $customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE); $customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE); $customField->save(); // make sure all values are present in the object for further processing $customField->find(TRUE); $triggerRebuild = CRM_Utils_Array::value('triggerRebuild', $params, TRUE); //create/drop the index when we toggle the is_searchable flag if (!empty($params['id'])) { self::createField($customField, 'modify', $indexExist, $triggerRebuild); } else { if (!isset($origParams['column_name'])) { $columnName .= "_{$customField->id}"; $params['column_name'] = $columnName; } $customField->column_name = $columnName; $customField->save(); // make sure all values are present in the object $customField->find(TRUE); $indexExist = FALSE; self::createField($customField, 'add', $indexExist, $triggerRebuild); } // complete transaction $transaction->commit(); CRM_Utils_System::flushCache(); return $customField; }
/** * takes an associative array and creates a custom field object * * This function is invoked from within the web form layer and also from the api layer * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Core_DAO_CustomField object * @access public * @static */ static function create(&$params) { if (!isset($params['id']) && !isset($params['column_name'])) { // if add mode & column_name not present, calculate it. require_once 'CRM/Utils/String.php'; $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32)); } else { if (isset($params['id'])) { $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name'); } } $indexExist = false; //as during create if field is_searchable we had created index. if (CRM_Utils_Array::value('id', $params)) { $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); } if (($params['html_type'] == 'CheckBox' || $params['html_type'] == 'AdvMulti-Select' || $params['html_type'] == 'Multi-Select') && isset($params['default_checkbox_option'])) { $tempArray = array_keys($params['default_checkbox_option']); $defaultArray = array(); foreach ($tempArray as $k => $v) { if ($params['option_value'][$v]) { $defaultArray[] = $params['option_value'][$v]; } } if (!empty($defaultArray)) { // also add the seperator before and after the value per new conventio (CRM-1604) $params['default_value'] = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultArray) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; } } else { if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) { $params['default_value'] = $params['option_value'][$params['default_option']]; } } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); // create any option group & values if required if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money')) && !empty($params['option_value']) && is_array($params['option_value'])) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name'); if ($params['option_type'] == 1) { // first create an option group for this custom group require_once 'CRM/Core/BAO/OptionGroup.php'; $optionGroup =& new CRM_Core_DAO_OptionGroup(); $optionGroup->name = "{$params['column_name']}_" . date('YmdHis'); $optionGroup->label = $params['label']; $optionGroup->is_active = 1; $optionGroup->save(); $params['option_group_id'] = $optionGroup->id; require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Utils/String.php'; foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $optionGroup->id; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); switch ($params['data_type']) { case 'Money': require_once 'CRM/Utils/Rule.php'; $optionValue->value = number_format(CRM_Utils_Rule::cleanMoney($v), 2); break; case 'Int': $optionValue->value = intval($v); break; case 'Float': $optionValue->value = floatval($v); break; default: $optionValue->value = $v; } $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], false); $optionValue->save(); } } } } // check for orphan option groups if (CRM_Utils_Array::value('option_group_id', $params)) { if (CRM_Utils_Array::value('id', $params)) { self::fixOptionGroups($params['id'], $params['option_group_id']); } // if we dont have a default value // retrive it from one of the other custom fields which use this option group if (!CRM_Utils_Array::value('default_value', $params)) { //don't insert only value separator as default value, CRM-4579 $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']); if (!CRM_Utils_System::isNull(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultValue))) { $params['default_value'] = $defaultValue; } } } // since we need to save option group id :) if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') { $params['attributes'] = 'rows=4, cols=60'; } $customField =& new CRM_Core_DAO_CustomField(); $customField->copyValues($params); $customField->is_required = CRM_Utils_Array::value('is_required', $params, false); $customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, false); $customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, false); $customField->is_active = CRM_Utils_Array::value('is_active', $params, false); $customField->is_view = CRM_Utils_Array::value('is_view', $params, false); $customField->save(); // make sure all values are present in the object for further processing $customField->find(true); //create/drop the index when we toggle the is_searchable flag if (CRM_Utils_Array::value('id', $params)) { self::createField($customField, 'modify', $indexExist); } else { $customField->column_name .= "_{$customField->id}"; $customField->save(); // make sure all values are present in the object $customField->find(true); self::createField($customField, 'add'); } // complete transaction $transaction->commit(); // reset the cache require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); // reset various static arrays used here require_once 'CRM/Contact/BAO/Contact.php'; CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = self::$_importFields = null; return $customField; }
/** * Process the form. * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues('Set'); $nameLength = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'name'); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE); $compIds = array(); $extends = CRM_Utils_Array::value('extends', $params); if (is_array($extends)) { foreach ($extends as $compId => $selected) { if ($selected) { $compIds[] = $compId; } } } $params['extends'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $compIds); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_sid; } else { $params['name'] = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $nameLength)); } $set = CRM_Price_BAO_PriceSet::create($params); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Session::setStatus(ts('The Set \'%1\' has been saved.', array(1 => $set->title)), ts('Saved'), 'success'); } else { // Jump directly to adding a field if popups are disabled $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? 'browse' : 'add'; $url = CRM_Utils_System::url('civicrm/admin/price/field', array('reset' => 1, 'action' => $action, 'sid' => $set->id, 'new' => 1)); CRM_Core_Session::setStatus(ts("Your Set '%1' has been added. You can add fields to this set now.", array(1 => $set->title)), ts('Saved'), 'success'); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }
/** * Build the form object. */ public function buildQuickForm() { parent::buildQuickForm(); if (!empty($this->_varNames)) { foreach ($this->_varNames as $groupName => $groupValues) { $formName = CRM_Utils_String::titleToVar($groupName); $this->assign('formName', $formName); $fields = array(); foreach ($groupValues as $fieldName => $fieldValue) { $fields[$fieldName] = $fieldValue; switch ($fieldValue['html_type']) { case 'text': $this->addElement('text', $fieldName, $fieldValue['title'], array('maxlength' => 64, 'size' => 32)); break; case 'textarea': case 'checkbox': $this->add($fieldValue['html_type'], $fieldName, $fieldValue['title']); break; case 'radio': $options = CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE); $this->addRadio($fieldName, $fieldValue['title'], $options, NULL, ' '); break; case 'checkboxes': $options = array_flip(CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE)); $newOptions = array(); foreach ($options as $key => $val) { $newOptions[$key] = $val; } $this->addCheckBox($fieldName, $fieldValue['title'], $newOptions, NULL, NULL, NULL, NULL, array(' ', ' ', '<br/>')); break; case 'select': $this->addElement('select', $fieldName, $fieldValue['title'], $fieldValue['option_values']); break; case 'wysiwyg': $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']); break; case 'entity_reference': $this->addEntityRef($fieldName, $fieldValue['title'], CRM_Utils_Array::value('options', $fieldValue, array())); } } $fields = CRM_Utils_Array::crmArraySortByField($fields, 'weight'); $this->assign('fields', $fields); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * TODO: Find a way to move this into CRM_Simplemail_Form_Task_SimpleMail::postProcess() * * Note: A lot of the logic in this method (for creating hidden and smart groups) is taken from * CRM_Mailing_Form_Group::postProcess() * * @return null|string * @throws Exception */ private static function createSmartContactGroupForSearchContacts() { $searchParams = simplemail_civicrm_getFromSessionScope('searchParams'); $contactIds = simplemail_civicrm_getFromSessionScope('contactIds'); $smartGroupId = NULL; if ($contactIds) { $resultSelectOption = $searchParams['radio_ts']; // Only the ticked contacts in the search result need to be sent mailing - create a hidden group for them if ($resultSelectOption == 'ts_sel') { // create a static grp if only a subset of result set was selected: $randID = md5(time()); $grpTitle = "Hidden Group {$randID}"; $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title'); if (!$grpID) { $groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1)); $group = CRM_Contact_BAO_Group::create($groupParams); $grpID = $group->id; CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $group->id); $newGroupTitle = "Hidden Group {$grpID}"; $groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle, 'group_type' => array('2' => 1)); $group = CRM_Contact_BAO_Group::create($groupParams); } // note at this point its a static group $smartGroupId = $grpID; } else { // Get the saved search ID $ssId = simplemail_civicrm_getFromSessionScope('ssId'); $formValues = simplemail_civicrm_getFromSessionScope('formValues'); $customSearchId = simplemail_civicrm_getFromSessionScope('customSearchId'); $context = simplemail_civicrm_getFromSessionScope('context'); $hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $formValues, 'saved_search_id' => $ssId, 'search_custom_id' => $customSearchId, 'search_context' => $context); list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); // Set the saved search ID if (!$ssId) { if ($savedSearchId) { simplemail_civicrm_addToSessionScope('ssId', $savedSearchId); } else { CRM_Core_Error::fatal(); } } } } simplemail_civicrm_addToSessionScope('smartGroupId', $smartGroupId); }
public function postProcess() { $values = $this->controller->exportValues($this->_name); //build hidden smart group. when user want to send mailing //through search contact-> more action -> send Mailing. CRM-3711 $groups = array(); if ($this->_searchBasedMailing && $this->_contactIds) { $session = CRM_Core_Session::singleton(); if ($this->_resultSelectOption == 'ts_sel') { // create a static grp if only a subset of result set was selected: $randID = md5(time()); $grpTitle = "Hidden Group {$randID}"; $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title'); if (!$grpID) { $groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1)); $group = CRM_Contact_BAO_Group::create($groupParams); $grpID = $group->id; CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id); $newGroupTitle = "Hidden Group {$grpID}"; $groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle); $group = CRM_Contact_BAO_Group::create($groupParams); } // note at this point its a static group $smartGroupId = $grpID; } else { //get the hidden smart group id. $ssId = $this->get('ssID'); $hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context')); list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); //set the saved search id. if (!$ssId) { if ($savedSearchId) { $this->set('ssID', $savedSearchId); } else { CRM_Core_Error::fatal(); } } } //get the base group for this mailing, CRM-3711 $groups['base'] = array($values['baseGroup']); $values['includeGroups'][] = $smartGroupId; } foreach (array('name', 'group_id', 'search_id', 'search_args', 'campaign_id', 'dedupe_email') as $n) { if (CRM_Utils_Array::value($n, $values)) { $params[$n] = $values[$n]; } } $qf_Group_submit = $this->controller->exportValue($this->_name, '_qf_Group_submit'); $this->set('name', $params['name']); $inGroups = $values['includeGroups']; $outGroups = $values['excludeGroups']; $inMailings = $values['includeMailings']; $outMailings = $values['excludeMailings']; if (is_array($inGroups)) { foreach ($inGroups as $key => $id) { if ($id) { $groups['include'][] = $id; } } } if (is_array($outGroups)) { foreach ($outGroups as $key => $id) { if ($id) { $groups['exclude'][] = $id; } } } $mailings = array(); if (is_array($inMailings)) { foreach ($inMailings as $key => $id) { if ($id) { $mailings['include'][] = $id; } } } if (is_array($outMailings)) { foreach ($outMailings as $key => $id) { if ($id) { $mailings['exclude'][] = $id; } } } $session = CRM_Core_Session::singleton(); $params['groups'] = $groups; $params['mailings'] = $mailings; if ($this->get('mailing_id')) { $ids = array(); // don't create a new mailing if already exists $ids['mailing_id'] = $this->get('mailing_id'); $groupTableName = CRM_Contact_BAO_Group::getTableName(); $mailingTableName = CRM_Mailing_BAO_Mailing::getTableName(); // delete previous includes/excludes, if mailing already existed foreach (array('groups', 'mailings') as $entity) { $mg = new CRM_Mailing_DAO_Group(); $mg->mailing_id = $ids['mailing_id']; $mg->entity_table = $entity == 'groups' ? $groupTableName : $mailingTableName; $mg->find(); while ($mg->fetch()) { $mg->delete(); } } } else { // new mailing, so lets set the created_id $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids); $this->set('mailing_id', $mailing->id); $dedupeEmail = FALSE; if (isset($params['dedupe_email'])) { $dedupeEmail = $params['dedupe_email']; } // also compute the recipients and store them in the mailing recipients table CRM_Mailing_BAO_Mailing::getRecipients($mailing->id, $mailing->id, NULL, NULL, TRUE, $dedupeEmail); $count = CRM_Mailing_BAO_Recipients::mailingSize($mailing->id); $this->set('count', $count); $this->assign('count', $count); $this->set('groups', $groups); $this->set('mailings', $mailings); if ($qf_Group_submit) { //when user perform mailing from search context //redirect it to search result CRM-3711. $ssID = $this->get('ssID'); $context = $this->get('context'); if ($ssID && $this->_searchBasedMailing) { if ($this->_action == CRM_Core_Action::BASIC) { $fragment = 'search'; } elseif ($this->_action == CRM_Core_Action::PROFILE) { $fragment = 'search/builder'; } elseif ($this->_action == CRM_Core_Action::ADVANCED) { $fragment = 'search/advanced'; } else { $fragment = 'search/custom'; } $context = $this->get('context'); if (!CRM_Contact_Form_Search::isSearchContext($context)) { $context = 'search'; } $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}"; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL)); CRM_Core_Session::setStatus($status); //replace user context to search. $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); return $this->controller->setDestination($url); } else { $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it."); CRM_Core_Session::setStatus($status); $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1'); return $this->controller->setDestination($url); } } }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues(); $batchParams = array(); $batchParams['title'] = $params['title']; $batchParams['name'] = CRM_Utils_String::titleToVar($params['title'], 63); $batchParams['description'] = $params['description']; $batchParams['batch_type'] = "Gift Aid"; $session =& CRM_Core_Session::singleton(); $batchParams['created_id'] = $session->get('userID'); $batchParams['created_date'] = date("YmdHis"); $batchParams['status_id'] = 0; $batchMode = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'mode_id', array('labelColumn' => 'name')); $batchParams['mode_id'] = CRM_Utils_Array::key('Manual Batch', $batchMode); $batchParams['modified_date'] = date('YmdHis'); $batchParams['modified_id'] = $session->get('userID'); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //require_once 'CRM/Core/BAO/Batch.php'; //version 4.2 require_once 'CRM/Batch/BAO/Batch.php'; $createdBatch = CRM_Batch_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; $batchLabel = $batchParams['title']; // Save current settings for the batch CRM_Civigiftaid_BAO_BatchSettings::create(array('batch_id' => $batchID)); require_once 'CRM/Civigiftaid/Utils/Contribution.php'; list($total, $added, $notAdded) = CRM_Civigiftaid_Utils_Contribution::addContributionToBatch($this->_contributionIds, $batchID); if ($added <= 0) { // rollback since there were no contributions added, and we might not want to keep an empty batch $transaction->rollback(); $status = ts('Could not create batch "%1", as there were no valid contribution(s) to be added.', array(1 => $batchLabel)); } else { $status = array(ts('Added Contribution(s) to %1', array(1 => $batchLabel)), ts('Total Selected Contribution(s): %1', array(1 => $total))); if ($added) { $status[] = ts('Total Contribution(s) added to batch: %1', array(1 => $added)); } if ($notAdded) { $status[] = ts('Total Contribution(s) already in batch or not valid: %1', array(1 => $notAdded)); } $status = implode('<br/>', $status); } $transaction->commit(); CRM_Core_Session::setStatus($status); }
/** * Given this task's list of targets, produce a hidden group. * * @return array * Array(0 => int $groupID, 1 => int|NULL $ssID). * @throws Exception */ public function createHiddenGroup() { // Did the user select "All" matches or cherry-pick a few records? $searchParams = $this->controller->exportValues(); if ($searchParams['radio_ts'] == 'ts_sel') { // Create a static group. $randID = md5(time() . rand(1, 1000)); // groups require a unique name $grpTitle = "Hidden Group {$randID}"; $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title'); if (!$grpID) { $groupParams = array('title' => $grpTitle, 'is_active' => 1, 'is_hidden' => 1, 'group_type' => array('2' => 1)); $group = CRM_Contact_BAO_Group::create($groupParams); $grpID = $group->id; CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id); $newGroupTitle = "Hidden Group {$grpID}"; $groupParams = array('id' => $grpID, 'name' => CRM_Utils_String::titleToVar($newGroupTitle), 'title' => $newGroupTitle, 'group_type' => array('2' => 1)); $group = CRM_Contact_BAO_Group::create($groupParams); } // note at this point its a static group return array($grpID, NULL); } else { // Create a smart group. $ssId = $this->get('ssID'); $hiddenSmartParams = array('group_type' => array('2' => 1), 'form_values' => $this->get('formValues'), 'saved_search_id' => $ssId, 'search_custom_id' => $this->get('customSearchID'), 'search_context' => $this->get('context')); list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams); return array($smartGroupId, $savedSearchId); } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues('Set'); $nameLength = CRM_Core_DAO::getAttribute('CRM_Price_DAO_Set', 'name'); $params['name'] = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $nameLength)); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $compIds = array(); $extends = CRM_Utils_Array::value('extends', $params); if (is_array($extends)) { foreach ($extends as $compId => $selected) { if ($selected) { $compIds[] = $compId; } } } $params['extends'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $compIds); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_sid; } $set = CRM_Price_BAO_Set::create($params); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Session::setStatus(ts('The Set \'%1\' has been saved.', array(1 => $set->title))); } else { $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $set->id); CRM_Core_Session::setStatus(ts('Your Set \'%1\' has been added. You can add fields to this set now.', array(1 => $set->title))); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }