Example #1
0
function bebop_manage_oers()
{
    if (bp_is_current_component('bebop') && bp_is_current_action('bebop-manager')) {
        if (isset($_POST['action'])) {
            global $wpdb;
            global $bp;
            $oer_count = 0;
            $success = false;
            //Add OER's to the activity stream.
            if ($_POST['action'] == 'verify') {
                foreach (array_keys($_POST) as $oer) {
                    if ($oer != 'action') {
                        $data = bebop_tables::fetch_individual_oer_data($oer);
                        //go and fetch data from the activity buffer table.
                        if (!empty($data->id)) {
                            $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification');
                            if ($should_users_verify_content != 'no') {
                                global $wpdb;
                                if (!bp_has_activities('action=bebop_oer_plugin&item_id=' . $data->id)) {
                                    $new_activity_item = array('user_id' => $data->user_id, 'component' => 'bebop_oer_plugin', 'type' => $data->type, 'action' => $data->action, 'content' => $data->content, 'item_id' => $data->id, 'date_recorded' => $data->date_recorded, 'hide_sitewide' => $data->hide_sitewide);
                                    if (bp_activity_add($new_activity_item)) {
                                        bebop_tables::update_oer_data($data->id, 'status', 'verified');
                                        bebop_tables::update_oer_data($data->id, 'activity_stream_id', $wpdb->insert_id);
                                        $oer_count++;
                                    } else {
                                        bebop_tables::log_error(__('Activity Stream', 'bebop'), __('Could not update the content status.', 'bebop'));
                                    }
                                } else {
                                    bebop_tables::log_error(__('Activity Stream', 'bebop'), __('This content already exists in the activity stream.', 'bebop'));
                                }
                            }
                            //End if ( $should_users_verify_content != 'no' ) {
                        }
                    }
                }
                //End foreach ( array_keys($_POST) as $oer ) {
                if ($oer_count > 1) {
                    $success = true;
                    $message = __('Resources verified.', 'bebop');
                } else {
                    $success = true;
                    $message = __('Resource verified.', 'bebop');
                }
            } else {
                if ($_POST['action'] == 'delete') {
                    foreach (array_keys($_POST) as $oer) {
                        if ($oer != 'action') {
                            $data = bebop_tables::fetch_individual_oer_data($oer);
                            //go and fetch data from the activity buffer table.
                            if (!empty($data->id)) {
                                //delete the activity, let the filter update the tables.
                                if (!empty($data->activity_stream_id)) {
                                    $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification');
                                    if ($should_users_verify_content != 'no') {
                                        bp_activity_delete(array('id' => $data->activity_stream_id));
                                    }
                                }
                                bebop_tables::update_oer_data($data->id, 'status', 'deleted');
                                $oer_count++;
                            }
                        }
                    }
                    //End foreach ( array_keys( $_POST ) as $oer ) {
                    if ($oer_count > 1) {
                        $success = true;
                        $message = __('Resources deleted.', 'bebop');
                    } else {
                        $success = true;
                        $message = __('Resource deleted.', 'bebop');
                    }
                } else {
                    if ($_POST['action'] == 'undelete') {
                        foreach (array_keys($_POST) as $oer) {
                            $exclude_array = array('action', 'submit');
                            if (!in_array($oer, $exclude_array)) {
                                $data = bebop_tables::fetch_individual_oer_data($oer);
                                //go and fetch data from the activity buffer table.
                                $should_users_verify_content = bebop_tables::get_option_value('bebop_' . $data->type . '_content_user_verification');
                                if ($should_users_verify_content != 'no') {
                                    bebop_tables::update_oer_data($data->id, 'status', 'unverified');
                                    $oer_count++;
                                }
                            }
                        }
                        if ($oer_count > 1) {
                            $success = true;
                            $message = __('Resources undeleted.', 'bebop');
                        } else {
                            $success = true;
                            $message = __('Resource undeleted.', 'bebop');
                        }
                    }
                }
            }
            if ($success) {
                bp_core_add_message($message);
            } else {
                bp_core_add_message(__('We couldnt do that for you. Please try again.', 'bebop'), __('error', 'bebop'));
            }
            bp_core_redirect($bp->loggedin_user->domain . bp_current_component() . '/' . bp_current_action());
        }
        //End if ( isset( $_POST['action'] ) ) {
    }
    //End if ( bp_is_current_component( 'bebop' ) && bp_is_current_action('bebop-manager' ) ) {
    add_action('wp_enqueue_scripts', 'bebop_oer_js');
    //enqueue  selectall/none script
}
Example #2
0
function bebop_feed_get_date_recorded($secondary_item_id)
{
    $data = bebop_tables::fetch_individual_oer_data($secondary_item_id);
    return $data->date_recorded;
}