Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class QuotePage extends Page{
- }
- class QuotePage_Controller extends ContentController {
- private static $allowed_actions = array(
- 'index','ExistingQuotes','CreateQuoteForm','EditQuoteForm','edit'
- );
- public function init(){
- parent::init();
- }
- public function index() {
- return $this->renderWith(array("QuotePage","Page"));
- }
- public function ExistingQuotes(){
- $ExistingQuotes = DataObject::get('Quote');
- return $ExistingQuotes;
- }
- // Template method
- public function CreateQuoteForm() {
- $group = DataObject::get_one("Group", "Title = 'Customers'");
- $members = $group->Members();
- $fields = new FieldList(
- new DropdownField('Customer', 'Customer', $members->map("ID", "Name", "Please Select"))
- );
- $actions = new FieldList(
- FormAction::create("doCreateQuote")->setTitle("Create Quote")
- );
- $form = new Form($this, 'CreateQuoteForm', $fields, $actions);
- return $form;
- }
- public function EditQuoteForm() {
- if($this->request->isPOST()){
- $ID = $this->request->postVar('QuoteID');
- } else {
- $ID = $this->request->param('ID');
- }
- $Quote = DataObject::get_by_id('Quote', $this->request->param('ID'));
- $fields = new FieldList();
- $fields->push(new HiddenField('QuoteID','QuoteID',$Quote->ID));
- $fields->push(new HiddenField('CustomerID','CustomerID',$Quote->Customer()->ID));
- $fields->push(new TextField('Code','Code',$Quote->Code));
- $fields->push(new DropdownField('AddProduct','Add a Product',DataObject::get("Product")->map("ID", "Name", "Please Select")));
- $fields->push(new InlineFormAction('doAddProduct','Add Product'));
- foreach($Quote->Product as $Product){
- $productDropdown = new DropdownField('Product_' . $Product->ID,'Product',DataObject::get("Product")->map("ID", "Name", "Please Select"));
- $fields->push($productDropdown);
- }
- $actions = new FieldList(
- FormAction::create("doSaveQuote")->setTitle("Save Quote")
- );
- $form = new Form($this,'EditQuoteForm', $fields, $actions);
- return $form;
- }
- public function edit() {
- if(($ID = $this->request->param('ID')) && ($Quote = DataObject::get_by_id('Quote', $ID))) {
- return $this->renderWith(array('QuoteEditorPage', 'Page'));
- }
- else return 'Quote does not exist';
- }
- public function doSaveQuote($data, Form $form) {
- $Quote = DataObject::get_by_id('Quote', $data['QuoteID']);
- $Quote->Code = $data["Code"];
- $Quote->write();
- echo($data['QuoteID']);
- return $this->renderWith(array("QuoteEditorPage","Page"));
- }
- public function doCreateQuote($data, Form $form) {
- $NewQuote = new Quote();
- $NewQuote->CustomerID = $data["Customer"];
- $NewQuote->write();
- return $this->renderWith(array("QuotePage","Page"));
- }
- public function doAddProduct($data, Form $form) {
- $NewQuotedProduct = new QuotedProduct();
- $NewQuotedProduct->Code = "Testing123";
- echo("Hello" . $data["QuoteID"] ."," . $data["Product"]);
- return $this->redirectBack();
- $NewQuotedProduct->QuoteID = $data["QuoteID"];
- $NewQuoteProduct->ProductID = $data["Product"];
- $NewQuotedProduct->write();
- // return $this->customise($data)->renderWith(array('QuoteEditorPage', 'Page'));*/
- }
- function Link($action = ''){
- return self::join_links('quote', $action);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement