Development

Changeset 10079

You must first sign up to be able to contribute.

Changeset 10079

Show
Ignore:
Timestamp:
07/03/08 03:24:38 (2 years ago)
Author:
Leon.van.der.Ree
Message:

MAJOR REWRITE FOR GENERATOR CODE
rewritten lots of methods and removed some hacks
fixes for (foreign-key)PHP-names and custom-method-PHP-names
changed code for getI18NString-method
NEW CAPABILITY to handle multiple ForeignKeys? to a same table

Files:

Legend:

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

    r9848 r10079  
    22{ 
    33<?php 
    4   // TODO: hs not used properly... only set, never checked!!! 
     4  // TODO: hs not used properly... only set, never checked!!!(don't know it it is wanted though, since we can now use hides to hide fields which can be made visible from the column-header-menu) 
    55  $hs = $this->getParameterValue('edit.hide', array()); 
    66 
     
    4444  } 
    4545 
    46   // This 'fix' will require you to have your partials be non-foreign, which actually is bad. 
    47   if ( (!$column->isPartial()) && (!$column->isComponent()) ) 
    48   { 
    49     // 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) 
    50     // Due to this hack the column looses all info (like type, length, etc and keys (like isPartial, isLink, isComponent ) 
    51     $column = $this->getAdminColumnForField($columnName); 
    52   } 
     46  // unfortunately we cannot use the '/' to distinquish the class and the field, because the name is used as variable in _list_ajax_layout.php 
     47  echo "\"".str_replace('/', $this->tableDelimiter, $columnName)."\": \"[?php echo extjs_escape_json_string(".$this->getColumnListTag($column)."); ?]\""; 
    5348 
    54   // unfortunately we cannot use the '/' to distinquish the class and the field, because the name is used as variable in _list_ajax_layout.php 
    55   echo "\"".str_replace('/', $this->tableDelimiter, $columnName)."\": \"[?php echo extjs_escape_json_string(".$this->getColumnAjaxTag($column)."); ?]\""; 
    56  
    57   //don't add it twice 
     49  //don't add it twice, which isn't possible anyway since the uniqueColumns-method is used... 
    5850  $hs[] = $columnName; 
    5951 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_td_list.php

    r9848 r10079  
    22{ 
    33<?php 
    4 // TODO: hs not used properly, only set, never checked! 
     4// TODO: hs not used properly... only set, never checked!!!(don't know it it is wanted though, since we can now use hides to hide fields which can be made visible from the column-header-menu) 
    55$hs = $this->getParameterValue('list.hide', array()); 
    66 
     
    1515foreach ($columns as $columnName => $column) : 
    1616  if ($column->key == '*') continue; 
    17   $columnName = $column->key; 
    1817 
    19   $credentials = $this->getParameterValue('list.fields.'.$columnName.'.credentials'); 
     18  $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 
    2019?> 
    2120<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
     
    2928  } 
    3029 
    31   // This 'fix' will require you to have your partials be non-foreign, which actually is bad. 
    32   if ( (!$column->isPartial()) && (!$column->isComponent()) ) 
    33   { 
    34     // 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) 
    35     // Due to this hack the column looses all info (like type, length, etc and keys (like isPartial, isLink, isComponent ) 
    36     $column = $this->getAdminColumnForField($columnName); 
    37   } 
    38  
    3930  // unfortunately we cannot use the '/' to distinquish the class and the field, because the name is used as variable in _list_ajax_layout.php 
    40   echo "\"".str_replace('/', $this->tableDelimiter, $columnName)."\": \"[?php echo extjs_escape_json_string(".$this->getColumnAjaxTag($column)."); ?]\""; 
     31  echo "\"".str_replace('/', $this->tableDelimiter, $columnName)."\": \"[?php echo extjs_escape_json_string(".$this->getColumnListTag($column)."); ?]\""; 
    4132 
    4233  //don't add it twice 
  • plugins/sfExtjsThemePlugin/lib/sfAdminCustomGenerator.php

    r7331 r10079  
    1010 *   filter_header_map: {client_name: client_id} 
    1111 *   batch_actions: 
    12  *     _deleteSelected:  ~    
    13  *  
     12 *     _deleteSelected:  ~ 
     13 * 
    1414 */ 
    1515class sfAdminCustomGenerator extends sfExtjsPropelCrudGenerator 
     
    5454    elseif ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL ) 
    5555    { 
    56     if (!array_key_exists('helper', $params)) 
    57    
    58       $params = array_merge($params, array('helper' => 'format_number')); 
    59     }  
    60     } 
    61      
     56      if (!array_key_exists('helper', $params)) 
     57     
     58        $params = array_merge($params, array('helper' => 'format_number')); 
     59      } 
     60    } 
     61 
    6262    // user sets a specific tag to use 
    6363    if ($inputType = $this->getParameterValue('edit.fields.'.$column->getName().'.type')) 
     
    7676    return parent::getCrudColumnEditTag($column, $params); 
    7777  } 
    78    
    79   /**  
    80    * Returns HTML code for an action option in a select tag.  
    81    *  
    82    * @param string  The action name  
    83    * @param array   The parameters  
     78 
     79  /** 
     80   * Returns HTML code for an action option in a select tag. 
    8481   * 
    85    * @return string HTML code  
    86    */  
    87   public function getOptionToAction($actionName, $params)  
    88   {  
     82   * @param string  The action name 
     83   * @param array   The parameters 
     84   * 
     85   * @return string HTML code 
     86   */ 
     87  public function getOptionToAction($actionName, $params) 
     88  { 
    8989    $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); 
    90   
    91     // default values  
    92     if ($actionName[0] == '_')  
    93     {  
    94       $actionName = substr($actionName, 1);  
    95       if ($actionName == 'deleteSelected')  
    96       {  
    97         $params['name'] = 'Delete Selected';  
    98       }  
    99     }  
    100     $name = isset($params['name']) ? $params['name'] : $actionName;  
    101  
    102     $options['value'] = $actionName;  
    103  
    104     $phpOptions = var_export($options, true);  
    105        
    106     return '[?php echo content_tag(\'option\', __(\''.$name.'\')'.($options ? ', '.$phpOptions : '').') ?]';  
     90 
     91    // default values 
     92    if ($actionName[0] == '_') 
     93    { 
     94      $actionName = substr($actionName, 1); 
     95      if ($actionName == 'deleteSelected') 
     96      { 
     97        $params['name'] = 'Delete Selected'; 
     98      } 
     99    } 
     100    $name = isset($params['name']) ? $params['name'] : $actionName; 
     101 
     102    $options['value'] = $actionName; 
     103 
     104    $phpOptions = var_export($options, true); 
     105 
     106    return '[?php echo content_tag(\'option\', __(\''.$name.'\')'.($options ? ', '.$phpOptions : '').') ?]'; 
    107107  } 
    108108 
     
    115115    return $this->getColumnHelper(parent::getColumnListTag($column, $params), $column, $params); 
    116116  } 
    117    
     117 
    118118  /** 
    119119   * Checks and adds helper for column values 
     
    135135        $helperparams = ', array('.$valuepairs.')'; 
    136136      } 
    137          
     137 
    138138      return $helper.'('.$value.$helperparams.')'; 
    139139    } 
     
    143143    } 
    144144  } 
    145    
     145 
    146146 
    147147  /** 
     
    152152  public function getColumnFilterColumn($column) 
    153153  { 
    154   // Set filtercolumn default to column name 
     154    // Set filtercolumn default to column name 
    155155    $filtercolumn  = $column->getName(); 
    156156 
     
    162162    } 
    163163 
    164     // Check if filter is set for column  
     164    // Check if filter is set for column 
    165165    if ($filters = $this->getParameterValue('list.filters') and in_array($filtercolumn, $filters)!=false) 
    166166    { 
    167167      // Return the connected admin field 
    168168      list($field, $flags) = $this->splitFlag($filtercolumn); 
    169       return $this->getAdminColumnForField($field, $flags); 
    170     }  
    171   } 
    172    
     169      return $this->getAdminColumnForField($field, null, $flags); //OBSOLETE ARGUMENNTS 
     170    } 
     171  } 
     172 
    173173  /** 
    174174   * Implements custom filtertypes 
     
    180180    $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); 
    181181    $params      = $user_params ? array_merge($params, $user_params) : $params; 
    182      
     182 
    183183    // Check for / in field name 
    184184    if (strpos($column->getName(),'::')!==false) 
    185185    { 
    186     //die($column->getName()); 
     186      //die($column->getName()); 
    187187    } 
    188188 
    189189    // user sets a specific tag to use 
    190     if ($inputType = $this->getParameterValue('list.fields.'.$column->getName().'.filtertype') and  
     190    if ($inputType = $this->getParameterValue('list.fields.'.$column->getName().'.filtertype') and 
    191191      !$column->isComponent() and 
    192192      !$column->isPartial() 
     
    196196      $unquotedName = 'filters['.$column->getName().']'; 
    197197      $name = "'$unquotedName'"; 
    198        
     198 
    199199      $size = ($column->getSize() < 15 ? $column->getSize() : 15); 
    200200      $params = $this->getObjectTagParams($params, array('size' => $size)); 
     
    203203    } 
    204204    // many-to-many, indicated by the presence of param through_class 
    205     else if (array_key_exists('through_class', $params))  
     205    else if (array_key_exists('through_class', $params)) 
    206206    { 
    207207      $options1 = "_get_options_from_objects(sfPropelManyToMany::getAllObjects(new " . $this->getClassName(). ", '" . $params['through_class'] . "', NULL, '" . ($params['peer_method'] ? $params['peer_method'] : 'doSelect') . "')"; 
     
    220220   * @param object column $column 
    221221   * @param boolean $developed (optional) writes out function with current class 
    222    * @param string $prefix  
     222   * @param string $prefix 
    223223   */ 
    224224  function getColumnGetter($column, $developed = false, $prefix = '') 
     
    235235    } 
    236236  } 
    237    
     237 
    238238  /** 
    239239   * Build function to set column value 
    240240   * @param object column $column 
    241241   * @param boolean $developed (optional) writes out function with current class 
    242    * @param string $prefix  
     242   * @param string $prefix 
    243243   */ 
    244244  function getColumnSetter($column, $developed = false, $prefix = '') 
     
    255255    } 
    256256  } 
    257      
     257 
    258258  function getColumnConstant($column) 
    259259  { 
     
    266266      if ($nameParts[$namePartsCount]=='') 
    267267        sfContext::getInstance()->getLogger()->error('Can not use __toString method with '.$name.' In getColumnConstant'); 
    268        
     268 
    269269      return $nameParts[$namePartsCount-1].'Peer::'.strtoupper($nameParts[$namePartsCount]); 
    270270    } 
    271271    else 
    272272    { 
    273     return $this->getPeerClassName().'::'.strtoupper($column->getName()); 
     273      return $this->getPeerClassName().'::'.strtoupper($column->getName()); 
    274274    } 
    275275  } 
     
    281281   * If fieldname is empty after the /, the __toString method is called. 
    282282   * Produces a string like: 
    283    * (($modelvalue=$singularname->getmodelpeer())?(($modelvalue = $modelvalue->getmodelpeer())?$modelvalue->getField():''):'')  
     283   * (($modelvalue=$singularname->getmodelpeer())?(($modelvalue = $modelvalue->getmodelpeer())?$modelvalue->getField():''):'') 
    284284   * @param string $phpName column name to process 
    285285   * @param string $method (optional) function prefix 
    286286   */ 
    287   protected function processColumnName($PhpName, $prefix, $method='get', $iterated = false) 
     287  protected function processColumnName($PhpName, $prefix='', $method='get', $iterated = false) 
    288288  { 
    289289    // Detect if there is / or :: indicating foreign model peer class 
     
    292292      list($peer, $PhpName) = explode('::', $PhpName,2); 
    293293      $PhpNameExploded = explode('::', $PhpName); 
    294        
    295           // _ means use __toString method of model peer class  
     294 
     295          // _ means use __toString method of model peer class 
    296296      if ($PhpName == '') 
    297297      { 
     
    322322    } 
    323323  } 
    324    
     324 
    325325// For debugging purposes only 
    326326//  public function getColumns($paramName, $category = 'NONE') 
  • plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php

    r10055 r10079  
    6969    // find %%xx%% strings 
    7070    preg_match_all('/%%([^%]+)%%/', $value, $matches, PREG_PATTERN_ORDER); 
    71     $this->params['tmp']['display'] = array(); 
     71    $fields = array(); 
    7272    foreach ($matches[1] as $name) 
    7373    { 
    74       $this->params['tmp']['display'][] = $name; 
     74      $fields[] = $name; 
    7575    } 
    7676 
    7777    $i = 0; 
    7878    $vars = array(); 
    79     foreach ($this->getColumns('tmp.display') as $column) 
    80     { 
     79 
     80    foreach ($fields as $field) 
     81    { 
     82      $column = $this->getAdminColumnForField($field); 
     83      $column->key = $field; 
     84 
    8185      if ($column->isLink()) 
    8286      { 
     
    517521 
    518522    //check if primary key has been defined, else set it 
     523    //WE DON'T HANDLE MULTIPLE PRIMARY KEYS! 
    519524    if (!isset($groupedColumns['pk']) || ($groupedColumns['pk'] == array()) || ($groupedColumns['pk'] == null)) 
    520525    { 
     
    535540    foreach ($columnNames as $columnName) 
    536541    { 
     542      // get its group (for fieldsets) 
    537543      $group = 'NONE'; 
    538544      if (false !== strpos($columnName, '\\')) 
     
    541547      } 
    542548 
     549      //get flags (should make no difference if you placed flags in front, or in between (for foreign-fields) 
    543550      list($columnName, $flags) = $this->splitFlag($columnName); 
    544551 
    545       $column = $this->getAdminColumnForField($columnName, $flags, $peerName); 
    546  
    547       // check if column is foreign 
     552      // if column is foreign 
    548553      if (false !== strpos($columnName, '/')) 
    549554      { 
    550         $columnPhpName = $column->getPhpName(); 
    551         list($relatedTablePhpName, $relatedColumnPhpName) = explode('::', $columnPhpName, 2); 
    552         list($foreignKey, $relatedColumnName) = explode('/', $columnName, 2); 
    553  
    554         $relatedPeerName = $relatedTablePhpName.'Peer'; 
     555        list($foreignKey,   $relatedColumnName) = explode('/', $columnName, 2); 
    555556 
    556557        // Add invisible foreign-key 
    557         // there is no check added here to see if the hidden column is already added to this columns-hierarchy, 
    558         $column = $this->getAdminColumnForField($foreignKey, $flags, $peerName); 
    559         $column->visible = false; 
     558        $fkColumn = $this->getAdminColumnForField($foreignKey, $peerName); //flags are useless, it a foreign-key! 
     559 
     560        // get relatedPeerName for propagation 
     561        $relatedTableName = $fkColumn->getColumn()->getRelatedTableName(); 
     562        $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 
     563        $relatedPeerName = $relatedTable->getPhpName().'Peer'; 
     564 
    560565        //add an option to show this field should be visible 
    561         $column->key = $foreignKey; 
    562         $column->index = $i; //foreign key have the same index! 
    563         $groupedColumns['columns'][$group][] = $column; 
     566        $fkColumn->visible = false; 
     567        $fkColumn->key = $foreignKey; 
     568        $fkColumn->index = $i; //foreign key have the same index! 
     569        $groupedColumns['columns'][$group][] = $fkColumn; // Add foreign-key-Column to columns //TODO: maybe add them under their own key (fks or something, which would also remove the need for the property (in)visible) 
    564570 
    565571        // check if related groupedColumn hierarchy is already defined, if not define it. 
     
    570576        } 
    571577 
    572         //rebuild flags //TODO: don't know if this is desired! if so, why? 
     578        //rebuild flags, so they can be propogated to end-field 
    573579        $flagPrefix = ''; 
    574580        foreach ($flags as $flag) 
     
    579585        /* 
    580586         * add foreign column recursively (so it can for instance handle productgroup/product/name and beyond) 
     587         * 
     588         * provide: 
     589         *  - stripped fieldname (propogated group and flags) 
     590         *  - relative peername 
     591         *  - stepped in hierarchy (related) 
     592         *  - increased counter for display-order 
    581593         */ 
    582594        $groupedColumns['related'][$foreignKey] = $this->setupGroupedColumns($group.'\\'.$flagPrefix.$relatedColumnName, $relatedPeerName, $related, $i++);  //$relatedTableName 
    583595 
    584596      } 
    585       else // local columns (which should be visible (so E.G. list.display, edit.display or list.filters or [list.display and list.group.display])) 
    586       { 
    587         $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
    588         // there is no check added here to see if the column is already added to this columns-hierarchy, 
    589         // the check should be done elsewhere (probably during json-encoding and columnmodel creation) or 
     597      // local columns (which should be visible (so E.G. list.display, edit.display or list.filters or [list.display and list.group.display])) 
     598      else 
     599      { 
     600        // this gets/creates the local column to be stored in the hierarchy (containing info like flags, PhpName, and the ColumnMap 
     601        $column = $this->getAdminColumnForField($columnName, $peerName, $flags); 
     602 
     603        // add an option to show this field should be visible 
     604        $column->visible = true; 
     605        //set the key, used to be able to retreive its relative location from within the hierarchy, when retreiving (based on from where it is retreived, with recursion) 
     606//        $columnUnderscore = sfInflector::underscore($column->getPhpName()); 
     607        $column->key = $columnName; //$columnUnderscore; // this should probably be the same as $columnName 
     608        //set the display-sorting-index 
     609        $column->index = $i++; 
     610        // columns can be added multiple times to the hierarchy 
     611        // filtering double fields should be done elsewhere (probably during json-encoding and columnmodel creation) or 
    590612        // else you cannot see a column multiple times in your grid (if someone happened to want that) 
    591         $column->visible = true; 
    592         //add an option to show this field should be visible 
    593         $column->key = $columnUnderscore; 
    594         $column->index = $i++; 
    595613        $groupedColumns['columns'][$group][] = $column; 
    596614      } 
    597615 
    598     } 
     616    } // process next column 
    599617 
    600618    return $groupedColumns; 
     
    802820      $column = $groupedColumns['pk']; 
    803821      $column->key = $prefix.$pkName; 
     822 
     823      $phpName = $this->getPhpNameForField($column->key); 
     824      $column->setPhpName($phpName); 
     825 
    804826      $columnList[] = $column; 
    805827    } 
     
    815837      foreach ($columnsFromGroup as $columnName => $column) 
    816838      { 
    817         // copy by value 
    818         $newColumn = clone($column); 
    819         // rename key-name 
    820         $columnName = $newColumn->key; 
    821  
    822         if ($returnInvisible || $newColumn->visible) 
    823         { 
    824           $newColumn->key = $prefix.$columnName; 
     839        if ($returnInvisible || $column->visible) 
     840        { 
     841          // copy by value 
     842          $newColumn = clone($column); 
     843          // rename key-name 
     844          $newColumn->key = $prefix.$newColumn->key; 
     845 
     846          $phpName = $this->getPhpNameForField($newColumn->key); 
     847          $newColumn->setPhpName($phpName); 
     848 
    825849          $columnList[] = $newColumn; 
    826850        } 
     
    957981   * @return string HTML code 
    958982   */ 
    959   public function getColumnAjaxTag($column, $params = array(), $for = 'list') 
    960   { 
     983//  public function getColumnAjaxTag($column) //, $params = array(), $for = 'list' 
     984//  { 
     985//    $type = $column->getCreoleType(); 
     986// 
     987//    if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP) 
     988//    { 
     989//      $columnGetter = $this->getColumnGetter($column, true); 
     990// 
     991//      $format = isset($params['date_format']) ? $params['date_format'] : 'MM/dd/yyyy'; 
     992//      return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''"; 
     993//    } 
     994//    else if ($type == CreoleTypes::BOOLEAN) 
     995//    { 
     996//      $columnGetter = $this->getColumnGetter($column, true); 
     997// 
     998//      return $for == 'edit' ? "$columnGetter ? 'true' : 'false'" : "$columnGetter ? 1 : 0"; 
     999//    } 
     1000// 
     1001//    return $this->getColumnListTag($column, $params); 
     1002//  } 
     1003 
     1004  /** 
     1005   * Implements helpers for lists 
     1006   * Usage: specify helper (and helper_params) in field definition 
     1007   */ 
     1008//  public function getColumnListTag($column, $params = array()) 
     1009//  { 
     1010//    $result = parent::getColumnListTag($column, $params); 
     1011//    return $result; 
     1012//  } 
     1013 
     1014  /** 
     1015   * Returns HTML code for a column in list mode. 
     1016   * 
     1017   * @param string  The column name 
     1018   * @param array   The parameters 
     1019   * 
     1020   * @return string HTML code 
     1021   */ 
     1022  public function getColumnListTag($column, $params = array()) 
     1023  { 
     1024    $user_params = $this->getParameterValue('list.fields.'.$column->key.'.params'); 
     1025    $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); 
     1026    $params      = $user_params ? array_merge($params, $user_params) : $params; 
     1027 
    9611028    $type = $column->getCreoleType(); 
    9621029 
    963     if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP) 
    964     { 
    965       $columnGetter = $this->getColumnGetter($column, true); 
    966  
    967       $format = isset($params['date_format']) ? $params['date_format'] : 'MM/dd/yyyy'; 
    968       return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''"; 
    969     } 
    970     else if ($type == CreoleTypes::BOOLEAN) 
    971     { 
    972       $columnGetter = $this->getColumnGetter($column, true); 
    973  
    974       return $for == 'edit' ? "$columnGetter ? 'true' : 'false'" : "$columnGetter ? 1 : 0"; 
    975     } 
    976  
    977     return parent::getColumnListTag($column, $params); 
     1030    $columnGetter = $this->getColumnGetter($column, true); 
     1031 
     1032    if ($column->isComponent()) 
     1033    { 
     1034      return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; 
     1035    } 
     1036    else if ($column->isPartial()) 
     1037    { 
     1038      return "get_partial('".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))"; 
     1039    } 
     1040    else if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP) 
     1041    { 
     1042      $format = isset($params['date_format']) ? $params['date_format'] : ($type == CreoleTypes::DATE ? 'D' : 'f'); 
     1043      return "($columnGetter !== null && $columnGetter !== '') ?  format_date($columnGetter, \"$format\") : ''"; 
     1044    } 
     1045    elseif ($type == CreoleTypes::BOOLEAN) 
     1046    { 
     1047      return "$columnGetter ? image_tag(sfConfig::get('sf_admin_web_dir').'/images/tick.png') : '&nbsp;'"; 
     1048    } 
     1049    else 
     1050    { 
     1051      return "$columnGetter"; 
     1052    } 
    9781053  } 
    9791054 
     
    13811456  } 
    13821457 
    1383   /** This method overwrites the original method so it can handle foreign-keys in the fieldname 
    1384    */ 
    1385   public function getAdminColumnForField($field, $flags = array(), $peerName = null) 
    1386   { 
    1387  
    1388     //re-disabled ;) 
    1389     //$phpName = sfInflector::camelize($field); 
    1390  
    1391     //Re-enabled 
     1458  public function getPhpNameForField($field, $peerName = null, $flags = array()) 
     1459  { 
    13921460    $fields = explode('/', $field); 
    13931461 
     
    13971465      $lastPeerClassName = $peerName; 
    13981466    } 
     1467 
    13991468    $phpName = ""; 
    1400  
    14011469    if ((!in_array('_', $flags)) && ($field!='*'))// no-partial or row expander 
    14021470    { 
     
    14211489          } 
    14221490 
     1491          // if column not found, it is a partial or a customMethod 
    14231492          if (!$found) 
    14241493          { 
    1425 //            throw new sfConfigurationException(sprintf('Illegal field-name provided, you should provide:<br> [foreignkey-field(s)/]fieldname<br>&nbsp;<br>E.G. city_id/country_id/name<br>to get the country-name for the city of this module (if this module contains a foreign-key city_id to a city table<br>&nbsp<br>Stopped while parcing: "<i>%s</i>" of "%s"', $fields[$i], $field)); 
    14261494            // not a "real" column, but we generate one here 
    14271495            $flagPrefix = ''; 
     
    14301498              $flagPrefix .= $flag; 
    14311499            } 
    1432             $name = strtoupper($flagPrefix.$field); 
     1500            $name = strtoupper($flagPrefix.$currentField); 
    14331501 
    14341502            $tableMap = call_user_func(array($lastPeerClassName, 'getTableMap')); 
    14351503            $column = new ColumnMap($name, $tableMap); 
    1436             //TODO:  this is a hack, we hit this too many times in the loop, should be moved out of the loop 
    1437             $methodName = (isset($fields[1])) ? $fields[1] : $fields[0]; 
    1438             $column->setPhpName(sfInflector::camelize($methodName)); 
    1439             //TODO SET A FLAG TELLING THIS IS A CUSTOM METHOD/PARTIAL 
     1504//            $methodName = (isset($fields[1])) ? $fields[1] : $fields[0]; // This is nonsense (, by the way what I did before as well, it should be current-field) 
     1505            $column->setPhpName(sfInflector::camelize(sfInflector::camelize($currentField))); 
     1506            //TODO set a flag this is a partial/custom method, WHY? 
    14401507          } 
    14411508        } 
    14421509 
     1510        // if not last field, return table getter 
    14431511        if ($i != count($fields) - 1) 
    14441512        { 
     
    14461514          $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 
    14471515 
    1448           $phpName .= $relatedTable->getPhpName().'::'; 
     1516          $phpName .= $relatedTable->getPhpName(); 
     1517 
     1518          // if this column is not the only column refering to this foreing table add text 
     1519          if ($this->isMultipleFK($column)) { 
     1520            $phpName .= 'RelatedBy'.$column->getPhpName(); 
     1521          } 
     1522 
     1523          $phpName .= '::'; 
    14491524 
    14501525          $lastPeerClassName = $relatedTable->getPhpName().'Peer'; 
    14511526        } 
     1527        //if last field return column getter 
    14521528        else 
    14531529        { 
     
    14611537    } 
    14621538 
     1539    return $phpName; 
     1540  } 
     1541 
     1542 
     1543  /** This method overwrites the original method so it can handle foreign-field by providing a peerName 
     1544   */ 
     1545  public function getAdminColumnForField($field, $peerName = null, $flags = array()) 
     1546  { 
     1547    $fields = explode('/', $field); 
     1548 
     1549    $lastPeerClassName = $this->getPeerClassName(); 
     1550    if ($peerName) 
     1551    { 
     1552      $lastPeerClassName = $peerName; 
     1553    } 
     1554 
     1555    $phpName = ""; 
     1556    if ((!in_array('_', $flags)) && ($field!='*'))// no-partial or row expander 
     1557    { 
     1558      //get PHP-name for (all) foreign tables (from foreign-key) 
     1559      for ($i = 0; $i < count($fields); $i++) 
     1560      { 
     1561        $currentField = $fields[$i]; 
     1562        list($currentField, $currentFlags) = $this->splitFlag($currentField); 
     1563 
     1564        if (!in_array('_', $currentFlags)) // no-partial 
     1565        { 
     1566          $tableMap = call_user_func(array($lastPeerClassName, 'getTableMap')); 
     1567          // search the matching column for this key 
     1568          $found = false; 
     1569          foreach ($tableMap->getColumns() as $column) 
     1570          { 
     1571            if ($column->getColumnName() == strtoupper($currentField)) // TODO not tested if strtoupper is always correct, maybe both strtoupper... 
     1572            { 
     1573              $found = true; 
     1574              break; 
     1575            } 
     1576          } 
     1577 
     1578          // if column not found, it is a partial or a customMethod 
     1579          if (!$found) 
     1580          { 
     1581            // not a "real" column, but we generate one here 
     1582            $name = strtoupper($currentField); 
     1583 
     1584            $tableMap = call_user_func(array($lastPeerClassName, 'getTableMap')); 
     1585            $column = new ColumnMap($name, $tableMap); 
     1586          } 
     1587        } 
     1588 
     1589        // if not last field, return table getter 
     1590        if ($i != count($fields) - 1) 
     1591        { 
     1592          $relatedTableName = $column->getRelatedTableName(); 
     1593          $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 
     1594 
     1595          $lastPeerClassName = $relatedTable->getPhpName().'Peer'; 
     1596        } 
     1597      } 
     1598    } 
     1599 
     1600    $phpName = $this->getPhpNameForField($field, $peerName, $flags); 
     1601 
    14631602    return new sfExtjsAdminColumn($phpName, $this->getColumnForPhpName($phpName, $lastPeerClassName, $field, $flags), $flags); 
    14641603  } 
     
    14681607   * returns a column phpName or null if none was found 
    14691608   */ 
    1470   public function getColumnForPhpName($phpName, $peerName = null, $field = '', $flags = array()) 
     1609  public function getColumnForPhpName($fullPhpName, $peerName = null, $field = '', $flags = array()) 
    14711610  { 
    14721611    //strip 
    1473     $fields = explode('::', $phpName); 
    1474     $phpName = $fields[count($fields) - 1]; 
     1612    $phpNames = explode('::', $fullPhpName); 
     1613    $phpName = $phpNames[count($phpNames) - 1]; 
    14751614 
    14761615    if ($peerName == null) 
    14771616    { 
    14781617      $peerName = $this->getPeerClassName(); 
    1479     } 
    1480  
    1481     if (count($fields)>1) 
    1482     { 
    1483       $className = $fields[count($fields) - 2]
    1484       $peerName = $className."Peer"; 
     1618 
     1619      if (count($phpNames)>1) 
     1620      { 
     1621        $className = $phpNames[count($phpNames) - 2]; 
     1622        $peerName = $className."Peer"
     1623      } 
    14851624    } 
    14861625 
     
    15871726  } 
    15881727 
     1728  /** 
     1729   * Determine if this column is a foreign key that refers to the 
     1730   * same table as another foreign key column in this table. 
     1731   */ 
     1732  // METHOD below should be used FROM COLUMN.PHP (/symfony/lib/vendor/propel-generator/classes/propel/engine/database/model/Column.php) 
     1733  public function isMultipleFK($column) 
     1734  { 
     1735    // test if this column is a foreign-key 
     1736    if ($relatedTableName = $column->getRelatedTableName()) { 
     1737 
     1738      //this columnName 
     1739      $columnName = $column->getColumnName(); 
     1740 
     1741      $parentTable = $column->getTable(); 
     1742      $otherColumns = $parentTable->getColumns(); 
     1743 
     1744      // TODO this should be a method of the TableMap 
     1745      foreach ($otherColumns as $otherColumn) { 
     1746        if ($otherColumn == $column) continue; // I said otherColumns, not this column 
     1747 
     1748        // test if this column is the only FK to its relatedTable 
     1749        if ($otherColumn->getRelatedTableName() == $relatedTableName) return true; 
     1750      } 
     1751    } 
     1752 
     1753    // No multiple foreign keys. 
     1754    return false; 
     1755  } 
    15891756} 
    15901757 
     
    16201787  } 
    16211788 
     1789  /** 
     1790   * return the internal column 
     1791   * 
     1792   * @return ColumnMap 
     1793   */ 
     1794  public function getColumn() 
     1795  { 
     1796    return $this->column; 
     1797  } 
     1798 
     1799  /** 
     1800   * Sets(/changes) the phpName after construction 
     1801   * 
     1802   * @param string $phpName 
     1803   */ 
     1804  public function setPhpName($phpName) 
     1805  { 
     1806    $this->phpName = $phpName; 
     1807  } 
    16221808 
    16231809} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.