public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/functions.php
/**
 * Get a list of unit post objects that match the specified module ID.
 *
 * @since 1.0.0
 *
 * @param integer $moduleID The ID of the module to get the units for (0 = unassigned units).
 *
 * @return array A list of unit objects in the order that they appear.
 */
Get a list of unit post objects that match the specified module ID.

@param integer $moduleID The ID of the module to get the units for (0 = unassigned units).

@return array A list of unit objects in the order that they appear.
Get a list of unit post objects that match the specified module ID . @param integer $moduleID The ID of the module to get the units for ( 0 = unassigned units ) . @return array A list of unit objects in the order that they appear .
function WPCW_units_getListOfUnits( $moduleID ) {
	global $wpcwdb, $wpdb;
	$wpdb->show_errors();
	$current_user = wp_get_current_user();
	$SQL_USER_CONDITION = false;
	if ( is_admin() && ! user_can( $current_user, 'manage_wpcw_settings' ) ) {
		$SQL_USER_CONDITION = $wpdb->prepare( ' AND unit_author = %d', $current_user->ID );
	}
	$SQL = $wpdb->prepare( "
		SELECT *
		FROM $wpcwdb->units_meta
		WHERE parent_module_id = %d
		$SQL_USER_CONDITION
		ORDER BY unit_order ASC, unit_id ASC
	", $moduleID );
	$rawUnits = $wpdb->get_results( $SQL );
	if ( ! $rawUnits ) {
		return false;
	}
	$unitIDList = array();
	foreach ( $rawUnits as $rawUnit ) {
		$unitIDList[ $rawUnit->unit_id ] = $rawUnit;
	}
	$uniPostObjsArgs = array(
		'post_type' => 'course_unit',                
		'number'    => - 1,                            
		'orderby'   => 'none',                        
		'include'   => array_keys( $unitIDList )         List of posts to get.
	);
	 Check permissions
	if ( is_admin() && ! user_can( $current_user, 'manage_wpcw_settings' ) ) {
		$uniPostObjsArgs['post_author'] = $current_user->ID;
	}
	 Get Units
	$unitPostObjsRaw = get_posts( $uniPostObjsArgs );
	if ( ! $unitPostObjsRaw ) {
		return false;
	}
	 Re-order post objects so that they are ID => Object details, rather than 0 => Object, 1 => Object
	$unitPostObjs = array();
	foreach ( $unitPostObjsRaw as $obj ) {
		 Add our metadata
		$obj->unit_meta = $unitIDList[ $obj->ID ];
		$unitPostObjs[ $obj->ID ] = $obj;
	}
	 Use unit ordering from table to return actual ordering list.
	$unitDataRet = array();
	foreach ( $unitIDList as $unitID => $unitObj ) {
		if ( isset( $unitPostObjs[ $unitID ] ) ) {
			$unitDataRet[ $unitID ] = $unitPostObjs[ $unitID ];
		}
	}
	return $unitDataRet;
}
function WPCW_units_getListOfUnits ( $ moduleID ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; $ current_user = wp_get_current_user ( ) ; $ SQL_USER_CONDITION = false ; if ( is_admin ( ) && ! user_can ( $ current_user , 'manage_wpcw_settings' ) ) { $ SQL_USER_CONDITION = $ wpdb -> prepare ( ' AND unit_author = %d' , $ current_user -> ID ) ; } $ SQL = $ wpdb -> prepare ( " 
		SELECT *
		FROM  $ wpcwdb -> units_meta 
		WHERE parent_module_id = %d
		 $ SQL_USER_CONDITION 
		ORDER BY unit_order ASC, unit_id ASC
	 " , $ moduleID ) ; $ rawUnits = $ wpdb -> get_results ( $ SQL ) ; if ( ! $ rawUnits ) { return false ; } $ unitIDList = array ( ) ; foreach ( $ rawUnits as $ rawUnit ) { $ unitIDList [ $ rawUnit -> unit_id ] = $ rawUnit ; } $ uniPostObjsArgs = array ( 'post_type' => 'course_unit' , 'number' => - 1 , 'orderby' => 'none' , 'include' => array_keys ( $ unitIDList ) ) ; if ( is_admin ( ) && ! user_can ( $ current_user , 'manage_wpcw_settings' ) ) { $ uniPostObjsArgs [ 'post_author' ] = $ current_user -> ID ; } $ unitPostObjsRaw = get_posts ( $ uniPostObjsArgs ) ; if ( ! $ unitPostObjsRaw ) { return false ; } $ unitPostObjs = array ( ) ; foreach ( $ unitPostObjsRaw as $ obj ) { $ obj -> unit_meta = $ unitIDList [ $ obj -> ID ] ; $ unitPostObjs [ $ obj -> ID ] = $ obj ; } $ unitDataRet = array ( ) ; foreach ( $ unitIDList as $ unitID => $ unitObj ) { if ( isset ( $ unitPostObjs [ $ unitID ] ) ) { $ unitDataRet [ $ unitID ] = $ unitPostObjs [ $ unitID ] ; } } return $ unitDataRet ; }
Get a list of unit post objects that match the specified module ID.
Get a list of unit post objects that match the specified module ID .
// Current user // No list of associated IDs? Abort, and return false, as no units or unit objects. // Turn list into ID => meta list // Get list of IDs, and use this for WordPress query to get the full objects // Just course units // No limit, i.e. all // // List of posts to get. // Check permissions // Get Units // Re-order post objects so that they are ID => Object details, rather than 0 => Object, 1 => Object // Add our metadata // Use unit ordering from table to return actual ordering list.