'Class Topics', "slug" => 'topics' ); parent::init($args); } /* * Display the topics as they are. */ public function display() { global $bp; $args = array( 'post_type' => 'cisy_topic', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $topics = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); if ($meta["cisy_visible"][0] != "true") continue; $topics[] = array( "id" => get_the_id(), "name" => get_the_title(), "body" => get_the_content(), "begins" => $meta["cisy_date_begins"][0], "begins_ts" => strtotime($meta["cisy_date_begins"][0]), "ends" => $meta["cisy_date_ends"][0], "ends_ts" => strtotime($meta["cisy_date_ends"][0]), ); } } //If there are no posts else { ?>

Class Topics:

There are presently no class topics posted.

Class Topics:

Date Topic

'⟶ Edit', "slug" => 'edit-topics', "access" => 'admin', "show_tab" => 'admin' ); parent::init($args); } /* * Figure out what to display. */ public function display() { global $bp; if (isset($_POST["add_new_topic"])) $this->add_topic_form(); elseif (isset($_POST["add_topic_submit"])) $this->add_topic_submit(); elseif (isset($_POST["delete_topic"])) $this->delete_topic(); elseif (isset($_POST["edit_topic"])) $this->edit_topic(); elseif (isset($_POST["edit_topic_submit"])) $this->edit_topic_submit(); else $this->display_topics(); } /* * Display the topics as they are. */ public function display_topics() { global $bp; echo '

Edit Topics:

'; $args = array( 'post_type' => 'cisy_topic', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $topics = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $topics[] = array( "id" => get_the_id(), "name" => get_the_title(), "body" => get_the_content(), "begins" => $meta["cisy_date_begins"][0], "begins_ts" => strtotime($meta["cisy_date_begins"][0]), "ends" => $meta["cisy_date_ends"][0], "ends_ts" => strtotime($meta["cisy_date_ends"][0]), "visible" => $meta["cisy_visible"][0] ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //print_r($topics); //Sort the topics so they're in chronological order usort($topics, function($a,$b) { if ($a["begins_ts"] == $b["begins_ts"]) return 0; return ($a["begins_ts"] < $b["begins_ts"]) ? -1 : 1; }); $counter = 1; ?>
Date Topic


[GroupID: ]

" placeholder="Topic Title"/>

Add New Topic:

topic_form(); ?>
fields as $f) $add[$f] = $_POST[$f]; //Scrub'em foreach ($add as $k=>$a) $add[$k] = sanitize_text_field($a); //Add fields that need to be scrubbed differently $the_title = sanitize_text_field($_POST["the_title"]); $the_content = $_POST["the_content"]; //Create the new Topic post // 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' => $the_title, 'post_status' => 'publish', 'post_type' => 'cisy_topic', 'post_content' => $the_content ) ); if ($post_id == -1) { echo '

There was an error adding the topic.

'; } else { //Add the metadata //Special add_post_meta($post_id, 'cisy_group', bp_get_group_id(), true); //From the list foreach ($add as $k=>$a) add_post_meta($post_id, $a, $k, true); echo '

Topic "'.$the_title.'" added.

'; } //Add the metadata //Tell the user it's done //Display the topics list below it $this->display_topics(); }//END add_topic_submit /* * Deletes a topic. */ function delete_topic() { if (!isset($_POST["the_topic"])) { echo "

You didn't specify a topic to delete.

"; $this->display_topics(); return; } if (!is_numeric($_POST["the_topic"])) { echo "

That isn't a valid topic to delete.

"; $this->display_topics(); return; } //Sanitize the id $topic_id = intval($_POST["the_topic"]); $topic = get_post($topic_id); if ($topic === null) { echo "

That isn't a valid topic to delete.

"; $this->display_topics(); return; } //Snag metadata $meta = get_post_meta($topic_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That topic does not belong to this class.

"; $this->display_topics(); return; } wp_delete_post($topic_id); echo "

Topic deleted!

"; $this->display_topics(); } /* * Edit a topic. */ public function edit_topic() { global $bp; if (!isset($_POST["the_topic"])) { echo "

You didn't specify a topic to edit.

"; $this->display_topics(); return; } if (!is_numeric($_POST["the_topic"])) { echo "

That isn't a valid topic to edit.

"; $this->display_topics(); return; } //Sanitize the id $topic_id = intval($_POST["the_topic"]); $topic = get_post($topic_id); if ($topic === null) { echo "

That isn't a valid topic to edit.

"; $this->display_topics(); return; } //Snag metadata $meta = get_post_meta($topic_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That topic does not belong to this class.

"; $this->display_topics(); return; } $data = array(); //Load title and content $data["the_title"] = $topic->post_title; $data["the_content"] = $topic->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; /* $data = array( "the_title" => $topic->post_title, "the_topic_body" => $topic->post_content, "the_topic_date_begins" => $meta["cisy_date_begins"][0], "the_topic_date_ends" => $meta["cisy_date_ends"][0], );*/ ?>

Edit Topic:

topic_form($data); ?>
You didn't specify a topic to edit.

"; $this->display_topics(); return; } if (!is_numeric($_POST["the_topic"])) { echo "

That isn't a valid topic to edit.

"; $this->display_topics(); return; } //Sanitize the id $topic_id = intval($_POST["the_topic"]); $topic = get_post($topic_id); if ($topic === null) { echo "

That isn't a valid topic to edit.

"; $this->display_topics(); return; } //Snag metadata $meta = get_post_meta($topic_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That topic does not belong to this class.

"; $this->display_topics(); return; } //Grab all inputs $the_title = $_POST["the_title"]; $the_content = $_POST["the_content"]; $meta = array(); foreach ($this->fields as $f) $meta[$f] = $_POST[$f]; //Scrub'em $the_title = sanitize_text_field($the_title); $the_content = $the_content; foreach ($meta as $k=>$m) $meta[$k] = implode("\n", array_map('sanitize_text_field', explode("\n", $m)));//sanitize_text_field($m); //Create the new Topic post // Set the post ID so that we know the post was created successfully $post_id = wp_update_post( array( 'ID' => $topic_id, 'post_title' => $the_title, 'post_content' => $the_content, ) ); if (is_wp_error($post_id)) { echo '

