All pastes #562899 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-12 23:04 UTC
rendered paste body
public function create(RFPTemplate $t) {
	
	$type = (int) $t->getTypeID();
	
	if(!is_int($type)) {
	    throw new RFPException('Unable to get TypeID: '. $type);
	}
	
	//figure out the type of RFP, Actual Name "Wedding"
	$query = '
	    SELECT
		Type
	    FROM
		RFP_Types
	    WHERE
		ID = '. $type .'
	    LIMIT 1';
	
	$typeName = $this->dbObj->getField($query);
	
	//How many other same type RFPs are there?
	$query = '
	    SELECT
		count(ID)
	    FROM
		RFP_Forms
	    WHERE
		TypeID = '. $type;
	
	$number = $this->dbObj->getField($query) + 1;
	
	//Create the Record for the RFP
	$query = '
	    INSERT INTO
		RFP_Forms
	    SET
		Name = "'. $typeName .' '. $number .'",
		TypeID = '. $type .',
		AccountID = '. $_SESSION['user']->getAccountID();
	
	$this->dbObj->query($query);
	
	$this->setName($typeName .' '. $number);
	
	//save the id of the form we just created
	$FormID = $this->dbObj->getLastID();
	
	$this->id = $FormID;
	
	//add the questions
	if(!is_array($t->getQuestions())) {
	    throw new RFPException('Unable to load questions no array: $this->questions');
	}
	
	$questions = $t->getQuestions();
	
	$query = '
	    INSERT INTO RFP_FormQuestions
	    (`FormID`,`QuestionID`,`Order`,`IsActive`) VALUES 
	';
	
	$i = 1;
	
	while($i <= count($questions)) {
	    
	    $query .= '('. $FormID .', '. $questions[($i - 1)] .', '. $i .', 1)';
	    
	    if($i != count($questions)) {
		$query .= ', ';
	    }
	    
	    $i++;
	    
	}
	
	$this->dbObj->query($query);
	
	$query = '
	    INSERT INTO RFP_FormDesign
	    SET
		FormID = '. $FormID .',
		title = "'. $this->getName() .'",
		text = "Please fill out the request...",
		IsActive = 1
	';
	
	$this->dbObj->query($query);
	
    }