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;
 }
/**
 * 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();
}
 /**
  * screen_handler( $action_vars )
  *
  * Assignment screens handler.
  * Handles uris like groups/ID/courseware/assignments/args
  */
 function screen_handler($action_vars)
 {
     if (reset($action_vars) == 'new_assignment') {
         $this->current_course = BPSP_Courses::is_course();
         //Load editor
         add_action('bp_head', array(&$this, 'load_editor'));
         do_action('courseware_list_assignments_screen');
         do_action('courseware_new_assignment_screen');
         add_filter('courseware_group_template', array(&$this, 'new_assignment_screen'));
     } elseif (reset($action_vars) == 'assignment') {
         $current_assignment = BPSP_Assignments::is_assignment($action_vars[1]);
         if (isset($action_vars[1]) && null != $current_assignment) {
             $this->current_assignment = $current_assignment;
         } else {
             wp_redirect(wp_redirect(get_option('siteurl')));
         }
         if (isset($action_vars[2]) && 'edit' == $action_vars[2]) {
             // Try to serve the form data
             if (isset($_GET['get_form_data'])) {
                 $this->get_form_data();
             }
             add_action('bp_head', array(&$this, 'load_editor'));
             do_action('courseware_edit_assignment_screen');
             add_filter('courseware_group_template', array(&$this, 'edit_assignment_screen'));
         } elseif (isset($action_vars[2]) && 'delete' == $action_vars[2]) {
             add_filter('courseware_group_template', array(&$this, 'delete_assignment_screen'));
         } elseif (isset($action_vars[2]) && 'enable_forum' == $action_vars[2]) {
             do_action('courseware_bibliography_screen');
             add_filter('courseware_group_template', array(&$this, 'enable_forum_assignment_screen'));
         } else {
             do_action('courseware_bibliography_screen');
             do_action('courseware_assignment_screen');
             add_filter('courseware_group_template', array(&$this, 'single_assignment_screen'));
         }
         do_action('courseware_assignment_screen_handler', $action_vars);
     } elseif (reset($action_vars) == 'assignments') {
         do_action('courseware_list_assignments_screen');
         add_filter('courseware_group_template', array(&$this, 'list_assignments_screen'));
     }
 }
 /**
  * gradebook_screen( $vars )
  *
  * Hooks into screen_handler
  * Adds a UI to assignments for gradebook management.
  *
  * @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 gradebook_screen($vars)
 {
     global $bp;
     $nonce_name = 'gradebook_nonce';
     $nonce_import_name = 'gradebook_import_nonce';
     $nonce_clear_name = 'gradebook_clear_nonce';
     if (!$this->has_gradebook_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to manage gradebook.', 'bpsp');
         return $vars;
     }
     $students = BP_Groups_Member::get_all_for_group($bp->groups->current_group->id);
     if (isset($_POST['_nxtnonce'])) {
         $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name);
     }
     if (isset($_POST['_nxtnonce']) && true != $is_nonce) {
         $vars['die'] = __('BuddyPress Courseware Nonce Error while updating gradebook.', 'bpsp');
         return $vars;
     }
     $gradebook_id = $this->has_gradebook($this->current_assignment);
     if (!$gradebook_id) {
         $vars['die'] = __('BuddyPress Courseware Error while creating gradebook.', 'bpsp');
         return $vars;
     }
     if (!empty($_POST['grade'])) {
         foreach ($_POST['grade'] as $grade) {
             if (!empty($grade) && !empty($grade['uid']) && !empty($grade['value'])) {
                 # If grade was added or updated!
                 $status = $this->save_grade($gradebook_id, $grade);
                 if ($status !== null) {
                     $data = array('grade' => $grade, 'teacher' => $bp->loggedin_user->userdata, 'assignment' => $this->current_assignment);
                     if ($status == true) {
                         do_action('courseware_grade_added', $data);
                     } else {
                         do_action('courseware_grade_updated', $data);
                     }
                 }
             }
         }
         $vars['message'] = __('Gradebook saved.', 'bpsp');
     }
     $vars['name'] = 'gradebook';
     $vars['students'] = $students['members'];
     if (empty($vars['grades'])) {
         $vars['grades'] = $this->load_grades($gradebook_id, true);
     }
     $vars['bpsp_gradebook_format'] = get_option('bpsp_gradebook_format');
     $vars['assignment'] = BPSP_Assignments::is_assignment($this->current_assignment);
     $vars['gradebook_permalink'] = $vars['assignment_permalink'] . '/gradebook';
     $vars['clear_gradebook_permalink'] = add_query_arg('_nxtnonce', nxt_create_nonce($nonce_clear_name), $vars['gradebook_permalink'] . '/clear');
     $vars['import_gradebook_nonce'] = nxt_nonce_field($nonce_import_name, '_nxtnonce', true, false);
     $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     return $vars;
 }
 /**
  * screen_handler( $action_vars )
  *
  * Response screens handler.
  * Handles uris like groups/ID/courseware/response/args
  */
 function screen_handler($action_vars)
 {
     $this->current_assignment = BPSP_Assignments::is_assignment($action_vars[1]);
     // Check if we got a valid parent assignment
     if (!$this->current_assignment) {
         wp_redirect(wp_redirect(get_option('siteurl')));
     }
     if ($action_vars[2] == 'add_response') {
         //Load editor
         add_action('bp_head', array(&$this, 'load_editor'));
         add_filter('courseware_group_template', array(&$this, 'new_response_screen'));
     } elseif ($action_vars[2] == 'response') {
         $current_response = $this->is_response($action_vars[3]);
         if (isset($action_vars[3]) && !empty($current_response)) {
             $this->current_response = $current_response;
         } else {
             wp_redirect(wp_redirect(get_option('siteurl')));
         }
         if (isset($action_vars[4]) && 'delete' == $action_vars[4]) {
             add_filter('courseware_group_template', array(&$this, 'delete_response_screen'));
         } else {
             add_filter('courseware_group_template', array(&$this, 'single_response_screen'));
         }
     }
 }
 /**
  * toICS()
  *
  * Outputs group schedules in ICS format
  */
 function toICS()
 {
     require_once BPSP_PLUGIN_DIR . '/schedules/iCalcreator.class.php';
     global $bp;
     define('ICAL_LANG', get_bloginfo('language'));
     $cal = new vcalendar();
     $cal->setConfig('unique_id', str_replace('http://', '', get_bloginfo('siteurl')));
     $cal->setConfig('filename', $bp->groups->current_group->slug);
     $cal->setProperty('X-WR-CALNAME', __('Calendar for: ', 'bpsp') . $bp->groups->current_group->name);
     $cal->setProperty('X-WR-CALDESC', $bp->groups->current_group->description);
     $cal->setProperty('X-WR-TIMEZONE', get_option('timezone_string'));
     $schedules = $this->has_schedules();
     $assignments = BPSP_Assignments::has_assignments();
     $entries = array_merge($assignments, $schedules);
     foreach ($entries as $entry) {
         setup_postdata($entry);
         $e = new vevent();
         if ($entry->post_type == "schedule") {
             $date = getdate(strtotime($entry->start_date));
         } elseif ($entry->post_type == "assignment") {
             $date = getdate(strtotime($entry->post_date));
         }
         $dtstart['year'] = $date['year'];
         $dtstart['month'] = $date['mon'];
         $dtstart['day'] = $date['mday'];
         $dtstart['hour'] = $date['hours'];
         $dtstart['min'] = $date['minutes'];
         $dtstart['sec'] = $date['seconds'];
         $e->setProperty('dtstart', $dtstart);
         $e->setProperty('description', get_the_content() . "\n\n" . $entry->permalink);
         if (!empty($entry->location)) {
             $e->setProperty('location', $entry->location);
         }
         if ($entry->post_type == "assignment") {
             $entry->end_date = $entry->due_date;
         }
         // make assignments compatible with schedule parser
         if (!empty($entry->end_date)) {
             $date = getdate(strtotime($entry->end_date));
             $dtend['year'] = $date['year'];
             $dtend['month'] = $date['mon'];
             $dtend['day'] = $date['mday'];
             $dtend['hour'] = $date['hours'];
             $dtend['min'] = $date['minutes'];
             $dtend['sec'] = $date['seconds'];
             $e->setProperty('dtend', $dtend);
         } else {
             $e->setProperty('duration', 0, 1, 0);
         }
         // Assume it's an one day event
         $e->setProperty('summary', get_the_title($entry->ID));
         $e->setProperty('status', 'CONFIRMED');
         $cal->setComponent($e);
     }
     header("HTTP/1.1 200 OK");
     die($cal->returnCalendar());
 }
Example #7
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;
 }