There was an error editing the topic.

'; $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo '

'.$error.'

'; } } else { //Update the metadata foreach ($meta as $k=>$m) update_post_meta($topic_id, $k, $m); echo '

Topic "'.$the_title.'" edited.

'; } //Display the topics list below it $this->display_topics(); } } //END CISY_Topics class //bp_register_group_extension('CISY_Edit_Topics'); /** * The Assignments tab */ class CISY_Assignments extends BP_Group_Extension { public $fields = array( 'cisy_date_begins', 'cisy_date_ends', 'cisy_date_late', 'cisy_points', 'cisy_quiz', 'cisy_files_allowed', 'cisy_grade_category', 'cisy_visible' ); /* * Constructor */ public function __construct() { $args = array( "name" => 'Assignments', "slug" => 'assignments' ); parent::init($args); } /* * Display the topics as they are. */ public function display() { if (isset($_POST["do_assignment"])) $this->do_assignment(); elseif (isset($_POST["submit_assignment"])) $this->submit_assignment(); else $this->display_assignments(); } public function display_assignments() { global $bp; $args = array( 'post_type' => 'cisy_assignment', 'meta_query' => array( array( "key" => 'cisy_group', "value" => bp_get_group_id() ), array( "key" => 'cisy_visible', "value" => "true" ), ), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //echo '
';
				//print_r($meta);
				//echo '
'; $assignments[get_the_id()] = array( "id" => get_the_id(), "name" => get_the_title(), "body" => get_the_content(), "begins" => $meta["cisy_date_begins"][0], "begins_ts" => strtotime($meta["cisy_date_begins"][0]), "ends" => $meta["cisy_date_ends"][0], "ends_ts" => strtotime($meta["cisy_date_ends"][0]), ); } } //If there are no posts else { ?>

Assignments:

