Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1.   public function configure()
  2.   {
  3.    
  4.     $this->useFields(array('name', 'description'));
  5.     $this->mergeForm(new LocationForm(LocationPeer::retrieveByPK($this->getObject()->getLocation())));
  6.    
  7.     //Embed project quote template
  8.     $pq = new Projectquote();
  9.     $pq->setProject($this->getObject());
  10.     $pq->setIsTemplate(true);      
  11.     $subForm = new ProjectquoteForm($pq);
  12.    
  13.     $pqSubForm = new sfForm();
  14.     for($i = 0; $i < 2; $i++){
  15.         $wp = new Workpackage();
  16.         $wp->setProjectquote($pq);
  17.        
  18.         $wpf = new WorkpackageForm($wp);
  19.         $pqSubForm->embedForm($i, $wpf);
  20.     }
  21.     $subForm->embedForm('packages', $pqSubForm);         
  22.     $this->embedForm('quote', $subForm);
  23.    
  24.     //$this->embedForm(new WorkpackageForm(), $this);
  25.    
  26.    
  27.     $this->widgetSchema->setLabels(array(
  28.       'name' => 'Name',
  29.       'description' => 'Description'
  30.     ));
  31.    
  32.     $this->setValidators(array(
  33.       'name'   => new sfValidatorString(array('max_length' => 255, 'min_length' => 5)),
  34.       'description'   => new sfValidatorString(array('max_length' => 255)),    
  35.     ));
  36.   }
  37.  
  38.   public function save($con = null){
  39.     parent::save();
  40.     $this->updateLocationInfo();
  41.     return $this->object;
  42.   }
  43.  
  44.   protected function updateLocationInfo(){
  45.     if(!is_null($locInfo = $this->getLocInfo())){
  46.         $values = $this->getValues();
  47.         if($locInfo->isNew()){
  48.             $values['location_id'] = $this->object->getId();           
  49.         }
  50.        
  51.         $locInfo->fromArray($values, BasePeer::TYPE_FIELDNAME);
  52.         $locInfo->save();
  53.     }
  54.   }
  55.  
  56.   protected function getLocInfo(){
  57.     if(!$this->object->getLocation()){
  58.         return new Location();
  59.     }
  60.    
  61.     return $this->object->getLocation();
  62.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement