本文整理汇总了PHP中FormElement::setTypeAsRadioButtons方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::setTypeAsRadioButtons方法的具体用法?PHP FormElement::setTypeAsRadioButtons怎么用?PHP FormElement::setTypeAsRadioButtons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::setTypeAsRadioButtons方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: WPCW_showPage_ImportExport_export
/**
* Show the export course page.
*/
function WPCW_showPage_ImportExport_export()
{
$page = new PageBuilder(true);
$page->showPageHeader(__('Export Training Course', 'wp_courseware'), '75%', WPCW_icon_getPageIconURL());
// Show form of courses that can be exported.
$form = new FormBuilder('wpcw_export');
$form->setSubmitLabel(__('Export Course', 'wp_courseware'));
// Course selection
$formElem = new FormElement('export_course_id', __('Course to Export', 'wp_courseware'), true);
$formElem->setTypeAsComboBox(WPCW_courses_getCourseList(__('--- Select a course to export ---', 'wp_courseware')));
$form->addFormElement($formElem);
// Options for what to export
$formElem = new FormElement('what_to_export', __('What to Export', 'wp_courseware'), true);
$formElem->setTypeAsRadioButtons(array('whole_course' => __('<b>All</b> - The whole course - including modules, units and quizzes.', 'wp_courseware'), 'just_course' => __('<b>Just the Course</b> - Just the course title, description and settings (no modules, units or quizzes).', 'wp_courseware'), 'course_modules' => __('<b>Course and Modules</b> - Just the course settings and module settings (no units or quizzes).', 'wp_courseware'), 'course_modules_and_units' => __('<b>Course, Modules and Units</b> - The course settings and module settings and units (no quizzes).', 'wp_courseware')));
$form->addFormElement($formElem);
$form->setDefaultValues(array('what_to_export' => 'whole_course'));
if ($form->formSubmitted()) {
// Do the full export
if ($form->formValid()) {
// If data is valid, export will be handled by export class.
} else {
$page->showListOfErrors($form->getListOfErrors(), __('Sorry, but unfortunately there were some errors. Please fix the errors and try again.', 'wp_courseware'));
}
}
// Show selection menu for import/export to save pages
WPCW_showPage_ImportExport_menu('export');
printf('<p class="wpcw_doc_quick">');
_e('When you export a course, you\'ll get an <b>XML file</b>, which you can then <b>import into another WordPress website</b> that\'s running <b>WP Courseware</b>.<br/>
When you export the course units with a course, just the <b>HTML to render images and video</b> will be copied, but the <b>actual images and video files will not be exported</b>.', 'wp_courseware');
printf('</p>');
echo $form->toString();
$page->showPageFooter();
}
示例2: showMembershipMappingLevels_specificLevel
/**
* Show the form for editing the specific courses a user can access based on what level that they have access to.
* @param PageBuilder $page The page rendering object.
* @param Array $levelDetails The list of level details
*/
private function showMembershipMappingLevels_specificLevel($page, $levelDetails)
{
// Show a nice summary of what level is being edited.
printf('<div id="wpcw_member_level_name_title">%s</div>', sprintf(__('Editing permissions for <b>%s</b> level with <b>%s</b>:', 'wp_courseware'), $levelDetails['name'], $this->extensionName));
// Get a list of course IDs that exist
$courses = WPCW_courses_getCourseList(false);
// Get list of courses already associated with level.
$courseListInDB = $this->getCourseAccessListForLevel($levelDetails['id']);
// Create the summary URL to return
$summaryURL = admin_url('admin.php?page=' . $this->extensionID);
// Update form...
$form = new FormBuilder('wpcw_member_levels_edit');
$form->setSubmitLabel(__('Save Changes', 'wp_courseware'));
// Create list of courses using checkboxes (max of 2 columns)
$elem = new FormElement('level_courses', __('Courses user can access with this level', 'wp_courseware'), false);
$elem->setTypeAsCheckboxList($courses);
$elem->checkboxListCols = 2;
$form->addFormElement($elem);
// Create retroactive option
$elem = new FormElement('retroactive_assignment', __('Do you want to retroactively assign these courses to current customers?', 'wp_courseware'), true);
$elem->setTypeAsRadioButtons(array('Yes' => __('Yes', 'wp_courseware'), 'No' => __('No', 'wp_courseware')));
$form->addFormElement($elem);
$form->setDefaultValues(array('retroactive_assignment' => 'No'));
// Normally would check for errors too, but there's not a lot to check here.
if ($form->formSubmitted()) {
if ($form->formValid()) {
$mapplingList = $form->getValue('level_courses');
global $wpdb, $wpcwdb;
$wpdb->show_errors();
// Remove all previous level mappings (as some will have been removed)
$wpdb->query($wpdb->prepare("\n\t\t\t\t\t\tDELETE \n\t\t\t\t\t\tFROM {$wpcwdb->map_member_levels} \n\t\t\t\t\t\tWHERE member_level_id = %s\n\t\t\t\t\t", $levelDetails['id']));
// Add all of the new mappings the user has chosen.
if ($mapplingList && count($mapplingList) > 0) {
foreach ($mapplingList as $courseID => $itemState) {
$wpdb->query($wpdb->prepare("\n\t\t\t\t\t\t\t\tINSERT INTO {$wpcwdb->map_member_levels} \n\t\t\t\t\t\t\t\t(course_id, member_level_id) \n\t\t\t\t\t\t\t\tVALUES (%d, %s)\n\t\t\t\t\t\t\t", $courseID, $levelDetails['id']));
}
}
// Get retroactive selection
$retroactive_assignment = $form->getValue('retroactive_assignment');
// Call the retroactive assignment function passing the member level ID
if ($retroactive_assignment == 'Yes' && count($mapplingList) >= 0) {
$level_ID = $levelDetails['id'];
$this->retroactive_assignment($level_ID);
//$page->showMessage(__('All members were successfully retroactively enrolled into the selected courses.', 'wp_courseware'));
}
// Show a success message.
$page->showMessage(__('Level and course permissions successfully updated.', 'wp_courseware') . '<br/><br/>' . sprintf(__('Want to return to the <a href="%s">Course Access Settings summary</a>?', 'wp_courseware'), $summaryURL));
}
// if ($form->formValid())
} else {
$form->setDefaultValues(array('level_courses' => $courseListInDB));
}
// Show the form
echo $form->toString();
printf('<a href="%s" class="button-secondary">%s</a>', $summaryURL, __('« Return to Course Access Settings summary', 'wp_courseware'));
}
示例3: createElementObject
/**
* Convert an array of details into a form element.
* @param String $fieldName The name of the form element
* @param Array $fieldDetails The list of details for the form element.
*/
protected function createElementObject($fieldName, $fieldDetails)
{
// Extract fields
$label = $this->formObj->getArrayValue($fieldDetails, 'label');
$type = $this->formObj->getArrayValue($fieldDetails, 'type');
// Required 'true' or true are valid
$required = $this->formObj->getArrayValue($fieldDetails, 'required');
$required = $required == 'true' || $required == '1';
// Start creating form element if anything other than a break.
$elem = false;
if ($type != 'break') {
$elem = new FormElement($fieldName, $label, $required);
}
// Handle specific types
switch ($type) {
// Text Area
case 'textarea':
$rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0;
if ($rows == 0) {
$rows = 5;
}
$elem->setTypeAsTextArea($rows, 70);
break;
// Select/Dropdown
// Select/Dropdown
case 'select':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsComboBox($options);
break;
// Radio Buttons
// Radio Buttons
case 'radio':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsRadioButtons($options);
break;
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// File upload
// File upload
case 'uploadfile':
$elem->setTypeAsUploadFile($this->formObj->getArrayValue($fieldDetails, 'show_existing'), $this->formObj->getArrayValue($fieldDetails, 'valid_if_value'));
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
//.........这里部分代码省略.........
示例4: createElementObject
/**
* Convert an array of details into a form element.
* @param String $fieldName The name of the form element
* @param Array $fieldDetails The list of details for the form element.
*/
protected function createElementObject($fieldName, $fieldDetails)
{
// Extract fields
$label = $this->formObj->getArrayValue($fieldDetails, 'label');
$type = $this->formObj->getArrayValue($fieldDetails, 'type');
// Required 'true' or true are valid
$required = $this->formObj->getArrayValue($fieldDetails, 'required');
$required = $required == 'true' || $required == '1';
// Start creating form element if anything other than a break.
$elem = false;
if ($type != 'break') {
$elem = new FormElement($fieldName, $label, $required);
}
// Handle specific types
switch ($type) {
// Text Area
case 'textarea':
$rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0;
if ($rows == 0) {
$rows = 5;
}
$elem->setTypeAsTextArea($rows, 70);
break;
// Select/Dropdown
// Select/Dropdown
case 'select':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsComboBox($options);
break;
// Radio Buttons
// Radio Buttons
case 'radio':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsRadioButtons($options);
break;
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
// Add optional fields
if ($type != 'break') {
// Element description
if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) {
$elem->description = $desc;
//.........这里部分代码省略.........