There are presently no assignments posted.
'cisy_submission', 'meta_query' => array( array( "key" => 'cisy_assignment', "value" => array_keys($assignments), "compare" => 'IN' ) ), 'author' => get_current_user_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $submission_list = $the_query->get_posts(); $submissions = array(); if (count($submission_list) > 0) foreach ($submission_list as $submission) { $meta = get_post_meta($submission->ID); $submissions[$meta["cisy_assignment"][0]] = array( "id" => $submission->ID, //"cisy_grade" => $meta["cisy_grade"][0], "cisy_released" => $meta["cisy_released"][0] ); } $counter = 1; ?>

Assignments:

0) foreach ($assignments as $assignment_id => $assignment) : ?>
Due Assignment

= $assignment["begins_ts"] && $current_time <= $assignment["ends_ts"]; $is_submitted = isset($submissions[$assignment_id]); $is_released = $submissions[$assignment_id]["cisy_released"] == "true"; $status_tag = ""; $button_text = ""; if ($isnt_open_yet) { $status_tag = "[Not open yet]"; $diff = $assignment["begins_ts"] - current_time('timestamp',0); $days=floor($diff/(60*60*24)); $hours=floor(($diff-$days*60*60*24)/(60*60)); $status_tag = '[Opens in ';//.$diff; if (($days == 0) & ($hours == 0)) { $status_tag .= 'less than an hour!'; } else { if ($days == 1) $status_tag .= '1 day and '; elseif ($days > 1) $status_tag .= $days.' days and'; if ($hours == 1) $status_tag .= '1 hour'; elseif ($hours > 1) $status_tag .= $hours.' hours'; } $status_tag .= ']'; } elseif ($is_open) { $diff = $assignment["ends_ts"] - current_time('timestamp',0); $days=floor($diff/(60*60*24)); $hours=round(($diff-$days*60*60*24)/(60*60)); if ($diff > 0) { if ( ($days == 0) & ($hours == 0) ) { $status_tag = '[Closing soon!]'; } else { $status_tag = '['; if ($days == 1) $status_tag .= '1 day'; elseif ($days > 1) $status_tag .= $days.' days'; if ($days > 0 & $hours > 0) $status_tag .= ' and '; if ($hours == 1) $status_tag .= '1 hour'; elseif ($hours > 1) $status_tag .= $hours.' hours'; $status_tag .= ' remain]'; } } else { $status_tag = "[OPEN]"; } } else $status_tag = "[Currently closed]"; if ($is_open & !$is_submitted) { $button_text = "View It"; } elseif ($is_submitted & !$is_released) { $button_text = "Review"; } elseif ($is_submitted & $is_released) { $button_text = "View Submission"; } elseif ($is_closed & $is_released) { $button_text = "View Missed Assignment"; } if ($status_tag != "") echo '
'.$status_tag.''; echo '
'; echo '
'; if ($button_text != "") echo ''; echo ''; //echo ''.($is_open?1:0).'_'.($is_submitted?1:0).'_'.($is_released?1:0).''; echo '
'; echo '
'; ?>
You didn't specify an assignment to edit.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; ?>

Pass/Fail points
Category:
Begins: Ends: 0) { echo '
Time Remaining: '; if (($days == 0) & ($hours == 0)) { echo 'Less than an hour!'; } else { if ($days === 1) echo '1 day and '; elseif ($days > 1) echo $days.' days and'; if ($hours === 1) echo '1 hour!'; elseif ($hours > 1) echo $hours.' hours.'; } }// */ ?>
No Late Submissions
'cisy_submission', 'meta_key' => 'cisy_assignment', 'meta_value' => $assignment_id, 'author' => get_current_user_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_assignment_query = new WP_Query( $args ); if ( $the_assignment_query->have_posts() ) : $submission_id = $the_assignment_query->post->ID; $submission = $the_assignment_query->post; $submission_meta = get_post_meta($submission_id); if ($submission_meta["cisy_grade"][0] == "false") echo '

You have already submitted this assignment, and it has not been graded yet.

'; elseif ($submission_meta["cisy_released"][0] == "false") echo '

You have already submitted this assignment. It has been graded, but it has not been released back to you yet.

'; else { echo '

Your assignment has been graded. ('.round($submission_meta["cisy_grade"][0]*100,1).'%)

'; if (isset($submission_meta["cisy_manually_added"])) echo '

This grade was entered manually by the professor.

'; $gift = new GIFT($submission_meta["cisy_quiz"][0]); echo $gift->gradeQuiz(unserialize($submission_meta["cisy_answers"][0]),"return"); } ?>
printQuiz(); ?>

Upload File (required):

The required file must be zipped (.zip). Unzipped files will be rejected.

You didn't specify an assignment to edit.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to submit.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } //Check if the assignment has already been submitted $args = array( 'post_type' => 'cisy_submission', 'meta_key' => 'cisy_assignment', 'meta_value' => $assignment_id, 'author' => get_current_user_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_assignment_query = new WP_Query( $args ); if ( $the_assignment_query->have_posts() ) { echo "

You have already submitted this assignment.

"; $this->do_assignment(); return; } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //In order for it to be auto-graded, the assignment must // a) Not have any ungradable questions (essay) // b) Not have a file upload $autograde = true; $giftTest = null; $giftAnswers = array(); $giftGrade = null; //Get GIFT answers if there are any if (strlen(trim($meta["cisy_quiz"][0])) > 0) { //echo '

Checking quiz response...

'; $giftTest = $meta["cisy_quiz"][0]; if (isset($_POST["GIFTquestion"])) $giftAnswers = $_POST["GIFTquestion"]; } //Check for a file, if there is one required if ($meta["cisy_files_allowed"][0] == "true") { echo '

Checking file upload...

'; //If there is a file to upload if (isset($_FILES["assignment_upload"])) { $autograde = false; //Only allow zipped files $allowed = array( "application/zip" => ".zip", "application/x-zip-compressed" => ".zip", "application/octet-stream" => ".zip" ); //Check for file type if (!in_array($_FILES["assignment_upload"]["type"],array_keys($allowed))) { echo '

You either have not attached a file as required, or you tried to upload an invalid file type (the file type received was "'.$_FILES["assignment_upload"]["type"].'"). Please hit the back button, and upload a *zipped* version of the file(s) you wish to submit. Anything other than a single .zip file will be rejected.

'; return; } //Check for upload errors if ($_FILES["assignment_upload"]["error"] != UPLOAD_ERR_OK) { echo '

There was an error uploading your file. Please tell the Professor.

'; return; } //Check to see if the student's uploads directory exists $class_dir = dirname( __FILE__ ) . '/' . 'uploads' . '/' . bp_get_group_id(); $student_dir = $class_dir . '/' . get_current_user_id(); //echo "

".$class_dir."

"; //echo "

".$student_dir."

"; //If the course directory doesn't exist, make it if (!is_dir($class_dir)) { //echo '

Creating class directory...

'; if (!mkdir($class_dir, 0775, true)) { echo '

I was not able to make the class directory. Please tell the Professor.

'; return; } } //If the student's directory doesn't exist, make it if (!is_dir($student_dir)) { //echo '

Creating student directory...

'; if (!mkdir($student_dir, 0775, true)) { echo '

I was not able to make the student directory. Please tell the Professor.

'; return; } } //DESIGN ASSUMPTION: //We are assuming that a student is only allowed *ONE* file per assignment. //Not per submission of said assignment. One *per* assignment. //New submissions will overwrite old submissions. $move_from = $_FILES["assignment_upload"]["tmp_name"]; $move_to = $student_dir . '/' . $assignment_id . '.zip'; move_uploaded_file($move_from, $move_to); } } //Submission fields /* submission id the assignment quiz questions - in text in case it changes in the future student's answers - serialized – CONTENT graded? - is there a grade entry for it? released? - can they view how they did? */ $add = array(); $add["cisy_assignment"] = $assignment_id; $add["cisy_quiz"] = $giftTest; $add["cisy_grade"] = "false"; $add["cisy_released"] = "false"; //Grab all inputs (clean this up) //foreach ($this->fields as $f) $add[$f] = $_POST[$f]; //Scrub'em foreach ($add as $k=>$a) $add[$k] = implode("\n", array_map('sanitize_text_field', explode("\n", $a))); //Answers can't be scrubbed $add["cisy_answers"] = $giftAnswers; //Add fields that need to be scrubbed differently //$the_content = sanitize_text_field(serialize($giftAnswers)); //print "
";
		//print_r($add);
		//print_r($the_content);
		//print "
"; //Create the new Topic post // Initialize the page ID to -1. This indicates no action has been taken. $submission_id = -1; // Set the post ID so that we know the post was created successfully $submission_id = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => get_current_user_id(), 'post_status' => 'publish', 'post_type' => 'cisy_submission', 'post_content' => '' ) ); if ($submission_id == -1) { echo '

There was an error adding the submission.

'; } else { //Add the metadata //Special //The group add_post_meta($submission_id, 'cisy_group', bp_get_group_id(), true); //From the list foreach ($add as $k=>$a) add_post_meta($submission_id, $k, $a, true); echo '

You have successfully submitted "'.$assignment->post_title.'."

'; } //Display the topics list below it $this->do_assignment(); }//END submit_assignment } //END CISY_Assignments class bp_register_group_extension('CISY_Assignments'); /** * The Edit Assignments tab */ class CISY_Edit_Assignments extends BP_Group_Extension { public $fields = array( 'cisy_date_begins', 'cisy_date_ends', 'cisy_date_late', 'cisy_points', 'cisy_quiz', 'cisy_files_allowed', 'cisy_grade_category', 'cisy_visible' ); /* * Constructor */ public function __construct() { $args = array( "name" => '⟶ Edit', "slug" => 'edit-assignments', "access" => 'admin', "show_tab" => 'admin' ); parent::init($args); } /* * Figure out what to display. */ public function display() { global $bp; if (isset($_POST["add_new_assignment"])) $this->add_assignment_form(); elseif (isset($_POST["add_assignment_submit"])) $this->add_assignment_submit(); elseif (isset($_POST["delete_assignment"])) $this->delete_assignment(); elseif (isset($_POST["edit_assignment"])) $this->edit_assignment(); elseif (isset($_POST["edit_assignment_submit"])) $this->edit_assignment_submit(); else $this->display_assignments(); } /* * Display the assignments as they are. */ public function display_assignments() { global $bp; echo '

Edit Assignments:

'; $args = array( 'post_type' => 'cisy_assignment', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $assignments[] = array( "id" => get_the_id(), "name" => get_the_title(), "body" => get_the_content(), "begins" => $meta["cisy_date_begins"][0], "begins_ts" => strtotime($meta["cisy_date_begins"][0]), "ends" => $meta["cisy_date_ends"][0], "ends_ts" => strtotime($meta["cisy_date_ends"][0]), "visible" => $meta["cisy_visible"][0] ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //print_r($topics); //Sort the topics so they're in chronological order usort($assignments, function($a,$b) { if ($a["ends_ts"] == $b["ends_ts"]) return 0; return ($a["ends_ts"] < $b["ends_ts"]) ? -1 : 1; }); $counter = 1; ?>
Due Assignment

HIDDEN: ":'' ?> = $assignment["begins_ts"] && $current_time <= $assignment["ends_ts"] ) { echo '[open]'; } else { echo '[closed]'; } ?>

[GroupID: ]

" placeholder="Assignment Title"/> 'cisy_grade_category', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $grade_categories[] = array( "id" => get_the_id(), "name" => get_the_title(), ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); ?>

Add New Assignment:

assignment_form(); ?>
"; //print_r($_POST); //print ""; //return; $add = array(); //Grab all inputs (clean this up) foreach ($this->fields as $f) $add[$f] = $_POST[$f]; //Scrub'em //foreach ($add as $k=>$a) $add[$k] = sanitize_text_field($a); //Add fields that need to be scrubbed differently $the_title = sanitize_text_field($_POST["the_title"]); $the_content = wp_kses_post($_POST["the_content"]); //Create the new Topic post // 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' => $the_title, 'post_status' => 'publish', 'post_type' => 'cisy_assignment', 'post_content' => $the_content ) ); if ($post_id == -1) { echo '

There was an error adding the assignment.

'; } else { //Add the metadata //Special add_post_meta($post_id, 'cisy_group', bp_get_group_id(), true); //From the list foreach ($add as $k=>$a) add_post_meta($post_id, $k, $a, true); echo '

Assignment "'.$the_title.'" added.

'; } //Display the topics list below it $this->display_assignments(); }//END add_topic_submit /* * Deletes a topic. */ function delete_assignment() { if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to delete.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to delete.

"; $this->display_assignments(); return; } //Sanitize the id $topic_id = intval($_POST["the_assignment"]); $topic = get_post($topic_id); if ($topic === null) { echo "

That isn't a valid assignment to delete.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($topic_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } wp_delete_post($topic_id); echo "

Assignment deleted!

"; $this->display_assignments(); } /* * Edit a topic. */ public function edit_assignment() { global $bp; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to edit.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignmnt does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; ?>

Edit Assignment:

assignment_form($data); ?>
"; //print_r($_POST); //print ""; //return; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to edit.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to edit.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } //Grab all inputs $the_title = $_POST["the_title"]; $the_content = $_POST["the_content"]; $meta = array(); foreach ($this->fields as $f) $meta[$f] = $_POST[$f]; //Scrub'em $the_title = sanitize_text_field($the_title); $the_content = wp_kses_post($the_content); foreach ($meta as $k=>$m) ###### $meta[$k] = implode("\n", array_map('sanitize_text_field', explode("\n", $m)));//sanitize_text_field($m); //Create the new Topic post // Set the post ID so that we know the post was created successfully $post_id = wp_update_post( array( 'ID' => $assignment_id, 'post_title' => $the_title, 'post_content' => $the_content, ) ); if (is_wp_error($post_id)) { echo '

There was an error editing the topic.

'; $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo '

'.$error.'

'; } } else { //Update the metadata foreach ($meta as $k=>$m) update_post_meta($assignment_id, $k, $m); echo '

Topic "'.$the_title.'" edited.

'; } //Display the assignments list below it $this->display_assignments(); } } //END CISY_Edit_Assignments class bp_register_group_extension('CISY_Edit_Assignments'); /** * The Grade Assignments tab */ class CISY_Grade_Assignments extends BP_Group_Extension { public $fields = array( 'cisy_date_begins', 'cisy_date_ends', 'cisy_date_late', 'cisy_points', 'cisy_quiz', 'cisy_files_allowed', 'cisy_grade_category', 'cisy_visible', 'cisy_notes' ); public function __construct() { $args = array( "name" => '⟶ Grade', "slug" => 'grade-assignments', "access" => 'admin', "show_tab" => 'admin' ); parent::init($args); } public function display() { global $bp; if (isset($_POST["grade_submissions"])) $this->grade_submissions(); elseif (isset($_POST["save_all_submissions"])) $this->save_all_submissions(); elseif (isset($_POST["delete_submission"])) $this->delete_submission(); elseif (isset($_POST["toggle_release_submission"])) $this->toggle_release_submission(); elseif (isset($_REQUEST["view_quiz"])) $this->view_quiz(); elseif (isset($_REQUEST["submit_incompletes"])) $this->submit_incompletes(); elseif (isset($_REQUEST["release_all_submissions"])) $this->release_pull_submissions("true"); elseif (isset($_REQUEST["pull_all_submissions"])) $this->release_pull_submissions("false"); else $this->list_assignments(); } /* * Display a list of assignments that need grading. */ public function list_assignments() { global $bp; echo '

Grade Assignments:

'; $args = array( 'post_type' => 'cisy_assignment', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $assignments[] = array( "id" => get_the_id(), "name" => get_the_title(), "body" => get_the_content(), "begins" => $meta["cisy_date_begins"][0], "begins_ts" => strtotime($meta["cisy_date_begins"][0]), "ends" => $meta["cisy_date_ends"][0], "ends_ts" => strtotime($meta["cisy_date_ends"][0]), ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //print_r($topics); //Sort the topics so they're in chronological order usort($assignments, function($a,$b) { if ($a["ends_ts"] == $b["ends_ts"]) return 0; return ($a["ends_ts"] < $b["ends_ts"]) ? -1 : 1; }); $counter = 1; ?>
Due Assignment

= $assignment["begins_ts"] && $current_time <= $assignment["ends_ts"] ) { echo '[open]'; } else { echo '[closed]'; } //Figure out how many need to be graded $args = array( 'meta_query' => array( array( 'key' => 'cisy_released', 'value' => 'false', 'compare' => 'like', ), array( 'key' => 'cisy_assignment', 'value' => $assignment["id"], ), ), 'post_type' => 'cisy_submission', 'posts_per_page' => -1 //otherwise it limits to 10! ); $assignment_submissions = new WP_Query( $args ); $to_be_graded = $assignment_submissions->found_posts; wp_reset_postdata(); ?>
= $assignment["begins_ts"] && $current_time <= $assignment["ends_ts"] ) { echo ''; } else { echo ''; } ?>
You didn't specify an assignment to grade.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; //echo '
';
		//print_r($data);
		//echo '
