/** * @return BfoxReadingPlan */ public function plan() { return BfoxReadingPlan::plan($this->plan_id); }
function bfox_bp_plans_screen_create() { global $bp; do_action('bfox_bp_plans_screen_create'); $bp->plans->plan_creation_steps = apply_filters('plans_create_plan_steps', array('plan-details' => array('name' => __('Plan Details', 'bfox'), 'position' => 0), 'plan-add-groups' => array('name' => __('Add Groups of Chapters', 'bfox'), 'position' => 10), 'plan-edit-readings' => array('name' => __('Edit Readings', 'bfox'), 'position' => 20), 'plan-avatar' => array('name' => __('Add an Avatar', 'bfox'), 'position' => 30))); /* If no current step is set, reset everything so we can start a fresh plan creation */ if (!($bp->plans->current_create_step = $bp->action_variables[1])) { unset($bp->plans->current_create_step); unset($bp->plans->completed_create_steps); setcookie('bp_new_plan_id', false, time() - 1000, COOKIEPATH); setcookie('bp_completed_plan_create_steps', false, time() - 1000, COOKIEPATH); $reset_steps = true; bp_core_redirect(bfox_bp_plans_create_url(array_shift(array_keys($bp->plans->plan_creation_steps)))); } /* If this is a creation step that is not recognized, just redirect them back to the first screen */ if ($bp->action_variables[1] && !$bp->plans->plan_creation_steps[$bp->action_variables[1]]) { bp_core_add_message(__('There was an error saving reading plan details. Please try again.', 'bfox'), 'error'); bp_core_redirect(bfox_bp_plans_create_url()); } /* Fetch the currently completed steps variable */ if (isset($_COOKIE['bp_completed_plan_create_steps']) && !$reset_steps) { $bp->plans->completed_create_steps = unserialize(stripslashes($_COOKIE['bp_completed_plan_create_steps'])); } /* Set the ID of the new plan, if it has already been created in a previous step */ if (isset($_COOKIE['bp_new_plan_id'])) { $new_plan_id = (int) $_COOKIE['bp_new_plan_id']; } else { $new_plan_id = 0; } $plan = bfox_bp_plan(BfoxReadingPlan::plan($new_plan_id)); bfox_bp_plans_must_own($plan); /* If the save, upload or skip button is hit, lets calculate what we need to save */ if (isset($_POST['save'])) { /* Check the nonce */ check_admin_referer('plans_create_save_' . $bp->plans->current_create_step); if ('plan-details' == $bp->plans->current_create_step) { if (empty($_POST['plan-name'])) { bp_core_add_message(__('Please fill in all of the required fields', 'bfox'), 'error'); bp_core_redirect(bfox_bp_plans_create_url($bp->plans->current_create_step)); } bfox_bp_plans_update_plan_details($plan); } elseif ('plan-add-groups' == $bp->plans->current_create_step || 'plan-edit-readings' == $bp->plans->current_create_step) { bfox_bp_plans_update_plan_readings($plan); } do_action('plans_create_plan_step_save_' . $bp->plans->current_create_step); do_action('plans_create_plan_step_complete'); // Mostly for clearing cache on a generic action name /** * Once we have successfully saved the details for this step of the creation process * we need to add the current step to the array of completed steps, then update the cookies * holding the information */ if (!in_array($bp->plans->current_create_step, (array) $bp->plans->completed_create_steps)) { $bp->plans->completed_create_steps[] = $bp->plans->current_create_step; } /* Reset cookie info */ setcookie('bp_new_plan_id', $plan->id, time() + 60 * 60 * 24, COOKIEPATH); setcookie('bp_completed_plan_create_steps', serialize($bp->plans->completed_create_steps), time() + 60 * 60 * 24, COOKIEPATH); /* If we have completed all steps and hit done on the final step we can redirect to the completed plan */ if (count($bp->plans->completed_create_steps) == count($bp->plans->plan_creation_steps) && $bp->plans->current_create_step == array_pop(array_keys($bp->plans->plan_creation_steps))) { unset($bp->plans->current_create_step); unset($bp->plans->completed_create_steps); /* Once we compelete all steps, record the plan creation in the activity stream. */ /*plans_record_activity( array( 'content' => apply_filters( 'plans_activity_created_plan', sprintf( __( '%s created the reading plan %s', 'bfox'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_plan_permalink( $plan ) . '">' . attribute_escape( $plan->name ) . '</a>' ) ), 'primary_link' => apply_filters( 'plans_activity_created_plan_primary_link', bp_get_plan_permalink( $plan ) ), 'component_action' => 'created_plan', 'item_id' => $plan->id ) );*/ do_action('plans_plan_create_complete', $plan->id); bp_core_redirect($plan->url() . 'add-schedule/'); } else { /** * Since we don't know what the next step is going to be (any plugin can insert steps) * we need to loop the step array and fetch the next step that way. */ foreach ($bp->plans->plan_creation_steps as $key => $value) { if ($key == $bp->plans->current_create_step) { $next = 1; continue; } if ($next) { $next_step = $key; break; } } bp_core_redirect(bfox_bp_plans_create_url($next_step)); } } if ('plan-avatar' == $bp->plans->current_create_step) { bfox_bp_plans_update_plan_avatar($plan, true); } bfox_bp_core_load_template(apply_filters('bfox_bp_plans_template_screen_create', 'plans/create')); }