本文整理汇总了PHP中CRM_Utils_String::titleToVar方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_String::titleToVar方法的具体用法?PHP CRM_Utils_String::titleToVar怎么用?PHP CRM_Utils_String::titleToVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_String
的用法示例。
在下文中一共展示了CRM_Utils_String::titleToVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* 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;
}
示例2: create
/**
* 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;
}
示例3: create
/**
* 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;
}
示例4: add
/**
* 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();
}
示例5: _addParticipantWithPayment
/**
* 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);
}
示例6: create
/**
* 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;
}
示例7: addParticipantWithContribution
/**
* 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);
}
示例8: implode
/**
* 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'])) {
//.........这里部分代码省略.........
示例9: postProcess
/**
* 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();
}
示例10: testfixEventLevel
/**
* 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);
}
示例11: formRule
/**
* 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;
}
示例12: postProcess
/**
* 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));
}
}
示例13: implode
/**
* 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;
}
示例14: create
/**
* 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]));
}
//.........这里部分代码省略.........
示例15: postProcess
/**
* 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');
}