'; ?>

Grading:

Pass/Fail points
Category:
"; //print_r($students); //print ""; ?> 'cisy_submission', 'meta_key' => 'cisy_assignment', 'meta_value' => $assignment_id, 'author' => $s->user_id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_assignment_query = new WP_Query( $args ); //print "
";
			//print_r($the_assignment_query);
			//print "
"; wp_reset_postdata(); if ($the_assignment_query->post_count == 0) : ?> post; $submission_id = $submission->ID; $submission_meta = get_post_meta($submission_id); ?>
Student Submission Grade Actions
user_id, 100); ?>
display_name ?>
No submission.
user_id, 100); ?>
display_name ?>
[view quiz]'; } if ($data["cisy_files_allowed"] == "true") { //echo plugin_dir_url( __FILE__ ); //URL $class_dir = plugin_dir_url( __FILE__ ) . '/' . 'uploads' . '/' . bp_get_group_id(); $student_dir = $class_dir . '/' . $submission->post_author; $file_url = $student_dir . '/' . $assignment_id . '.zip'; //PATH $class_path = plugin_dir_path( __FILE__ ) . '/' . 'uploads' . '/' . bp_get_group_id(); $student_path = $class_path . '/' . $submission->post_author; $file_path = $student_path . '/' . $assignment_id . '.zip'; if (is_file($file_path)) echo ' [download]'; else echo '[no submission]'; } ?> gradeQuiz($answers,"stats"); echo ''; } else { echo ''; } ?> '; } else { echo ''; } echo ''; ?>

