Development

Changeset 6212

You must first sign up to be able to contribute.

Changeset 6212

Show
Ignore:
Timestamp:
11/29/07 21:56:35 (1 year ago)
Author:
Leon.van.der.Ree
Message:

groupedColumns are now being used at some locations, with success. Some things are now broken: you cannot show a field twice in the grid, fields are shown alfabetically, master-detail groups have broken links in renderer due to new name of PK, sorting (due to new naming), drop-down-combo-boxes.

Only lists are partially adapted to groupedColumns, filters and edit-pages still have to be done completely!

Files:

Legend:

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

    r6171 r6212  
    750750  { 
    751751    return array( 
    752 <?php $fields = $this->getFieldsProperties(); 
    753       $fieldsName = $fields['names']; 
    754       foreach ($fieldsName as $name => $fieldName): ?> 
    755   '<?php echo $name ?>' => '<?php echo $fieldName ?>', 
     752<?php  
     753  $fields = $this->getFieldsProperties(); 
     754  $fieldsName = $fields['names']; 
     755?> 
     756<?php foreach ($fieldsName as $name => $fieldName): ?> 
     757      '<?php echo $name ?>' => '<?php echo $fieldName ?>', 
    756758<?php endforeach; ?> 
    757759    ); 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_list_td.php

    r6192 r6212  
    1 [?php //TODO: maybe later BUT INSIDE JSON_LIST_TD include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?] 
     1[?php  
     2//TODO: maybe later BUT INSIDE JSON_LIST_TD include_partial('list_td_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>))  
     3?] 
    24 
    35[?php use_helper('Date'); ?] 
    46{ 
    57<?php 
    6 $for = 'list.display'; //TODO make this also work for list.filters and edit.display 
    78 
    89$tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
    910 
    10 //TODO This probably does not work with partials and links (=columnname) 
    1111$hs = $this->getParameterValue('list.hide', array()); 
    12 $display = $this->getParameterValue($for, array());  
    1312 
    14 // iterate through all columns of all class (inc. related) 
    15 $completeColumns = $this->getColumnsGrouped($for); 
    16  
    17 //TODO: this should probably be obsolete when using $completeColumns 
    18 $columns = $this->getColumns($for); 
    19 //add PrimaryKey of class 
    20 $columns[] = $completeColumns['pk']; 
    21  
    22 //add grouping.field (which does not necesarrily has to be defined in the display array) 
    23 $groupingDisplay = $this->getParameterValue('list.grouping.display', array()); 
    24 $groupColumnName = $this->getParameterValue('list.grouping.field', null); 
    25 if ($groupColumnName)  
    26 
    27   if (!in_array($groupColumnName, $display))  
    28   { 
    29     $columns[] = $this->getAdminColumnForField($groupColumnName); 
    30   } 
    31 
    32  
    33 //add grouping.display.fields (which do not necesarrily has to be defined in the display array) 
    34 if (count($groupingDisplay) > 0)  
    35 
    36   $groupColumns = $this->getColumns('list.grouping.display'); 
    37    
    38   foreach ($groupColumns as $groupColumn) 
    39   { 
    40     $groupColumnName = $groupColumn->getName(); 
    41      
    42     if (!in_array($groupColumnName, $display))  
    43     { 
    44       $columns[] = $this->getAdminColumnForField($groupColumnName); 
    45     } 
    46   } 
    47 
    48  
    49 //add PrimaryKeys of foreign-classes 
    50 foreach ($columns as $column) 
    51 
    52   if ($foreign = (false !== strpos($column->getName(), '/'))) 
    53   { 
    54     // construct foreign-id name 
    55     list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    56     $columnPk = $completeColumns['related'][$relatedClassName]['pk']; 
    57     $columnName = $relatedClassName.'/'.$columnPk->getName(); 
    58  
    59     // add column if not already in list 
    60     if (!in_array($columnName, $display))  
    61     { 
    62       $columns[] = $this->getAdminColumnForField($columnName); 
    63     } 
    64   } 
    65 
    66  
     13// iterate through all (related) columns of all classes 
     14$for = 'list.display'; 
     15$groupedColumns = $this->getColumnsGrouped($for); 
     16$columns = $this->getListColumns($groupedColumns, true); 
    6717 
    6818//iterate through all columns 
    6919$i = 0; 
    70 foreach ($columns as $column) : 
     20foreach ($columns as $columnName => $column) : 
    7121 
    72   // set name 
    73   $columnName = $column->getName(); 
    74   // add classname to json data for fields of current class 
    75   if (!$foreign = (false !== strpos($column->getName(), '/'))) 
     22  // remove base classname for checks (This way you can check on fields like name, instead of product/name) 
     23  list($class, $checkName) = explode('/', $columnName, 2); 
     24  if (strtolower($class) != strtolower($this->getClassName())) 
    7625  { 
    77     $columnName = strtolower($this->getClassName()).'/'.$column->getName()
     26    $checkName = $columnName
    7827  } 
     28  // TODO: this is a hack! this should be fixed by letting getColumnAjaxTag take the relative $columnName into account, something like $this->getColumnAjaxTag($column, $checkName or $columnName) 
     29  // Due to this hack the column looses all info (like type, length, etc)  
     30  $column = $this->getAdminColumnForField($checkName); 
     31   
     32  if (in_array($checkName, $hs)) continue; 
    7933 
    80   if (in_array($column->getName(), $hs)) continue; 
    81  
    82   $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials'); 
     34  $credentials = $this->getParameterValue('list.fields.'.$checkName.'.credentials'); 
    8335 
    8436?> 
     
    9446 
    9547  // unfortunately we cannot use the '/' to distinquish the class and the field, because the name is used as variable in _list_ajax_layout.php 
    96   echo "\"".str_replace('/',$tableDelimiter,$columnName)."\": \"[?php echo str_replace('\"', '\\\"', ".$this->getColumnAjaxTag($column).") ?]\""; 
     48  echo "\"".str_replace('/', $tableDelimiter, $columnName)."\": \"[?php echo str_replace('\"', '\\\"', ".$this->getColumnAjaxTag($column).") ?]\""; 
    9749 
    9850  //don't add it twice 
    99   $hs[] = $column->getName()
     51  $hs[] = $checkName
    10052 
    10153  $i++; 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_columnmodel.php

    r6192 r6212  
    44<?php  
    55$tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
    6 $completeColumns = $this->getColumnsGrouped('list.display'); 
    7 $i = 0;  
     6 
     7$hs = $this->getParameterValue('list.hide', array()); 
     8 
     9// iterate through all (related) columns of all classes 
     10$for = array('list.display', 'list.grouping.field'); 
     11$groupedColumns = $this->getColumnsGrouped($for, true); 
     12$columns = $this->getListColumns($groupedColumns, false); 
     13 
    814$cmOptions = array();  
    915$expander = false; 
     16 
     17$i = 0;  
     18 
     19foreach ($columns as $columnName => $column) : 
     20 
     21  // remove base classname for checks (This way you can check on fields like name, instead of product/name) 
     22  list($class, $checkName) = explode('/', $columnName, 2); 
     23  if (strtolower($class) != strtolower($this->getClassName())) 
     24  { 
     25    $checkName = $columnName; 
     26  } 
     27  // TODO: this is a hack! this should be fixed by letting getColumnAjaxTag take the relative $columnName into account, something like $this->getColumnAjaxTag($column, $checkName or $columnName) 
     28  // Due to this hack the column looses all info (like type, length, etc)  
     29//  $column = $this->getAdminColumnForField($checkName); 
     30 
     31  if(count($this->getParameterValue('list.expander')) != 0) 
     32  { 
     33    $expander = true; 
     34    if(in_array($column->getName(),  $this->getParameterValue('list.expander'))) continue; 
     35  } 
     36   
     37  if (in_array($checkName, $hs)) continue; 
     38   
     39  $credentials = $this->getParameterValue('list.fields.'.$checkName.'.credentials'); 
     40 
    1041?> 
    11 <?php $hs = $this->getParameterValue('list.hide', array()) ?> 
    12 <?php $columns = $this->getColumns('list.display'); ?> 
    13 <?php $columns = $this->addGroupColumn($columns); ?> 
    14 <?php foreach ($columns as $column): ?> 
     42<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
     43    echo "\n[?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?]"; 
     44    //TODO This check should be done when writing the javascript for this field AT RUNTIME (html generation, Not cache-template generation) 
     45<?php endif; ?> 
    1546<?php 
    16 if(count($this->getParameterValue('list.expander'))!=0) 
    17 { 
    18   $expander = true; 
    19   if(in_array($column->getName(),  $this->getParameterValue('list.expander'))) continue; 
    20 } 
    21 ?> 
    22 <?php if (in_array($column->getName(), $hs)) continue; ?> 
    23 <?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?> 
    24 <?php if ($credentials) continue; 
    25 //TODO: Check credentials line above, compare with original theme. Does not look OK at first sight... There should be a credential test during "runtime" 
    2647 
    27   $header = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->getName().'.name')); 
     48  $header = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$checkName.'.name')); 
    2849  list($header) = explode('/', $header); 
    2950 
    30   // Set dataIndex 
    31   if (false !== strpos($column->getName(), '/')) 
    32   { 
    33     //exception for grouping-fields 
    34 //    if ($column->getName() == $this->getParameterValue('list.grouping.field', null)) 
    35     if (isset($column->groupBy) && $column->groupBy) 
    36     { 
    37       // when grouping field, dataIndex is this group-field, UNLESS we can set a renderer which looks up the group-field from its id 
    38       $dataIndex = $this->getGroupField(); 
    39       //$header .= " group"; //why? maybe set this on generator.yml? 
    40     } 
    41     else 
    42     { 
    43       list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    44       $dataIndex = $relatedClassName.$tableDelimiter.$completeColumns['related'][$relatedClassName]['pk']->getName(); 
    45     } 
    46   } 
    47   else 
    48   { 
    49     $dataIndex = sfInflector::underscore($this->getClassName()).$tableDelimiter.$column->getName(); 
    50   } 
    51  
     51//  // Set dataIndex 
     52//  if (false !== strpos($column->getName(), '/')) 
     53//  { 
     54//    //exception for grouping-fields 
     55////    if ($column->getName() == $this->getParameterValue('list.grouping.field', null)) 
     56//    if (isset($column->groupBy) && $column->groupBy) 
     57//    { 
     58//      // when grouping field, dataIndex is this group-field, UNLESS we can set a renderer which looks up the group-field from its id 
     59//      $dataIndex = $this->getGroupField(); 
     60//      //$header .= " group"; //why? maybe set this on generator.yml? 
     61//    } 
     62//    else 
     63//    { 
     64//      list($relatedClassName, $relatedColumn) = explode('/', $checkName); 
     65//      $dataIndex = $relatedClassName.$tableDelimiter.$groupedColumns['related'][$relatedClassName]['pk']->getName(); 
     66//    } 
     67//  } 
     68//  else 
     69//  { 
     70//    $dataIndex = sfInflector::underscore($this->getClassName()).$tableDelimiter.$column->getName(); 
     71//  } 
     72   
     73  $dataIndex = str_replace('/',$tableDelimiter,$columnName); 
    5274 
    5375?> 
     
    5880  $cmOptions[$i]['header'] = $header; 
    5981  $cmOptions[$i]['dataIndex'] = $dataIndex; 
     82   
     83  if ($checkName == $this->getParameterValue('list.grouping.field', null)) 
     84  { 
     85    $column->groupBy = true; 
     86  } 
    6087 
    6188  $options = array(); 
    62   $cmOptions[$i] += $this->getColumnAjaxDefinition($column, $options, 'list', $completeColumns); 
     89  $cmOptions[$i] += $this->getColumnAjaxDefinition($column, $options, 'list', $groupedColumns); 
    6390  $i++; 
    6491?> 
     92<?php if ($credentials): ?> 
     93    echo "\n[?php endif; ?]"; 
     94<?php endif; ?> 
    6595<?php endforeach; ?> 
    6696 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_renderer.php

    r6192 r6212  
    11<?php 
    2  
    32// get the controller, used for URL creation 
    43static $controller; 
     
    98 
    109$tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
    11 $prefix = strtolower($this->getClassName()); 
    12  
    13 //iterate through all columns of all class 
    14 $completeColumns = $this->getColumnsGrouped('list.display'); 
    15 $pkn = $completeColumns['pk']->getName(); 
     10$prefix = sfInflector::underscore($this->getClassName()).$tableDelimiter; 
    1611 
    1712?> 
    1813<?php if ($this->getParameterValue('list.grouping.field', null)) : ?> 
    19       function renderHeader(value, p, record){ 
    20 <?php  
    21 $display = $this->getParameterValue('list.grouping.display', null); 
    22 if ($display!=null)  
    23 
     14<?php    
     15  $hs = $this->getParameterValue('list.hide', array()); 
     16   
     17  if ($this->getParameterValue('list.grouping.display', null))  
     18  { 
     19    // iterate through all (related) columns of all classes 
     20    $for = 'list.grouping.display'; 
     21    $groupedColumns = $this->getColumnsGrouped($for); 
     22    $columns = $this->getListColumns($groupedColumns, false); 
     23    $pkn = $groupedColumns['pk']->getName(); 
     24       
     25    // the header text which is build from the list.grouping.display-array with this code 
     26    $headerText = ""; 
     27   
     28    //iterate through all columns for grouping display 
     29    foreach ($columns as $columnName => $column) 
     30    { 
     31      // remove base classname for checks (This way you can check on fields like name, instead of product/name) 
     32      list($class, $checkName) = explode('/', $columnName, 2); 
     33      if (strtolower($class) != strtolower($this->getClassName())) 
     34      { 
     35        $checkName = $columnName; 
     36      } 
     37       
     38      if (false !== strpos($checkName, '/')) 
     39      { 
     40        list($relatedClassName, $relatedColumn) = explode('/', $checkName,2); 
     41        $key_name = $groupedColumns['related'][$relatedClassName]['pk']->getName(); 
     42         
     43        // TODO: add iteration to define related-column-names 
     44        $relatedColumn = str_replace('/', $tableDelimiter, $relatedColumn); 
     45      } 
     46       
     47      //header values 
     48      $h_moduleName = $relatedClassName; 
     49      $h_tableName = $relatedClassName; 
     50      $h_pkn = $key_name; 
     51      $params = $this->getParameterValue('list.fields.'.$checkName.'.params'); 
     52      $params = is_array($params) ? $params : sfToolkit::stringToArray($params); 
     53      $h_valuePrefix = isset($params['header_valuePrefix']) ? $params['header_valuePrefix'] : ''; 
     54      $h_valueSuffix = isset($params['header_valueSuffix']) ? $params['header_valueSuffix'] : ''; 
     55       
     56      // TODO: Prevent collapsing when clicking link (by changing the CSS of the header) 
     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['".str_replace('/', $tableDelimiter, $columnName)."']+'".$h_valueSuffix; 
     63      if ($column->isLink()) 
     64      { 
     65        $headerText .= "</a></u>"; 
     66      } 
     67    } 
     68  } 
     69  else // no grouping.display defined use grouping.field 
     70  { 
     71    $columnName = $this->getParameterValue('list.grouping.field', null); 
    2472     
    25   // the header text which is build from the list.grouping.display-array with this code 
    26   $headerText = ""; 
    27  
    28   $columns = $this->getColumns('list.grouping.display'); 
    29    
    30   //iterate through all columns for grouping display 
    31   foreach ($columns as $column) 
    32   { 
    33     if (false !== strpos($column->getName(), '/')) 
    34     { 
    35       list($relatedClassName, $relatedColumn) = explode('/', $column->getName(),2); 
    36       $key_name = $completeColumns['related'][$relatedClassName]['pk']->getName(); 
    37        
    38       // TODO: add iteration to define related-column-names 
    39       $relatedColumn = str_replace('/', $tableDelimiter, $relatedColumn); 
     73    $h_valuePrefix = ''; 
     74    $h_valueSuffix = ''; 
     75     
     76    if ($columnName != null) { 
     77      $params = $this->getParameterValue('list.fields.'.$columnName.'.params'); 
     78      $params = is_array($params) ? $params : sfToolkit::stringToArray($params); 
     79      $h_valuePrefix = isset($params['header_valuePrefix']) ? $params['header_valuePrefix'] : ''; 
     80      $h_valueSuffix = isset($params['header_valueSuffix']) ? $params['header_valueSuffix'] : ''; 
    4081    } 
    4182     
    42     //header values 
    43     $h_moduleName = $relatedClassName; 
    44     $h_tableName = $relatedClassName; 
    45     $h_pkn = $key_name; 
    46     $params = $this->getParameterValue('list.fields.'.$column->getName().'.params'); 
    47     $params = is_array($params) ? $params : sfToolkit::stringToArray($params); 
    48     $h_valuePrefix = isset($params['header_valuePrefix']) ? $params['header_valuePrefix'] : ''; 
    49     $h_valueSuffix = isset($params['header_valueSuffix']) ? $params['header_valueSuffix'] : ''; 
    50      
    51     // TODO: Prevent collapsing when clicking link (change CSS of header) 
    52     if ($column->isLink()) 
    53     { 
    54       //TODO remove hardcoded tag for underline, add option to set stylesheet-class, don't forget to remove the closing tag as well... 
    55       $headerText .= "<u><a href=\'".$controller->genUrl($h_moduleName."/edit?".$h_pkn."=")."/'+record.data['".$h_tableName.$tableDelimiter.$h_pkn."']+'\'>"; 
    56     } 
    57     $headerText .= $h_valuePrefix."'+record.data['".$h_tableName.$tableDelimiter.$relatedColumn."']+'".$h_valueSuffix; 
    58     if ($column->isLink()) 
    59     { 
    60       $headerText .= "</a></u>"; 
    61     } 
     83    $headerText = $h_valuePrefix."'+value+'".$h_valueSuffix; 
    6284  } 
    63 } 
    64 else // no grouping.display defined use grouping.field 
    65 { 
    66   $columnName = $this->getParameterValue('list.grouping.field', null); 
    67    
    68   $h_valuePrefix = ''; 
    69   $h_valueSuffix = ''; 
    70    
    71   if ($columnName != null) { 
    72     $params = $this->getParameterValue('list.fields.'.$columnName.'.params'); 
    73     $params = is_array($params) ? $params : sfToolkit::stringToArray($params); 
    74     $h_valuePrefix = isset($params['header_valuePrefix']) ? $params['header_valuePrefix'] : ''; 
    75     $h_valueSuffix = isset($params['header_valueSuffix']) ? $params['header_valueSuffix'] : ''; 
    76   } 
    77  
    78   $headerText = $h_valuePrefix."'+value+'".$h_valueSuffix; 
    79 } 
    8085?> 
     86      function renderHeader(value, p, record){ 
    8187          return '<?php echo $headerText ?>'; 
    8288      } 
     
    8793      // a column with a value which is a link (to edit) 
    8894      function renderLink(value, p, record){ 
    89           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 ?>']); 
     95          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.$pkn ?>']); 
    9096      } 
    9197 
     
    101107 
    102108      function formatNumber(value){ 
    103         return value.toFixed(2); 
     109        //return value.toFixed(2); <- TODO: this is broken 
     110        return value; 
    104111      } 
    105112 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_store.php

    r6192 r6212  
    1515 
    1616$tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 
    17 $prefix = sfInflector::underscore($this->getClassName())
     17$prefix = sfInflector::underscore($this->getClassName()).$tableDelimiter
    1818 
    19 //iterate through all columns of all class 
    20 $columns = $this->getColumnsGrouped('list.display'); 
    21 $pkn = $columns['pk']->getName(); 
     19$hs = $this->getParameterValue('list.hide', array()); 
    2220 
     21// iterate through all (related) columns of all classes 
     22$for = 'list.display'; 
     23$groupedColumns = $this->getColumnsGrouped($for); 
     24$columns = $this->getListColumns($groupedColumns, true); 
     25$pkn = $groupedColumns['pk']->getName(); 
     26 
     27// set group field 
    2328$group_field = $this->getParameterValue('list.grouping.field', null); 
    2429if ($group_field) 
    2530{ 
    26   if (false !== strpos($group_field, '/')) 
    27   { 
    28     if ($tableDelimiter != '/' ) 
    29     { 
    30       $group_field = str_replace('/', $tableDelimiter, $group_field); 
    31     } 
    32   } 
    33   else 
    34   { 
    35     $group_field = strtolower($this->getClassName()).$tableDelimiter.$group_field; 
    36   } 
     31  $group_field = $prefix.str_replace('/', $tableDelimiter, $group_field); 
    3732} 
    3833 
     
    5045        $i = 0; 
    5146        $listDisplay = array(); 
    52         $fieldsProperties = $this->getFieldsProperties('list'); 
     47//        $fieldsProperties = $this->getFieldsProperties('list'); 
    5348 
    54         foreach ($fieldsProperties['names'] as $name => $fieldName) 
     49        //foreach ($fieldsProperties['names'] as $name => $fieldName) 
     50        foreach ($columns as $columnName => $column)  
    5551        { 
     52          $fieldName = str_replace('/', $tableDelimiter, $columnName); 
     53           
    5654          $listDisplay[$i++] = array('name' => $fieldName, 
    5755                                     'mapping' => $fieldName, 
    58                                      'type' => extjs_convert_propel_type($fieldsProperties['types'][$name])); 
     56                                     'type' => extjs_convert_propel_type($column->getType()) ////$fieldsProperties['types'][$name]) 
     57                                     ); 
    5958        } 
    6059 
    61         $options = array('id' => $prefix.$tableDelimiter.$pkn, 
     60        $options = array('id' => $prefix.$pkn, 
    6261                         'root' => 'data', 
    6362                         'totalProperty' => 'totalCount'); 
     
    7069          $options['groupField'] = $group_field; 
    7170          $options['remoteGroup'] = 'true'; 
    72           $options['sortInfo'] = array('field' => $group_field, 
    73                                         'direction' => 'asc'); 
     71//TODO: Reenable          $options['sortInfo'] = array('field' => $group_field, 
     72//                                        'direction' => 'asc'); 
    7473        } 
    7574        $options['remoteSort'] = 'true'; 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_related_ajax_renderer.php

    r6192 r6212  
    8787<?php 
    8888      // iterate through all requested columns of current class 
    89       foreach ($relatedClasses['columns'] as $relatedColumn => $column): 
     89      foreach ($relatedClasses['columns'] as $group => $columnsFromGroup): //TODO $groupedColumns 
     90      foreach ($columnsFromGroup as $relatedColumn => $column): 
     91         
    9092        $columnName = $column->getName(); 
    9193   
     
    104106<?php endif; ?> 
    105107<?php endforeach; ?> 
     108<?php endforeach; ?> 
    106109        var r = new Record(record_data); 
    107110   
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_related_ajax_stores.php

    r6192 r6212  
    6363  if(array_key_exists('related', $columns)): 
    6464  foreach ($columns['related'] as $class => $relatedClasses): 
    65  
     65   
    6666    $pk = $relatedClasses['pk']->getName(); 
    6767    $listDisplay = array(array('name' => $class.$tableDelimiter.$pk, 'mapping' => $class.$tableDelimiter.$pk)); 
    6868 
    6969    // iterate through all requested columns of current class 
    70     foreach ($relatedClasses['columns'] as $relatedColumn => $column): 
     70    foreach ($relatedClasses['columns'] as $group => $columnsFromGroup): //TODO $groupedColumns 
     71    foreach ($columnsFromGroup as $relatedColumn => $column): 
    7172      $columnName = $column->getName(); 
    7273 
     
    8788    [?php endif; ?] 
    8889<?php endif; ?> 
     90<?php endforeach; ?> 
    8991<?php endforeach; ?> 
    9092<?php 
  • plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php

    r6192 r6212  
    263263   *  
    264264   * @param string[] $columnNames (Array of columnNames which should be added to the columnsGrouped) 
    265    * @param string $singularName  
     265   * @param string $peerName  
    266266   * @param array() $columnsGrouped (Array containing columns in a hierarchy) 
     267   * @return unknown 
    267268   */ 
    268269  protected function setupGroupedColumns($columnNames, $peerName = null, $columnsGrouped = array('pk' => array(), 'columns' => array(), 'related' => array()))  
     
    288289        if ($col->isPrimaryKey()) 
    289290        { 
    290           $columnsGrouped['pk'] = $this->getAdminColumnForField($col->getPhpName()); //TODO: $this->get... will probably will not work with recursion 
     291          $column = $this->getAdminColumnForField($col->getPhpName(), null, $peerName); 
     292          $columnsGrouped['pk'] = $column;  
    291293          break; // end foreach when found 
    292294        } 
     
    297299    foreach ($columnNames as $columnName) 
    298300    { 
     301      $group = 'NONE'; 
     302      if (false !== strpos($columnName, '\\')) 
     303      { 
     304        list($group, $columnName) = explode('\\', $columnName, 2); 
     305      } 
     306       
    299307      list($columnName, $flags) = $this->splitFlag($columnName); 
    300308       
    301       $column = $this->getAdminColumnForField($columnName, $flags); //TODO: $this->get... will probably will not work with recursion 
     309      $column = $this->getAdminColumnForField($columnName, $flags, $peerName); 
    302310       
    303311      // check if column is foreign  
     
    320328            $colFKName = $col->getPhpName(); 
    321329            $colFKUnderscore = sfInflector::underscore($colFKName); 
    322             $columnsGrouped['columns'][$colFKUnderscore] = $this->getAdminColumnForField($colFKName); //TODO: $this->get... will probably will not work with recursion 
     330            $adminColumn = $this->getAdminColumnForField($colFKName, null, $peerName); 
    323331            // add an option to which tells to hide this field (for iteration in grid and edit views) 
    324332            // this way it CAN be used for en/de-coding in json-data   
    325 //TODO            $columns['columns'][$colFKUnderscore]['visible'] = false; 
     333            $adminColumn->visible = false; 
     334            $columnsGrouped['columns'][$group][$colFKUnderscore] = $adminColumn;  
    326335             
    327336            break; // stop foreach 
     
    334343        { 
    335344          $related = $columnsGrouped['related'][$relatedTableName]; 
     345        } 
     346         
     347         
     348        //rebuild flags 
     349        $flagPrefix = ''; 
     350        foreach ($flags as $flag)  
     351        { 
     352          $flagPrefix .= $flag; 
    336353        } 
    337354         
     
    339356         * add foreign column recursively (so it can for instance handle productgroup/product/name and beyond) 
    340357         */ 
    341         $columnsGrouped['related'][$relatedTableName] = $this->setupGroupedColumns($relatedColumnName, $relatedPeerName, $related); 
     358        $columnsGrouped['related'][$relatedTableName] = $this->setupGroupedColumns($flagPrefix.$relatedColumnName, $relatedPeerName, $related); 
    342359 
    343360      } 
     
    348365        // the check should be done elsewhere (probably during json-encoding and columnmodel creation) or  
    349366        // else you cannot see a column multiple times in your grid (if someone happened to want that) 
    350         $columnsGrouped['columns'][$columnUnderscore] = $column
     367        $column->visible = true
    351368        //add an option to show this field should be visible 
    352 //TODO        $columns['columns'][$columnUnderscore]['visible'] = true
     369        $columnsGrouped['columns'][$group][$columnUnderscore] = $column
    353370      } 
    354371    } 
    355372     
    356373    return $columnsGrouped; 
     374  } 
     375 
     376  /** 
     377   * Return the columns and all related columns with their primary key grouped for a specific view. 
     378   * 
     379   * @param string $for      (which can be e.g. 'list.display', 'edit.display' or 'filters.filters' or multiple by providing an array: array('list.display', 'edit.display')) 
     380   * @param boolean $strict  disables automatic additions when set to true (like adding list.grouping.field and list.grouping.display, when asking for list.display) 
     381   * @return                 hierarchically arranged (recursively per related table) array of columns  
     382   */ 
     383  public function getColumnsGrouped($for = array('list.display'), $strict = false) 
     384  { 
     385    if (!is_array($for)) 
     386    { 
     387       $for = array($for); 
     388    } 
     389     
     390    $columnNames = array(); 
     391     
     392    if (!$strict)  
     393    { 
     394      // check if you want to display list, add groupes automatically 
     395      if (in_array('list.display', $for)) 
     396      { 
     397        // add grouping.field if set 
     398        $groupColumnName = $this->getParameterValue('list.grouping.field', null); 
     399        if ($groupColumnName) $columnNames[] = $groupColumnName; 
     400   
     401        // you don't have to add 'list.grouping.display' to the arguments of this method, it is taken into account automatically if you provide 'list.display'  
     402        if (!in_array('list.grouping.display',$for)) 
     403        { 
     404          $groupColumnDisplay = $this->getParameterValue('list.grouping.display', null); 
     405          if ($groupColumnDisplay) $for[] = 'list.grouping.display'; 
     406        } 
     407      } 
     408    } 
     409     
     410    for ($i = 0; $i < count($for); $i++) 
     411    { 
     412      // set group info, delimitor is \ 
     413      $fields = $this->getParameterValue($for[$i]); 
     414      if (!is_array($fields)) 
     415      { 
     416        $columnNames[] = $fields; 
     417        continue;  
     418      }       
     419      else 
     420      { 
     421        // categories? 
     422        if (isset($fields[0])) 
     423        { 
     424          // simulate a default one 
     425          $fields = array('NONE' => $fields); 
     426        } 
     427   
     428        if (!$fields) 
     429        { 
     430          $fields = array(); 
     431        } 
     432      }  
     433      
     434       
     435      // add group-name to field-name 
     436      $fieldsWithGroup = array(); 
     437      foreach ($fields as $group => $fieldNames) 
     438      { 
     439        foreach ($fieldNames as $fieldName) 
     440        { 
     441          $fieldsWithGroup[] = $group.'\\'.$fieldName; 
     442        }  
     443      } 
     444         
     445      $columnNames = array_merge($columnNames, $fieldsWithGroup); 
     446    } 
     447         
     448    $groupedColumns = $this->setupGroupedColumns($columnNames); 
     449    return $groupedColumns;  
     450  } 
     451 
     452  /** 
     453   * returns the hierarchically-grouped-columns-array as a single array, with relative-column-names as key 
     454   * PLEASE NOTE2: This will remove the group-hierarchy! (which can be used in edit.display...) 
     455   * PLEASE NOTE2: This removes double columns (so if you defined product/name twice in your list.display it will return only once)  
     456   * TODO? So maybe we should fix this by returing the column-name encapsulated (array($columnname, $group, $column), or we can have an other function for this... 
     457   * 
     458   * @param array() $groupedColumns   Hierarchically arranged array with columns   
     459   * @param boolean $returnInvisible  should invisible fields be returned  
     460   */ 
     461  public function getListColumns($groupedColumns, $returnInvisible = false, $prefix = "", $addPK = true) 
     462  { 
     463    $columnList = array(); 
     464     
     465    $prefix .= $groupedColumns['pk']->getTable()->getName().'/'; 
     466     
     467    if ($addPK && $returnInvisible) 
     468    { 
     469      $pkName = strtolower($groupedColumns['pk']->getPhpName()); 
     470      $columnList[$prefix.$pkName] = $groupedColumns['pk']; 
     471    } 
     472     
     473    // get All Columns of current Table 
     474    foreach($groupedColumns['columns'] as $group => $columnsFromGroup) 
     475    { 
     476      foreach ($columnsFromGroup as $columnName => $column) 
     477      { 
     478        if ($returnInvisible || $column->visible) 
     479        { 
     480          // This is the reason why fields will return only once: They have the same key.. 
     481          // another way to do this is by ecapsulating the name and the column in an extra array. 
     482          $columnList[$prefix.$columnName] = $column; 
     483        } 
     484      } 
     485    } 
     486    // Iterate through all its related tables recursively 
     487    foreach($groupedColumns['related'] as $relatedName => $relatedTable) 
     488    { 
     489      $relatedColumnList = $this->getListColumns($relatedTable, $returnInvisible, $prefix, false); 
     490      $columnList = array_merge($columnList, $relatedColumnList); 
     491    } 
     492     
     493    return $columnList; 
    357494  } 
    358495   
    359496  /** 
    360    * Return the columns and all related columns with their primary key grouped for a specific view. 
    361    * 
    362    * @param string $for (which can be e.g. 'list.display', 'edit.display' or 'filters.filters' or multiple by providing an array: array('list.display', 'edit.display')) 
    363    */ 
    364   // TODO maybe we again can make this somewhat nicer,  
    365   // contains much copy-paste to support grouping and group-display-array  
    366   // in same way as to process regular (display)columns 
    367   public function getColumnsGrouped($for = array('list.display')) 
    368   { 
    369     if (!is_array($for)) 
    370     { 
    371        $for = array($for); 
    372     } 
    373      
    374     $columnNames = array(); 
    375      
    376     // check if you want to display list, add groupes automatically 
    377     if (in_array('list.display',$for)) 
    378     { 
    379       // add grouping.field if set 
    380       $groupColumnName = $this->getParameterValue('list.grouping.field', null); 
    381       if ($groupColumnName) $columnNames[] = $groupColumnName; 
    382  
    383       // you don't have to add 'list.grouping.display' to the arguments of this method, it is taken into account automatically if you provide 'list.display'  
    384       if (!in_array('list.grouping.display',$for)) 
    385       { 
    386         $groupColumnDisplay = $this->getParameterValue('list.grouping.display', null); 
    387         if ($groupColumnDisplay) $for[] = 'list.grouping.display'; 
    388       } 
    389     } 
    390      
    391     for ($i = 0; $i < count($for); $i++) 
    392     { 
    393       $columnNames = array_merge($columnNames, $this->getParameterValue($for[$i])); 
    394     } 
    395      
    396     // TODO, place them in a group somehow, this is used in symfony: 
    397     /* 
    398       $fields = $this->getParameterValue($paramName); 
    399     if (is_array($fields)) 
    400     { 
    401       // categories? 
    402       if (isset($fields[0])) 
    403       { 
    404         // simulate a default one 
    405         $fields = array('NONE' => $fields); 
    406       } 
    407  
    408       if (!$fields) 
    409       { 
    410         return array(); 
    411       } 
    412       */     
    413      
    414     return $this->setupGroupedColumns($columnNames); 
    415      
    416     ///////////////////////////////////////////////////////// 
    417      
    418     $columns = array('pk' => array(), 'columns' => array(), 'related' => array()); 
    419  
    420     // define primary key 
    421     $columns['pk'] = $this->getPrimaryKeyAdminColumn(); 
    422  
    423     // grouping related, only counts for lists 
    424     if (in_array('list.display', $for)) 
    425     { 
    426       //add grouping.field (which does not necesarrily has to be defined in the display array 
    427       $groupColumnName = $this->getParameterValue('list.grouping.field', null); 
    428       if ($groupColumnName) 
    429       { 
    430         $display = $this->getParameterValue('list.display', array()); 
    431         if (!in_array($groupColumnName, $display)) 
    432         { 
    433  
    434           $column = $this->getAdminColumnForField($groupColumnName); 
    435  
    436           // check if foreign 
    437           if (false !== strpos($groupColumnName, '/')) 
    438           { 
    439             $columnPhpName = $column->getPhpName(); 
    440             list($peerName, $relatedColumn) = explode('::', $columnPhpName); 
    441             $relatedClassName = sfInflector::underscore($peerName); 
    442  
    443             if (!isset($columns['related'][$relatedClassName]['pk'])) 
    444             { 
    445               //tableMap = call_user_func(array($this....'Peer', 'getTableMap')); 
    446               // find column with relatedTableName and relatedColumnName 
    447               // nicest would be to add a method which can be called recusively, which contains a variable currentPeer (next to relatedPeer) 
    448                
    449               //set this as well, makes data complete, and can easily be ignored when creating json-data for example. 
    450               $tableMap = call_user_func(array($peerName.'Peer', 'getTableMap')); 
    451               foreach ($tableMap->getColumns() as $col) 
    452               { 
    453                 if (!isset($columns['related'][$relatedClassName]['pk']) && $col->isPrimaryKey()) 
    454                 { 
    455                   $columns['related'][$relatedClassName]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
    456                   break; 
    457                 } 
    458               } 
    459             } 
    460  
    461             $relatedColumnUnderscore = sfInflector::underscore($relatedColumn); 
    462             $columns['related'][$relatedClassName]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
    463  
    464           } 
    465           else // local column 
    466           { 
    467             $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
    468             $columns['columns'][$columnUnderscore] = $column; 
    469           } 
    470         } 
    471       } 
    472  
    473       //iterate through all columns of grouping.display fields 
    474       foreach ($this->getColumns('list.grouping.display') as $column) 
    475       { 
    476         if ($column->isPrimaryKey()) continue; 
    477  
    478         // check if foreign 
    479         if (false !== strpos($column->getName(), '/')) 
    480         { 
    481           $columnPhpName = $column->getPhpName(); 
    482           list($peerName, $relatedColumn) = explode('::', $columnPhpName,2); 
    483           $relatedClassName = sfInflector::underscore($peerName); 
    484  
    485           // TODO, now hardcoded adding a third level (foreigntable->foreigntable->field), this should be solved with recursion 
    486           if (false !== strpos($relatedColumn, '::')) 
    487           { 
    488             list($peerName2, $relatedColumn) = explode('::', $relatedColumn,2); 
    489             $relatedClassName2 = sfInflector::underscore($peerName2); 
    490  
    491             if (!isset($columns['related'][$relatedClassName]['pk'])) 
    492             { 
    493               $tableMap = call_user_func(array($peerName.'Peer', 'getTableMap')); 
    494  
    495               foreach ($tableMap->getColumns() as $col) 
    496               { 
    497                 if (!isset($columns['related'][$relatedClassName]['pk']) && $col->isPrimaryKey()) 
    498                 { 
    499                   $columns['related'][$relatedClassName]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
    500                   break; 
    501                 } 
    502               } 
    503             } 
    504  
    505             if (!isset($columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk'])) 
    506             { 
    507               $tableMap = call_user_func(array($peerName2.'Peer', 'getTableMap')); 
    508  
    509               foreach ($tableMap->getColumns() as $col) 
    510               { 
    511                 if (!isset($columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk']) && $col->isPrimaryKey()) 
    512                 { 
    513                   $columns['related'][$relatedClassName]['related'][$relatedClassName2]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
    514                   break; 
    515                 } 
    516               } 
    517             } 
    518  
    519             $relatedColumnUnderscore = sfInflector::underscore($relatedColumn); 
    520             $columns['related'][$relatedClassName]['related'][$relatedClassName2]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
    521           } 
    522           else 
    523           { 
    524             if (!isset($columns['related'][$relatedClassName]['pk'])) 
    525             { 
    526               $tableMap = call_user_func(array($peerName.'Peer', 'getTableMap')); 
    527  
    528               foreach ($tableMap->getColumns() as $col) 
    529               { 
    530                 if (!isset($columns['related'][$relatedClassName]['pk']) && $col->isPrimaryKey()) 
    531                 { 
    532                   $columns['related'][$relatedClassName]['pk'] = $this->getAdminColumnForField($col->getPhpName()); 
    533                   break; 
    534                 } 
    535               } 
    536             } 
    537  
    538             $relatedColumnUnderscore = sfInflector::underscore($relatedColumn); 
    539             $columns['related'][$relatedClassName]['columns'][$relatedColumnUnderscore] = $this->getAdminColumnForField($relatedColumn); 
    540           } 
    541         } 
    542         else // local column 
    543         { 
    544           $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
    545           $columns['columns'][$columnUnderscore] = $column; 
    546         } 
    547       } 
    548  
    549     } // end $for == 'list.display' 
    550