root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/'; if (groups_is_user_member( get_current_user_id(), $bp->groups->current_group->id )) bp_core_new_subnav_item( array( 'name' => 'Grades', 'slug' => 'grades', 'parent_slug' => $bp->groups->current_group->slug, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'screen_function' => 'raritanval_grades_function_to_show_screen', 'position' => 1000 ) ); } add_action( 'wp', 'raritanval_grades_page'); function raritanval_grades_function_to_show_screen() { add_action( 'bp_template_title', 'raritanval_grades_function_to_show_screen_title' ); add_action( 'bp_template_content', 'raritanval_grades_function_to_show_screen_content' ); $templates = array('groups/single/plugins.php','plugin-template.php'); if( strstr( locate_template($templates), 'groups/single/plugins.php' ) ) { bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/single/plugins' ) ); } else { bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) ); } } function raritanval_grades_function_to_show_screen_title() { echo 'Grades'; } function raritanval_grades_function_to_show_screen_content() { global $bp; $args = array( 'post_type' => 'grade', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'cisy114_student', 'value' => get_current_user_id() ), array( 'key' => 'cisy114_class_group', 'value' => $bp->groups->current_group->id ) ), //'meta_key' => 'cisy114_student', //'meta_value' => $bp->displayed_user->id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); $grades[] = array( "id" => get_the_id(), "name" => get_the_title(), "score" => $meta["cisy114_score"][0], "outof" => $meta["cisy114_outof"][0], "class_group" => $meta["cisy114_class_group"][0], "notes" => get_the_content(), ); } } /* Restore original Post Data */ wp_reset_postdata(); if (count($grades) == 0) echo '

No grades currently on file.

'; else { usort( $grades, function ($a, $b) { return strnatcmp($a['name'], $b['name']); } ); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($grades as $grade) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
Assignment:Score:Notes:
'.$grade["name"].''.$grade["score"].'/'.$grade["outof"].''.$grade["notes"].'
'; } }//end raritanval_grades_function_to_show_screen_content function cisy114_nav() { global $bp; if (current_user_can( 'administrator' )) { // (get_current_user_id() == $bp->displayed_user->id) | bp_core_new_nav_item( array( 'name' => __( 'Edit Grades', 'buddypress' ), 'slug' => 'edit-grades', 'position' => 1000, 'screen_function' => 'cisy114_link', 'show_for_displayed_user' => true, 'default_subnav_slug' => 'edit-grades', 'item_css_id' => 'grades' ) ); } } add_action( 'bp_setup_nav', 'cisy114_nav', 1000 ); function cisy114_title() { echo 'My Grades'; } function cisy114_content() { global $bp; if ( current_user_can( 'administrator' ) ) { if (isset($_REQUEST["cisy114_kill"])) { wp_delete_post(sanitize_text_field($_REQUEST["cisy114_kill"]),true); echo '

Grade deleted.