You didn't specify an assignment to grade.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; //Nab the cisy_grades submitted $grades = $_POST["cisy_grade"]; $notes = $_POST["cisy_notes"]; //print "
";
		//print_r($_POST);
		//print "
"; //Go over each submitted grade if (count($grades) > 0) foreach ($grades as $submission_id => $grade) { //Get the submission $submission = get_post($submission_id); $submission_meta = get_post_meta($submission_id); //print_r($submission); //If it's not NULL, update it. if ($grade != "null") { update_post_meta($submission_id,"cisy_grade",$grade); } //If it is NULL, delete it (well, set it to false) else { update_post_meta($submission_id,"cisy_grade","false"); } //Update the notes section update_post_meta($submission_id,"cisy_notes",$notes[$submission_id]); } echo '

All grades updated!

'; $this->grade_submissions(); }//end save_all_submissions /* * Delete a submission entirely */ function delete_submission() { global $bp; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to grade.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; //Nab the cisy_delete submitted $delete = $_POST["delete_submission"]; $delete = array_keys($delete); $submission_id = $delete[0]; $submission = get_post($submission_id); if ($submission == null) { echo '

That submission does not exist.

'; $this->grade_submissions(); return; } if ($submission->post_type !== "cisy_submission") { echo '

That post is not a submission.

'; $this->grade_submissions(); return; } wp_delete_post($submission_id,true); echo '

Submission deleted!

'; $this->grade_submissions(); }//end save_all_submissions /* * Release or pull a submission */ function toggle_release_submission() { global $bp; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to grade.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; //Nab the cisy_delete submitted $submission_id = $_POST["toggle_release_submission"]; $submission_id = array_keys($submission_id); $submission_id = $submission_id[0]; $submission = get_post($submission_id); if ($submission == null) { echo '

That submission does not exist.

'; $this->grade_submissions(); return; } if ($submission->post_type !== "cisy_submission") { echo '

That post is not a submission.

'; $this->grade_submissions(); return; } $state = get_post_meta($submission_id,'cisy_released',true); if ($state === "false") { update_post_meta($submission_id,'cisy_released',"true"); echo '

Submission released!

'; } else { update_post_meta($submission_id,'cisy_released',"false"); echo '

Submission pulled!

'; } $this->grade_submissions(); }//end toggle_release_submission /* * Release or pull all submissions */ function release_pull_submissions($action) { global $bp; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to grade.

"; $this->display_assignments(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to grade.

"; $this->display_assignments(); return; } //Snag metadata $meta = get_post_meta($assignment_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That assignment does not belong to this class.

"; $this->display_assignments(); return; } $data = array(); //Load title and content $data["the_title"] = $assignment->post_title; $data["the_content"] = $assignment->post_content; //Load fields foreach ($this->fields as $f) $data[$f] = $meta[$f][0]; if (isset($_REQUEST["cisy_grade"])) if (count($_REQUEST["cisy_grade"]) > 0) foreach ($_REQUEST["cisy_grade"] as $submission_id => $grade) { $submission = get_post($submission_id); if ($submission == null) { echo '

That submission does not exist.

'; $this->grade_submissions(); return; } if ($submission->post_type !== "cisy_submission") { echo '

That post is not a submission.

'; $this->grade_submissions(); return; } update_post_meta($submission_id,'cisy_released',$action); } if ($action == "true") echo '

All submissions released!

'; else echo '

All submissions pulled!

'; $this->grade_submissions(); }//end toggle_release_submission /* * View an auto-graded quiz */ function view_quiz() { global $bp; //Nab the cisy_delete submitted $submission_id = intval($_REQUEST["view_quiz"]); $submission = get_post($submission_id); if ($submission == null) { echo '

