public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/admin/functions.php
/**
 * Create a dropdown tag list.
 *
 * @since 1.0.0
 *
 * @param boolean $showBlank If true, add a blank to the start.
 * @param string  $fieldName The name of the HTML field.
 * @param string  $currentTag If specified, the current tag to mark as selected.
 * @param string  $cssClassName The CSS name for the field.
 * @param boolean $showQuestionStr If true, show the string 'questions' after each tag.
 * @param boolean $showCountOfQuestions If true, then show the count of questions per tag.
 *
 * @return string The HTML for rendering the dropdown.
 */
Create a dropdown tag list.

@param boolean $showBlank If true, add a blank to the start.
@param string  $fieldName The name of the HTML field.
@param string  $currentTag If specified, the current tag to mark as selected.
@param string  $cssClassName The CSS name for the field.
@param boolean $showQuestionStr If true, show the string 'questions' after each tag.
@param boolean $showCountOfQuestions If true, then show the count of questions per tag.

@return string The HTML for rendering the dropdown.
Create a dropdown tag list . @param boolean $showBlank If true add a blank to the start . @param string $fieldName The name of the HTML field . @param string $currentTag If specified the current tag to mark as selected . @param string $cssClassName The CSS name for the field . @param boolean $showQuestionStr If true show the string ' questions ' after each tag . @param boolean $showCountOfQuestions If true then show the count of questions per tag . @return string The HTML for rendering the dropdown .
function WPCW_questions_tags_getTagDropdown( $showBlank = false, $fieldName, $currentTag, $cssClassName, $showQuestionStr = false, $showCountOfQuestions = true ) {
	global $wpcwdb, $wpdb;
	$wpdb->show_errors();
	$tagsToShow   = array();
	$current_user = wp_get_current_user();
	static $tagsToShow_cached;
	if ( ! $tagsToShow_cached ) {
		$TAG_SQL_QUERY = "SELECT * FROM $wpcwdb->question_tags ORDER BY question_tag_name ASC";
		if ( ! user_can( $current_user, 'manage_wpcw_settings' ) ) {
			$TAG_SQL_QUERY = $wpdb->prepare( "SELECT * FROM $wpcwdb->question_tags WHERE question_tag_author = %d ORDER BY question_tag_name ASC;", $current_user->ID );
		}
		$tagList = $wpdb->get_results( $TAG_SQL_QUERY );
		if ( ! empty( $tagList ) ) {
			foreach ( $tagList as $singleTag ) {
				$tagsToShow[ $singleTag->question_tag_id ] = array(
					'label' => $singleTag->question_tag_name,
					'data'  => $singleTag->question_tag_usage,
					'data2' => $singleTag->question_tag_name,
				);
				if ( is_admin() && user_can( $current_user, 'manage_wpcw_settings' ) && $singleTag->question_tag_author != $current_user->ID ) {
					foreach ( $tagList as $checkTag ) {
						if ( $checkTag->question_tag_author == $current_user->ID && $checkTag->question_tag_name == $singleTag->question_tag_name ) {
							if ( $tagAuthor = get_user_by( 'id', $singleTag->question_tag_author ) ) {
								$tagsToShow[ $singleTag->question_tag_id ]['label'] .= sprintf( ' [%s] ', $tagAuthor->display_name );
							}
						}
					}
				}
				if ( $showCountOfQuestions ) {
					$tagsToShow[ $singleTag->question_tag_id ]['label'] .= ' (' . $singleTag->question_tag_usage . ( $showQuestionStr ? ' ' . __( 'Questions', 'wp-courseware' ) : '' ) . ')';
				}
			}
		}
		$tagsToShow_cached = $tagsToShow;
	} else {
		$tagsToShow = $tagsToShow_cached;
	}
	if ( $showBlank ) {
		$tagsToShow = array( '' => $showBlank ) + $tagsToShow;
	}
	return WPCW_forms_createDropdown( $fieldName, $tagsToShow, $currentTag, false, $cssClassName );
}
function WPCW_questions_tags_getTagDropdown ( $ showBlank = false , $ fieldName , $ currentTag , $ cssClassName , $ showQuestionStr = false , $ showCountOfQuestions = true ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; $ tagsToShow = array ( ) ; $ current_user = wp_get_current_user ( ) ; static $ tagsToShow_cached ; if ( ! $ tagsToShow_cached ) { $ TAG_SQL_QUERY = " SELECT * FROM  $ wpcwdb -> question_tags  ORDER BY question_tag_name ASC " ; if ( ! user_can ( $ current_user , 'manage_wpcw_settings' ) ) { $ TAG_SQL_QUERY = $ wpdb -> prepare ( " SELECT * FROM  $ wpcwdb -> question_tags  WHERE question_tag_author = %d ORDER BY question_tag_name ASC; " , $ current_user -> ID ) ; } $ tagList = $ wpdb -> get_results ( $ TAG_SQL_QUERY ) ; if ( ! empty ( $ tagList ) ) { foreach ( $ tagList as $ singleTag ) { $ tagsToShow [ $ singleTag -> question_tag_id ] = array ( 'label' => $ singleTag -> question_tag_name , 'data' => $ singleTag -> question_tag_usage , 'data2' => $ singleTag -> question_tag_name , ) ; if ( is_admin ( ) && user_can ( $ current_user , 'manage_wpcw_settings' ) && $ singleTag -> question_tag_author != $ current_user -> ID ) { foreach ( $ tagList as $ checkTag ) { if ( $ checkTag -> question_tag_author == $ current_user -> ID && $ checkTag -> question_tag_name == $ singleTag -> question_tag_name ) { if ( $ tagAuthor = get_user_by ( 'id' , $ singleTag -> question_tag_author ) ) { $ tagsToShow [ $ singleTag -> question_tag_id ] [ 'label' ] .= sprintf ( ' [%s] ' , $ tagAuthor -> display_name ) ; } } } } if ( $ showCountOfQuestions ) { $ tagsToShow [ $ singleTag -> question_tag_id ] [ 'label' ] .= ' (' . $ singleTag -> question_tag_usage . ( $ showQuestionStr ? ' ' . __ ( 'Questions' , 'wp-courseware' ) : '' ) . ')' ; } } } $ tagsToShow_cached = $ tagsToShow ; } else { $ tagsToShow = $ tagsToShow_cached ; } if ( $ showBlank ) { $ tagsToShow = array ( '' => $ showBlank ) + $ tagsToShow ; } return WPCW_forms_createDropdown ( $ fieldName , $ tagsToShow , $ currentTag , false , $ cssClassName ) ; }
Create a dropdown tag list.
Create a dropdown tag list .
// Save the SQL query, used the cached variable if available. // Default Query // $TAG_SQL_QUERY = "SELECT * FROM $wpcwdb->question_tags WHERE question_tag_usage > 0 ORDER BY question_tag_name ASC"; // If a teacher or not admin // Create downdown with tag selection and number of questions that exist for that tag). // The HTML5 data tag is useful for setting the max on spinners. // Add Label to those tags that are the same, but have different authors. // Add count if requested. // Create the blank item to use, added to the front, but not cached. // Save to static variable to save execution again in same page load.