To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Show
Ignore:
Timestamp:
07/14/10 12:12:43 (22 months ago)
Author:
johnnyoffline
Message:

i have some modified base classes probably from a build all

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • sandboxes/asandbox/branches/1.4/lib/form/doctrine/apostrophePlugin/base/BaseaPageForm.class.php

    r1659 r1753  
    3030      'rgt'                   => new sfWidgetFormInputText(), 
    3131      'level'                 => new sfWidgetFormInputText(), 
     32      'media_categories_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aMediaCategory')), 
    3233      'blog_categories_list'  => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aBlogCategory')), 
    33       'media_categories_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aMediaCategory')), 
    3434    )); 
    3535 
     
    4949      'rgt'                   => new sfValidatorInteger(array('required' => false)), 
    5050      'level'                 => new sfValidatorInteger(array('required' => false)), 
     51      'media_categories_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aMediaCategory', 'required' => false)), 
    5152      'blog_categories_list'  => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aBlogCategory', 'required' => false)), 
    52       'media_categories_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aMediaCategory', 'required' => false)), 
    5353    )); 
    5454 
     
    7171    parent::updateDefaultsFromObject(); 
    7272 
     73    if (isset($this->widgetSchema['media_categories_list'])) 
     74    { 
     75      $this->setDefault('media_categories_list', $this->object->MediaCategories->getPrimaryKeys()); 
     76    } 
     77 
    7378    if (isset($this->widgetSchema['blog_categories_list'])) 
    7479    { 
    7580      $this->setDefault('blog_categories_list', $this->object->BlogCategories->getPrimaryKeys()); 
    76     } 
    77  
    78     if (isset($this->widgetSchema['media_categories_list'])) 
    79     { 
    80       $this->setDefault('media_categories_list', $this->object->MediaCategories->getPrimaryKeys()); 
    8181    } 
    8282 
     
    8585  protected function doSave($con = null) 
    8686  { 
     87    $this->saveMediaCategoriesList($con); 
    8788    $this->saveBlogCategoriesList($con); 
    88     $this->saveMediaCategoriesList($con); 
    8989 
    9090    parent::doSave($con); 
     91  } 
     92 
     93  public function saveMediaCategoriesList($con = null) 
     94  { 
     95    if (!$this->isValid()) 
     96    { 
     97      throw $this->getErrorSchema(); 
     98    } 
     99 
     100    if (!isset($this->widgetSchema['media_categories_list'])) 
     101    { 
     102      // somebody has unset this widget 
     103      return; 
     104    } 
     105 
     106    if (null === $con) 
     107    { 
     108      $con = $this->getConnection(); 
     109    } 
     110 
     111    $existing = $this->object->MediaCategories->getPrimaryKeys(); 
     112    $values = $this->getValue('media_categories_list'); 
     113    if (!is_array($values)) 
     114    { 
     115      $values = array(); 
     116    } 
     117 
     118    $unlink = array_diff($existing, $values); 
     119    if (count($unlink)) 
     120    { 
     121      $this->object->unlink('MediaCategories', array_values($unlink)); 
     122    } 
     123 
     124    $link = array_diff($values, $existing); 
     125    if (count($link)) 
     126    { 
     127      $this->object->link('MediaCategories', array_values($link)); 
     128    } 
    91129  } 
    92130 
     
    129167  } 
    130168 
    131   public function saveMediaCategoriesList($con = null) 
    132   { 
    133     if (!$this->isValid()) 
    134     { 
    135       throw $this->getErrorSchema(); 
    136     } 
    137  
    138     if (!isset($this->widgetSchema['media_categories_list'])) 
    139     { 
    140       // somebody has unset this widget 
    141       return; 
    142     } 
    143  
    144     if (null === $con) 
    145     { 
    146       $con = $this->getConnection(); 
    147     } 
    148  
    149     $existing = $this->object->MediaCategories->getPrimaryKeys(); 
    150     $values = $this->getValue('media_categories_list'); 
    151     if (!is_array($values)) 
    152     { 
    153       $values = array(); 
    154     } 
    155  
    156     $unlink = array_diff($existing, $values); 
    157     if (count($unlink)) 
    158     { 
    159       $this->object->unlink('MediaCategories', array_values($unlink)); 
    160     } 
    161  
    162     $link = array_diff($values, $existing); 
    163     if (count($link)) 
    164     { 
    165       $this->object->link('MediaCategories', array_values($link)); 
    166     } 
    167   } 
    168  
    169169}