That submission does not exist.

'; $this->grade_submissions(); return; } if ($submission->post_type !== "cisy_submission") { echo '

That post is not a submission.

'; $this->grade_submissions(); return; } $quiz = get_post_meta($submission_id,'cisy_quiz',true); $answers = get_post_meta($submission_id,'cisy_answers',true); if ($quiz === "") { echo '

This submission does not have a quiz attached to it.

'; $this->grade_submissions(); } else { $userdata = get_userdata($submission->post_author); //print "
";
			//print_r($userdata->display_name);
			//print "
"; echo '

'.$userdata->display_name.'\'s Autograded Quiz

'; $gift = new GIFT($quiz); print $gift->gradeQuiz($answers,"return"); } }//end view_quiz /* * Submit zero grades for all not submitted. */ function submit_incompletes() { //Step 1: Nab the assignment -------------------- global $bp; if (!isset($_POST["the_assignment"])) { echo "

You didn't specify an assignment to submit incompletes to.

"; $this->grade_submissions(); return; } if (!is_numeric($_POST["the_assignment"])) { echo "

That isn't a valid assignment to submit incompletes to.

"; $this->grade_submissions(); return; } //Sanitize the id $assignment_id = intval($_POST["the_assignment"]); $assignment = get_post($assignment_id); if ($assignment === null) { echo "

That isn't a valid assignment to submit incompletes to.

"; $this->grade_submissions(); return; } //Step 2: Nab the students --------------------------------------- $students = BP_Groups_Member::get_all_for_group(bp_get_group_id()); if (isset($students["members"])) $students = $students["members"]; else $students = array(); //Construct the metadata array //It's the same for every submitted zero. ########## $add = array(); $add["cisy_assignment"] = $assignment_id; $add["cisy_quiz"] = get_post_meta($assignment_id,'cisy_quiz',true);//$giftTest; $add["cisy_grade"] = "0"; $add["cisy_released"] = "false"; $add["cisy_manually_added"] = "true"; //Scrub'em foreach ($add as $k=>$a) $add[$k] = implode("\n", array_map('sanitize_text_field', explode("\n", $a))); //Answers can't be scrubbed //Blank array as there were no submitted answers $add["cisy_answers"] = array(); //Step 3: Iterate over every student and add new submissions with zero as the grade //---Loop here--- foreach ($students as $s) { //Get their assignment $args = array( 'post_type' => 'cisy_submission', 'meta_key' => 'cisy_assignment', 'meta_value' => $assignment_id, 'author' => $s->user_id, 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_assignment_query = new WP_Query( $args ); //print "
";
			//print_r($the_assignment_query);
			//print "
"; wp_reset_postdata(); if ($the_assignment_query->post_count == 0) { //If they don't have a submission //Create the new submission // Initialize the page ID to -1. This indicates no action has been taken. $submission_id = -1; //Inserting //echo '

Inserting: ('.$s->user_id.') '.$s->display_name.'\'s zero. '.serialize($add).'

'; // Set the post ID so that we know the post was created successfully $submission_id = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $s->user_id, //!!!! The author ID is the student //get_current_user_id(), 'post_status' => 'publish', 'post_type' => 'cisy_submission', 'post_content' => '' ) ); if ($submission_id == -1) { echo '

ERROR adding zero for "'.$s->display_name.'."

'; } else { //Add the metadata //Special //The group add_post_meta($submission_id, 'cisy_group', bp_get_group_id(), true); //From the list foreach ($add as $k=>$a) add_post_meta($submission_id, $k, $a, true); echo '

Zero submitted for "'.$s->display_name.'."

'; } } } //---loop here ends--- $this->grade_submissions(); }//end submit_incompletes } //END CISY_Edit_Grades class bp_register_group_extension('CISY_Grade_Assignments'); /** * The Grades tab */ class CISY_Grades extends BP_Group_Extension { public function __construct() { $args = array( "name" => 'Grades', "slug" => 'grades' ); parent::init($args); } public function display() { global $bp; echo '

Your Grades:

'; $args = array( 'post_type' => 'cisy_grade_category', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $grade_categories[get_the_id()] = array( "id" => get_the_id(), "name" => get_the_title(), "weight" => $meta["cisy_weight"][0], "order" => $meta["cisy_order"][0], "assignments" => array() ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //Grab all class assignments $assignments = array(); $args = array( 'meta_query' => array( array( 'key' => 'cisy_group', 'value' => bp_get_group_id(), ), array( 'key' => 'cisy_visible', 'value' => 'true' ), ), 'meta_key' => 'cisy_date_ends', 'orderby' => 'meta_value', 'post_type' => 'cisy_assignment', 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments_list = $the_query->get_posts(); //Put them into the array if ( count($assignments_list) > 0 ) foreach ($assignments_list as $assignment) { $meta = get_post_meta($assignment->ID); $assignments[$assignment->ID] = array( "category" => $meta["cisy_grade_category"][0], "title" => $assignment->post_title, "points" => $meta["cisy_points"][0] ); } //wp_reset_postdata(); //And grab student's submissions $args = array( 'meta_query' => array( array( 'key' => 'cisy_assignment', 'value' => array_keys($assignments), 'compare' => 'IN' ), array( 'key' => 'cisy_released', 'value' => 'true' ), ), 'author' => get_current_user_id(), 'post_type' => 'cisy_submission', 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $submissions_list = $the_query->get_posts(); //Put them into the array if ( count($submissions_list) > 0 ) foreach ($submissions_list as $submission) { $meta = get_post_meta($submission->ID); if (isset($assignments[$meta["cisy_assignment"][0]])) $assignments[$meta["cisy_assignment"][0]]["score"] = $meta["cisy_grade"][0]; $assignments[$meta["cisy_assignment"][0]]["notes"] = $meta["cisy_notes"][0]; } //wp_reset_postdata(); //print '
';
		//print_r($assignments);
		//print '
'; //Sort the categories so they're in sorted order if (count($grade_categories) > 0) uasort($grade_categories, function($a,$b) { if ($a["order"] == $b["order"]) return 0; return ($a["order"] < $b["order"]) ? -1 : 1; }); $counter = 1; $points_earned = 0; $points_total = 0; ?>
$category) : $tally += $category["weight"]; ?> 0) : ?>
'\\"')); ?> (%)

