Development

Changeset 7214

You must first sign up to be able to contribute.

Changeset 7214

Show
Ignore:
Timestamp:
01/29/08 17:58:17 (10 months ago)
Author:
KRavEN
Message:

Fixed sorting problem on line 746, $sortColumn need to be upper case

Files:

Legend:

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

    r7185 r7214  
    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   
    1612class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions 
    1713{ 
     
    2521   * this function does not affect the user-session, so sorting and your filters keep working 
    2622   */ 
    27   public function executeJsonAutocomplete() 
     23  public function executeJsonListAutocomplete() 
    2824  { 
    2925    // Require class 
    3026    if (!$this->hasRequestParameter('class')) 
    3127    { 
    32       throw new sfException(sprintf('Error, the JsonAutocomplete page requires a class-name as argument')); 
     28      throw new sfException(sprintf('Error, the JsonListAutocomplete page requires a class-name as argument')); 
    3329    } 
    3430    $class = sfInflector::camelize($this->getRequestParameter('class')); 
     
    4036 
    4137    // filter, define namespace to autocomplete, to not disturb normal filters of this module 
    42     $namespace = "autocomplete"; 
    43     $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 
    44     $this->processFilters($namespace); 
    45  
     38    $this->processFilters("autocomplete"); 
     39 
     40<?php if ($this->getParameterValue('list.filters')): ?> 
    4641    $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/autocomplete/filters'); 
     42<?php endif; ?> 
     43 
    4744 
    4845    // pager 
     
    6158  } 
    6259 
    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 ?>() 
     60 
     61  public function executeJsonList() 
    8162  { 
    8263    $limit = $this->getRequestParameter('limit', <?php echo $this->getParameterValue('list.max_per_page', sfConfig::get('app_sf_extjs_theme_plugin_list_max_per_page', 20)) ?>); 
    8364    $page = floor($this->getRequestParameter('start', 0) / $limit)+1; 
    84      
    85     $this->for = '<?php echo str_replace('.', '_', $page) ?>'; 
    8665 
    8766    $this->processSort(strtolower($this->getRequestParameter('dir'))); 
    8867 
    89     $this->processFilters(); //TODO: maybe set namespace to pagename... 
    90  
    91 <?php //if ($this->getParameterValue('list.filters')): ?> 
     68    $this->processFilters(); 
     69 
     70<?php if ($this->getParameterValue('list.filters')): ?> 
    9271    $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/filters'); 
    93 <?php //endif; ?> 
     72<?php endif; ?> 
    9473 
    9574    // pager 
    9675    $this->pager = new sfPropelPager('<?php echo $this->getClassName() ?>', $limit); 
    9776    $c = new Criteria(); 
    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;  ?> 
     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; ?> 
    12584    $this->addSortCriteria($c); 
    12685    $this->addFiltersCriteria($c); 
     
    12887    $this->pager->setPage($page); 
    12988<?php $peerMethod = $this->getParameterValue('list.peer_method') ? $this->getParameterValue('list.peer_method') : 'doSelectJoinAll'; 
    130     if (is_callable(array($this->getPeerClassName(), $peerMethod))): ?> 
     89    if (is_callable(array($this->getClassName().'Peer', $peerMethod))): ?> 
    13190    $this->pager->setPeerMethod('<?php echo $peerMethod ?>'); 
    13291<?php endif; ?> 
    13392 
    13493<?php $peerCountMethod = $this->getParameterValue('list.peer_count_method') ? $this->getParameterValue('list.peer_count_method') : 'doCountJoinAll'; 
    135     if (is_callable(array($this->getPeerClassName(), $peerCountMethod))): ?> 
     94    if (is_callable(array($this->getClassName().'Peer', $peerCountMethod))): ?> 
    13695    $this->pager->setPeerCountMethod('<?php echo $peerCountMethod ?>'); 
    13796<?php endif; ?> 
    13897    $this->pager->init(); 
    13998 
    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   } 
     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 
    156154 
    157155  public function executeList() 
     
    171169<?php foreach ($fields as $key => $field): ?> 
    172170<?php if ($join_fields = $this->getParameterValue('list.fields.'.$key.'.join_fields')): ?> 
    173     $c->addJoin(<?php echo $join_fields[0]?>,<?php echo $join_fields[1]?>); 
     171    $c->addJoin(<?=$join_fields[0]?>,<?=$join_fields[1]?>); 
    174172<?php endif; ?> 
    175173<?php endforeach; ?> 
     
    186184<?php endif; ?> 
    187185    $this->pager->init(); 
    188      
    189      
     186  } 
     187 
     188  public function executeCreate() 
     189  { 
     190    return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
     191  } 
     192 
     193  public function executeSave() 
     194  { 
     195    return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
     196  } 
     197 
     198  public function executeAjaxSave() 
     199  { 
     200    $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
     201 
     202    $request = array(); 
     203    $fieldName = ''; 
     204    if ($field = $this->getRequestParameter('field')) 
     205    { 
     206      $fieldsName = $this->getFields(); 
     207      $fieldName = array_search($field, $fieldsName); 
     208      $value = $this->getRequestParameter('value'); 
     209 
     210      $this->update<?php echo $this->getClassName() ?>ListFromRequest($fieldName, $value); 
     211    } 
     212    else 
     213    { 
     214      $this->update<?php echo $this->getClassName() ?>FromRequest($request); 
     215    } 
     216 
     217    $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 
     218 
     219    return $this->renderText('{ success: true, message: "Your modifications have been saved" }'); 
     220  } 
     221 
     222  public function executeEdit() 
     223  { 
     224    $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
     225 
     226    if ($this->getRequest()->getMethod() == sfRequest::POST) 
     227    { 
     228      $this->update<?php echo $this->getClassName() ?>FromRequest(); 
     229 
     230      $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 
     231 
     232      $this->setFlash('notice', 'Your modifications have been saved'); 
     233 
     234      if ($this->getRequestParameter('save_and_add')) 
     235      { 
     236        return $this->redirect('<?php echo $this->getModuleName() ?>/create'); 
     237      } 
     238      else if ($this->getRequestParameter('save_and_list')) 
     239      { 
     240        return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
     241      } 
     242      else 
     243      { 
     244        return $this->redirect('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams('this->') ?>); 
     245      } 
     246    } 
     247    else 
     248    { 
     249      $this->labels = $this->getLabels(); 
     250    } 
     251 
    190252<?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 
    191     $this->setTemplate('listAjax'); 
    192 <?php endif; ?> 
    193      
    194   } 
    195  
    196   public function executeCreate() 
    197   { 
    198     return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
    199   } 
    200  
    201   public function executeSave() 
    202   { 
    203     return $this->forward('<?php echo $this->getModuleName() ?>', 'edit'); 
    204   } 
    205  
    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      
    214     $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
    215  
    216     if ($fieldName = $this->getRequestParameter('field')) 
    217     { 
    218       $value = $this->getRequestParameter('value'); 
    219  
    220       $this->update<?php echo $this->getClassName() ?>ListFromRequest($fieldName, $value); 
    221     } 
    222     else 
    223     { 
    224       $this->update<?php echo $this->getClassName() ?>FromRequest(); 
    225     } 
    226  
    227     $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 
    228  
    229     $this->setLayout(false); 
     253    //if (!$this->getRequest()->isXmlHttpRequest()) 
     254    //{ 
     255      $this->setLayout(false); // TODO: maybe set to specific ajax layout 
     256    //} 
    230257    sfConfig::set('sf_web_debug', false); 
    231     return $this->renderText('{ success: true, message: "Your modifications have been saved" }'); 
    232   } 
    233  
    234   public function executeEdit() 
    235   { 
    236     $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 
    237  
    238     if ($this->getRequest()->getMethod() == sfRequest::POST) 
    239     { 
    240       $this->update<?php echo $this->getClassName() ?>FromRequest(); 
    241  
    242       $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 
    243  
    244       $this->setFlash('notice', 'Your modifications have been saved'); 
    245  
    246       if ($this->getRequestParameter('save_and_add')) 
    247       { 
    248         return $this->redirect('<?php echo $this->getModuleName() ?>/create'); 
    249       } 
    250       else if ($this->getRequestParameter('save_and_list')) 
    251       { 
    252         return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
    253       } 
    254       else 
    255       { 
    256         return $this->redirect('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams('this->') ?>); 
    257       } 
    258     } 
    259     else 
    260     { 
    261       $this->labels = $this->getLabels(); 
    262     } 
    263  
    264 <?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 
    265     if ($this->getRequest()->isXmlHttpRequest()) 
    266     { 
    267       $this->setLayout(false); 
    268       sfConfig::set('sf_web_debug', false); 
    269     } 
    270258    return 'AjaxSuccess'; 
    271259<?php endif; ?> 
     
    275263  public function executeDelete() 
    276264  { 
    277     $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>); 
     265    $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>); 
    278266    $this->forward404Unless($this-><?php echo $this->getSingularName() ?>); 
    279267 
     
    303291<?php endforeach; ?> 
    304292<?php if(! ($deleteNotification = $this->getParameterValue('edit.delete_notification'))) $deleteNotification = 'The '.$this->getModuleName().' has been deleted' ?> 
    305     $this->setFlash('notice', '<?php echo $deleteNotification ?>'); 
     293    $this->setFlash('notice', '<?= $deleteNotification ?>'); 
     294 
    306295 
    307296    return $this->redirect('<?php echo $this->getModuleName() ?>/list'); 
     
    328317 
    329318<?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 
    330 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?> 
    331 <?php $type = $column->getCreoleType() ?> 
     319<?php foreach ($this->getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> 
    332320<?php $name = $column->getName() ?> 
    333321<?php if ($column->isPrimaryKey()) continue ?> 
     
    392380  protected function update<?php echo $this->getClassName() ?>ListFromRequest($columnName, $columnValue) 
    393381  { 
    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') ?> 
     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') ?> 
    419391<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
    420392    if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) 
     
    422394<?php endif; ?> 
    423395<?php if ($type != CreoleTypes::BOOLEAN): ?> 
    424       if (isset($columnValue)) 
    425      
     396    if (isset($columnValue)) 
     397   
    426398<?php endif; ?> 
    427399<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
    428         if ($columnValue) 
    429         { 
    430           try 
     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 ?>'])) 
    431408          { 
    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); 
     409            $value = $dateFormat->format($columnValue, '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>')); 
    446410          } 
    447           catch (sfException $e) 
     411          else 
    448412          { 
    449             // not a date 
     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'] : '') : ''); 
    450415          } 
    451         } 
    452         else 
    453         { 
    454           $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(null); 
    455         } 
     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      } 
    456427<?php elseif ($type == CreoleTypes::BOOLEAN): ?> 
    457         $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0); 
     428    $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0); 
    458429<?php elseif ($column->isForeignKey()): ?> 
    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); 
     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); 
    462433<?php endif; ?> 
    463434<?php if ($type != CreoleTypes::BOOLEAN): ?> 
    464      
     435   
    465436<?php endif; ?> 
    466437<?php if ($credentials): ?> 
    467     } 
    468 <?php endif; ?> 
    469     } 
    470      
    471 <?php $first = false; endforeach; ?> 
     438      } 
     439<?php endif; ?> 
     440    } 
     441<?php endforeach; ?> 
    472442  } 
    473443 
     
    476446    $<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->getSingularName() ?>'); 
    477447 
    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 ?> 
     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)) ?> 
    505457    if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) 
    506458    { 
    507459<?php endif; ?> 
    508460<?php if ($input_type == 'admin_input_file_tag'): ?> 
    509 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.upload_dir')) ?> 
     461<?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$column->getName().'.upload_dir')) ?> 
    510462    $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 
    511463    if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove'])) 
     
    525477<?php endif; ?> 
    526478<?php if ($input_type == 'admin_input_file_tag'): ?> 
    527 <?php if ($this->getParameterValue('edit.fields.'.$checkName.'.filename')): ?> 
    528       $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.filename'))) ?>"; 
     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'))) ?>"; 
    529481<?php else: ?> 
    530482      $fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time().rand(0, 99999)); 
     
    566518      } 
    567519<?php elseif ($type == CreoleTypes::BOOLEAN): ?> 
    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); 
     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); 
    569521<?php elseif ($column->isForeignKey()): ?> 
    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 ?>']); 
     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 ?>']); 
    574525<?php endif; ?> 
    575526<?php if ($type != CreoleTypes::BOOLEAN): ?> 
     
    580531<?php endif; ?> 
    581532<?php endforeach; ?> 
     533<?php endforeach; ?> 
    582534  } 
    583535 
     
    590542    else 
    591543    { 
    592       $<?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>); 
     544      $<?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>); 
    593545 
    594546      $this->forward404Unless($<?php echo $this->getSingularName() ?>); 
     
    600552  protected function processFilters($namespace = "<?php echo $this->getSingularName() ?>") 
    601553  { 
     554<?php if ($this->getParameterValue('list.filters')): ?> 
    602555    if ($this->getRequest()->hasParameter('filter')) 
    603556    { 
    604557      $filters = $this->getRequestParameter('filters'); 
    605  
    606 <?php if ($this->getParameterValue('list.filters')): ?> 
    607558<?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> 
    608 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): //TODO replace $column->getName with $checkName ?> 
     559<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
    609560      if (isset($filters['<?php echo $column->getName() ?>']['from']) && $filters['<?php echo $column->getName() ?>']['from'] !== '') 
    610561      { 
     
    617568<?php endif; ?> 
    618569<?php endforeach; ?> 
    619 <?php endif; ?> 
    620570 
    621571      /* reset Multi-sort // TODO, this should be done somewhere else, 
     
    636586      $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 
    637587    } 
     588<?php endif; ?> 
    638589  } 
    639590 
     
    697648  protected function addFiltersCriteria($c, $namespace = '<?php echo $this->getSingularName() ?>') 
    698649  { 
    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 ?> 
     650<?php if ($this->getParameterValue('list.filters') || $this->getParameterValue('list.display')): ?> 
     651<?php $columns = array_merge($this->getColumns('list.filters'), $this->getColumns('list.display')) ?> 
    721652<?php foreach ($columns as $column):?> 
    722653<?php $type = $column->getCreoleType() ?> 
    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)); 
     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)); 
    739659      $c->add($criterion); 
    740660    } 
    741     else  
    742 <?php endif; ?> 
    743661<?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 
    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'] !== '') 
     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'] !== '') 
    747665      { 
    748666<?php if ($type == CreoleTypes::DATE): ?> 
    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'] !== '') 
     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'] !== '') 
    755673      { 
    756674        if (isset($criterion)) 
    757675        { 
    758676<?php if ($type == CreoleTypes::DATE): ?> 
    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)); 
     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)); 
    762680<?php endif; ?> 
    763681        } 
     
    765683        { 
    766684<?php if ($type == CreoleTypes::DATE): ?> 
    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); 
     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); 
    770688<?php endif; ?> 
    771689        } 
     
    778696    } 
    779697<?php else: ?> 
    780     if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'] !== '') 
     698    else if (isset($this->filters['<?php echo $column->getName() ?>']) && $this->filters['<?php echo $column->getName() ?>'] !== '') 
    781699    { 
    782700<?php if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::LONGVARCHAR): ?> 
    783701      $q = ''; 
    784702      if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 
    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): ?> 
     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?> 
    788713      $q = ''; 
    789714      if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 
    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; ?> 
     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; ?> 
    798721  } 
    799722 
     
    802725    $sort_array = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/sort'); 
    803726    $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
     727    $fieldSufix = sfConfig::get('app_sf_extjs_theme_plugin_field_suffix', ''); 
    804728 
    805729    if ($sort_array) // if sort-columns are set 
     
    808732      foreach($sort_array as $sort_column => $sort_type) 
    809733      { 
    810         //strange construction!? AND Note there is also something like: $this->getPeerClassName()  
    811734        $className = '<?php echo $this->getClassName() ?>'; 
    812735 
    813736        //fix for cookie error 
    814         $sortColumn = $sort_column; 
    815737        if (false !== strpos($sort_column, $tableDelimiter)) 
    816738        { 
    817           $elements = explode($tableDelimiter, $sort_column); 
    818           $className = $elements[count($elements)-2]; 
    819           $sortColumn = $elements[count($elements)-1];  
     739          list($className, $sortColumn) = explode($tableDelimiter, $sort_column); 
    820740          $className = sfInflector::camelize($className); 
    821741        } 
    822         //$sortColumn = str_replace(sfInflector::underscore($className).$tableDelimiter, '', $sort_column); 
     742        $sortColumn = str_replace(sfInflector::underscore($className).'-', '', $sort_column); 
    823743 
    824744        try 
    825745        { 
    826           $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); 
     746          $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), strtoupper($sortColumn), BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); 
    827747          $sort_columns[$fieldName] = $sort_type; 
    828748        } 
     
    830750        { 
    831751          // sort column does not exist, throw error 
    832           throw new sfException(sprintf('Cannot sort on column "%s", the column does not exist. Clearing your cookies will (temporarily) fix this error.', $sortColumn)); 
     752          throw new sfException(sprintf('Cannot sort on column "%s", the column does not exist. Clearing your cookies will (temporarily) fix this error.', strtoupper($sortColumn))); 
    833753        } 
    834754 
     
    855775  } 
    856776 
     777  protected function getFields() 
     778  { 
     779    return array( 
     780<?php $fields = $this->getFieldsProperties(); 
     781      $fieldsName = $fields['names']; 
     782      foreach ($fieldsName as $name => $fieldName): ?> 
     783  '<?php echo $name ?>' => '<?php echo $fieldName ?>', 
     784<?php endforeach; ?> 
     785    ); 
     786  } 
     787 
    857788  protected function getLabels() 
    858789  { 
    859790    return array( 
    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 ?>', 
     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; ?> 
    881795<?php endforeach; ?> 
    882796    );