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 '
Assignment: | '; echo 'Score: | '; echo 'Notes: | '; echo '
---|---|---|
'.$grade["name"].' | '; echo ''.$grade["score"].'/'.$grade["outof"].' | '; echo ''.$grade["notes"].' | '; 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 '
Assignment: | '; echo 'Score: | '; echo 'Notes: | '; if (current_user_can('administrator')) echo 'Delete... | '; echo '|
---|---|---|---|---|
'.$grade["name"].' | '; $have[$grade["name"]]++; echo ''.$grade["score"].'/'.$grade["outof"].' | '; echo ''.$grade["notes"].' | '; if (current_user_can('administrator')) echo ''; //echo ' | '.$grade["class_group"].' | '; echo '
# | '; echo 'Student: | '; foreach ($assignment_list as $assignment) echo ''.$assignment.': | '; echo '[QC] | '; echo '
---|---|---|---|
'.($count++).' | '; echo ''.$studentname.' | '; 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.' | '; } $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 ''.$g.' | '; 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 '
Assignment: | '; echo 'Score: | '; echo 'Notes: | '; if (current_user_can('administrator')) echo 'Delete... | '; echo '
---|---|---|---|
'.$grade["name"].' | '; echo ''.$grade["score"].'/'.$grade["outof"].' | '; echo ''.$grade["notes"].' | '; if (current_user_can('administrator')) echo ''; echo ' |