Everything Else %
0) { $final_score = round($points_earned/$points_total*100,1); $final_grade = array(90=>"A",85=>"B+",80=>"B",75=>"C+",68=>"C",60=>"D",0=>"F"); foreach ($final_grade as $k=>$g) if ($final_score >= $k) {$final_grade = $g; break;} echo '

Your current grade is
'.$final_score.'% ('.$final_grade.')

'; echo '
(Remember that this is your current cumulative grade, and does not include any work that is presently ungraded or unreleased.)
'; } else { echo '

You presently have no grades to report.

'; } ?>
'⟶ Categories', "slug" => 'edit-grade-categories', "access" => 'admin', "show_tab" => 'admin' ); parent::init($args); } public function display() { global $bp; if (isset($_POST["add_new_grade_category"])) $this->add_grade_category(); elseif (isset($_POST["grade_category_delete"])) $this->delete_category(); elseif (isset($_POST["update_grade_categories"])) $this->update_categories(); else $this->display_categories(); } public function display_categories() { global $bp; echo '

Grade Categories:

'; $args = array( 'post_type' => 'cisy_grade_category', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $assignments = array(); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $meta = get_post_meta(get_the_id()); //print_r($meta); $grade_categories[] = array( "id" => get_the_id(), "name" => get_the_title(), "weight" => $meta["cisy_weight"][0], "order" => $meta["cisy_order"][0] ); } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); //print_r($topics); //Sort the topics so they're in chronological order if (count($grade_categories) > 0) usort($grade_categories, function($a,$b) { if ($a["order"] == $b["order"]) return 0; return ($a["order"] < $b["order"]) ? -1 : 1; }); $counter = 1; ?>
0) : $tally = 0; ?>
Category Weight Options
][title]" type="text" value="'\\"')); ?>"/> ]" value="Del"/>
Everything Else % Total: 100%
All grades weighted equally.
fields as $f) $add[$f] = $_POST[$f]; //Scrub'em foreach ($add as $k=>$a) $add[$k] = sanitize_text_field($a); //Add fields that need to be scrubbed differently $the_title = sanitize_text_field($_POST["the_title"]); //$the_content = sanitize_text_field($_POST["the_content"]); //Check add-up $tally = 0; $args = array( 'post_type' => 'cisy_grade_category', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_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()); $tally += $meta["cisy_weight"][0]; } } /* Restore original Post Data so we don't mess up other loops */ wp_reset_postdata(); if ( (100 - $tally - $_POST["cisy_weight"]) < 0 ) { echo "

The total weights add up to more than 100%. Please choose a smaller weight.

"; $this->display_categories(); return; } //Create the new Topic post // 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' => $the_title, 'post_status' => 'publish', 'post_type' => 'cisy_grade_category', //'post_content' => $the_content ) ); if ($post_id == -1) { echo '

There was an error adding the assignment.

'; } else { //Add the metadata //Special add_post_meta($post_id, 'cisy_group', bp_get_group_id(), true); //From the list foreach ($add as $k=>$a) add_post_meta($post_id, $k, $a, true); echo '

Grade Category "'.$the_title.'" added.

'; } //Display the categories list below it $this->display_categories(); } /* * Deletes a category. */ function delete_category() { //print_r($_POST); //return; if (!isset($_POST["grade_category_delete"])) { echo "

You didn't specify an assignment to delete.

"; $this->display_categories(); return; } if (count($_POST["grade_category_delete"]) != 1) { echo "

You may only delete one grade category at a time.

"; $this->display_categories(); return; } $delete_id = $_POST["grade_category_delete"]; reset($delete_id); $delete_id = key($delete_id); if (!is_numeric($delete_id) || $delete_id <= 0) { echo "

That isn't a valid category to delete.

"; $this->display_categories(); return; } //Sanitize the id $cat_id = intval($delete_id); $cat = get_post($cat_id); if ($cat === null) { echo "

That isn't a valid category to delete.

"; $this->display_categories(); return; } //Snag metadata $meta = get_post_meta($cat_id); if ($meta["cisy_group"][0] != bp_get_group_id()) { echo "

That category does not belong to this class.

"; $this->display_categories(); return; } wp_delete_post($cat_id); echo "

Category deleted!

"; $this->display_categories(); } /* * Updates all grade category weights and names */ function update_categories() { //print '
';
		//print_r($_POST);
		//print '
'; if (isset($_POST["grade_category"])) { foreach ($_POST["grade_category"] as $cat_id => $data) { //Grab all inputs $the_title = $data["title"]; $weight = $data["weight"]; //Scrub'em $the_title = sanitize_text_field($the_title); $weight = sanitize_text_field($weight); // Set the post ID so that we know the post was created successfully $post_id = wp_update_post( array( 'ID' => $cat_id, 'post_title' => $the_title, ) ); if (is_wp_error($post_id)) { echo '

There was an error editing the topic.

'; $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo '

'.$error.'

'; } } else { //Update the metadata update_post_meta($cat_id, "cisy_weight", $weight); } }//end foreach echo "

Grade categories updated.

