本文整理汇总了PHP中CRM_Core_Form::addEntityRef方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::addEntityRef方法的具体用法?PHP CRM_Core_Form::addEntityRef怎么用?PHP CRM_Core_Form::addEntityRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::addEntityRef方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form)
{
$excludeCaseIds = (array) $form->_caseId;
$relatedCases = $form->get('relatedCases');
if (is_array($relatedCases) && !empty($relatedCases)) {
$excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases));
}
$form->addEntityRef('link_to_case_id', ts('Link To Case'), array('entity' => 'Case', 'api' => array('extra' => array('case_id.case_type_id.title', 'contact_id.sort_name'), 'params' => array('case_id' => array('NOT IN' => $excludeCaseIds), 'case_id.is_deleted' => 0))), TRUE);
}
示例2: buildQuickForm
/**
* Build tag widget if correct parent is passed
*
* @param CRM_Core_Form $form
* Form object.
* @param string $parentNames
* Parent name ( tag name).
* @param string $entityTable
* Entitytable 'eg: civicrm_contact'.
* @param int $entityId
* Entityid 'eg: contact id'.
* @param bool $skipTagCreate
* True if tag need be created using ajax.
* @param bool $skipEntityAction
* True if need to add entry in entry table via ajax.
* @param string $tagsetElementName
* If you need to create tagsetlist with specific name.
*/
public static function buildQuickForm(&$form, $parentNames, $entityTable, $entityId = NULL, $skipTagCreate = FALSE, $skipEntityAction = FALSE, $tagsetElementName = NULL)
{
$tagset = $form->_entityTagValues = array();
$form->assign("isTagset", FALSE);
$mode = NULL;
foreach ($parentNames as &$parentNameItem) {
// get the parent id for tag list input for keyword
$parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentNameItem, 'id', 'name');
// check if parent exists
if ($parentId) {
$tagsetItem = $tagsetElementName . 'parentId_' . $parentId;
$tagset[$tagsetItem]['parentID'] = $parentId;
list(, $mode) = explode('_', $entityTable);
if (!$tagsetElementName) {
$tagsetElementName = $mode . "_taglist";
}
$tagset[$tagsetItem]['tagsetElementName'] = $tagsetElementName;
$form->addEntityRef("{$tagsetElementName}[{$parentId}]", $parentNameItem, array('entity' => 'tag', 'multiple' => TRUE, 'create' => !$skipTagCreate, 'api' => array('params' => array('parent_id' => $parentId)), 'data-entity_table' => $entityTable, 'data-entity_id' => $entityId, 'class' => "crm-{$mode}-tagset"));
if ($entityId) {
$tagset[$tagsetItem]['entityId'] = $entityId;
$entityTags = CRM_Core_BAO_EntityTag::getChildEntityTags($parentId, $entityId, $entityTable);
if ($entityTags) {
$form->setDefaults(array("{$tagsetElementName}[{$parentId}]" => implode(',', array_keys($entityTags))));
}
} else {
$skipEntityAction = TRUE;
}
$tagset[$tagsetItem]['skipEntityAction'] = $skipEntityAction;
}
}
if (!empty($tagset)) {
// assign current tagsets which is used in postProcess
$form->_tagsetInfo = $tagset;
$form->assign("tagsetType", $mode);
// Merge this tagset info with possibly existing info in the template
$tagsetInfo = (array) $form->get_template_vars("tagsetInfo");
if (empty($tagsetInfo[$mode])) {
$tagsetInfo[$mode] = array();
}
$tagsetInfo[$mode] = array_merge($tagsetInfo[$mode], $tagset);
$form->assign("tagsetInfo", $tagsetInfo);
$form->assign("isTagset", TRUE);
}
}
示例3: buildSearchForm
/**
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form)
{
$dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE);
$form->assign('dataURLEventFee', $dataURLEventFee);
$form->addEntityRef('event_id', ts('Event Name'), array('entity' => 'event', 'placeholder' => ts('- any -'), 'multiple' => 1, 'select' => array('minimumInputLength' => 0)));
$form->addEntityRef('event_type_id', ts('Event Type'), array('entity' => 'option_value', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0), 'api' => array('params' => array('option_group_id' => 'event_type'))));
$obj = new CRM_Report_Form_Event_ParticipantListing();
$form->add('select', 'participant_fee_id', ts('Fee Level'), $obj->getPriceLevels(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')));
CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE);
$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>')));
$form->addSelect('participant_status_id', array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')));
$form->addSelect('participant_role_id', array('entity' => 'participant', 'label' => ts('Participant Role'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')));
$form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE);
$form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE);
$form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
$form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
$form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money');
$form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money');
// add all the custom searchable fields
$extends = array('Participant', 'Event');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('participantGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id');
$form->assign('validCiviEvent', TRUE);
$form->setDefaults(array('participant_test' => 0));
}
示例4: buildSearchForm
/**
* Build the search form.
*
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form)
{
$membershipStatus = CRM_Member_PseudoConstant::membershipStatus();
$form->add('select', 'membership_status_id', ts('Membership Status(s)'), $membershipStatus, FALSE, array('id' => 'membership_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2'));
$form->addEntityRef('membership_type_id', ts('Membership Type(s)'), array('entity' => 'MembershipType', 'multiple' => TRUE, 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0)));
$form->addElement('text', 'member_source', ts('Source'));
CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE);
$form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE);
$form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE);
$form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE);
$form->addYesNo('member_test', ts('Membership is a Test?'), TRUE);
$form->addYesNo('member_is_override', ts('Membership Status Is Override?'), TRUE);
// add all the custom searchable fields
$extends = array('Membership');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('membershipGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
}
}
}
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id');
$form->assign('validCiviMember', TRUE);
$form->setDefaults(array('member_test' => 0));
}
示例5: addQuickFormElement
//.........这里部分代码省略.........
$qf->addGroup($operators, $elementName . '_operator');
$qf->setDefaults(array($elementName . '_operator' => 'or'));
}
break;
case 'AdvMulti-Select':
$include =& $qf->addElement('advmultiselect', $elementName, $label, $options, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal));
$include->setButtonAttributes('add', array('value' => ts('Add >>')));
$include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'CheckBox':
$check = array();
foreach ($options as $v => $l) {
$check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal));
}
$qf->addGroup($check, $elementName, $label);
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'File':
// we should not build upload file in search mode
if ($search) {
return;
}
$qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
$qf->addUploadElement($elementName);
break;
case 'RichTextEditor':
$attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
$qf->addWysiwyg($elementName, $label, $attributes, $search);
break;
case 'Autocomplete-Select':
static $customUrls = array();
// Fixme: why is this a string in the first place??
$attributes = array();
if ($field->attributes) {
foreach (explode(' ', $field->attributes) as $at) {
if (strpos($at, '=')) {
list($k, $v) = explode('=', $at);
$attributes[$k] = trim($v, ' "');
}
}
}
if ($field->data_type == 'ContactReference') {
$attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge';
$attributes['data-api-entity'] = 'contact';
$qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
$urlParams = "context=customfield&id={$field->id}";
$customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE);
} else {
// FIXME: This won't work with customFieldOptions hook
$attributes += array('entity' => 'option_value', 'placeholder' => $placeholder, 'multiple' => $search, 'api' => array('params' => array('option_group_id' => $field->option_group_id)));
$qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
}
$qf->assign('customUrls', $customUrls);
break;
}
switch ($field->data_type) {
case 'Int':
// integers will have numeric rule applied to them.
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer');
$qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer');
} elseif ($widget == 'Text') {
$qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer');
}
break;
case 'Float':
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
$qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
} elseif ($widget == 'Text') {
$qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric');
}
break;
case 'Money':
if ($field->is_search_range && $search) {
$qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
$qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
} elseif ($widget == 'Text') {
$qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money');
}
break;
case 'Link':
$element->setAttribute('onfocus', "if (!this.value) {this.value='http://';}");
$element->setAttribute('onblur', "if (this.value == 'http://') {this.value='';}");
$element->setAttribute('class', "url");
$qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL');
break;
}
if ($field->is_view && !$search) {
$qf->freeze($elementName);
}
}
示例6: buildSearchForm
/**
* @param CRM_Core_Form $form
*/
static function buildSearchForm(&$form)
{
$dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee', "reset=1", FALSE, NULL, FALSE);
$form->assign('dataURLEventFee', $dataURLEventFee);
$eventId = $form->addEntityRef('event_id', ts('Event Name'), array('entity' => 'event', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0)));
$eventType = $form->addEntityRef('event_type_id', ts('Event Type'), array('entity' => 'option_value', 'placeholder' => ts('- any -'), 'select' => array('minimumInputLength' => 0), 'api' => array('params' => array('option_group_id' => 'event_type'))));
$form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select'));
CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
$status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
foreach ($status as $id => $Name) {
$form->_participantStatus =& $form->addElement('checkbox', "participant_status_id[{$id}]", NULL, $Name);
}
foreach (CRM_Event_PseudoConstant::participantRole() as $rId => $rName) {
$form->_participantRole =& $form->addElement('checkbox', "participant_role_id[{$rId}]", NULL, $rName);
}
$form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE);
$form->addYesNo('participant_pay_later', ts('Participant is Pay Later?'), TRUE);
$form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
$form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
$form->addRule('participant_fee_amount_low', ts('Please enter a valid money value.'), 'money');
$form->addRule('participant_fee_amount_high', ts('Please enter a valid money value.'), 'money');
// add all the custom searchable fields
$extends = array('Participant', 'Event');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('participantGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
}
}
}
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'participant_campaign_id');
$form->assign('validCiviEvent', TRUE);
$form->setDefaults(array('participant_test' => 0));
}
示例7: buildQuickForm
/**
* This function provides the HTML form elements that are specific
* to the Individual Contact Type
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*
* @return void
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
$nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2');
//prefix
$prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
if (isset($nameFields['Prefix']) && !empty($prefix)) {
$form->addSelect('prefix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Prefix')));
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
if (isset($nameFields['Formal Title'])) {
$form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']);
}
// first_name
if (isset($nameFields['First Name'])) {
$form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
}
//middle_name
if (isset($nameFields['Middle Name'])) {
$form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
}
// last_name
if (isset($nameFields['Last Name'])) {
$form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
}
// suffix
$suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
if (isset($nameFields['Suffix']) && $suffix) {
$form->addSelect('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix')));
}
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addElement('text', 'nick_name', ts('Nickname'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
// job title
// override the size for UI to look better
$attributes['job_title']['size'] = 30;
$form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
//Current Employer Element
$props = array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE);
$form->addEntityRef('employer_id', ts('Current Employer'), $props);
$attributes['source']['class'] = 'big';
$form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
}
if (!$inlineEditMode) {
$checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE);
if ($checkSimilar == NULL) {
$checkSimilar = 0;
}
$form->assign('checkSimilar', $checkSimilar);
//External Identifier Element
$form->add('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE);
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
$config = CRM_Core_Config::singleton();
CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
}
}