function get_group_courseware($group_id = null)
 {
     if (!$group_id) {
         global $bp;
         $group_id = $bp->groups->current_group->id;
     }
     $group_data['bibliography'] = array();
     $group_data['responses_count'] = 0;
     $group_data['assignment_topics_count'] = 0;
     $group_data['user_grades'] = array();
     $group_data['courses'] = (array) BPSP_Courses::has_courses($group_id);
     $group_data['assignments'] = (array) BPSP_Assignments::has_assignments($group_id);
     $group_data['schedules'] = BPSP_Schedules::has_schedules($group_id);
     $posts = array_merge($group_data['courses'], $group_data['assignments']);
     if ($posts) {
         foreach ($posts as &$post) {
             // Get group bibs
             $group_data['bibliography'] = array_merge($group_data['bibliography'], BPSP_Bibliography::get_bibs($post->ID));
             // Get group responses
             if ($post->post_type == 'assignment') {
                 // Forum threads
                 if (get_post_meta($post->ID, 'topic_link', true) != '') {
                     $group_data['assignment_topics_count'] += 1;
                 }
                 // Responses
                 $post->responses = get_children(array('post_parent' => $post->ID, 'post_type' => 'response'));
                 $group_data['responses_count'] += count($post->responses);
                 // Gradebook
                 $group_data['user_grades'][] = BPSP_Gradebook::load_grade_by_user_id($post->ID, $bp->loggedin_user->id);
             }
         }
     }
     $group_data['bibliography_count'] = count($group_data['bibliography']);
     return $group_data;
 }
Пример #2
0
/**
 * Register post types and taxonomies
 */
function bpsp_registration()
{
    BPSP_Courses::register_post_types();
    BPSP_Assignments::register_post_types();
    BPSP_Responses::register_post_types();
    BPSP_Gradebook::register_post_types();
    BPSP_Bibliography::register_post_types();
    BPSP_Schedules::register_post_types();
}
 /**
  * is_assignment( $assignment_identifier )
  *
  * Checks if a assignment with $assignment_identifier exists
  *
  * @param $assignment_identifier ID or Name of the assignment to be checked
  * @return Assignment object if assignment exists and null if not.
  */
 function is_assignment($assignment_identifier = null)
 {
     global $bp, $post;
     $courseware_uri = bp_get_group_permalink($bp->groups->current_group) . 'courseware/';
     if (is_object($assignment_identifier) && $assignment_identifier->post_type == "assignment") {
         if ($assignment_identifier->group[0]->name == $bp->groups->current_group->id) {
             return $assignment_identifier;
         } else {
             return null;
         }
     }
     if (!$assignment_identifier && get_class((object) $this->current_assignment) == __CLASS__) {
         return $this->current_assignment;
     }
     $assignment_query = array('post_type' => 'assignment', 'group_id' => $bp->groups->current_group->id);
     if ($assignment_identifier != null) {
         if (is_numeric($assignment_identifier)) {
             $assignment_query['p'] = $assignment_identifier;
         } else {
             $assignment_query['name'] = $assignment_identifier;
         }
     }
     $assignment = get_posts($assignment_query);
     if (!empty($assignment[0])) {
         $post = $assignment[0];
         $assignment[0]->due_date = get_post_meta($assignment[0]->ID, 'due_date', true);
         $assignment[0]->group = wp_get_object_terms($assignment[0]->ID, 'group_id');
         $assignment_course = wp_get_object_terms($assignment[0]->ID, 'course_id');
         $assignment[0]->course = BPSP_Courses::is_course($assignment_course[0]->name);
         $assignment_lecture = get_post_meta($assignment[0]->ID, 'lecture_id', true);
         $assignment[0]->lecture = $assignment_lecture ? BPSP_Lectures::is_lecture($assignment_lecture) : null;
         $assignment[0]->forum_link = get_post_meta($assignment[0]->ID, 'topic_link', true);
         $assignment[0]->responded_author = get_post_meta($assignment[0]->ID, 'responded_author');
         $assignment[0]->form_data = get_post_meta($assignment[0]->ID, 'form_data', true);
         $assignment[0]->permalink = $courseware_uri . 'assignment/' . $assignment[0]->post_name;
         // If Assignment has form, render it first
         if (!empty($assignment[0]->form_data)) {
             if (!isset($this) || !isset($this->frmb)) {
                 $frmb = new FormBuilder();
             } else {
                 $frmb = $this->frmb;
             }
             $frmb->set_data($assignment[0]->form_data);
             $assignment[0]->form = $frmb->render();
         }
         return $assignment[0];
     } else {
         return null;
     }
 }
