Development

Changeset 8447

You must first sign up to be able to contribute.

Changeset 8447

Show
Ignore:
Timestamp:
04/14/08 16:32:21 (6 months ago)
Author:
naholyr
Message:

[sfAdvancedAdminGenerator]
Added support for sorting on foreign key. Set the "sort_key" parameter to the name of the constant to activate sorting on a foreign key.
Example (in the generator.yml of adminAuthor) : post: { sort_key: "PostPeer::TITLE" }

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfAdvancedAdminGeneratorPlugin/branches/naholyr/data/generator/sfAdvancedAdmin/default/template/actions/actions.class.php

    r8435 r8447  
    533533  } 
    534534 
     535  protected function getSortColumn($field_name) 
     536  { 
     537    switch ($field_name) { 
     538      <?php foreach ($this->getColumns('list.display') as $column): ?> 
     539      <?php if ($sort_key = $this->getParameterValue('list.fields.'.$column->getName().'.sort_key')): ?> 
     540      case '<?php echo $column->getName() ?>': 
     541        return <?php echo $sort_key ?>; 
     542      <?php endif ?> 
     543      <?php endforeach ?> 
     544    } 
     545     
     546    return <?php echo $this->getClassName() ?>Peer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);; 
     547  } 
     548 
    535549  protected function addSortCriteria($c) 
    536550  { 
    537551    if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort')) 
    538552    { 
    539       $sort_column = <?php echo $this->getClassName() ?>Peer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); 
     553      $sort_column = $this->getSortColumn($sort_column); 
    540554      if ($this->getUser()->getAttribute('type', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == 'asc') 
    541555      { 
  • plugins/sfAdvancedAdminGeneratorPlugin/branches/naholyr/data/generator/sfAdvancedAdmin/default/template/templates/_list_th_tabular.php

    r8312 r8447  
    77<?php endif; ?> 
    88  <th id="sf_admin_list_th_<?php echo $column->getName() ?>"> 
    9     <?php if ($column->isReal()): ?> 
     9    <?php if ($this->isSortable($column)): ?> 
    1010      [?php if ($sf_user->getAttribute('sort', null, 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == '<?php echo $column->getName() ?>'): ?] 
    1111      [?php echo link_to(__('<?php echo str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')) ?>'), '<?php echo $this->getModuleName() ?>/list?sort=<?php echo $column->getName() ?>&type='.($sf_user->getAttribute('type', 'asc', 'sf_admin/<?php echo $this->getSingularName() ?>/sort') == 'asc' ? 'desc' : 'asc')) ?] 
  • plugins/sfAdvancedAdminGeneratorPlugin/branches/naholyr/lib/sfAdvancedAdminGenerator.class.php

    r8435 r8447  
    2323{ 
    2424   
    25   /** 
    26    * Returns table name from "extended" class name (supports the Class.Column syntax 
    27    * used for self-referencing many-to-many relations). 
    28    * 
    29    * @param string $class_name 
    30    * @return string 
    31    */ 
    32   public function getTableName($class_name) 
    33   { 
     25  public function isSortable(sfAdminColumn $column) 
     26  { 
     27    $sort_key = $this->getParameterValue('list.fields.'.$column->getName().'.sort_key'); 
     28     
     29    return $column->isReal() || !is_null($sort_key); 
     30  } 
     31   
     32  /** 
     33   * Returns table name from "extended" class name (supports the Class.Column syntax 
     34   * used for self-referencing many-to-many relations). 
     35   * 
     36   * @param string $class_name 
     37   * @return string 
     38   */ 
     39  public function getTableName($class_name) 
     40  { 
    3441    if (false !== strpos($class_name, '.')) { 
    35     list($class_name, $ref_column) = explode('.', $class_name, 2); 
     42      list($class_name, $ref_column) = explode('.', $class_name, 2); 
    3643    } 
    3744     
    38    return constant($class_name . 'Peer::TABLE_NAME'); 
    39 
    40    
     45    return constant($class_name . 'Peer::TABLE_NAME'); 
     46 
     47   
    4148  /** 
    4249   * Initializes the current sfGenerator instance. 
     
    110117  function getPHPObjectHelper($helperName, $column, $params, $localParams = array()) 
    111118  { 
    112   if (null !== ($map = $this->getParameterValue('maps.'.$column->getName()))) { 
    113      // Load map 
    114      $params['map'] = $map; 
    115      $helperName    = 'select_map_tag';  
    116  
    117    
    118   return parent::getPHPObjectHelper($helperName, $column, $params, $localParams); 
     119    if (null !== ($map = $this->getParameterValue('maps.'.$column->getName()))) { 
     120      // Load map 
     121      $params['map'] = $map; 
     122      $helperName    = 'select_map_tag';  
     123   
     124     
     125    return parent::getPHPObjectHelper($helperName, $column, $params, $localParams); 
    119126  } 
    120127   
    121128  public function getColumnShowTag($column, $params = array()) 
    122129  { 
    123   return $this->getColumnListTag($column, $params); 
     130    return $this->getColumnListTag($column, $params); 
    124131  } 
    125132   
    126133  public function getColumnListTag($column, $params = array()) { 
    127   $return = parent::getColumnListTag($column, $params); 
    128   if (!$column->isComponent() && !$column->isPartial()) { 
    129      $return = '(null !== ($val = '.$return.') && isset($maps["'.$column->getName().'"][$val])?$maps["'.$column->getName().'"][$val]:$val)'; 
    130  
    131   return $return; 
     134    $return = parent::getColumnListTag($column, $params); 
     135    if (!$column->isComponent() && !$column->isPartial()) { 
     136      $return = '(null !== ($val = '.$return.') && isset($maps["'.$column->getName().'"][$val])?$maps["'.$column->getName().'"][$val]:$val)'; 
     137   
     138    return $return; 
    132139  } 
    133140   
     
    157164     
    158165    // Add support for _show 
    159   if ($actionName === '_show') { 
    160     return preg_replace('/\/show_icon.png/', '/filter.png', $ret); 
     166    if ($actionName === '_show') { 
     167      return preg_replace('/\/show_icon.png/', '/filter.png', $ret); 
    161168    } 
    162169    else {