View difference between Paste ID: i5DPRMdq and msgb4Bpf
SHOW: | | - or go back to the newest paste.
1
<?php
2
class QuotePage extends Page{
3
	
4
}
5
6
class QuotePage_Controller extends ContentController {
7
    
8
	private static $allowed_actions = array(
9
		'index','ExistingQuotes','CreateQuoteForm','EditQuoteForm','edit'
10
	);
11
12
	public function init(){
13
		parent::init();
14
	}
15
16
	public function index() {
17
		
18
		return $this->renderWith(array("QuotePage","Page"));
19
	}
20
		
21
	public function ExistingQuotes(){
22
		$ExistingQuotes = DataObject::get('Quote');
23
		return $ExistingQuotes;
24
	}
25
	
26
	// Template method
27
	public function CreateQuoteForm() {
28
		$group = DataObject::get_one("Group", "Title = 'Customers'");
29
		$members = $group->Members();
30
31
		$fields = new FieldList(
32
			new DropdownField('Customer', 'Customer', $members->map("ID", "Name", "Please Select"))
33
		);
34
35
		$actions = new FieldList(
36
			FormAction::create("doCreateQuote")->setTitle("Create Quote")
37
		);
38
		
39
		$form = new Form($this, 'CreateQuoteForm', $fields, $actions);
40-
		// Load the form with previously sent data
40+
41-
		$form->loadDataFrom($this->request->postVars());
41+
42
	
43
	public function EditQuoteForm() {
44
		if($this->request->isPOST()){
45
			$ID = $this->request->postVar('QuoteID');
46-
		//if(($ID = $this->request->param('ID')) && ($Quote = DataObject::get_by_id('Quote', $ID))) {
46+
		} else {
47-
			$Quote = DataObject::get_by_id('Quote', $this->request->param('ID'));
47+
			$ID = $this->request->param('ID');
48-
			$fields = new FieldList();
48+
49-
			$fields->push(new HiddenField('QuoteID','QuoteID',$Quote->ID));
49+
		$Quote = DataObject::get_by_id('Quote', $this->request->param('ID'));
50-
			$fields->push(new HiddenField('CustomerID','CustomerID',$Quote->Customer()->ID));
50+
		$fields = new FieldList();
51-
			$fields->push(new TextField('Code','Code',$Quote->Code));
51+
		$fields->push(new HiddenField('QuoteID','QuoteID',$Quote->ID));
52-
			
52+
		$fields->push(new HiddenField('CustomerID','CustomerID',$Quote->Customer()->ID));
53-
			$fields->push(new DropdownField('AddProduct','Add a Product',DataObject::get("Product")->map("ID", "Name", "Please Select")));
53+
		$fields->push(new TextField('Code','Code',$Quote->Code));
54-
			$fields->push(new InlineFormAction('doAddProduct','Add Product'));
54+
55-
			
55+
		$fields->push(new DropdownField('AddProduct','Add a Product',DataObject::get("Product")->map("ID", "Name", "Please Select")));
56-
			foreach($Quote->Product as $Product){
56+
		$fields->push(new InlineFormAction('doAddProduct','Add Product'));
57-
				$productDropdown = new DropdownField('Product_' . $Product->ID,'Product',DataObject::get("Product")->map("ID", "Name", "Please Select"));
57+
58-
				$fields->push($productDropdown);
58+
		foreach($Quote->Product as $Product){
59-
			}
59+
			$productDropdown = new DropdownField('Product_' . $Product->ID,'Product',DataObject::get("Product")->map("ID", "Name", "Please Select"));
60-
			
60+
			$fields->push($productDropdown);
61-
			$actions = new FieldList(
61+
62-
				//FormAction::create("doAddProduct")->setTitle("AddProduct"),
62+
63-
				FormAction::create("doSaveQuote")->setTitle("Save Quote")
63+
64-
			);
64+
			FormAction::create("doSaveQuote")->setTitle("Save Quote")
65
		);
66-
			$form = new Form($this,'EditQuoteForm', $fields, $actions);
66+
67
		$form = new Form($this,'EditQuoteForm', $fields, $actions);
68-
			// Load the form with previously sent data
68+
69-
			$form->loadDataFrom($this->request->postVars());
69+
70-
			return $form;
70+
71-
		//}// else{
71+
72-
			//print_r($data);
72+
73-
		//}
73+
74
			return $this->renderWith(array('QuoteEditorPage', 'Page'));
75
		}
76
		else return 'Quote does not exist';
77
	}
78
	
79
	public function doSaveQuote($data, Form $form) {
80
		$Quote = DataObject::get_by_id('Quote', $data['QuoteID']);
81
		$Quote->Code = $data["Code"];
82
		$Quote->write();
83
		echo($data['QuoteID']);
84-
		echo("save");
84+
85-
		exit;
85+
86
87
	public function doCreateQuote($data, Form $form) {
88
		$NewQuote = new Quote();
89
		$NewQuote->CustomerID = $data["Customer"];
90-
		exit;
90+
91
		return $this->renderWith(array("QuotePage","Page"));
92
	}
93
	
94
	public function doAddProduct($data, Form $form) {
95-
		// Do something with $data
95+
96
		$NewQuotedProduct->Code = "Testing123";
97
		echo("Hello" . $data["QuoteID"] ."," . $data["Product"]);
98
		return $this->redirectBack();
99
		$NewQuotedProduct->QuoteID = $data["QuoteID"];
100
		$NewQuoteProduct->ProductID = $data["Product"];
101
		$NewQuotedProduct->write();
102
//		return $this->customise($data)->renderWith(array('QuoteEditorPage', 'Page'));*/
103
	}
104
	
105
	function Link($action = ''){
106
		return self::join_links('quote', $action);
107-
		/*exit;
107+
108
}