Advertisement
Guest User

LimResFPAForms

a guest
Nov 17th, 2013
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.67 KB | None | 0 0
  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.         return $this->renderWith(array("QuotePage","Page"));
  18.     }
  19.        
  20.     public function ExistingQuotes(){
  21.         $ExistingQuotes = DataObject::get('Quote');
  22.         return $ExistingQuotes;
  23.     }
  24.    
  25.     // Template method
  26.     public function CreateQuoteForm() {
  27.         $group = DataObject::get_one("Group", "Title = 'Customers'");
  28.         $members = $group->Members();
  29.  
  30.         $fields = new FieldList(
  31.             new DropdownField('Customer', 'Customer', $members->map("ID", "Name", "Please Select"))
  32.         );
  33.  
  34.         $actions = new FieldList(
  35.             FormAction::create("doCreateQuote")->setTitle("Create Quote")
  36.         );
  37.        
  38.         $form = new Form($this, 'CreateQuoteForm', $fields, $actions);
  39.        
  40.         // Load the form with previously sent data
  41.         $form->loadDataFrom($this->request->postVars());
  42.         return $form;
  43.     }
  44.    
  45.     public function EditQuoteForm() {
  46.         //if(($ID = $this->request->param('ID')) && ($Quote = DataObject::get_by_id('Quote', $ID))) {
  47.             $Quote = DataObject::get_by_id('Quote', $this->request->param('ID'));
  48.             $fields = new FieldList();
  49.             $fields->push(new HiddenField('QuoteID','QuoteID',$Quote->ID));
  50.             $fields->push(new HiddenField('CustomerID','CustomerID',$Quote->Customer()->ID));
  51.             $fields->push(new TextField('Code','Code',$Quote->Code));
  52.            
  53.             $fields->push(new DropdownField('AddProduct','Add a Product',DataObject::get("Product")->map("ID", "Name", "Please Select")));
  54.             $fields->push(new InlineFormAction('doAddProduct','Add Product'));
  55.            
  56.             foreach($Quote->Product as $Product){
  57.                 $productDropdown = new DropdownField('Product_' . $Product->ID,'Product',DataObject::get("Product")->map("ID", "Name", "Please Select"));
  58.                 $fields->push($productDropdown);
  59.             }
  60.            
  61.             $actions = new FieldList(
  62.                 //FormAction::create("doAddProduct")->setTitle("AddProduct"),
  63.                 FormAction::create("doSaveQuote")->setTitle("Save Quote")
  64.             );
  65.  
  66.             $form = new Form($this,'EditQuoteForm', $fields, $actions);
  67.  
  68.             // Load the form with previously sent data
  69.             $form->loadDataFrom($this->request->postVars());
  70.             return $form;
  71.         //}// else{
  72.             //print_r($data);
  73.         //}
  74.     }
  75.    
  76.     public function edit() {
  77.         if(($ID = $this->request->param('ID')) && ($Quote = DataObject::get_by_id('Quote', $ID))) {        
  78.             return $this->renderWith(array('QuoteEditorPage', 'Page'));
  79.         }
  80.         else return 'Quote does not exist';
  81.     }
  82.    
  83.     public function doSaveQuote($data, Form $form) {
  84.         echo("save");
  85.         exit;
  86.         $Quote = DataObject::get_by_id('Quote', $data['QuoteID']);
  87.         $Quote->Code = $data["Code"];
  88.         $Quote->write();
  89.         echo($data['QuoteID']);
  90.         exit;
  91.         return $this->renderWith(array("QuoteEditorPage","Page"));
  92.     }
  93.  
  94.     public function doCreateQuote($data, Form $form) {
  95.         // Do something with $data
  96.         $NewQuote = new Quote();
  97.         $NewQuote->CustomerID = $data["Customer"];
  98.         $NewQuote->write();
  99.         return $this->renderWith(array("QuotePage","Page"));
  100.     }
  101.    
  102.     public function doAddProduct($data, Form $form) {
  103.         $NewQuotedProduct = new QuotedProduct();
  104.         $NewQuotedProduct->Code = "Testing123";
  105.         echo("Hello" . $data["QuoteID"] ."," . $data["Product"]);
  106.         return $this->redirectBack();
  107.         /*exit;
  108.         $NewQuotedProduct->QuoteID = $data["QuoteID"];
  109.         $NewQuoteProduct->ProductID = $data["Product"];
  110.         $NewQuotedProduct->write();
  111.         return $this->customise($data)->renderWith(array('QuoteEditorPage', 'Page'));*/
  112.     }
  113.    
  114.     public function FormObjectLink($http) {
  115.         return 'quote/' . $this->request->param('Action') .  '/'.$this->request->param('ID').'/';
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement