Changeset 10079
- Timestamp:
- 07/03/08 03:24:38 (2 years ago)
- Files:
-
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_td_edit.php (modified) (2 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_td_list.php (modified) (3 diffs)
- plugins/sfExtjsThemePlugin/lib/sfAdminCustomGenerator.php (modified) (18 diffs)
- plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_td_edit.php
r9848 r10079 2 2 { 3 3 <?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) 5 5 $hs = $this->getParameterValue('edit.hide', array()); 6 6 … … 44 44 } 45 45 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)."); ?]\""; 53 48 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... 58 50 $hs[] = $columnName; 59 51 plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_td_list.php
r9848 r10079 2 2 { 3 3 <?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) 5 5 $hs = $this->getParameterValue('list.hide', array()); 6 6 … … 15 15 foreach ($columns as $columnName => $column) : 16 16 if ($column->key == '*') continue; 17 $columnName = $column->key;18 17 19 $credentials = $this->getParameterValue('list.fields.'.$column Name.'.credentials');18 $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 20 19 ?> 21 20 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> … … 29 28 } 30 29 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 39 30 // 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->getColumn AjaxTag($column)."); ?]\"";31 echo "\"".str_replace('/', $this->tableDelimiter, $columnName)."\": \"[?php echo extjs_escape_json_string(".$this->getColumnListTag($column)."); ?]\""; 41 32 42 33 //don't add it twice plugins/sfExtjsThemePlugin/lib/sfAdminCustomGenerator.php
r7331 r10079 10 10 * filter_header_map: {client_name: client_id} 11 11 * batch_actions: 12 * _deleteSelected: ~ 13 * 12 * _deleteSelected: ~ 13 * 14 14 */ 15 15 class sfAdminCustomGenerator extends sfExtjsPropelCrudGenerator … … 54 54 elseif ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL ) 55 55 { 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 62 62 // user sets a specific tag to use 63 63 if ($inputType = $this->getParameterValue('edit.fields.'.$column->getName().'.type')) … … 76 76 return parent::getCrudColumnEditTag($column, $params); 77 77 } 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. 84 81 * 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 { 89 89 $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 : '').') ?]'; 107 107 } 108 108 … … 115 115 return $this->getColumnHelper(parent::getColumnListTag($column, $params), $column, $params); 116 116 } 117 117 118 118 /** 119 119 * Checks and adds helper for column values … … 135 135 $helperparams = ', array('.$valuepairs.')'; 136 136 } 137 137 138 138 return $helper.'('.$value.$helperparams.')'; 139 139 } … … 143 143 } 144 144 } 145 145 146 146 147 147 /** … … 152 152 public function getColumnFilterColumn($column) 153 153 { 154 // Set filtercolumn default to column name154 // Set filtercolumn default to column name 155 155 $filtercolumn = $column->getName(); 156 156 … … 162 162 } 163 163 164 // Check if filter is set for column 164 // Check if filter is set for column 165 165 if ($filters = $this->getParameterValue('list.filters') and in_array($filtercolumn, $filters)!=false) 166 166 { 167 167 // Return the connected admin field 168 168 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 173 173 /** 174 174 * Implements custom filtertypes … … 180 180 $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); 181 181 $params = $user_params ? array_merge($params, $user_params) : $params; 182 182 183 183 // Check for / in field name 184 184 if (strpos($column->getName(),'::')!==false) 185 185 { 186 //die($column->getName());186 //die($column->getName()); 187 187 } 188 188 189 189 // 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 191 191 !$column->isComponent() and 192 192 !$column->isPartial() … … 196 196 $unquotedName = 'filters['.$column->getName().']'; 197 197 $name = "'$unquotedName'"; 198 198 199 199 $size = ($column->getSize() < 15 ? $column->getSize() : 15); 200 200 $params = $this->getObjectTagParams($params, array('size' => $size)); … … 203 203 } 204 204 // 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)) 206 206 { 207 207 $options1 = "_get_options_from_objects(sfPropelManyToMany::getAllObjects(new " . $this->getClassName(). ", '" . $params['through_class'] . "', NULL, '" . ($params['peer_method'] ? $params['peer_method'] : 'doSelect') . "')"; … … 220 220 * @param object column $column 221 221 * @param boolean $developed (optional) writes out function with current class 222 * @param string $prefix 222 * @param string $prefix 223 223 */ 224 224 function getColumnGetter($column, $developed = false, $prefix = '') … … 235 235 } 236 236 } 237 237 238 238 /** 239 239 * Build function to set column value 240 240 * @param object column $column 241 241 * @param boolean $developed (optional) writes out function with current class 242 * @param string $prefix 242 * @param string $prefix 243 243 */ 244 244 function getColumnSetter($column, $developed = false, $prefix = '') … … 255 255 } 256 256 } 257 257 258 258 function getColumnConstant($column) 259 259 { … … 266 266 if ($nameParts[$namePartsCount]=='') 267 267 sfContext::getInstance()->getLogger()->error('Can not use __toString method with '.$name.' In getColumnConstant'); 268 268 269 269 return $nameParts[$namePartsCount-1].'Peer::'.strtoupper($nameParts[$namePartsCount]); 270 270 } 271 271 else 272 272 { 273 return $this->getPeerClassName().'::'.strtoupper($column->getName());273 return $this->getPeerClassName().'::'.strtoupper($column->getName()); 274 274 } 275 275 } … … 281 281 * If fieldname is empty after the /, the __toString method is called. 282 282 * Produces a string like: 283 * (($modelvalue=$singularname->getmodelpeer())?(($modelvalue = $modelvalue->getmodelpeer())?$modelvalue->getField():''):'') 283 * (($modelvalue=$singularname->getmodelpeer())?(($modelvalue = $modelvalue->getmodelpeer())?$modelvalue->getField():''):'') 284 284 * @param string $phpName column name to process 285 285 * @param string $method (optional) function prefix 286 286 */ 287 protected function processColumnName($PhpName, $prefix , $method='get', $iterated = false)287 protected function processColumnName($PhpName, $prefix='', $method='get', $iterated = false) 288 288 { 289 289 // Detect if there is / or :: indicating foreign model peer class … … 292 292 list($peer, $PhpName) = explode('::', $PhpName,2); 293 293 $PhpNameExploded = explode('::', $PhpName); 294 295 // _ means use __toString method of model peer class 294 295 // _ means use __toString method of model peer class 296 296 if ($PhpName == '') 297 297 { … … 322 322 } 323 323 } 324 324 325 325 // For debugging purposes only 326 326 // public function getColumns($paramName, $category = 'NONE') plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php
r10055 r10079 69 69 // find %%xx%% strings 70 70 preg_match_all('/%%([^%]+)%%/', $value, $matches, PREG_PATTERN_ORDER); 71 $ this->params['tmp']['display']= array();71 $fields = array(); 72 72 foreach ($matches[1] as $name) 73 73 { 74 $ this->params['tmp']['display'][] = $name;74 $fields[] = $name; 75 75 } 76 76 77 77 $i = 0; 78 78 $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 81 85 if ($column->isLink()) 82 86 { … … 517 521 518 522 //check if primary key has been defined, else set it 523 //WE DON'T HANDLE MULTIPLE PRIMARY KEYS! 519 524 if (!isset($groupedColumns['pk']) || ($groupedColumns['pk'] == array()) || ($groupedColumns['pk'] == null)) 520 525 { … … 535 540 foreach ($columnNames as $columnName) 536 541 { 542 // get its group (for fieldsets) 537 543 $group = 'NONE'; 538 544 if (false !== strpos($columnName, '\\')) … … 541 547 } 542 548 549 //get flags (should make no difference if you placed flags in front, or in between (for foreign-fields) 543 550 list($columnName, $flags) = $this->splitFlag($columnName); 544 551 545 $column = $this->getAdminColumnForField($columnName, $flags, $peerName); 546 547 // check if column is foreign 552 // if column is foreign 548 553 if (false !== strpos($columnName, '/')) 549 554 { 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); 555 556 556 557 // 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 560 565 //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) 564 570 565 571 // check if related groupedColumn hierarchy is already defined, if not define it. … … 570 576 } 571 577 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 573 579 $flagPrefix = ''; 574 580 foreach ($flags as $flag) … … 579 585 /* 580 586 * 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 581 593 */ 582 594 $groupedColumns['related'][$foreignKey] = $this->setupGroupedColumns($group.'\\'.$flagPrefix.$relatedColumnName, $relatedPeerName, $related, $i++); //$relatedTableName 583 595 584 596 } 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 590 612 // 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 visible593 $column->key = $columnUnderscore;594 $column->index = $i++;595 613 $groupedColumns['columns'][$group][] = $column; 596 614 } 597 615 598 } 616 } // process next column 599 617 600 618 return $groupedColumns; … … 802 820 $column = $groupedColumns['pk']; 803 821 $column->key = $prefix.$pkName; 822 823 $phpName = $this->getPhpNameForField($column->key); 824 $column->setPhpName($phpName); 825 804 826 $columnList[] = $column; 805 827 } … … 815 837 foreach ($columnsFromGroup as $columnName => $column) 816 838 { 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 825 849 $columnList[] = $newColumn; 826 850 } … … 957 981 * @return string HTML code 958 982 */ 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 961 1028 $type = $column->getCreoleType(); 962 1029 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') : ' '"; 1048 } 1049 else 1050 { 1051 return "$columnGetter"; 1052 } 978 1053 } 979 1054 … … 1381 1456 } 1382 1457 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 { 1392 1460 $fields = explode('/', $field); 1393 1461 … … 1397 1465 $lastPeerClassName = $peerName; 1398 1466 } 1467 1399 1468 $phpName = ""; 1400 1401 1469 if ((!in_array('_', $flags)) && ($field!='*'))// no-partial or row expander 1402 1470 { … … 1421 1489 } 1422 1490 1491 // if column not found, it is a partial or a customMethod 1423 1492 if (!$found) 1424 1493 { 1425 // throw new sfConfigurationException(sprintf('Illegal field-name provided, you should provide:<br> [foreignkey-field(s)/]fieldname<br> <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> <br>Stopped while parcing: "<i>%s</i>" of "%s"', $fields[$i], $field));1426 1494 // not a "real" column, but we generate one here 1427 1495 $flagPrefix = ''; … … 1430 1498 $flagPrefix .= $flag; 1431 1499 } 1432 $name = strtoupper($flagPrefix.$ field);1500 $name = strtoupper($flagPrefix.$currentField); 1433 1501 1434 1502 $tableMap = call_user_func(array($lastPeerClassName, 'getTableMap')); 1435 1503 $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? 1440 1507 } 1441 1508 } 1442 1509 1510 // if not last field, return table getter 1443 1511 if ($i != count($fields) - 1) 1444 1512 { … … 1446 1514 $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 1447 1515 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 .= '::'; 1449 1524 1450 1525 $lastPeerClassName = $relatedTable->getPhpName().'Peer'; 1451 1526 } 1527 //if last field return column getter 1452 1528 else 1453 1529 { … … 1461 1537 } 1462 1538 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 1463 1602 return new sfExtjsAdminColumn($phpName, $this->getColumnForPhpName($phpName, $lastPeerClassName, $field, $flags), $flags); 1464 1603 } … … 1468 1607 * returns a column phpName or null if none was found 1469 1608 */ 1470 public function getColumnForPhpName($ phpName, $peerName = null, $field = '', $flags = array())1609 public function getColumnForPhpName($fullPhpName, $peerName = null, $field = '', $flags = array()) 1471 1610 { 1472 1611 //strip 1473 $ fields = explode('::', $phpName);1474 $phpName = $ fields[count($fields) - 1];1612 $phpNames = explode('::', $fullPhpName); 1613 $phpName = $phpNames[count($phpNames) - 1]; 1475 1614 1476 1615 if ($peerName == null) 1477 1616 { 1478 1617 $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 } 1485 1624 } 1486 1625 … … 1587 1726 } 1588 1727 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 } 1589 1756 } 1590 1757 … … 1620 1787 } 1621 1788 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 } 1622 1808 1623 1809 }

