本文整理汇总了PHP中CRM_Core_Form::createElement方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::createElement方法的具体用法?PHP CRM_Core_Form::createElement怎么用?PHP CRM_Core_Form::createElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::createElement方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* Build the form object elements for Communication Preferences object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*
* @return void
*/
public static function buildQuickForm(&$form)
{
// since the pcm - preferred comminication method is logically
// grouped hence we'll use groups of HTML_QuickForm
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$privacy = $commPreff = $commPreference = array();
$privacyOptions = CRM_Core_SelectValues::privacy();
// we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
unset($privacyOptions['is_opt_out']);
foreach ($privacyOptions as $name => $label) {
$privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
}
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' ');
// preferred communication method
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
foreach ($comm as $value => $title) {
$commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
}
$form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)'));
$form->addSelect('preferred_language');
if (!empty($privacyOptions)) {
$commPreference['privacy'] = $privacyOptions;
}
if (!empty($comm)) {
$commPreference['preferred_communication_method'] = $comm;
}
//using for display purpose.
$form->assign('commPreference', $commPreference);
$form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf());
$form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)'));
$communicationStyleOptions = array();
$communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE));
foreach ($communicationStyle as $key => $var) {
$communicationStyleOptions[$key] = $form->createElement('radio', NULL, ts('Communication Style'), $var, $key, array('id' => "civicrm_communication_style_{$var}_{$key}"));
}
if (!empty($communicationStyleOptions)) {
$form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style'));
}
//check contact type and build filter clause accordingly for greeting types, CRM-4575
$greetings = self::getGreetingFields($form->_contactType);
foreach ($greetings as $greeting => $fields) {
$filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
//add addressee in Contact form
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
if (!empty($greetingTokens)) {
$form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
//custom addressee
$form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
}
}
}
示例2: buildQuickForm
/**
* Function used to build form element for soft credit block.
*
* @param CRM_Core_Form $form
*
* @return \CRM_Core_Form
*/
public static function buildQuickForm(&$form)
{
if (!empty($form->_honor_block_is_active)) {
$ufJoinDAO = new CRM_Core_DAO_UFJoin();
$ufJoinDAO->module = 'soft_credit';
$ufJoinDAO->entity_id = $form->_id;
if ($ufJoinDAO->find(TRUE)) {
$jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, 'soft_credit');
if ($jsonData) {
foreach (array('honor_block_title', 'honor_block_text') as $name) {
$form->assign($name, $jsonData[$name]);
}
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
// radio button for Honor Type
foreach ($jsonData['soft_credit_types'] as $value) {
$honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
$form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
}
}
return $form;
}
// by default generate 10 blocks
$item_count = 11;
$showSoftCreditRow = 2;
if ($form->getAction() & CRM_Core_Action::UPDATE) {
$form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
} elseif (!empty($form->_pledgeID)) {
//Check and select most recent completed contrubtion and use it to retrieve
//soft-credit information to use as default for current pledge payment, CRM-13981
$pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
foreach ($pledgePayments as $id => $record) {
if ($record['contribution_id']) {
$softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
if ($record['status'] == 'Completed' && count($softCredits) > 0) {
$form->_softCreditInfo = $softCredits;
}
}
}
}
if (property_exists($form, "_softCreditInfo")) {
if (!empty($form->_softCreditInfo['soft_credit'])) {
$showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
$showSoftCreditRow++;
}
}
for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
$form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
$form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
$form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
$form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
}
}
self::addPCPFields($form);
$form->assign('showSoftCreditRow', $showSoftCreditRow);
$form->assign('rowCount', $item_count);
$form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
}
示例3: buildQuickForm
/**
* build the form elements for Demographics object
*
* @param CRM_Core_Form $form reference to the form object
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
// radio button for gender
$genderOptions = array();
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
foreach ($gender as $key => $var) {
$genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key, array('id' => "civicrm_gender_{$var}_{$key}"));
}
$form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('unselectable', TRUE);
$form->addDate('birth_date', ts('Date of Birth'), FALSE, array('formatType' => 'birth'));
$form->addElement('checkbox', 'is_deceased', NULL, ts('Contact is deceased'), array('onclick' => "showDeceasedDate()"));
$form->addDate('deceased_date', ts('Deceased date'), FALSE, array('formatType' => 'birth'));
}
示例4: buildAdvanceSetting
/**
* Build the form object for Advance Settings.
*
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function buildAdvanceSetting(&$form)
{
// should mapping be enabled for this group
$form->addElement('checkbox', 'is_map', ts('Enable mapping for this profile?'));
// should we allow updates on a exisitng contact
$options = array();
$options[] = $form->createElement('radio', NULL, NULL, ts('Issue warning and do not save'), 0);
$options[] = $form->createElement('radio', NULL, NULL, ts('Update the matching contact'), 1);
$options[] = $form->createElement('radio', NULL, NULL, ts('Allow duplicate contact to be created'), 2);
$form->addGroup($options, 'is_update_dupe', ts('What to do upon duplicate match'));
// we do not have any url checks to allow relative urls
$form->addElement('text', 'post_URL', ts('Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'post_URL'));
$form->addElement('text', 'cancel_URL', ts('Cancel Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_URL'));
// add select for groups
$group = array('' => ts('- select -')) + $form->_group;
$form->_groupElement =& $form->addElement('select', 'group', ts('Limit listings to a specific Group?'), $group);
//add notify field
$form->addElement('text', 'notify', ts('Notify when profile form is submitted?'));
//group where new contacts are directed.
$form->addElement('select', 'add_contact_to_group', ts('Add new contacts to a Group?'), $group);
// add CAPTCHA To this group ?
$form->addElement('checkbox', 'add_captcha', ts('Include reCAPTCHA?'));
// should we display an edit link
$form->addElement('checkbox', 'is_edit_link', ts('Include profile edit links in search results?'));
// should we display a link to the website profile
$config = CRM_Core_Config::singleton();
$form->addElement('checkbox', 'is_uf_link', ts('Include %1 user account information links in search results?', array(1 => $config->userFramework)));
// want to create cms user
$session = CRM_Core_Session::singleton();
$cmsId = FALSE;
if ($form->_cId = $session->get('userID')) {
$form->_cmsId = TRUE;
}
$options = array();
$options[] = $form->createElement('radio', NULL, NULL, ts('No account create option'), 0);
$options[] = $form->createElement('radio', NULL, NULL, ts('Give option, but not required'), 1);
$options[] = $form->createElement('radio', NULL, NULL, ts('Account creation required'), 2);
$form->addGroup($options, 'is_cms_user', ts('%1 user account registration option?', array(1 => $config->userFramework)));
// options for including Proximity Search in the profile search form
$proxOptions = array();
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('None'), 0);
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Optional'), 1);
$proxOptions[] = $form->createElement('radio', NULL, NULL, ts('Required'), 2);
$form->addGroup($proxOptions, 'is_proximity_search', ts('Proximity Search'));
}
示例5: addQuickFormElement
//.........这里部分代码省略.........
$element->freeze();
}
//CRM-10117
if (!empty($qf->_quickConfig)) {
$message = ts('Please enter a valid amount.');
$type = 'money';
} else {
$message = ts('%1 must be an integer (whole number).', array(1 => $label));
$type = 'positiveInteger';
}
// integers will have numeric rule applied to them.
$qf->addRule($elementName, $message, $type);
break;
case 'Radio':
$choice = array();
if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
$qf->assign('contriPriceset', $elementName);
}
foreach ($customOption as $opId => $opt) {
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] : '';
$opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
}
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
$extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName);
if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
$extra += array('onclick' => 'clearAmountOther();');
} elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
$extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
$qf->assign('membershipFieldID', $field->id);
}
$choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
// CRM-6902
if (in_array($opId, $feezeOptions)) {
$choice[$opId]->freeze();
}
}
if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
$choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('onclick' => 'clearAmountOther();'));
}
if (!$field->is_required) {
// add "none" option
if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
$none = ts('Other Amount');
} elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
$none = ts('No thank you');
} else {
$none = ts('- none -');
}
$choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0'))));
}
$element =& $qf->addGroup($choice, $elementName, $label);
// make contribution field required for quick config when membership block is enabled
if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) {
$useRequired = $field->is_required = TRUE;
}
if ($useRequired && $field->is_required) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'Select':
示例6: buildComponentForm
/**
* Add onbehalf/honoree profile fields and native module fields.
*
* @param int $id
* @param CRM_Core_Form $form
*/
public function buildComponentForm($id, $form)
{
if (empty($id)) {
return;
}
$contactID = $this->getContactID();
foreach (array('soft_credit', 'on_behalf') as $module) {
if ($module == 'soft_credit') {
if (empty($form->_values['honoree_profile_id'])) {
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
}
$profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
$requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
$validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
if (!$validProfile) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
}
foreach (array('honor_block_title', 'honor_block_text') as $name) {
$form->assign($name, $form->_values[$name]);
}
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
// radio button for Honor Type
foreach ($form->_values['soft_credit_types'] as $value) {
$honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
$form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
$honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
$form->assign('honoreeProfileFields', $honoreeProfileFields);
// add the form elements
foreach ($honoreeProfileFields as $name => $field) {
// If soft credit type is not chosen then make omit requiredness from honoree profile fields
if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
$field['is_required'] = FALSE;
}
CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
}
} else {
if (empty($form->_values['onbehalf_profile_id'])) {
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
}
$member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
if (empty($member['is_active'])) {
$msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
$onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
foreach (array('Individual', 'Organization', 'Household') as $contactType) {
if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
CRM_Core_Error::fatal($msg);
}
}
}
if ($contactID) {
// retrieve all permissioned organizations of contact $contactID
$organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
if (count($organizations)) {
// Related org url - pass checksum if needed
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
if (!empty($_GET['cs'])) {
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
}
$locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
$form->assign('locDataURL', $locDataURL);
}
if (count($organizations) > 0) {
$form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
$orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
$form->addRadio('org_option', ts('options'), $orgOptions);
$form->setDefaults(array('org_option' => 0));
}
}
$form->assign('fieldSetTitle', ts('Organization Details'));
if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
if ($form->_values['is_for_organization'] == 2) {
$form->assign('onBehalfRequired', TRUE);
} else {
$form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
}
}
$profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
$form->assign('onBehalfOfFields', $profileFields);
if (!empty($form->_submitValues['onbehalf'])) {
if (!empty($form->_submitValues['onbehalfof_id'])) {
$form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
}
$form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
}
$fieldTypes = array('Contact', 'Organization');
$contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
$fieldTypes = array_merge($fieldTypes, $contactSubType);
//.........这里部分代码省略.........
示例7: buildProfile
//.........这里部分代码省略.........
$form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
} else {
$form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
}
if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
$form->freeze($name . '-provider_id');
}
}
} elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
$form->addDate($name, $title, $required, array('formatType' => 'birth'));
} elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
$form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
} elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
$sel =& $form->addElement('hierselect', $name, $title);
$select = array('' => ts('- select -'));
if (count($orgInfo) == 1 && $field['is_required']) {
// we only have one org - so we should default to it. Not sure about defaulting to first type
// as it could be missed - so adding a select
// however, possibly that is more similar to the membership form
if (count($types[1]) > 1) {
$types[1] = $select + $types[1];
}
} else {
$orgInfo = $select + $orgInfo;
}
$sel->setOptions(array($orgInfo, $types));
} elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required);
} elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) {
$options = array();
$pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName);
foreach ($pseudoValues as $key => $var) {
$options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key);
}
$group = $form->addGroup($options, $name, $title);
if ($required) {
$form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required');
} else {
$group->setAttribute('allowClear', TRUE);
}
} elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') {
$form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required);
} elseif ($fieldName === 'contact_sub_type') {
$gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field);
if ($usedFor == 'onbehalf') {
$profileType = 'Organization';
} elseif ($usedFor == 'honor') {
$profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']);
} else {
$profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL;
if ($profileType == 'Contact') {
$profileType = 'Individual';
}
}
$setSubtype = FALSE;
if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
$setSubtype = $profileType;
$profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
}
$subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array();
if ($setSubtype) {
$subtypeList = array();
$subtypeList[$setSubtype] = $subtypes[$setSubtype];
} else {
$subtypeList = $subtypes;
示例8: buildPremiumPreviewBlock
/**
* Build Premium B im Contribution Pages.
*
* @param CRM_Core_Form $form
* @param int $productID
* @param int $premiumProductID
*/
public function buildPremiumPreviewBlock($form, $productID, $premiumProductID = NULL)
{
if ($premiumProductID) {
$dao = new CRM_Contribute_DAO_PremiumsProduct();
$dao->id = $premiumProductID;
$dao->find(TRUE);
$productID = $dao->product_id;
}
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $productID;
$productDAO->is_active = 1;
if ($productDAO->find(TRUE)) {
CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
}
$radio[$productDAO->id] = $form->createElement('radio', NULL, NULL, NULL, $productDAO->id, NULL);
$options = $temp = array();
$temp = explode(',', $productDAO->options);
foreach ($temp as $value) {
$options[$value] = $value;
}
if ($temp[0] != '') {
$form->add('select', 'options_' . $productDAO->id, NULL, $options);
}
$form->addGroup($radio, 'selectProduct', NULL);
$form->assign('showRadio', TRUE);
$form->assign('showSelectOptions', TRUE);
$form->assign('products', $products);
$form->assign('preview', TRUE);
}
示例9: buildQuickForm
/**
* Build form.
*
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form)
{
// FIXME: this is using the following as keys rather than the standard numeric keys returned by CRM_Utils_Date
$dayOfTheWeek = array();
$dayKeys = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
foreach (CRM_Utils_Date::getAbbrWeekdayNames() as $k => $label) {
$dayOfTheWeek[$dayKeys[$k]] = $label;
}
$form->add('select', 'repetition_frequency_unit', ts('Repeats every'), CRM_Core_SelectValues::getRecurringFrequencyUnits(), FALSE, array('class' => 'required'));
$numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
$form->add('select', 'repetition_frequency_interval', NULL, $numericOptions, FALSE, array('class' => 'required'));
$form->addDateTime('repetition_start_date', ts('Repetition Start Date'), FALSE, array('formatType' => 'activityDateTime'));
foreach ($dayOfTheWeek as $key => $val) {
$startActionCondition[] = $form->createElement('checkbox', $key, NULL, $val);
}
$form->addGroup($startActionCondition, 'start_action_condition', ts('Repeats on'));
$roptionTypes = array('1' => ts('day of the month'), '2' => ts('day of the week'));
$form->addRadio('repeats_by', ts("Repeats by"), $roptionTypes, array('required' => TRUE), NULL);
$form->add('select', 'limit_to', '', CRM_Core_SelectValues::getNumericOptions(1, 31));
$dayOfTheWeekNo = array('first' => ts('First'), 'second' => ts('Second'), 'third' => ts('Third'), 'fourth' => ts('Fourth'), 'last' => ts('Last'));
$form->add('select', 'entity_status_1', '', $dayOfTheWeekNo);
$form->add('select', 'entity_status_2', '', $dayOfTheWeek);
$eoptionTypes = array('1' => ts('After'), '2' => ts('On'));
$form->addRadio('ends', ts("Ends"), $eoptionTypes, array('class' => 'required'), NULL);
// Offset options gets key=>val pairs like 1=>2 because the BAO wants to know the number of
// children while it makes more sense to the user to see the total number including the parent.
$offsetOptions = range(1, 30);
unset($offsetOptions[0]);
$form->add('select', 'start_action_offset', NULL, $offsetOptions, FALSE);
$form->addFormRule(array('CRM_Core_Form_RecurringEntity', 'formRule'));
$form->addDate('repeat_absolute_date', ts('On'), FALSE, array('formatType' => 'mailing'));
$form->add('text', 'exclude_date_list', ts('Exclude Dates'), array('class' => 'twenty'));
$form->addElement('hidden', 'allowRepeatConfigToSubmit', '', array('id' => 'allowRepeatConfigToSubmit'));
$form->addButtons(array(array('type' => 'submit', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
// For client-side pluralization
$form->assign('recurringFrequencyOptions', array('single' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits()), 'plural' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::getRecurringFrequencyUnits(2))));
}
示例10: addQuickFormElement
/**
* This function for building custom fields.
*
* @param CRM_Core_Form $qf
* Form object (reference).
* @param string $elementName
* Name of the custom field.
* @param int $fieldId
* @param bool $inactiveNeeded
* -deprecated.
* @param bool $useRequired
* True if required else false.
* @param bool $search
* True if used for search else false.
* @param string $label
* Label for custom field.
*
*/
public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL)
{
$field = self::getFieldObject($fieldId);
$widget = $field->html_type;
// Custom field HTML should indicate group+field name
$groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
$dataCrmCustomVal = $groupName . ':' . $field->name;
$dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
$field->attributes .= $dataCrmCustomAttr;
// Fixed for Issue CRM-2183
if ($widget == 'TextArea' && $search) {
$widget = 'Text';
}
$placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
// FIXME: Why are select state/country separate widget types?
$isSelect = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio'));
if ($isSelect) {
$options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_{$fieldId}", 'context' => $search ? 'search' : 'create'), array()));
// Consolidate widget types to simplify the below switch statement
if ($search || $widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE) {
$widget = 'Select';
}
$selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2');
// Search field is always multi-select
if ($search || strpos($field->html_type, 'Multi') !== FALSE) {
$selectAttributes['class'] .= ' huge';
$selectAttributes['multiple'] = 'multiple';
$selectAttributes['placeholder'] = $placeholder;
}
// Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect
if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
$selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id));
}
}
if (!isset($label)) {
$label = $field->label;
}
/**
* at some point in time we might want to split the below into small functions
**/
switch ($widget) {
case 'Text':
case 'Link':
if ($field->is_search_range && $search) {
$qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes);
$qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
} else {
$element =& $qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search);
}
break;
case 'TextArea':
$attributes = $dataCrmCustomAttr;
if ($field->note_rows) {
$attributes .= 'rows=' . $field->note_rows;
} else {
$attributes .= 'rows=4';
}
if ($field->note_columns) {
$attributes .= ' cols=' . $field->note_columns;
} else {
$attributes .= ' cols=60';
}
if ($field->text_length) {
$attributes .= ' maxlength=' . $field->text_length;
}
$element =& $qf->add('textarea', $elementName, $label, $attributes, $useRequired && !$search);
break;
case 'Select Date':
if ($field->is_search_range && $search) {
$qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
$qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
} else {
$required = $useRequired && !$search;
$qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
}
break;
case 'Radio':
$choice = array();
foreach ($options as $v => $l) {
$choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
}
$group = $qf->addGroup($choice, $elementName, $label);
//.........这里部分代码省略.........
示例11: buildPledgeBlock
/**
* Build Pledge Block in Contribution Pages.
*
* @param CRM_Core_Form $form
*/
public static function buildPledgeBlock($form)
{
//build pledge payment fields.
if (!empty($form->_values['pledge_id'])) {
//get all payments required details.
$allPayments = array();
$returnProperties = array('status_id', 'scheduled_date', 'scheduled_amount', 'currency', 'pledge_start_date');
CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $form->_values['pledge_id'], $allPayments, $returnProperties);
// get all status
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$nextPayment = array();
$isNextPayment = FALSE;
$overduePayments = array();
foreach ($allPayments as $payID => $value) {
if ($allStatus[$value['status_id']] == 'Overdue') {
$overduePayments[$payID] = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
} elseif (!$isNextPayment && $allStatus[$value['status_id']] == 'Pending') {
// get the next payment.
$nextPayment = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_amount_currency' => $value['currency'], 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d'));
$isNextPayment = TRUE;
}
}
// build check box array for payments.
$payments = array();
if (!empty($overduePayments)) {
foreach ($overduePayments as $id => $payment) {
$label = ts("%1 - due on %2 (overdue)", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $payment), CRM_Utils_Array::value('scheduled_amount_currency', $payment)), 2 => CRM_Utils_Array::value('scheduled_date', $payment)));
$paymentID = CRM_Utils_Array::value('id', $payment);
$payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $payment)));
}
}
if (!empty($nextPayment)) {
$label = ts("%1 - due on %2", array(1 => CRM_Utils_Money::format(CRM_Utils_Array::value('scheduled_amount', $nextPayment), CRM_Utils_Array::value('scheduled_amount_currency', $nextPayment)), 2 => CRM_Utils_Array::value('scheduled_date', $nextPayment)));
$paymentID = CRM_Utils_Array::value('id', $nextPayment);
$payments[] = $form->createElement('checkbox', $paymentID, NULL, $label, array('amount' => CRM_Utils_Array::value('scheduled_amount', $nextPayment)));
}
// give error if empty or build form for payment.
if (empty($payments)) {
CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment."));
} else {
$form->assign('is_pledge_payment', TRUE);
$form->addGroup($payments, 'pledge_amount', ts('Make Pledge Payment(s):'), '<br />');
}
} else {
$pledgeBlock = self::getPledgeBlock($form->_id);
// build form for pledge creation.
$pledgeOptions = array('0' => ts('I want to make a one-time contribution'), '1' => ts('I pledge to contribute this amount every'));
$form->addRadio('is_pledge', ts('Pledge Frequency Interval'), $pledgeOptions, NULL, array('<br/>'));
$form->addElement('text', 'pledge_installments', ts('Installments'), array('size' => 3));
if (!empty($pledgeBlock['is_pledge_interval'])) {
$form->assign('is_pledge_interval', CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock));
$form->addElement('text', 'pledge_frequency_interval', NULL, array('size' => 3));
} else {
$form->add('hidden', 'pledge_frequency_interval', 1);
}
// Frequency unit drop-down label suffixes switch from *ly to *(s)
$freqUnitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlock['pledge_frequency_unit']);
$freqUnits = array();
$frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
foreach ($freqUnitVals as $key => $val) {
if (array_key_exists($val, $frequencyUnits)) {
$freqUnits[$val] = !empty($pledgeBlock['is_pledge_interval']) ? "{$frequencyUnits[$val]}(s)" : $frequencyUnits[$val];
}
}
$form->addElement('select', 'pledge_frequency_unit', NULL, $freqUnits);
// CRM-18854
if (CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)) {
if (CRM_Utils_Array::value('pledge_start_date', $pledgeBlock)) {
$defaults = array();
$date = (array) json_decode($pledgeBlock['pledge_start_date']);
list($field, $value) = each($date);
switch ($field) {
case 'contribution_date':
$form->addDate('start_date', ts('First installment payment'));
$paymentDate = $value = date('d/m/Y');
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
$form->assign('is_date', TRUE);
break;
case 'calendar_date':
$form->addDate('start_date', ts('First installment payment'));
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($value);
$form->assign('is_date', TRUE);
$paymentDate = $value;
break;
case 'calendar_month':
$month = CRM_Utils_Date::getCalendarDayOfMonth();
$form->add('select', 'start_date', ts('Day of month installments paid'), $month);
$paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate($value);
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($paymentDate);
break;
default:
break;
}
$form->setDefaults($defaults);
$form->assign('start_date_display', $paymentDate);
//.........这里部分代码省略.........
示例12: buildQuickForm
/**
* Function used to build form element for soft credit block.
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function buildQuickForm(&$form)
{
if (!empty($form->_honor_block_is_active)) {
$ufJoinDAO = new CRM_Core_DAO_UFJoin();
$ufJoinDAO->module = 'soft_credit';
$ufJoinDAO->entity_id = $form->_id;
if ($ufJoinDAO->find(TRUE)) {
$jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE);
if ($jsonData) {
foreach (array('honor_block_title', 'honor_block_text') as $name) {
$form->assign($name, $jsonData[$name]);
}
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
// radio button for Honor Type
foreach ($jsonData['soft_credit_types'] as $value) {
$honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
$form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
}
}
return $form;
}
// by default generate 10 blocks
$item_count = 11;
$showSoftCreditRow = 2;
if ($form->getAction() & CRM_Core_Action::UPDATE) {
$form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
} elseif (!empty($form->_pledgeID)) {
//Check and select most recent completed contrubtion and use it to retrieve
//soft-credit information to use as default for current pledge payment, CRM-13981
$pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($form->_pledgeID);
foreach ($pledgePayments as $id => $record) {
if ($record['contribution_id']) {
$softCredits = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($record['contribution_id'], TRUE);
if ($record['status'] == 'Completed' && count($softCredits) > 0) {
$form->_softCreditInfo = $softCredits;
}
}
}
}
if (property_exists($form, "_softCreditInfo")) {
if (!empty($form->_softCreditInfo['soft_credit'])) {
$showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
$showSoftCreditRow++;
}
}
for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
$form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
$form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
$form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
$form->add('hidden', "soft_credit_id[{$rowNumber}]", $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
}
}
// CRM-7368 allow user to set or edit PCP link for contributions
$siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
$form->assign('siteHasPCPs', 1);
// Fixme: Not a true entityRef field. Relies on PCP.js.tpl
$form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
// stores the label
$form->add('hidden', 'pcp_made_through');
$form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
$form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
$form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
}
$form->assign('showSoftCreditRow', $showSoftCreditRow);
$form->assign('rowCount', $item_count);
$form->addElement('hidden', 'sct_default_id', CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id'));
}
示例13: addQuickFormElement
//.........这里部分代码省略.........
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator"> - </span>' : '';
$preHelpText = $postHelpText = '';
if (isset($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ';
}
if (isset($opt['help_post'])) {
$postHelpText = ': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}
if (isset($taxAmount) && $invoicing) {
if ($displayOpt == 'Do_not_show') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
} elseif ($displayOpt == 'Inclusive') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
} else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
}
} else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
}
$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
}
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
$extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName, 'data-price-field-values' => json_encode($customOption));
if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
$extra += array('onclick' => 'clearAmountOther();');
} elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
$extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
$qf->assign('membershipFieldID', $field->id);
}
$choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
// CRM-6902 - Add "max" option for a price set field
if (in_array($opId, $freezeOptions)) {
self::freezeIfEnabled($choice[$opId], $customOption[$opId]);
// CRM-14696 - Improve display for sold out price set options
$choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . ' (' . ts('Sold out') . ')</span>');
}
}
if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
$choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('price' => json_encode(array($elementName, '0|0')), 'data-currency' => $currencyName, 'onclick' => 'clearAmountOther();'));
}
if (!$field->is_required) {
// add "none" option
if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
$none = ts('Other Amount');
} elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
$none = ts('No thank you');
} else {
$none = ts('- none -');
}
$choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0'))));
}
$element =& $qf->addGroup($choice, $elementName, $label);
// make contribution field required for quick config when membership block is enabled
if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) {
$useRequired = $field->is_required = TRUE;
}
if ($useRequired && $field->is_required) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}