"; }//end if $this->display_categories(); } } //END CISY_Edit_Grade_Categories class bp_register_group_extension('CISY_Edit_Grade_Categories'); /** * The Edit Grades tab */ class CISY_Gradesheet extends BP_Group_Extension { public $fields = array( //'cisy_weight' ); public function __construct() { $args = array( "name" => '⟶ Sheet', "slug" => 'gradesheet', "access" => 'admin', "show_tab" => 'admin' ); parent::init($args); } public function display() { //Do we have assignments? //Get assignment categories $categories = array(); //Make the query $args = array( 'post_type' => 'cisy_grade_category', 'meta_key' => 'cisy_group', 'meta_value' => bp_get_group_id(), 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); //We'll put the categories in here $categories_list = $the_query->get_posts(); //Plunk them all in if ( count($categories_list) > 0 ) foreach ($categories_list as $category) { $meta = get_post_meta($category->ID); $categories[$category->ID] = array( "id" => $category->ID, "name" => $category->post_title, "weight" => $meta["cisy_weight"][0], "order" => $meta["cisy_order"][0], "assignments" => array() ); } //Sort the categories so they're in sorted order if (count($categories) > 0) uasort($categories, function($a,$b) { if ($a["order"] == $b["order"]) return 0; return ($a["order"] < $b["order"]) ? -1 : 1; }); //Grab the assignments $assignments = array(); //Make the query $args = array( 'meta_query' => array( array( 'key' => 'cisy_group', 'value' => bp_get_group_id(), ) ), 'meta_key' => 'cisy_date_ends', 'orderby' => 'meta_value', 'post_type' => 'cisy_assignment', 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); //We'll put them in here $assignments_list = $the_query->get_posts(); //Put them into the array if ( count($assignments_list) > 0 ) foreach ($assignments_list as $assignment) { $meta = get_post_meta($assignment->ID); $date_endss = date_parse($meta["cisy_date_ends"][0]); $assignments[$assignment->ID] = array( "category" => $meta["cisy_grade_category"][0], "title" => $assignment->post_title, "points" => $meta["cisy_points"][0], "date" => $date_endss["month"].'/'.$date_endss["day"] ); $cat = $meta["cisy_grade_category"][0]; if ($cat == "") $cat = "other"; $categories[$cat]["assignments"][] = $assignment->ID; } //print "
";
		//print_r($categories);
		//print "
"; echo '
'; echo ''; echo ''; echo ''; foreach ($categories as $category) { $title = $category["name"]; if ($title == "") $title = "Other"; $span = count($category["assignments"]); if ($span <= 0) $span = 1; echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($categories as $category) { if (count($category["assignments"]) == 0) { echo ''; } else foreach ($category["assignments"] as $a_id) { $title = $assignments[$a_id]["title"]; if ($title == "") $title = "???"; echo ''; } } echo ''; //Do we have students? $students = BP_Groups_Member::get_all_for_group(bp_get_group_id()); if (isset($students["members"])) { $students = $students["members"]; foreach ($students as $k=>$s) { //Get student user data $students[$k] = get_userdata($s->user_id); } } else $students = array(); //print_r($students); //Sort the students in last_name,first_name alphabetical order usort($students, function ($a, $b) { return strnatcmp($a->last_name.' '.$a->first_name, $b->last_name.' '.$b->first_name); }); $final_roster = array(); foreach ($students as $student) { echo ''; //Student's name echo ''; //Get grade data $args = array( 'author' => $student->ID, 'meta_query' => array( array( 'key' => 'cisy_assignment', 'value' => array_keys($assignments), 'compare' => 'IN' ) ), 'post_type' => 'cisy_submission', 'posts_per_page' => -1 //otherwise it limits to 10! ); $the_query = new WP_Query( $args ); $submissions_list = $the_query->get_posts(); $submissions = array(); if (count($submissions_list) > 0) foreach ($submissions_list as $submission) { $smeta = get_post_meta($submission->ID); $submissions[$smeta["cisy_assignment"][0]] = $smeta;//["cisy_grade"][0]; } //Begin to tally points $points_earned = 0; $points_total = 0; //Go through each category and each assignment foreach ($categories as $category) { if (count($category["assignments"]) == 0) { echo ''; } else foreach ($category["assignments"] as $a_id) { $score = ''; $color = ''; if (isset($submissions[$a_id])) { $score = $submissions[$a_id]["cisy_grade"][0]; if ($score == "false") $score = "..."; else { $score = floatval($score); if ($score >= .8) $color = 'background-color:#CFC;'; elseif ($score >= .6) $color = 'background-color:#FFC;'; else $color = 'background-color:#FCC;'; $score = round($score * 100,1).'%'; //Calculate weights etc. $total_points = get_post_meta($submissions[$a_id]["cisy_assignment"][0],"cisy_points",true); $points_worth = $total_points * ($category["weight"]/100); $points_earned += $score * $points_worth; $points_total += $points_worth; } } // echo ''; } } //Student's name again echo ''; $final_score = round($points_earned/$points_total,1); $final_grade = array(90=>"A",85=>"B+",80=>"B",75=>"C+",68=>"C",60=>"D",0=>"F"); foreach ($final_grade as $k=>$g) if ($final_score >= $k) {$final_grade = $g; break;} echo ''; $final_roster["score"][] = $final_score; $final_roster["grade"][] = $final_grade; echo ''; } echo '
Students'.$title; if (isset($category["weight"])) echo ' ('.$category["weight"].'%)'; echo 'StudentCurrent
Grade
Assignments: '.$title.' ('.$assignments[$a_id]["date"].')
'.get_avatar($student->ID, 20).' '.$student->last_name.', '.$student->first_name.' '; echo $score; echo ''.get_avatar($student->ID, 20).' '.$student->last_name.', '.$student->first_name.''.$final_score.'
('.$final_grade.')
'; $mean = array_sum($final_roster["score"]) / count($final_roster["score"]); $mean = round($mean,1); echo 'Mean: '.$mean.' '; rsort($final_roster["score"]); $middle = round(count($final_roster["score"]) / 2); $median = $final_roster["score"][$middle-1]; echo 'Median: '.$median.' '; echo '
'; } } //END CISY_Edit_Grades class bp_register_group_extension('CISY_Gradesheet'); /** * The Group Chooser tab */ class CISY_Group_Chooser extends BP_Group_Extension { public function __construct() { $args = array( "name" => 'Group Chooser', "slug" => 'group-chooser' ); parent::init($args); } public function display() { //Do we have students? $students = BP_Groups_Member::get_all_for_group(bp_get_group_id()); if (isset($students["members"])) { $students = $students["members"]; foreach ($students as $k=>$s) { //Get student user data $students[$k] = get_userdata($s->user_id); } } else $students = array(); //print_r($students); //Sort the students in last_name,first_name alphabetical order usort($students, function ($a, $b) { return strnatcmp($a->last_name.' '.$a->first_name, $b->last_name.' '.$b->first_name); }); echo ''; ?>