/** * 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 at this level', 'wp_courseware'), false); $elem->setTypeAsCheckboxList($courses); $elem->checkboxListCols = 2; $form->addFormElement($elem); // 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'])); } } // 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')); }
public function testGetValue() { $this->element->value('test'); $this->assertSame('test', $this->element->getValue()); }