Advertisement
Guest User

LimResFPAForms2

a guest
Nov 17th, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         return $form;
  41.     }
  42.    
  43.     public function EditQuoteForm() {
  44.         if($this->request->isPOST()){
  45.             $ID = $this->request->postVar('QuoteID');
  46.         } else {
  47.             $ID = $this->request->param('ID');
  48.         }
  49.         $Quote = DataObject::get_by_id('Quote', $this->request->param('ID'));
  50.         $fields = new FieldList();
  51.         $fields->push(new HiddenField('QuoteID','QuoteID',$Quote->ID));
  52.         $fields->push(new HiddenField('CustomerID','CustomerID',$Quote->Customer()->ID));
  53.         $fields->push(new TextField('Code','Code',$Quote->Code));
  54.  
  55.         $fields->push(new DropdownField('AddProduct','Add a Product',DataObject::get("Product")->map("ID", "Name", "Please Select")));
  56.         $fields->push(new InlineFormAction('doAddProduct','Add Product'));
  57.  
  58.         foreach($Quote->Product as $Product){
  59.             $productDropdown = new DropdownField('Product_' . $Product->ID,'Product',DataObject::get("Product")->map("ID", "Name", "Please Select"));
  60.             $fields->push($productDropdown);
  61.         }
  62.  
  63.         $actions = new FieldList(
  64.             FormAction::create("doSaveQuote")->setTitle("Save Quote")
  65.         );
  66.  
  67.         $form = new Form($this,'EditQuoteForm', $fields, $actions);
  68.  
  69.         return $form;
  70.     }
  71.    
  72.     public function edit() {
  73.         if(($ID = $this->request->param('ID')) && ($Quote = DataObject::get_by_id('Quote', $ID))) {        
  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.         return $this->renderWith(array("QuoteEditorPage","Page"));
  85.     }
  86.  
  87.     public function doCreateQuote($data, Form $form) {
  88.         $NewQuote = new Quote();
  89.         $NewQuote->CustomerID = $data["Customer"];
  90.         $NewQuote->write();
  91.         return $this->renderWith(array("QuotePage","Page"));
  92.     }
  93.    
  94.     public function doAddProduct($data, Form $form) {
  95.         $NewQuotedProduct = new QuotedProduct();
  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.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement