Development

Changeset 7216

You must first sign up to be able to contribute.

Changeset 7216

Show
Ignore:
Timestamp:
01/29/08 18:52:12 (10 months ago)
Author:
KRavEN
Message:

Checked in wrong version

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/actions/actions.class.php

    r7214 r7216  
    1010 * @version    SVN: $Id: actions.class.php 3501 2007-02-18 10:28:17Z fabien $ 
    1111 */ 
     12 <?php 
     13   $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-');     
     14 ?> 
     15  
    1216class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions 
    1317{ 
     
    2125   * this function does not affect the user-session, so sorting and your filters keep working 
    2226   */ 
    23   public function executeJsonListAutocomplete() 
     27  public function executeJsonAutocomplete() 
    2428  { 
    2529    // Require class 
    2630    if (!$this->hasRequestParameter('class')) 
    2731    { 
    28       throw new sfException(sprintf('Error, the JsonListAutocomplete page requires a class-name as argument')); 
     32      throw new sfException(sprintf('Error, the JsonAutocomplete page requires a class-name as argument')); 
    2933    } 
    3034    $class = sfInflector::camelize($this->getRequestParameter('class')); 
     
    3640 
    3741    // filter, define namespace to autocomplete, to not disturb normal filters of this module 
    38     $this->processFilters("autocomplete"); 
    39  
    40 <?php if ($this->getParameterValue('list.filters')): ?> 
     42    $namespace = "autocomplete"; 
     43    $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 
     44    $this->processFilters($namespace); 
     45 
    4146    $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/autocomplete/filters'); 
    42 <?php endif; ?> 
    43  
    4447 
    4548    // pager 
     
    5861  } 
    5962 
    60  
    61   public function executeJsonList() 
     63  //seperate JSON-lists for every list, edit and edit.page -pages 
     64<?php 
     65  $for = array('list'); 
     66  if ($this->getParameterValue('edit.display', null) || !$this->getParameterValue('edit.pages', null)) { 
     67    $for[] = 'edit'; 
     68  } 
     69 
     70  $edit_pages = $this->getParameterValue('edit.pages', array()); 
     71   
     72  foreach ($edit_pages as $pageName => $page)  
     73  { 
     74    $for[] = 'edit.pages.'.$pageName; 
     75  } 
     76 
     77  foreach($for as $page): 
     78    $page_name = ucFirst(sfInflector::camelize(str_replace('.','_', $page))); 
     79?> 
     80  public function executeJson<?php echo $page_name ?>() 
    6281  { 
    6382    $limit = $this->getRequestParameter('limit', <?php echo $this->getParameterValue('list.max_per_page', sfConfig::get('app_sf_extjs_theme_plugin_list_max_per_page', 20)) ?>); 
    6483    $page = floor($this->getRequestParameter('start', 0) / $limit)+1; 
     84     
     85    $this->for = '<?php echo str_replace('.', '_', $page) ?>'; 
    6586 
    6687    $this->processSort(strtolower($this->getRequestParameter('dir'))); 
    6788 
    68     $this->processFilters(); 
    69  
    70 <?php if ($this->getParameterValue('list.filters')): ?> 
     89    $this->processFilters(); //TODO: maybe set namespace to pagename... 
     90 
     91<?php //if ($this->getParameterValue('list.filters')): ?> 
    7192    $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/filters'); 
    72 <?php endif; ?> 
     93<?php //endif; ?> 
    7394 
    7495    // pager 
    7596    $this->pager = new sfPropelPager('<?php echo $this->getClassName() ?>', $limit); 
    7697    $c = new Criteria(); 
    77 <?php //if ($fields = $this->getParameterValue('list.fields')): ?> 
    78 <?php //foreach ($fields as $key => $field): ?> 
    79 <?php //if ($join_fields = $this->getParameterValue('list.fields.'.$key.'.join_fields')): ?> 
    80     //$c->addJoin(<?//=$join_fields[0]?>,<?//=$join_fields[1]?>); 
    81 <?php //endif; ?> 
    82 <?php //endforeach; ?> 
    83 <?php //endif; ?> 
     98<?php if ($sortColumn = $this->getGroupField()) :  
     99 
     100    //strange construction!? AND Note there is also something like: $this->getPeerClassName()  
     101    $className = '<?php echo $this->getClassName() ?>'; 
     102 
     103    if (false !== strpos($sortColumn, $tableDelimiter)) 
     104    { 
     105      $elements = explode($tableDelimiter, $sortColumn); 
     106       
     107      $className = sfInflector::camelize($elements[count($elements)-2]); 
     108      $sortColumn = $elements[count($elements)-1];  
     109    } 
     110 
     111    try 
     112    { 
     113      $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); 
     114    } 
     115    catch (Exception $e) 
     116    { 
     117      // sort column does not exist, throw error 
     118      throw new sfException(sprintf('Cannot sort on column "%s", the column does not exist. Clearing your cookies will (temporarily) fix this error.', $sortColumn)); 
     119    } 
     120?> 
     121    // first sort on group-by column 
     122    // TODO: this can be enhanced with options for the generator.yml file. 
     123    $c->addAscendingOrderByColumn('<?php echo $fieldName ?>'); 
     124<?php endif;  ?> 
    84125    $this->addSortCriteria($c); 
    85126    $this->addFiltersCriteria($c); 
     
    87128    $this->pager->setPage($page); 
    88129<?php $peerMethod = $this->getParameterValue('list.peer_method') ? $this->getParameterValue('list.peer_method') : 'doSelectJoinAll'; 
    89     if (is_callable(array($this->getClassName().'Peer', $peerMethod))): ?> 
     130    if (is_callable(array($this->getPeerClassName(), $peerMethod))): ?> 
    90131    $this->pager->setPeerMethod('<?php echo $peerMethod ?>'); 
    91132<?php endif; ?> 
    92133 
    93134<?php $peerCountMethod = $this->getParameterValue('list.peer_count_method') ? $this->getParameterValue('list.peer_count_method') : 'doCountJoinAll'; 
    94     if (is_callable(array($this->getClassName().'Peer', $peerCountMethod))): ?> 
     135    if (is_callable(array($this->getPeerClassName(), $peerCountMethod))): ?> 
    95136    $this->pager->setPeerCountMethod('<?php echo $peerCountMethod ?>'); 
    96137<?php endif; ?> 
    97138    $this->pager->init(); 
    98139 
    99 //    $this->setLayout(false); 
    100 //    sfConfig::set('sf_web_debug', false); 
    101   } 
    102  
    103   <?php 
    104   $columns = $this->getColumnsGroup(); 
    105   if (isset($columns['related'])): 
    106     foreach ($columns['related'] as $class => $relatedColumns): 
    107     $className = sfInflector::camelize($class); 
    108     ?> 
    109     public function executeJsonList<?php echo $class ?>() 
    110     { 
    111       //connect extjs to symfony 
    112       $limit = $this->getRequestParameter('limit', 10); 
    113  
    114       // pager 
    115       $this->pager = new sfPropelPager('<?php echo $className ?>', $limit); 
    116       $c = new Criteria(); 
    117       $this->pager->setCriteria($c); 
    118       $this->pager->setPage(1); 
    119       $this->pager->init(); 
    120  
    121       $this->setLayout(false); 
    122       sfConfig::set('sf_web_debug', false); 
    123  
    124       $render = ' 
    125       {totalCount:"'.$this->pager->getNbResults().'", data:[ 
    126       '; 
    127       $i = 0; 
    128       foreach ($this->pager->getResults() as $result) 
    129       { 
    130         if ($i > 0) $render .= ', '; 
    131         <?php 
    132         $pkName = $relatedColumns['pk']->getName(); 
    133         $pkMethod = 'get'.sfInflector::camelize($pkName); 
    134         ?> 
    135         $render .= '{ "<?php echo $pkName ?>": "'.$result-><?php echo $pkMethod ?>().'", '; 
    136         <?php $j = 0; foreach ($relatedColumns['columns'] as $col): 
    137         $colName = $col->getName(); 
    138         $colMethod = 'get'.sfInflector::camelize($colName); 
    139         ?> 
    140           <?php if ($j > 0): ?>$render .= ', ';<?php endif; ?> 
    141           $render .= ' "<?php echo $colName ?>": "'.$result-><?php echo $colMethod ?>().'"'; 
    142         <?php $j++; endforeach; ?> 
    143         $render .= ' }'; 
    144         $i++; 
    145       } 
    146       $render .= ' 
    147       ]}'; 
    148  
    149       return $this->renderText($render); 
    150     } 
    151     <?php endforeach; ?> 
    152   <?php endif; ?> 
    153  
     140    $this->setLayout(false); 
     141    sfConfig::set('sf_web_debug', false); 
     142    $this->setTemplate('json'); 
     143  } 
     144<?php endforeach; ?> 
     145 
     146  public function executeListPrint() 
     147  { 
     148    $this->executeList(); 
     149     
     150    $this->print = true; 
     151 
     152    $this->setLayout(false); // TODO: set to a print layout... 
     153    sfConfig::set('sf_web_debug', false); 
     154    $this->setTemplate('list'); 
     155  } 
    154156 
    155157  public function executeList() 
     
    169171<?php foreach ($fields as $key => $field): ?> 
    170172<?php if ($join_fields = $this->getParameterValue('list.fields.'.$key.'.join_fields')): ?> 
    171     $c->addJoin(<?=$join_fields[0]?>,<?=$join_fields[1]?>); 
     173    $c->addJoin(<?php echo $join_fields[0]?>,<?php echo $join_fields[1]?>); 
    172174<?php endif; ?> 
    173175<?php endforeach; ?> 
     
    184186<?php endif; ?> 
    185187    $this->pager->init(); 
     188     
     189     
     190<?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 
     191    $this->setTemplate('listAjax'); 
     192<?php endif; ?> 
     193     
    186194  } 
    187195 
     
    196204  } 
    197205 
    198   public function executeAjaxSave() 
    199   { 
     206  public function executeAjaxEdit() 
     207  { 
     208    // Check if retreiving instead of saving... 
     209    if ($this->getRequest()->hasParameter('filter'))  
     210    { 
     211      return $this->forward('<?php echo $this->getModuleName() ?>', 'jsonList'); 
     212    } 
     213     
    200214    $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
    201215 
    202     $request = array(); 
    203     $fieldName = ''; 
    204     if ($field = $this->getRequestParameter('field')) 
    205     { 
    206       $fieldsName = $this->getFields(); 
    207       $fieldName = array_search($field, $fieldsName); 
     216    if ($fieldName = $this->getRequestParameter('field')) 
     217    { 
    208218      $value = $this->getRequestParameter('value'); 
    209219 
     
    212222    else 
    213223    { 
    214       $this->update<?php echo $this->getClassName() ?>FromRequest($request); 
     224      $this->update<?php echo $this->getClassName() ?>FromRequest(); 
    215225    } 
    216226 
    217227    $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 
    218228 
     229    $this->setLayout(false); 
     230    sfConfig::set('sf_web_debug', false); 
    219231    return $this->renderText('{ success: true, message: "Your modifications have been saved" }'); 
    220232  } 
     
    251263 
    252264<?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 
    253     //if (!$this->getRequest()->isXmlHttpRequest()) 
    254     //
    255       $this->setLayout(false); // TODO: maybe set to specific ajax layout 
    256     //} 
    257     sfConfig::set('sf_web_debug', false); 
     265    if ($this->getRequest()->isXmlHttpRequest()) 
     266   
     267      $this->setLayout(false); 
     268      sfConfig::set('sf_web_debug', false); 
     269    } 
    258270    return 'AjaxSuccess'; 
    259271<?php endif; ?> 
     
    263275  public function executeDelete() 
    264276  { 
    265     $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>); 
     277    $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>); 
    266278    $this->forward404Unless($this-><?php echo $this->getSingularName() ?>); 
    267279 
     
    291303<?php endforeach; ?> 
    292304<?php if(! ($deleteNotification = $this->getParameterValue('edit.delete_notification'))) $deleteNotification = 'The '.$this->getModuleName().' has been deleted' ?> 
    293     $this->setFlash('notice', '<?= $deleteNotification ?>'); 
    294  
     305    $this->setFlash('notice', '<?php echo $deleteNotification ?>'); 
    295306 
    296307    return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
     
    317328 
    318329<?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 
    319 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> 
     330<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?> 
     331<?php $type = $column->getCreoleType() ?> 
    320332<?php $name = $column->getName() ?> 
    321333<?php if ($column->isPrimaryKey()) continue ?> 
     
    380392  protected function update<?php echo $this->getClassName() ?>ListFromRequest($columnName, $columnValue) 
    381393  { 
    382 <?php $columns = $this->getColumns('list.display'); ?> 
    383 <?php foreach ($columns as $column): $type = $column->getCreoleType(); ?> 
    384 <?php $name = $column->getName(); ?> 
    385 <?php if ($column->isPrimaryKey()) continue ?> 
    386 <?php if (false !== strpos($name, '/')) continue; // TODO: at the moment cannot handle foreign fields ?> 
    387  
    388     if ($columnName == '<?php echo $column->getName() ?>') 
    389     { 
    390 <?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?> 
     394<?php  
     395  $groupedColumns = $this->getColumnsGrouped('list.display'); 
     396  $columns = $this->getListUniqueColumns($groupedColumns, true); 
     397   
     398  $tableName = $this->getTableName(); 
     399  $first = true; 
     400 
     401  foreach ($columns as $column):  
     402   
     403    $columnName = $column->key;   
     404    list($class, $checkName) = explode('/',$columnName, 2); 
     405    
     406    if (strtolower($class) != strtolower($tableName)) 
     407    { 
     408      $checkName = $columnName; 
     409    } 
     410     
     411    if ($column->isPrimaryKey()) continue; 
     412    if (false !== strpos($checkName, '/')) continue; // TODO: at the moment cannot handle foreign fields  
     413     
     414    $type = $column->getCreoleType();  
     415?> 
     416    <?php echo !$first ? 'else' : '' ?>if ($columnName == '<?php echo str_replace('/', $tableDelimiter, $column->key) ?>') 
     417    { 
     418<?php $credentials = $this->getParameterValue('list.fields.'.$checkName.'.credentials') ?> 
    391419<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
    392420    if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) 
     
    394422<?php endif; ?> 
    395423<?php if ($type != CreoleTypes::BOOLEAN): ?> 
    396     if (isset($columnValue)) 
    397    
     424      if (isset($columnValue)) 
     425     
    398426<?php endif; ?> 
    399427<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
    400       if ($columnValue) 
    401       { 
    402         try 
    403         { 
    404           $dateFormat = new sfDateFormat($this->getUser()->getCulture()); 
    405           <?php $inputPattern  = $type == CreoleTypes::DATE ? 'd' : 'g'; ?> 
    406           <?php $outputPattern = $type == CreoleTypes::DATE ? 'i' : 'I'; ?> 
    407           if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'])) 
     428        if ($columnValue) 
     429        { 
     430          try 
    408431          { 
    409             $value = $dateFormat->format($columnValue, '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>')); 
     432            $dateFormat = new sfDateFormat($this->getUser()->getCulture()); 
     433            <?php $inputPattern  = $type == CreoleTypes::DATE ? 'd' : 'g'; ?> 
     434            <?php $outputPattern = $type == CreoleTypes::DATE ? 'i' : 'I'; ?> 
     435            //TODO : check $columnName below, this was $name, but this was obviously wrong! I don't know if $columnName is correct here.. 
     436            if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $columnName ?>'])) 
     437            { 
     438              $value = $dateFormat->format($columnValue, '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>')); 
     439            } 
     440            else 
     441            { 
     442              $value_array = $columnValue; 
     443              $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : ''); 
     444            } 
     445            $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($value); 
    410446          } 
    411           else 
     447          catch (sfException $e) 
    412448          { 
    413             $value_array = $columnValue; 
    414             $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : ''); 
     449            // not a date 
    415450          } 
    416           $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($value); 
    417         } 
    418         catch (sfException $e) 
    419         { 
    420           // not a date 
    421         } 
    422       } 
    423       else 
    424       { 
    425         $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(null); 
    426       } 
     451        } 
     452        else 
     453        { 
     454          $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(null); 
     455        } 
    427456<?php elseif ($type == CreoleTypes::BOOLEAN): ?> 
    428     $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0); 
     457        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0); 
    429458<?php elseif ($column->isForeignKey()): ?> 
    430     $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null); 
    431 <?php else: ?> 
    432       $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue); 
     459        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue); //save foreign-key 
     460<?php else: ?> 
     461        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue); 
    433462<?php endif; ?> 
    434463<?php if ($type != CreoleTypes::BOOLEAN): ?> 
    435    
     464     
    436465<?php endif; ?> 
    437466<?php if ($credentials): ?> 
    438       } 
    439 <?php endif; ?> 
    440     } 
    441 <?php endforeach; ?> 
     467    } 
     468<?php endif; ?> 
     469    } 
     470     
     471<?php $first = false; endforeach; ?> 
    442472  } 
    443473 
     
    446476    $<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->getSingularName() ?>'); 
    447477 
    448 <?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 
    449 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> 
    450 <?php $name = $column->getName() ?> 
    451 <?php if ($column->isPrimaryKey()) continue ?> 
    452 <?php if (false !== strpos($name, '/')) continue; // TODO: at the moment cannot handle foreign fields ?> 
    453  
    454 <?php $credentials = $this->getParameterValue('edit.fields.'.$column->getName().'.credentials') ?> 
    455 <?php $input_type = $this->getParameterValue('edit.fields.'.$column->getName().'.type') ?> 
    456 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
     478<?php  
     479  $groupedColumns = $this->getColumnsGrouped('edit.display'); 
     480  $columns = $this->getListUniqueColumns($groupedColumns, true); 
     481  $tableName = $this->getTableName(); 
     482 
     483  foreach ($columns as $column):  
     484    list($class, $checkName) = explode('/', $column->key, 2); 
     485      
     486    if (strtolower($class) != strtolower($tableName)) 
     487    { 
     488      $checkName = $columnName; 
     489    } 
     490     
     491    if ($column->isPrimaryKey()) continue; 
     492    if (false !== strpos($checkName, '/')) continue; // TODO: at the moment cannot handle foreign fields  
     493 
     494    $type = $column->getCreoleType(); 
     495    $name = str_replace('/', $tableDelimiter, $checkName); 
     496 
     497    $credentials = $this->getParameterValue('edit.fields.'.$checkName.'.credentials'); 
     498    $input_type = $this->getParameterValue('edit.fields.'.$checkName.'.type'); 
     499     
     500?> 
     501<?php  
     502  if ($credentials):  
     503    $credentials = str_replace("\n", ' ', var_export($credentials, true))  
     504?> 
    457505    if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) 
    458506    { 
    459507<?php endif; ?> 
    460508<?php if ($input_type == 'admin_input_file_tag'): ?> 
    461 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> 
     509<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.upload_dir')) ?> 
    462510    $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
    463511    if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove'])) 
     
    477525<?php endif; ?> 
    478526<?php if ($input_type == 'admin_input_file_tag'): ?> 
    479 <?php if ($this->getParameterValue('edit.fields.'.$column->getName().'.filename')): ?> 
    480       $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.filename'))) ?>"; 
     527<?php if ($this->getParameterValue('edit.fields.'.$checkName.'.filename')): ?> 
     528      $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.filename'))) ?>"; 
    481529<?php else: ?> 
    482530      $fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time().rand(0, 99999)); 
     
    518566      } 
    519567<?php elseif ($type == CreoleTypes::BOOLEAN): ?> 
    520     $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']) ? ($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] == 'on' ? 1 : 0) : 0); 
     568        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']) ? ($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] == 'on' ? 1 : 0) : 0); 
    521569<?php elseif ($column->isForeignKey()): ?> 
    522     $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null); 
    523 <?php else: ?> 
    524       $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 
     570//        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null); 
     571        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 
     572<?php else: ?> 
     573        $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 
    525574<?php endif; ?> 
    526575<?php if ($type != CreoleTypes::BOOLEAN): ?> 
     
    531580<?php endif; ?> 
    532581<?php endforeach; ?> 
    533 <?php endforeach; ?> 
    534582  } 
    535583 
     
    542590    else 
    543591    { 
    544       $<?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>); 
     592      $<?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>); 
    545593 
    546594      $this->forward404Unless($<?php echo $this->getSingularName() ?>); 
     
    552600  protected function processFilters($namespace = "<?php echo $this->getSingularName() ?>") 
    553601  { 
     602    if ($this->getRequest()->hasParameter('filter')) 
     603    { 
     604      $filters = $this->getRequestParameter('filters'); 
     605 
    554606<?php if ($this->getParameterValue('list.filters')): ?> 
    555     if ($this->getRequest()->hasParameter('filter')) 
    556     { 
    557       $filters = $this->getRequestParameter('filters'); 
    558607<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> 
    559 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
     608<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): //TODO replace $column->getName with $checkName ?> 
    560609      if (isset($filters['<?php echo $column->getName() ?>']['from']) && $filters['<?php echo $column->getName() ?>']['from'] !== '') 
    561610      { 
     
    568617<?php endif; ?> 
    569618<?php endforeach; ?> 
     619<?php endif; ?> 
    570620 
    571621      /* reset Multi-sort // TODO, this should be done somewhere else, 
     
    586636      $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 
    587637    } 
    588 <?php endif; ?> 
    589638  } 
    590639 
     
    648697  protected function addFiltersCriteria($c, $namespace = '<?php echo $this->getSingularName() ?>') 
    649698  { 
    650 <?php if ($this->getParameterValue('list.filters') || $this->getParameterValue('list.display')): ?> 
    651 <?php $columns = array_merge($this->getColumns('list.filters'), $this->getColumns('list.display')) ?> 
     699<?php 
     700  // filtering is also used for drop-down combo-box filtering and retreiving json-data for edit-pages!  
     701  $for = array('list.filters', 'list.display', 'edit.display'); 
     702  $groupedColumns = $this->getColumnsGrouped($for, false); 
     703   
     704  $pk = clone($groupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 
     705  $pk->key = strtolower($pk->getTableName().'/'.$pk->getName()); 
     706   
     707  $columns = array(); 
     708  $columns[] = $pk; // add primary key 
     709  // add primary keys of related classes 
     710  foreach ($groupedColumns['related'] as $relatedTable => $relatedGroupedColumns) 
     711  { 
     712    $pkr = clone($relatedGroupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 
     713    $pkr->key = strtolower($pk->getTableName().'/'.$pkr->getTableName().'/'.$pkr->getName()); 
     714     
     715    $columns[] = $pkr; // add related primary key 
     716  } 
     717  // add default keys below PKs 
     718  $columns = array_merge($columns, $this->getListUniqueColumns($groupedColumns, false)); 
     719   
     720?> 
    652721<?php foreach ($columns as $column):?> 
    653722<?php $type = $column->getCreoleType() ?> 
    654 <?php if (($column->isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue ?> 
    655     if (isset($this->filters['<?php echo $column->getName() ?>_is_empty'])) 
    656     { 
    657       $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, ''); 
    658       $criterion->addOr($c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, null, Criteria::ISNULL)); 
     723<?php  
     724  $peerClassName = $this->getPeerClassName(); 
     725  if (false !== strpos($column->key, '/')) 
     726  { 
     727    $parts = explode('/', $column->key); 
     728    $peer = $parts[count($parts)-2]; 
     729    $peerClassName = sfInflector::camelize($peer).'Peer'; 
     730  } 
     731  $columnName = strtoupper($column->getName()); 
     732?> 
     733<?php if (($column->isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue; ?> 
     734<?php if (!$column->isPrimaryKey()): ?> 
     735    if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>_is_empty'])) 
     736    { 
     737      $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, ''); 
     738      $criterion->addOr($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, null, Criteria::ISNULL)); 
    659739      $c->add($criterion); 
    660740    } 
     741    else  
     742<?php endif; ?> 
    661743<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
    662     else if (isset($this->filters['<?php echo $column->getName() ?>'])) 
    663     { 
    664       if (isset($this->filters['<?php echo $column->getName() ?>']['from']) && $this->filters['<?php echo $column->getName() ?>']['from'] !== '') 
     744    if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'])) 
     745    { 
     746      if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from'] !== '') 
    665747      { 
    666748<?php if ($type == CreoleTypes::DATE): ?> 
    667         $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['from']), Criteria::GREATER_EQUAL); 
    668 <?php else: ?> 
    669         $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['from'], Criteria::GREATER_EQUAL); 
    670 <?php endif; ?> 
    671       } 
    672       if (isset($this->filters['<?php echo $column->getName() ?>']['to']) && $this->filters['<?php echo $column->getName() ?>']['to'] !== '') 
     749        $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from']), Criteria::GREATER_EQUAL); 
     750<?php else: ?> 
     751        $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from'], Criteria::GREATER_EQUAL); 
     752<?php endif; ?> 
     753      } 
     754      if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'] !== '') 
    673755      { 
    674756        if (isset($criterion)) 
    675757        { 
    676758<?php if ($type == CreoleTypes::DATE): ?> 
    677           $criterion->addAnd($c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['to']), Criteria::LESS_EQUAL)); 
    678 <?php else: ?> 
    679           $criterion->addAnd($c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['to'], Criteria::LESS_EQUAL)); 
     759          $criterion->addAnd($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']), Criteria::LESS_EQUAL)); 
     760<?php else: ?> 
     761          $criterion->addAnd($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'], Criteria::LESS_EQUAL)); 
    680762<?php endif; ?> 
    681763        } 
     
    683765        { 
    684766<?php if ($type == CreoleTypes::DATE): ?> 
    685           $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['to']), Criteria::LESS_EQUAL); 
    686 <?php else: ?> 
    687           $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['to'], Criteria::LESS_EQUAL); 
     767          $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']), Criteria::LESS_EQUAL); 
     768<?php else: ?> 
     769          $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'], Criteria::LESS_EQUAL); 
    688770<?php endif; ?> 
    689771        } 
     
    696778    } 
    697779<?php else: ?> 
    698     else if (isset($this->filters['<?php echo $column->getName() ?>']) && $this->filters['<?php echo $column->getName() ?>'] !== '') 
     780    if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'] !== '') 
    699781    { 
    700782<?php if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::LONGVARCHAR): ?> 
    701783      $q = ''; 
    702784      if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 
    703       $c->add(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, strtr($this->filters['<?php echo $column->getName() ?>'].$q, '*', '%'), Criteria::LIKE); 
    704 <?php else: ?> 
    705 <?php 
    706   $columnName = $column->getName(); 
    707   $peer = $this->getPeerClassName(); 
    708   if (false !== strpos($columnName, '/')) 
    709   { 
    710     list($peer, $columnName) = explode('/', $columnName, 2); 
    711   } 
    712 ?> 
     785      $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, strtr($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'].$q, '*', '%'), Criteria::LIKE); 
     786<?php else: ?> 
     787<?php if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::LONGVARCHAR): ?> 
    713788      $q = ''; 
    714789      if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 
    715       $c->add('<?php echo $peer ?>.<?php echo strtoupper($columnName) ?>', strtr($this->filters['<?php echo $column->getName() ?>'].$q, '*', '%'), Criteria::LIKE); 
    716 <?php endif; ?> 
    717     } 
    718 <?php endif; ?> 
    719 <?php endforeach; ?> 
    720 <?php endif; ?> 
     790      $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, strtr($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'].$q, '*', '%'), Criteria::LIKE); 
     791<?php else: ?> 
     792      $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']); 
     793<?php endif; ?> 
     794<?php endif; ?> 
     795    } 
     796<?php endif; ?> 
     797<?php endforeach; ?> 
    721798  } 
    722799 
     
    725802    $sort_array = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/sort'); 
    726803    $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
    727     $fieldSufix = sfConfig::get('app_sf_extjs_theme_plugin_field_suffix', ''); 
    728804 
    729805    if ($sort_array) // if sort-columns are set 
     
    732808      foreach($sort_array as $sort_column => $sort_type) 
    733809      { 
     810        //strange construction!? AND Note there is also something like: $this->getPeerClassName()  
    734811        $className = '<?php echo $this->getClassName() ?>'; 
    735812 
    736813        //fix for cookie error 
     814        $sortColumn = $sort_column; 
    737815        if (false !== strpos($sort_column, $tableDelimiter)) 
    738816        { 
    739           list($className, $sortColumn) = explode($tableDelimiter, $sort_column); 
     817          $elements = explode($tableDelimiter, $sort_column); 
     818          $className = $elements[count($elements)-2]; 
     819          $sortColumn = $elements[count($elements)-1];  
    740820          $className = sfInflector::camelize($className); 
    741821        } 
    742         $sortColumn = str_replace(sfInflector::underscore($className).'-', '', $sort_column); 
     822        //$sortColumn = str_replace(sfInflector::underscore($className).$tableDelimiter, '', $sort_column); 
    743823 
    744824        try 
     
    775855  } 
    776856 
    777   protected function getFields() 
     857  protected function getLabels() 
    778858  { 
    779859    return array( 
    780 <?php $fields = $this->getFieldsProperties(); 
    781       $fieldsName = $fields['names']; 
    782       foreach ($fieldsName as $name => $fieldName): ?> 
    783   '<?php echo $name ?>' => '<?php echo $fieldName ?>', 
     860<?php  
     861  $groupedColumns = $this->getColumnsGrouped('edit.display');  
     862  $columns = $this->getListUniqueColumns($groupedColumns, true); 
     863  $tableName = $this->getTableName(); 
     864 
     865  foreach ($columns as $columnName => $column) : 
     866    $columnName = $column->key; 
     867 
     868    list($class, $checkName) = explode('/', $columnName, 2); 
     869      
     870    if (strtolower($class) != strtolower($tableName)) 
     871    { 
     872      $class = strtolower($tableName); 
     873      $checkName = $columnName; 
     874    }      
     875          
     876    $fieldName = str_replace('/', $tableDelimiter, $columnName); 
     877     
     878    $labelName = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$checkName.'.name')); 
     879?> 
     880      '<?php echo $fieldName ?>' => '<?php echo $labelName ?>', 
    784881<?php endforeach; ?> 
    785882    ); 
    786883  } 
    787  
    788   protected function getLabels() 
    789   { 
    790     return array( 
    791 <?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 
    792   <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?> 
    793       '<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}' => '<?php $label_name = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.name')); echo $label_name ?>', 
    794   <?php endforeach; ?> 
    795 <?php endforeach; ?> 
    796     ); 
    797   } 
    798884}