Development

Changeset 6100

You must first sign up to be able to contribute.

Changeset 6100

Show
Ignore:
Timestamp:
11/19/07 00:12:30 (1 year ago)
Author:
Leon.van.der.Ree
Message:

Added renderer for group-by-header, which supports master-detail up to 3th level of foreign-value (ForeignTable?->ForeignTable?->column). Used some hardcoding to reach 3th level, needs nicer solution with iteration.

Files:

Legend:

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

    r6067 r6100  
    1212 
    1313$hs = $this->getParameterValue('list.hide', array()); 
     14//TODO This probably does not work with partials and links (=columnname) 
    1415$display = $this->getParameterValue('list.display', array()); 
     16$groupingDisplay = $this->getParameterValue('list.grouping.display', array()); 
    1517$columns = $this->getColumns('list.display'); 
    1618 
     
    2123$columns[] = $this->getAdminColumnForField($pk); 
    2224 
    23  
    24 //add grouping.field (which does not necesarrily has to be defined in the display array 
     25//add grouping.field (which does not necesarrily has to be defined in the display array) 
    2526$groupColumnName = $this->getParameterValue('list.grouping.field', null); 
    2627if ($groupColumnName)  
    2728{ 
    28   if (!in_array($groupColumnName, $display)) { 
     29  if (!in_array($groupColumnName, $display))  
     30  { 
    2931    $columns[] = $this->getAdminColumnForField($groupColumnName); 
    3032  } 
    3133} 
    3234 
     35//add grouping.display.fields (which do not necesarrily has to be defined in the display array) 
     36if (count($groupingDisplay) > 0)  
     37{ 
     38  $groupColumns = $this->getColumns('list.grouping.display'); 
     39   
     40  foreach ($groupColumns as $groupColumn) 
     41  { 
     42    $groupColumnName = $groupColumn->getName(); 
     43     
     44    if (!in_array($groupColumnName, $display))  
     45    { 
     46      $columns[] = $this->getAdminColumnForField($groupColumnName); 
     47    } 
     48  } 
     49} 
    3350 
    3451//add PrimaryKeys of foreign-classes 
     
    4360 
    4461    // add column if not already in list 
    45     if (!in_array($columnName, $display)) { 
     62    if (!in_array($columnName, $display))  
     63    { 
    4664      $columns[] = $this->getAdminColumnForField($columnName); 
    4765    } 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_layout.php

    r6087 r6100  
    125125 
    126126  $hs = $this->getParameterValue('list.hide', array()); 
    127 //  $columns = $this->getColumns('list.display'); 
    128  
    129127 
    130128  // iterate through all related classes 
     
    218216 
    219217 
    220 [?php include_partial('<?php echo $this->getModuleName() ?>/list_ajax_renderer') ?] 
     218[?php include_partial('list_ajax_renderer') ?] 
    221219 
    222220  // ------------------------ 
     
    228226  $columns = $this->getColumns('list.display'); 
    229227 
    230   //iterate through all columns of current class 
     228  //iterate through all columns 
    231229  foreach ($columns as $column) : 
    232230    // can we skip it? 
     
    365363?> 
    366364<?php endforeach; ?> 
    367 [?php include_partial('<?php echo $this->getModuleName() ?>/list_ajax_plugin') ?] 
     365[?php include_partial('list_ajax_plugin') ?] 
    368366 
    369367      cm = <?php echo _extjs_write_class('grid.ColumnModel', array($cmOptions), true, $expander) ?>; 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_renderer.php

    r6075 r6100  
    1717$prefix = strtolower($this->getClassName()); 
    1818 
     19//iterate through all columns of all class 
     20$completeColumns = $this->getColumnsGroup($pk); 
     21 
    1922?> 
     23      function renderHeader(value, p, record){ 
     24<?php  
     25$display = $this->getParameterValue('list.grouping.display', null); 
     26if ($display!=null)  
     27{ 
     28     
     29  // the header text which is build from the list.grouping.display-array with this code 
     30  $headerText = ""; 
     31 
     32  $columns = $this->getColumns('list.grouping.display'); 
     33   
     34  //iterate through all columns for grouping display 
     35  foreach ($columns as $column) 
     36  { 
     37    if (false !== strpos($column->getName(), '/')) 
     38    { 
     39      list($relatedClassName, $relatedColumn) = explode('/', $column->getName(),2); 
     40      $key_name = $completeColumns['related'][$relatedClassName]['pk']->getName(); 
     41       
     42      // TODO: add iteration to define related-column-names 
     43      $relatedColumn = str_replace('/',$tableDelimiter,$relatedColumn); 
     44    } 
     45     
     46    //header values 
     47    $h_moduleName = $relatedClassName; 
     48    $h_tableName = $relatedClassName; 
     49    $h_pkn = $key_name; 
     50     
     51    $h_valuePrefix = $this->getParameterValue('list.fields.'.$column->getName().'.params.header_valuePrefix', 
     52                     $this->getParameterValue('fields.'.$column->getName().'.params.header_valuePrefix', ' ')); 
     53    $h_valueSuffix = $this->getParameterValue('list.fields.'.$column->getName().'.params.header_valueSuffix',  
     54                     $this->getParameterValue('fields.'.$column->getName().'.params.header_valueSuffix', ' ')); 
     55     
     56    // TODO: Prevent collapsing when clicking link 
     57    if ($column->isLink()) 
     58    { 
     59      //TODO remove hardcoded tag for underline, add option to set stylesheet-class, don't forget to remove the closing tag as well... 
     60      $headerText .= "<u><a href=\'".$controller->genUrl($h_moduleName."/edit?".$h_pkn."=")."/'+record.data['".$h_tableName.$tableDelimiter.$h_pkn."']+'\'>"; 
     61    } 
     62    $headerText .= $h_valuePrefix."'+record.data['".$h_tableName.$tableDelimiter.$relatedColumn."']+'".$h_valueSuffix; 
     63    if ($column->isLink()) 
     64    { 
     65      $headerText .= "</a></u>"; 
     66    } 
     67  } 
     68} 
     69else // no grouping.display defined use grouping.field 
     70{ 
     71  $columnName = $this->getParameterValue('list.grouping.field', null); 
     72   
     73  $h_valuePrefix = ''; 
     74  $h_valueSuffix = ''; 
     75   
     76  if ($columnName != null) { 
     77    $h_valuePrefix = $this->getParameterValue('list.fields.'.$columnName.'.params.header_valuePrefix', 
     78                     $this->getParameterValue('fields.'.$columnName.'.params.header_valuePrefix', ' ')); 
     79    $h_valueSuffix = $this->getParameterValue('list.fields.'.$columnName.'.params.header_valueSuffix',  
     80                     $this->getParameterValue('fields.'.$columnName.'.params.header_valueSuffix', ' ')); 
     81  } 
     82    
     83  $headerText = $h_valuePrefix."'+value+'".$h_valueSuffix; 
     84} 
     85?> 
     86          return '<?php echo $headerText ?>'; 
     87      } 
     88 
    2089 
    2190      // TODO: remove hardcoded html-tags, set css  
    2291      // a column with a value which is a link (to edit) 
    2392      function renderLink(value, p, record){ 
    24           return String.format('<u><b><a href="<?php echo $controller->genUrl($this->getModuleName().'/edit?'.$pkn.'=') ?>/{1}">{0}</a></b></u>', value, record.data['<?php echo $prefix.$tableDelimiter.$pkn ?>']); 
     93          return String.format('<u><b><a href=\'<?php echo $controller->genUrl($this->getModuleName().'/edit?'.$pkn.'=') ?>/{1}\'>{0}</a></b></u>', value, record.data['<?php echo $prefix.$tableDelimiter.$pkn ?>']); 
    2594      } 
    2695 
     
    46115      // a column with a weight 
    47116      function renderWeight(v){ 
     117        v = String(v); 
    48118        var ps = v.split('.'); 
    49119        var whole = ps[0]; 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/listSuccess.php

    r5945 r6100  
    3737  [?php echo __('no result') ?] 
    3838  [?php else: ?] 
    39   [?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager)) ?] 
     39  [?php include_partial('list', array('pager' => $pager)) ?] 
    4040  [?php endif; ?] 
    4141  [?php include_partial('list_actions') ?] 
  • plugins/sfExtjsThemePlugin/lib/helper/ExtjsHelper.php

    r5945 r6100  
    8787  } 
    8888 
    89   if ($type === 'float'
     89  if (($type === 'float') || ($type === 'double')
    9090  { 
    9191    return 'float'; 
  • plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php

    r6087 r6100  
    190190      return $for == 'edit' ? "$columnGetter ? 'true' : 'false'" : "$columnGetter ? 1 : 0"; 
    191191    } 
    192  
     192     
    193193    return parent::getColumnListTag($column, $params); 
    194194  } 
     
    231231 
    232232  /** 
    233    * Return all columns and all related columns with her primary key 
     233   * Return all columns and all related columns with their primary key 
    234234   * 
    235235   * @param string $pk (optional) primary key admin column 
    236236   */ 
     237  // TODO maybe we again can make this somewhat nicer, contains much copy-paste to support grouping and group-display-array in same way as to process regular (display)columns 
    237238  public function getColumnsGroup($pk = null) 
    238239  { 
     
    251252        $column = $this->getAdminColumnForField($groupColumnName); 
    252253 
     254        // check if foreign 
    253255        if (false !== strpos($groupColumnName, '/')) 
    254256        { 
    255257 
    256  
    257           list($peerName, $relatedColumn) = explode('::', $column->getPhpName()); 
     258          $columnPhpName = $column->getPhpName(); 
     259          list($peerName, $relatedColumn) = explode('::', $columnPhpName); 
    258260          $relatedClassName = sfInflector::underscore($peerName); 
    259261 
     
    275277          $columns['related'][$relatedClassName]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
    276278 
    277  
    278  
    279  
    280         } 
    281         else 
    282         { 
    283           $columns['column'][] = $column; 
    284         } 
    285       } 
    286     } 
    287  
    288     //iterate through all columns of all class 
     279        } 
     280        else // local column 
     281        { 
     282          $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
     283          $columns['column'][$columnUnderscore] = $column; 
     284        } 
     285      } 
     286    } 
     287 
     288    //iterate through all columns of grouping.display fields  
     289    foreach ($this->getColumns('list.grouping.display') as $column) 
     290    { 
     291      if ($column->isPrimaryKey()) continue; 
     292 
     293      // check if foreign 
     294      if (false !== strpos($column->getName(), '/')) 
     295      { 
     296        $columnPhpName = $column->getPhpName(); 
     297        list($peerName, $relatedColumn) = explode('::', $columnPhpName,2); 
     298        $relatedClassName = sfInflector::underscore($peerName); 
     299 
     300        // TODO, now hardcoded adding a third level (foreigntable->foreigntable->field), this should be solved with recursion 
     301        if (false !== strpos($relatedColumn, '::'))  
     302        { 
     303          list($peerName2, $relatedColumn) = explode('::', $relatedColumn,2); 
     304          $relatedClassName2 = sfInflector::underscore($peerName2); 
     305           
     306          if (!isset($columns['related'][$relatedClassName]['pk'])) 
     307          { 
     308            $tableMap = call_user_func(array($peerName.'Peer', 'getTableMap')); 
     309   
     310            foreach ($tableMap->getColumns() as $col) 
     311            { 
     312              if (!isset($columns['related'][$relatedClassName]['pk']) && $col->isPrimaryKey()) 
     313              { 
     314                $columns['related'][$relatedClassName]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
     315                break; 
     316              } 
     317            } 
     318          } 
     319 
     320          if (!isset($columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk'])) 
     321          { 
     322            $tableMap = call_user_func(array($peerName2.'Peer', 'getTableMap')); 
     323   
     324            foreach ($tableMap->getColumns() as $col) 
     325            { 
     326              if (!isset($columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk']) && $col->isPrimaryKey()) 
     327              { 
     328                $columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
     329                break; 
     330              } 
     331            } 
     332          } 
     333           
     334          $relatedColumnUnderscore = sfInflector::underscore($relatedColumn); 
     335          $columns['related'][$relatedClassName]['related'][$relatedClassName2]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
     336        }  
     337        else  
     338        { 
     339          if (!isset($columns['related'][$relatedClassName]['pk'])) 
     340          { 
     341            $tableMap = call_user_func(array($peerName.'Peer', 'getTableMap')); 
     342   
     343            foreach ($tableMap->getColumns() as $col) 
     344            { 
     345              if (!isset($columns['related'][$relatedClassName]['pk']) && $col->isPrimaryKey()) 
     346              { 
     347                $columns['related'][$relatedClassName]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
     348                break; 
     349              } 
     350            } 
     351          } 
     352 
     353          $relatedColumnUnderscore = sfInflector::underscore($relatedColumn); 
     354          $columns['related'][$relatedClassName]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
     355        } 
     356      } 
     357      else // local column 
     358      { 
     359        $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
     360        $columns['column'][$columnUnderscore] = $column; 
     361      } 
     362    }     
     363     
     364    //iterate through all columns of display-fields 
    289365    foreach ($this->getColumns('list.display') as $column) 
    290366    { 
    291367      if ($column->isPrimaryKey()) continue; 
    292368 
     369      // check if foreign 
    293370      if (false !== strpos($column->getName(), '/')) 
    294371      { 
     
    313390        $columns['related'][$relatedClassName]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
    314391      } 
    315       else 
     392      else // local column 
    316393      { 
    317394        $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
     
    347424    if (isset($columns['related'])) 
    348425    { 
    349       foreach ($columns['related'] as $class => $relatedClasses
     426      foreach ($columns['related'] as $class => $relatedClass
    350427      { 
    351428        // Add id 
    352         $fieldsName[$class.'_'.$relatedClasses['pk']->getName()] = $class.$tableDelimiter.$relatedClasses['pk']->getName(); 
    353         $fieldsType[$class.'_'.$relatedClasses['pk']->getName()] = $relatedClasses['pk']->getType(); 
     429        $fieldsName[$class.'_'.$relatedClass['pk']->getName()] = $class.$tableDelimiter.$relatedClass['pk']->getName(); 
     430        $fieldsType[$class.'_'.$relatedClass['pk']->getName()] = $relatedClass['pk']->getType(); 
    354431         
    355432        // Add preload-value 
    356         foreach ($relatedClasses['columns'] as $relatedColumn => $col) 
     433        foreach ($relatedClass['columns'] as $relatedColumn => $col) 
    357434        { 
    358435          $fieldsName[$class.'_'.$relatedColumn] = $class.$tableDelimiter.$relatedColumn; 
    359436          $fieldsType[$class.'_'.$relatedColumn] = $col->getType(); 
     437        } 
     438 
     439        // Add the related-related foreign-keys, TODO: Hardcoded, this should also be solved with recursion 
     440        if (isset($relatedClass['related'])) 
     441        { 
     442          foreach ($relatedClass['related'] as $class2 => $relatedClass2) 
     443          { 
     444            // Add preload-value 
     445            foreach ($relatedClass2['columns'] as $relatedColumn2 => $col2) 
     446            { 
     447              $fieldsName[$class.'_'.$class2.'_'.$relatedColumn2] = $class.$tableDelimiter.$class2.$tableDelimiter.$relatedColumn2; 
     448              $fieldsType[$class.'_'.$class2.'_'.$relatedColumn2] = $col->getType(); 
     449            } 
     450          } 
    360451        } 
    361452      } 
     
    417508        $options['vtype'] = $params['type']; 
    418509      } 
     510    } else { 
     511      $definition['renderer'] = isset($params['renderer']) ? $params['renderer'] : 'renderHeader'; 
    419512    } 
    420513     
     
    542635      } 
    543636    } 
    544     else if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT) 
     637    else if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT || 
     638             $type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL) 
    545639    { 
    546640      $editor = _extjs_write_class('form.NumberField', array($options), true); 
     
    557651        } 
    558652 
    559         if ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL) 
    560         { 
    561           $definition['renderer'] = isset($params['renderer']) ? $params['renderer'] : 'formatNumber'; 
    562         } 
     653        $definition['renderer'] = isset($params['renderer']) ? $params['renderer'] : 'formatNumber'; 
    563654 
    564655        return $definition;