コード例 #1
0
 /**
  * Get the current step.
  *
  * If StepID has been set in the URL, we attempt to get that record
  * by the ID. Otherwise, we check if there's a current step ID in
  * our session record. Failing those cases, we assume that the form has
  * just been started, and so we create the first step and return it.
  *
  * @return MultiFormStep subclass
  */
 public function getCurrentStep()
 {
     $startStepClass = static::$start_step;
     // Check if there was a start step defined on the subclass of MultiForm
     if (!isset($startStepClass)) {
         user_error('MultiForm::init(): Please define a $start_step on ' . $this->class, E_USER_ERROR);
     }
     // Determine whether we use the current step, or create one if it doesn't exist
     $currentStep = null;
     if (isset($_GET['StepID'])) {
         $stepID = (int) $_GET['StepID'];
         $currentStep = DataObject::get_one('MultiFormStep', "\"SessionID\" = {$this->session->ID} AND \"ID\" = {$stepID}");
     } elseif ($this->session->CurrentStepID) {
         $currentStep = $this->session->CurrentStep();
     }
     // Always fall back to creating a new step (in case the session or request data is invalid)
     if (!$currentStep || !$currentStep->ID) {
         $currentStep = Object::create($startStepClass);
         $currentStep->SessionID = $this->session->ID;
         $currentStep->write();
         $this->session->CurrentStepID = $currentStep->ID;
         $this->session->write();
         $this->session->flushCache();
     }
     if ($currentStep) {
         $currentStep->setForm($this);
     }
     return $currentStep;
 }
コード例 #2
0
	/**
	 * Get the current step.
	 * 
	 * If StepID has been set in the URL, we attempt to get that record
	 * by the ID. Otherwise, we check if there's a current step ID in
	 * our session record. Failing those cases, we assume that the form has
	 * just been started, and so we create the first step and return it.
	 * 
	 * @return MultiFormStep subclass
	 */
	public function getCurrentStep() {
		$startStepClass = $this->stat('start_step');
		
		// Check if there was a start step defined on the subclass of MultiForm
		if(!isset($startStepClass)) user_error('MultiForm::init(): Please define a $startStep on ' . $this->class, E_USER_ERROR);
		
		// Determine whether we use the current step, or create one if it doesn't exist
		if(isset($_GET['StepID'])) {
			$stepID = (int)$_GET['StepID'];
			$currentStep = DataObject::get_one('MultiFormStep', "SessionID = {$this->session->ID} AND ID = {$stepID}");
		} elseif($this->session->CurrentStepID) {
			$currentStep = $this->session->CurrentStep();
		} else {
			$currentStep = new $startStepClass();
			$currentStep->SessionID = $this->session->ID;
			$currentStep->write();
		}
		
		return $currentStep;
	}