Пример #4
0
 /**
  * edit_schedule_screen( $vars )
  *
  * Hooks into screen_handler
  * Edit schedule screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function edit_schedule_screen($vars)
 {
     global $bp;
     $nonce_name = 'edit_schedule';
     $old_schedule = $this->is_schedule($this->current_schedule);
     $old_schedule->terms = wp_get_object_terms($old_schedule->ID, 'group_id');
     if (!$this->has_schedule_caps($bp->loggedin_user->id) || !is_super_admin() && $bp->groups->current_group->id != $old_schedule->terms[0]->name) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the schedule.', 'bpsp');
         return $vars;
     }
     // Update schedule
     if (isset($_POST['schedule']) && $_POST['schedule']['object'] == 'group' && isset($_POST['_wpnonce'])) {
         if (empty($_POST['schedule']['desc']) || empty($_POST['schedule']['start_date'])) {
             $vars['error'] = __('New schedule could not be added. Missing description and/or start date.', 'bpsp');
             $_POST = null;
             return $this->edit_schedule_screen($vars);
         }
         $updated_schedule = $_POST['schedule'];
         if (isset($updated_schedule['end_date']) && !empty($updated_schedule['end_date'])) {
             $valid_dates = $this->datecheck($updated_schedule['start_date'], $updated_schedule['end_date']);
         } else {
             $valid_dates = true;
         }
         $is_nonce = wp_verify_nonce($_POST['_wpnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while editing a schedule.', 'bpsp');
         } else {
             if (!empty($updated_schedule['group_id']) && $valid_dates) {
                 $updated_schedule_id = wp_update_post(array('ID' => $old_schedule->ID, 'post_title' => sanitize_text_field($updated_schedule['title']), 'post_content' => sanitize_text_field($updated_schedule['desc'])));
                 if ($updated_schedule_id) {
                     if (!empty($updated_schedule['course_id']) && BPSP_Courses::is_course($updated_schedule['course_id'])) {
                         wp_set_post_terms($updated_schedule_id, $updated_schedule['course_id'], 'course_id');
                     } elseif (empty($updated_schedule['course_id'])) {
                         wp_set_post_terms($updated_schedule_id, '', 'course_id');
                     }
                     update_post_meta($updated_schedule_id, 'start_date', $updated_schedule['start_date'], $old_schedule->start_date);
                     update_post_meta($updated_schedule_id, 'end_date', $updated_schedule['end_date'], $old_schedule->end_date);
                     if (isset($updated_schedule['lecture_id'])) {
                         update_post_meta($updated_schedule_id, 'lecture_id', $updated_schedule['lecture_id']);
                     }
                     if (!empty($updated_schedule['location'])) {
                         if ($old_schedule->location) {
                             update_post_meta($updated_schedule_id, 'location', $updated_schedule['location'], $old_schedule->location);
                         } else {
                             add_post_meta($updated_schedule_id, 'location', $updated_schedule['location']);
                         }
                     }
                     $vars['message'] = __('Schedule was updated.', 'bpsp');
                 } else {
                     $vars['error'] = __('Schedule could not be updated.', 'bpsp');
                 }
             }
         }
     }
     $vars['name'] = 'edit_schedule';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['course_id'] = $this->current_course->ID;
     $vars['lecture_id'] = get_post_meta($old_schedule->ID, 'lecture_id', true);
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id);
     $vars['schedule'] = $this->is_schedule($old_schedule->ID);
     $vars['schedule_edit_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/edit';
     $vars['schedule_delete_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/delete';
     $vars['schedule_delete_title'] = __('Delete Course', 'bpsp');
     $vars['schedule_permalink'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule;
     $vars['nonce'] = wp_nonce_field($nonce_name, '_wpnonce', true, false);
     $vars['delete_nonce'] = add_query_arg('_wpnonce', wp_create_nonce('delete_schedule'), $vars['schedule_delete_uri']);
     $vars['trail'] = array($vars['schedule']->lecture->post_title => $vars['schedule']->lecture->permalink, __('Editing Schedule: ', 'bpsp') . $vars['schedule']->post_title => $vars['schedule']->permalink);
     return $vars;
 }
Пример #5
0
 /**
  * edit_bib_screen( $vars )
  *
  * Handles screen for editing the bibliographies
  * @param Array $vars, an array of variables
  * @return Array $vars modified
  */
 function edit_bib_screen($vars)
 {
     $nonce_name = 'edit_bib';
     $nonce_delete_name = 'delete_bib';
     $nonce_edit_name = $nonce_name;
     if (!$this->has_bib_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to edit bibliography.', 'bpsp');
         return $vars;
     }
     if (isset($_POST['_nxtnonce']) && isset($_GET['bhash'])) {
         if (!nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name)) {
             $vars['die'] = __('BuddyPress Courseware Nonce Error while editing bibliography.', 'bpsp');
             return $vars;
         }
     }
     $data = explode(',', sanitize_text_field($_GET['bhash']));
     $bhash = $data[0];
     $new_bhash = null;
     $post_id = null;
     if (isset($data[1]) && !empty($data[1])) {
         $post_id = $data[1];
         // Get the permalink for parent
         if (BPSP_Assignments::is_assignment($post_id)) {
             $vars['back_uri'] = $vars['nav_options'][__('Home', 'bpsp')] . '/assignment/' . $post_id;
         }
         if (BPSP_Courses::is_course($post_id)) {
             $vars['back_uri'] = $vars['nav_options'][__('Home', 'bpsp')] . '/course/' . $post_id;
         }
     } else {
         $bibdb_def = array('post_title' => 'BIBSDB', 'post_status' => 'draft', 'post_type' => 'bib');
         $bibdb_post = get_posts($bibdb_def);
         $post_id = $bibdb_post[0]->ID;
     }
     if ($post_id) {
         $old_bib = $this->get_bib($bhash, $post_id);
         if ($old_bib != null && isset($_POST['bib'])) {
             $new_bhash = $this->update_bib($_POST['bib'], true, $post_id, $old_bib);
             if (null != $new_bhash) {
                 $bhash = $new_bhash;
                 // Update for the next query
                 $vars['message'] = __('Entry updated.', 'bpsp');
             } else {
                 $vars['error'] = __('Entry could not be updated. Or nothing changed.', 'bpsp');
             }
         } elseif (!$old_bib && isset($_POST['bib'])) {
             $vars['error'] = __('Entry could not be found.', 'bpsp');
         }
     } else {
         $vars['error'] = __('No Bibliography database was created.', 'bpsp');
     }
     $vars['name'] = 'edit_bibliography';
     $vars['bib'] = shortcode_parse_atts($this->get_bib($bhash, $post_id));
     $vars['has_bibs'] = true;
     $vars['post_id'] = null;
     $vars['has_bib_caps'] = $this->has_bib_caps($bp->loggedin_user->id);
     $vars['bibs'] = $this->load_bibs(true);
     $vars['bibs_delete_permalink'] = $vars['current_uri'] . '/delete_bibliography';
     $vars['bibs_delete_uri'] = add_query_arg('_nxtnonce', nxt_create_nonce($nonce_delete_name), $vars['bibs_delete_permalink']);
     $vars['bibs_edit_uri'] = $vars['current_uri'] . '/edit_bibliography';
     $vars['bibs_form_uri'] = add_query_arg('bhash', $bhash . ',' . $post_id, $vars['bibs_edit_uri']);
     $vars['bibs_nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     $vars['trail'] = array(__('Editing Bibliography: ', 'bpsp') . $vars['bib']['title'] => '');
     return $vars;
 }
 /**
  * new_lecture_screen( $vars )
  *
  * Hooks into screen_handler
  * Adds a UI to add new lectures.
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function new_lecture_screen($vars)
 {
     global $bp;
     $nonce_name = 'new_lecture';
     if (!$this->has_lecture_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to add a new lecture.', 'bpsp');
         return $vars;
     }
     // Save new lecture
     $course = reset(BPSP_Courses::has_courses($bp->groups->current_group->id));
     if (isset($_POST['lecture']) && $_POST['lecture']['object'] == 'group' && isset($_POST['_wpnonce'])) {
         $new_lecture = $_POST['lecture'];
         $is_nonce = wp_verify_nonce($_POST['_wpnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while adding a lecture.', 'bpsp');
         } else {
             if (isset($new_lecture['title']) && isset($new_lecture['content']) && isset($new_lecture['group_id'])) {
                 $new_lecture['title'] = strip_tags($new_lecture['title']);
                 $new_lecture_id = wp_insert_post(array('post_author' => $bp->loggedin_user->id, 'post_title' => $new_lecture['title'], 'post_content' => $new_lecture['content'], 'post_parent' => isset($new_lecture['parent']) ? intval($new_lecture['parent']) : 0, 'menu_order' => isset($new_lecture['order']) ? intval($new_lecture['order']) : 0, 'post_status' => 'publish', 'post_type' => 'lecture'));
                 if ($new_lecture_id) {
                     wp_set_post_terms($new_lecture_id, $new_lecture['group_id'], 'group_id');
                     wp_set_post_terms($new_lecture_id, $course->ID, 'course_id');
                     self::$current_lecture = $this->is_lecture($new_lecture_id);
                     $vars['message'] = __('New lecture was added.', 'bpsp');
                     do_action('courseware_lecture_added', self::$current_lecture);
                     do_action('courseware_lecture_activity', self::$current_lecture, 'add');
                     return $this->single_lecture_screen($vars);
                 } else {
                     $vars['error'] = __('New lecture could not be added.', 'bpsp');
                 }
             } else {
                 $vars['error'] = __('Please fill in all the fields.', 'bpsp');
             }
         }
     }
     $vars['posted_data'] = isset($_POST['lecture']) ? $_POST['lecture'] : false;
     $vars['course'] = $course;
     $vars['lectures'] = $this->has_lectures($bp->groups->current_group->id);
     $vars['name'] = 'new_lecture';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['nonce'] = wp_nonce_field($nonce_name, '_wpnonce', true, false);
     $vars['trail'] = array($vars['course']->post_title => $vars['course']->permalink, __('New Lecture') => '');
     return $vars;
 }
 /**
  * edit_assignment_screen( $vars )
  *
  * Hooks into assignments_screen_handler
  * Edit assignment screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function edit_assignment_screen($vars)
 {
     global $bp;
     $nonce_name = 'edit_assignment';
     $updated_assignment_id = $this->current_assignment;
     $old_assignment = $this->is_assignment($this->current_assignment);
     if (!$this->has_assignment_caps($bp->loggedin_user->id) && $bp->loggedin_user->id != $old_course->post_author && $bp->groups->current_group->id != $old_course->group[0]->name && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the assignment.', 'bpsp');
         return $vars;
     }
     // Update course
     if (isset($_POST['assignment']) && $_POST['assignment']['object'] == 'group' && BPSP_Courses::is_course($_POST['assignment']['course_id']) && isset($_POST['_wpnonce'])) {
         $updated_assignment = $_POST['assignment'];
         $is_nonce = wp_verify_nonce($_POST['_wpnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while editing the assignment.', 'bpsp');
         } else {
             if (isset($updated_assignment['title']) && isset($updated_assignment['content']) && isset($updated_assignment['course_id']) && is_numeric($updated_assignment['group_id'])) {
                 $updated_assignment['title'] = strip_tags($updated_assignment['title']);
                 $updated_assignment_id = wp_update_post(array('ID' => $old_assignment->ID, 'post_title' => $updated_assignment['title'], 'post_content' => $updated_assignment['content']));
                 if ($updated_assignment_id) {
                     wp_set_post_terms($updated_assignment_id, $updated_assignment['course_id'], 'course_id');
                     if (strtotime($updated_assignment['due_date'])) {
                         update_post_meta($updated_assignment_id, 'due_date', $updated_assignment['due_date'], $old_assignment->due_date);
                     }
                     $vars['message'] = __('Assignment was updated.', 'bpsp');
                     do_action('courseware_assignment_activity', $this->is_assignment($updated_assignment_id), 'update');
                 } else {
                     $vars['error'] = __('Assignment could not be updated.', 'bpsp');
                 }
             }
         }
     }
     $vars['name'] = 'edit_assignment';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['courses'] = BPSP_Courses::has_courses($bp->groups->current_group->id);
     $vars['assignment'] = $this->is_assignment($updated_assignment_id);
     $vars['assignment_edit_uri'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name . '/edit';
     $vars['assignment_delete_uri'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name . '/delete';
     $vars['assignment_permalink'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name;
     $vars['nonce'] = wp_nonce_field($nonce_name, '_wpnonce', true, false);
     $vars['delete_nonce'] = add_query_arg('_wpnonce', wp_create_nonce('delete_assignment'), $vars['assignment_delete_uri']);
     return $vars;
 }
 function shortcode_courseware_dashboard($attributes)
 {
     global $bp;
     $course = false;
     if (isset($_GET['course_id'])) {
         $course = BPSP_Courses::is_course((int) $_GET['course_id']);
     }
     // @todo not pulling in # of lectures, assignments, etc
     if ($course) {
         $bp->groups->current_group->creator_id = 1;
         // @todo set to current user? no, to author of course post?
         $vars = array_merge($this->group_dashboard(array()), array('nav_options' => array(__('Home', 'bpsp') => ''), 'group_course' => $course));
         BPSP_Groups::load_template($vars);
     } else {
         echo '<p>Invalid course ID</p>';
     }
 }