'; } elseif (isset($_REQUEST["cisy114_submit"])) { $assignment = array( "name" => sanitize_text_field($_REQUEST["cisy114_assignment"]), "score" => sanitize_text_field($_REQUEST["cisy114_score"]), "outof" => sanitize_text_field($_REQUEST["cisy114_outof"]), "notes" => sanitize_text_field($_REQUEST["cisy114_notes"]), "class_group" => sanitize_text_field($_REQUEST["cisy114_class_group"]) ); //Assignment shortcuts if ($_REQUEST["cisy114_assignment_pulldown"] != "") { $assignment["name"] = sanitize_text_field($_REQUEST["cisy114_assignment_pulldown"]); } //Notes shortcuts if ($_REQUEST["cisy114_notes_pulldown"] != "") { if ($_REQUEST["cisy114_notes_pulldown"] == "[superlative]") { $superlatives = array( "Good job!", "Great!", "Excellent!", "Wonderful!", "Magnificent!", "Super!", "Perfect!", "Nailed it!", "Boom!", "Spot on!", "Good job! :-)", "Great! :-)", "Excellent! :-)", "Wonderful! :-)", "Magnificent! :-)", "Super! :-)", "Perfect! :-)", "Nailed it! :-)", "Boom! :-)", "Spot on! :-)", "All the pieces in place. :-)", "Wonderfully done. :-)", "Excellently done. :-)" ); $assignment["notes"] = $superlatives[array_rand($superlatives)]; } else { $assignment["notes"] = sanitize_text_field($_REQUEST["cisy114_notes_pulldown"]); } } // Initialize the page ID to -1. This indicates no action has been taken. $post_id = -1; // Set the post ID so that we know the post was created successfully $post_id = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_title' => $assignment["name"], 'post_status' => 'publish', 'post_type' => 'grade', 'post_content' => $assignment["notes"] ) ); if ($post_id == -1) { echo '

There was an error adding the grade.

'; } else { //Add the metadata add_post_meta($post_id, 'cisy114_score', $assignment["score"], true); add_post_meta($post_id, 'cisy114_outof', $assignment["outof"], true); add_post_meta($post_id, 'cisy114_class', $assignment["class"], true); add_post_meta($post_id, 'cisy114_class_group', $assignment["class_group"], true); add_post_meta($post_id, 'cisy114_student', $bp->displayed_user->id, true); echo '

Grade "'.$assignment["name"].'" added.

'; } } } $args = array( 'post_type' => 'grade', 'meta_key' => 'cisy114_student', 'meta_value' => $bp->displayed_user->id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $grades = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); $cg = $meta["cisy114_class_group"][0]; if ($cg == "") $cg = "0"; $grades[$cg][] = array( "id" => get_the_id(), "name" => get_the_title(), "score" => $meta["cisy114_score"][0], "outof" => $meta["cisy114_outof"][0], "class_group" => $meta["cisy114_class_group"][0], "notes" => get_the_content(), ); } } /* Restore original Post Data */ wp_reset_postdata(); //print "
";
	//print_r($grades);
	
	if ( (get_current_user_id() == $bp->displayed_user->id) |  current_user_can( 'administrator' )) {
		
		
		//Nab all the class groups they are a part of.
		$class_groups = array();
		$args = array(
			'per_page' => -1,
			'user_id' => $bp->displayed_user->id
		);
		if ( bp_has_groups ( $args ) ) {
			while ( bp_groups() ) { bp_the_group();
				$class_groups[bp_get_group_id()] = bp_get_group_name();
			}
		}
		
		
		//Keep grade names as an index to check later
		$have = array();
		
		
		if (count($grades) == 0) echo 'No grades currently on file.';
	
		else { 
			
			foreach ($grades as $groupid => $class_grades) {
			
				usort(	$class_grades,
						function ($a, $b) {
							return strnatcmp($a['name'], $b['name']);
						}
				);
				
				//Messy messy...
				if ($groupid == 0) {
					$group_name = "Uncategorized";
					$group_slug = "#";
				}
				else {
					$group = new BP_Groups_Group($groupid, true);
					$group_name = $group->name;
					$group_slug = $group->slug;
					unset($group);
				}
				
				echo '

'.$group_name.' ('.$groupid.')

'; echo ''; echo ''; echo ''; echo ''; echo ''; if (current_user_can('administrator')) echo ''; echo ''; foreach ($class_grades as $grade) { echo ''; echo ''; $have[$grade["name"]]++; echo ''; echo ''; if (current_user_can('administrator')) echo ''; //echo ''; echo ''; } echo '
Assignment:Score:Notes:Delete...
'.$grade["name"].''.$grade["score"].'/'.$grade["outof"].''.$grade["notes"].'
#
'.$grade["class_group"].'
'; } } } else { echo "You may not view other students' grades."; } if ( current_user_can( 'administrator' ) ) : ?>

Professor Menu

Assignment: or
Class:
Score: out of
Notes: or
_x( 'Grades', 'post type general name' ), 'singular_name' => _x( 'Grade', 'post type singular name' ), 'add_new' => _x( 'Add New', 'book' ), 'add_new_item' => __( 'Add New Grade' ), 'edit_item' => __( 'Edit Grade' ), 'new_item' => __( 'New Grade' ), 'all_items' => __( 'All Grades' ), 'view_item' => __( 'View Grade' ), 'search_items' => __( 'Search Grades' ), 'not_found' => __( 'No grades found' ), 'not_found_in_trash' => __( 'No grades found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Grades' ); $args = array( 'labels' => $labels, 'description' => 'Holds student grades.', 'public' => false, 'publicly_queryable' => false, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'custom-fields'), 'has_archive' => false, 'capabilities' => array( 'publish_posts' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'edit_post' => 'manage_options', 'delete_post' => 'manage_options', 'read_post' => 'manage_options', ), 'hierarchical' => false, 'menu_position' => 10, 'show_ui' => true, ); register_post_type( 'grade', $args ); } add_action( 'init', 'cisy114_register_post_type' ); //EMAIL DOMAIN NAME RESTRICTION add_action('registration_errors', 'cisy_restrict_domains', 10, 3); function cisy_restrict_domains( $errors, $login, $email ) { $whitelist = array( 'raritanval.edu', 'stu.raritanval.edu' ); if ( is_email($email) ) { $parts = explode('@', $email); $domain = $parts[count($parts)-1]; if ( !in_array(strtolower($domain), $whitelist) ) { $errors->add('email_domain', __('ERROR: You may ONLY register with an @raritanval.edu or @stu.raritanval.edu email address. No exceptions. THIS IS SPARTA!')); } } return $errors; } //CLASS ROSTER function raritanval_allgrades_page(){ if (!current_user_can( 'administrator' )) return; global $bp; $groups_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/'; if (groups_is_user_member( get_current_user_id(), $bp->groups->current_group->id )) bp_core_new_subnav_item( array( 'name' => 'Grade Sheet', 'slug' => 'grade-sheet', 'parent_slug' => $bp->groups->current_group->slug, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'screen_function' => 'raritanval_allgrades_function_to_show_screen', 'position' => 1001 ) ); } add_action( 'wp', 'raritanval_allgrades_page'); function raritanval_allgrades_function_to_show_screen() { add_action( 'bp_template_title', 'raritanval_allgrades_function_to_show_screen_title' ); add_action( 'bp_template_content', 'raritanval_allgrades_function_to_show_screen_content' ); $templates = array('groups/single/plugins.php','plugin-template.php'); if( strstr( locate_template($templates), 'groups/single/plugins.php' ) ) { bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/single/plugins' ) ); } else { bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'plugin-template' ) ); } } function raritanval_allgrades_function_to_show_screen_title() { echo 'Grade Sheet'; } function raritanval_allgrades_function_to_show_screen_content() { global $bp; $args = array( 'post_type' => 'grade', 'meta_query' => array( array( 'key' => 'cisy114_class_group', 'value' => $bp->groups->current_group->id ) ), //'meta_key' => 'cisy114_student', //'meta_value' => $bp->displayed_user->id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); $grades[$meta["cisy114_student"][0]][trim(get_the_title())] = array( "id" => get_the_id(), "name" => get_the_title(), "score" => $meta["cisy114_score"][0], "outof" => $meta["cisy114_outof"][0], "class_group" => $meta["cisy114_class_group"][0], //"notes" => get_the_content(), ); } } /* Restore original Post Data */ wp_reset_postdata(); if (count($grades) == 0) echo '

No grades currently on file.

'; else { //print_r($grades); //Build the assignment list //Cycle through all grades and put together a list of assignment names $assignment_list = array(); foreach ($grades as $studentid => $their_grades) { $assignment_list = array_unique(array_merge($assignment_list,array_keys($their_grades))); } //Sort the assignment names appropriately usort( $assignment_list, function ($a, $b) { return strnatcmp($a, $b); } ); echo '
'; echo ''; echo ''; echo ''; echo ''; foreach ($assignment_list as $assignment) echo ''; echo ''; echo ''; $count = 1; //I'll *eventually* alphabetize these... foreach ($grades as $studentid => $grade) { //User's name $studentname = get_userdata( $studentid ); $studentslug = $studentname->user_login; $studentname = $studentname->last_name.', '.$studentname->first_name; echo ''; $qc_score = 0; $qc_outof = 0; echo ''; echo ''; foreach ($assignment_list as $assignment) { $score = $grade[$assignment]["score"]; $outof = $grade[$assignment]["outof"]; $bg = "inherit"; $g = 0; //Choose color if (is_numeric($score) & is_numeric($outof) ){ $qc_score += $score; $qc_outof += $outof; $g = round($score/$outof,2); if ($g >= .80) $bg = "#EFE"; elseif ($g >= .60) $bg = "#FFE"; else $bg = "#FEE"; } echo ''; } $g = round($qc_score/$qc_outof,2); $bg = "inherit"; if ($g >= .80) $bg = "#EFE"; elseif ($g >= .70) $bg = "#FFE"; elseif ($g >= .60) $bg = "#FEE"; else $bg = "#F00"; echo ''; echo ''; } echo '
#Student:'.$assignment.':[QC]
'.($count++).''.$studentname.''.$g.''.$g.'
'; echo '
'; } }//end raritanval_allgrades_function_to_show_screen_content /* function cisy114_nav() { global $bp; if ( (get_current_user_id() == $bp->displayed_user->id) | current_user_can( 'administrator' )) { bp_core_new_nav_item( array( 'name' => __( 'Grades', 'buddypress' ), 'slug' => 'grades', 'position' => 1000, 'screen_function' => 'cisy114_link', 'show_for_displayed_user' => true, 'default_subnav_slug' => 'grades', 'item_css_id' => 'grades' ) ); } } add_action( 'bp_setup_nav', 'cisy114_nav', 1000 ); function cisy114_title() { echo 'My Grades'; } function cisy114_content() { global $bp; if ( current_user_can( 'administrator' ) ) { if (isset($_REQUEST["cisy114_kill"])) { wp_delete_post(sanitize_text_field($_REQUEST["cisy114_kill"]),true); echo '

Grade deleted.

'; } elseif (isset($_REQUEST["cisy114_submit"])) { $assignment = array( "name" => sanitize_text_field($_REQUEST["cisy114_assignment"]), "score" => sanitize_text_field($_REQUEST["cisy114_score"]), "outof" => sanitize_text_field($_REQUEST["cisy114_outof"]), "notes" => sanitize_text_field($_REQUEST["cisy114_notes"]) ); // Initialize the page ID to -1. This indicates no action has been taken. $post_id = -1; // Set the post ID so that we know the post was created successfully $post_id = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_title' => $assignment["name"], 'post_status' => 'publish', 'post_type' => 'grade', 'post_content' => $assignment["notes"] ) ); if ($post_id == -1) { echo '

There was an error adding the grade.

'; } else { //Add the metadata add_post_meta($post_id, 'cisy114_score', $assignment["score"], true); add_post_meta($post_id, 'cisy114_outof', $assignment["outof"], true); add_post_meta($post_id, 'cisy114_student', $bp->displayed_user->id, true); echo '

Grade "'.$assignment["name"].'" added.

'; } } } $args = array( 'post_type' => 'grade', 'meta_key' => 'cisy114_student', 'meta_value' => $bp->displayed_user->id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $grades = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); $grades[] = array( "id" => get_the_id(), "name" => get_the_title(), "score" => $meta["cisy114_score"][0], "outof" => $meta["cisy114_outof"][0], "notes" => get_the_content(), ); } } // Restore original Post Data wp_reset_postdata(); //print "
";
	//print_r($grades);
	
	if ( (get_current_user_id() == $bp->displayed_user->id) |  current_user_can( 'administrator' )) {
	
		if (count($grades) == 0) echo 'No grades currently on file.';
	
		else { 
	
			usort(	$grades,
					function ($a, $b) {
						return strnatcmp($a['name'], $b['name']);
					}
			);
	
		
			echo '';
			echo '';
			echo '';
			echo '';
			echo '';
			if (current_user_can('administrator')) echo '';
			echo '';
			foreach ($grades as $grade) {
				echo '';
				echo '';
				echo '';
				echo '';
				if (current_user_can('administrator')) echo '';
				echo '';
			}
			echo '
Assignment:Score:Notes:Delete...
'.$grade["name"].''.$grade["score"].'/'.$grade["outof"].''.$grade["notes"].'
#
'; } } else { echo "You may not view other students' grades."; } if ( current_user_can( 'administrator' ) ) : ?>

Professor Menu

Assignment Score: out of
_x( 'Grades', 'post type general name' ), 'singular_name' => _x( 'Grade', 'post type singular name' ), 'add_new' => _x( 'Add New', 'book' ), 'add_new_item' => __( 'Add New Grade' ), 'edit_item' => __( 'Edit Grade' ), 'new_item' => __( 'New Grade' ), 'all_items' => __( 'All Grades' ), 'view_item' => __( 'View Grade' ), 'search_items' => __( 'Search Grades' ), 'not_found' => __( 'No grades found' ), 'not_found_in_trash' => __( 'No grades found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Grades' ); $args = array( 'labels' => $labels, 'description' => 'Holds student grades.', 'public' => false, 'publicly_queryable' => false, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'custom-fields'), 'has_archive' => false, 'capabilities' => array( 'publish_posts' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'edit_post' => 'manage_options', 'delete_post' => 'manage_options', 'read_post' => 'manage_options', ), 'hierarchical' => false, 'menu_position' => 10, 'show_ui' => true, ); register_post_type( 'grade', $args ); } add_action( 'init', 'cisy114_register_post_type' ); // */ ?>