Changeset 7468
- Timestamp:
- 02/12/08 17:42:39 (2 years ago)
- Files:
-
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/actions/actions.class.php (modified) (15 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__ajax_store.php (modified) (2 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_form_ajax_inner.php (modified) (6 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__json_td.php (modified) (3 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_autocomplete_td.php (modified) (4 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_columnmodel.php (modified) (3 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_filter.php (modified) (2 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_layout.php (modified) (2 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_renderer.php (modified) (3 diffs)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_store.php (added)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_related_ajax_renderer.php (modified) (6 diffs)
- plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/actions/actions.class.php
r7414 r7468 96 96 $this->pager = new sfPropelPager('<?php echo $this->getClassName() ?>', $limit); 97 97 $c = new Criteria(); 98 <?php if ($sortColumn = $this->getGroupField()) : 99 100 //strange construction!? AND Note there is also something like: $this->getPeerClassName() 101 $className = '<?php echo $this->getClassName() ?>'; 102 103 if (false !== strpos($sortColumn, $tableDelimiter)) 104 { 105 $elements = explode($tableDelimiter, $sortColumn); 106 107 $className = sfInflector::camelize($elements[count($elements)-2]); 108 $sortColumn = $elements[count($elements)-1]; 98 <?php if ($sortColumnName = $this->getGroupField()) : 99 $sortColumnName = str_replace($tableDelimiter, '/', $sortColumnName); 100 $sortColumn = $this->getColumnForFieldName($sortColumnName); 101 102 $className = $this->getClassName(); 103 if (false !== strpos($sortColumnName, '/')) 104 { 105 $className = $sortColumn->getTable()->getPhpName(); 109 106 } 110 107 111 108 try 112 109 { 113 $sortColumn = sfInflector::camelize(strtolower($sortColumn)); 114 $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); 110 $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); 115 111 } 116 112 catch (Exception $e) … … 431 427 432 428 $columnName = $column->key; 433 list($class, $checkName) = explode('/',$columnName, 2);429 //list($class, $checkName) = explode('/',$columnName, 2); //TODO: not always two columns!!! class obsolete 434 430 435 if (strtolower($class) != strtolower($tableName))436 {437 $checkName = $columnName;438 }431 // if (strtolower($class) != strtolower($tableName)) 432 // { 433 // $checkName = $columnName; 434 // } 439 435 440 436 if ($column->isPrimaryKey()) continue; 441 if (false !== strpos($c heckName, '/')) continue; // TODO: at the moment cannot handle foreign fields437 if (false !== strpos($columnName, '/')) continue; // TODO: at the moment cannot handle foreign fields 442 438 443 439 $type = $column->getCreoleType(); … … 445 441 <?php echo !$first ? 'else' : '' ?>if ($columnName == '<?php echo str_replace('/', $tableDelimiter, $column->key) ?>') 446 442 { 447 <?php $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials') ?>443 <?php $credentials = $this->getParameterValue('list.fields.'.$columnName.'.credentials') ?> 448 444 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 449 445 if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) … … 503 499 protected function update<?php echo $this->getClassName() ?>FromRequest() 504 500 { 505 $<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->get SingularName() ?>');501 $<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->getTableName() ?>'); 506 502 507 503 <?php … … 511 507 512 508 foreach ($columns as $column): 513 list($class, $checkName) = explode('/', $column->key, 2);509 // list($class, $checkName) = explode('/', $column->key, 2); 514 510 515 if (strtolower($class) != strtolower($tableName))516 {517 $checkName = $columnName;518 }511 // if (strtolower($class) != strtolower($tableName)) 512 // { 513 // $checkName = $columnName; 514 // } 519 515 520 516 if ($column->isPrimaryKey()) continue; 521 if (false !== strpos($c heckName, '/')) continue; // TODO: at the moment cannot handle foreign fields517 if (false !== strpos($columnName, '/')) continue; // TODO: at the moment cannot handle foreign fields 522 518 523 519 $type = $column->getCreoleType(); 524 $name = str_replace('/', $tableDelimiter, $c heckName);525 526 $credentials = $this->getParameterValue('edit.fields.'.$c heckName.'.credentials');527 $input_type = $this->getParameterValue('edit.fields.'.$c heckName.'.type');520 $name = str_replace('/', $tableDelimiter, $columnName); 521 522 $credentials = $this->getParameterValue('edit.fields.'.$columnName.'.credentials'); 523 $input_type = $this->getParameterValue('edit.fields.'.$columnName.'.type'); 528 524 529 525 ?> … … 536 532 <?php endif; ?> 537 533 <?php if ($input_type == 'admin_input_file_tag'): ?> 538 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$c heckName.'.upload_dir')) ?>534 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$columnName.'.upload_dir')) ?> 539 535 $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 540 536 if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove'])) … … 554 550 <?php endif; ?> 555 551 <?php if ($input_type == 'admin_input_file_tag'): ?> 556 <?php if ($this->getParameterValue('edit.fields.'.$c heckName.'.filename')): ?>557 $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$c heckName.'.filename'))) ?>";552 <?php if ($this->getParameterValue('edit.fields.'.$columnName.'.filename')): ?> 553 $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$columnName.'.filename'))) ?>"; 558 554 <?php else: ?> 559 555 $fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time().rand(0, 99999)); … … 635 631 <?php if ($this->getParameterValue('list.filters')): ?> 636 632 <?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> 637 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): //TODO replace $column->getName with $c heckName ?>633 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): //TODO replace $column->getName with $columnName ?> 638 634 if (isset($filters['<?php echo $column->getName() ?>']['from']) && $filters['<?php echo $column->getName() ?>']['from'] !== '') 639 635 { … … 696 692 if (!$this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/sort')) 697 693 { 698 //<?php $mainclassPrefix = "" ?>699 //<?php if ($this->getParameterValue('sub_class.model_class')) $mainclassPrefix = $this->getSingularName()."_"; ?>700 701 694 <?php if ($sort = $this->getParameterValue('list.sort')): ?> 702 695 … … 731 724 $groupedColumns = $this->getColumnsGrouped($for, false); 732 725 733 $pk = clone($groupedColumns['pk']); // copy by value, you don't want to add $pk->key to groupedColumns['pk']734 $pk->key = strtolower($pk->get TableName().'/'.$pk->getName());726 $pk = clone($groupedColumns['pk']); //OBSOLETE copy by value, you don't want to add $pk->key to groupedColumns['pk'] 727 $pk->key = strtolower($pk->getName()); // $pk->getTableName().'/'. 735 728 736 729 $columns = array(); … … 740 733 { 741 734 $pkr = clone($relatedGroupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 742 $pkr->key = strtolower($pk ->getTableName().'/'.$pkr->getTableName().'/'.$pkr->getName());735 $pkr->key = strtolower($pkr->getTableName().'/'.$pkr->getName()); // $pk->getTableName().'/'. 743 736 744 737 $columns[] = $pkr; // add related primary key … … 754 747 if (false !== strpos($column->key, '/')) 755 748 { 756 $parts = explode('/', $column->key); 757 $peer = $parts[count($parts)-2]; 758 $peerClassName = sfInflector::camelize($peer).'Peer'; 749 $peerClassName = sfInflector::camelize($column->getTable()->getPhpName()).'Peer'; 759 750 } 760 751 $columnName = strtoupper($column->getName()); … … 837 828 foreach($sort_array as $sort_column => $sort_type) 838 829 { 839 //strange construction!? AND Note there is also something like: $this->getPeerClassName() 830 $fields = explode($tableDelimiter, $sort_column); 831 832 //get className 840 833 $className = '<?php echo $this->getClassName() ?>'; 841 842 //fix for cookie error 843 $sortColumn = $sort_column; 844 if (false !== strpos($sort_column, $tableDelimiter)) 845 { 846 $elements = explode($tableDelimiter, $sort_column); 847 $className = $elements[count($elements)-2]; 848 $sortColumn = $elements[count($elements)-1]; 849 $className = sfInflector::camelize($className); 850 } 851 //$sortColumn = str_replace(sfInflector::underscore($className).$tableDelimiter, '', $sort_column); 852 834 for ($i = 0; $i < count($fields) -1; $i++) 835 { 836 $map = call_user_func(array($className.'Peer', 'getTableMap')); 837 $columns = $map->getColumns(); 838 $found = false; 839 foreach ($columns as $column) 840 { 841 if ($column->getColumnName() == strtoupper($fields[$i])) 842 { 843 $found = true; 844 break; 845 } 846 } 847 848 if (!$found) 849 { 850 throw new Exception('Sort column "'.$sort_column.'" not found'); 851 } 852 853 $className = $this->translateTableNameToPhpName($column->getRelatedTableName()); 854 } 855 856 //get sortColumn 857 $map = call_user_func(array($className.'Peer', 'getTableMap')); 858 $columns = $map->getColumns(); 859 $found = false; 860 foreach ($columns as $column) 861 { 862 if ($column->getColumnName() == strtoupper($fields[$i])) 863 { 864 $found = true; 865 break; 866 } 867 } 868 869 if (!$found) 870 { 871 throw new Exception('Sort column "'.$sort_column.'" not found'); 872 } 873 853 874 try 854 875 { 855 // removed strtoupper 856 $sortColumn = sfInflector::camelize(strtolower($sortColumn)); 857 $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); 876 $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $column->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); 858 877 $sort_columns[$fieldName] = $sort_type; 859 878 } … … 898 917 $columnName = $column->key; 899 918 900 list($class, $checkName) = explode('/', $columnName, 2);901 902 if (strtolower($class) != strtolower($tableName))903 {904 $class = strtolower($tableName);905 $checkName = $columnName;906 }919 // list($class, $checkName) = explode('/', $columnName, 2); 920 // 921 // if (strtolower($class) != strtolower($tableName)) 922 // { 923 // $class = strtolower($tableName); 924 // $checkName = $columnName; 925 // } 907 926 908 927 $fieldName = str_replace('/', $tableDelimiter, $columnName); 909 928 910 $labelName = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$c heckName.'.name'));929 $labelName = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$columnName.'.name')); 911 930 ?> 912 931 '<?php echo $fieldName ?>' => '<?php echo $labelName ?>', … … 914 933 ); 915 934 } 935 936 937 protected function translateTableNameToPhpName($tableName) 938 { 939 switch($tableName) 940 { 941 <?php 942 $groupedColumns = $this->getColumnsGrouped(array('list.display', 'edit.display')); 943 foreach ($groupedColumns['related'] as $relatedTableName => $relatedTable): 944 ?> 945 case '<?php echo $relatedTableName ?>': 946 return '<?php echo $relatedTable['pk']->getTable()->getPhpName(); ?>'; 947 <?php endforeach; ?> 948 } 949 950 throw new Exception('Unknown table name: "'.$tableName.'"'); 951 } 952 916 953 917 954 public function executeListJs() plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__ajax_store.php
r7164 r7468 38 38 $columns = $this->getListUniqueColumns($groupedColumns, true); 39 39 $pkn = $groupedColumns['pk']->getName(); 40 $tableName = $groupedColumns['pk']->getTableName(); 40 41 41 42 … … 56 57 foreach ($columns as $columnName => $column) 57 58 { 58 $columnName = $column->key;59 60 list($class, $checkName) = explode('/', $columnName, 2);61 62 if (strtolower($class) != strtolower($tableName))63 {64 $class = $tableName;65 $checkName = $columnName;66 }59 // $columnName = $column->key; 60 // 61 // list($class, $checkName) = explode('/', $columnName, 2); 62 // 63 // if (strtolower($class) != strtolower($tableName)) 64 // { 65 // $class = $tableName; 66 // $checkName = $columnName; 67 // } 67 68 68 $fieldName = $class.'['.str_replace('/', $tableDelimiter, $checkName).']'; 69 $fieldMapping = str_replace('/', $tableDelimiter, $columnName); 69 $fieldName = str_replace('/', $tableDelimiter, $column->key); 70 70 71 $listDisplay[$i++] = array('name' => $ fieldName,72 'mapping' => $field Mapping,71 $listDisplay[$i++] = array('name' => $tableName.'['.$fieldName.']', 72 'mapping' => $fieldName, 73 73 'type' => extjs_convert_propel_type($column->getType()) 74 74 ); 75 75 } 76 76 77 $options = array('id' => $p refix.$tableDelimiter.$pkn,77 $options = array('id' => $pkn, 78 78 'root' => 'data', 79 79 'totalProperty' => 'totalCount'); plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_form_ajax_inner.php
r7356 r7468 111 111 [?php //load current details (if not new) ?] 112 112 [?php if (!$<?php echo $this->getSingularName() ?>->isNew()): ?] 113 <?php114 /*115 $columns = $this->getListUniqueColumns($groupedColumns);116 $tableName = $this->getTableName();117 $skip = array();118 119 foreach ($columns as $column):120 $columnName = $column->key;121 // remove base classname for checks (This way you can check on fields like name, instead of product/name)122 list($class, $checkName) = explode('/', $columnName, 2);123 124 if (strtolower($class) != strtolower($tableName))125 {126 $checkName = $columnName;127 }128 129 // skip local fields130 if (false === strpos($checkName, '/')) continue;131 132 list($relatedTableName, $relatedColumnName) = explode('/', $checkName, 2);133 134 if (in_array($relatedTableName, $skip)) continue; // been there done that135 136 $skip[] = $relatedTableName;137 endforeach;138 */139 ?>140 141 113 ds_<?php echo $edit_name ?>.on('load', <?php echo $edit_ns ?>.data_loaded); 142 ds_<?php echo $edit_name ?>.load({params: {filter: 1, 'filters[<?php echo $prefix.$pkn ?>]':[?php echo $sf_request->getParameter('<?php echo $pkn ?>', 0) ?]}}); 143 114 ds_<?php echo $edit_name ?>.load({params: {filter: 1, 'filters[<?php echo $pkn ?>]':[?php echo $sf_request->getParameter('<?php echo $pkn ?>', 0) ?]}}); 144 115 [?php endif; ?] 145 116 … … 199 170 // $column->key = $prefix.$column->key; 200 171 $columnName = $column->key ; 201 202 // remove base classname for checks (This way you can check on fields like name, instead of product/name)203 list($class, $checkName) = explode('/', $columnName, 2);204 $tableMap = $this->getTableMap();205 $tableName = $tableMap->getName();206 207 if (strtolower($class) != strtolower($tableName))208 {209 $checkName = $columnName;210 }211 172 ?> 212 <?php if (in_array($c heckName, $hides)) continue ?>173 <?php if (in_array($column->key, $hides)) continue ?> 213 174 <?php if ($column->isPrimaryKey()) continue ?> 214 <?php $credentials = $this->getParameterValue($edit_key.'.fields.'.$c heckName.'.credentials') ?>175 <?php $credentials = $this->getParameterValue($edit_key.'.fields.'.$column->key.'.credentials') ?> 215 176 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 216 177 [?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?] 217 178 <?php endif; ?> 218 179 <?php 219 $tableMap = $this->getTableMap(); 220 $tableName = $tableMap->getName(); 221 $fieldName = str_replace('/', $tableDelimiter, $checkName); 180 $tableName = $this->getTableName(); 181 $last = strrpos($column->key, '/'); 182 $relatedTableFKs = substr($column->key, 0, $last); 183 $fieldName = str_replace('/', $tableDelimiter, $column->key); 222 184 $options = array('name' => strtolower($tableName).'['.$fieldName.']', 223 185 'width' => 175); … … 283 245 // 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) 284 246 // Due to this hack the column looses all info (like type, length, etc) 285 $column2 = $this->getAdminColumnForField($c heckName);247 $column2 = $this->getAdminColumnForField($column->key); 286 248 ?> 287 249 // this should be done elsewhere... … … 312 274 }, // end init 313 275 276 277 <?php // todo: this code below has to be done for every column above, like in _related_ajax_renderer.php. Maybe we can also reuse some more code! ?> 314 278 data_loaded : function() { 315 279 // -- add preloaded data to the related stores … … 325 289 foreach ($columnsFromGroup as $column) 326 290 { 327 $columnName = $column->getTableName().'/'.$column->getName(); 328 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 329 list($class, $checkName) = explode('/', $columnName, 2); 330 $tableMap = $this->getTableMap(); 331 $tableName = $tableMap->getName(); 332 333 if (strtolower($class) != strtolower($tableName)) 334 { 335 $checkName = $columnName; 336 } 291 // correction to key 292 $column->key = $column->getTableName().'/'.$column->key; 337 293 338 $listDisplay[] = array('name' => str_replace('/', $tableDelimiter, $c heckName), 'mapping' => str_replace('/', $tableDelimiter, $checkName));294 $listDisplay[] = array('name' => str_replace('/', $tableDelimiter, $column->key), 'mapping' => str_replace('/', $tableDelimiter, $column->key)); 339 295 } 340 296 } 341 297 342 $foreign_key = $this->getForeignKeyToTable($relatedTableName, $groupedColumns);343 list($foreign_class, $foreign_checkName) = explode('/', $foreign_key, 2);344 345 $tableMap = $this->getTableMap();346 $tableName = $tableMap->getName();347 348 if (strtolower($foreign_class) == strtolower($tableName))349 {350 $foreign_key = $foreign_checkName;351 }352 353 $tableMap = $this->getTableMap();354 $tableName = $tableMap->getName();355 298 ?> 356 299 var Record = Ext.data.Record.create(<?php echo _extjs_property_encode($listDisplay) ?>); … … 360 303 var record_data = Array(); 361 304 362 record_data['<?php echo $pk ?>'] = ds_<?php echo $edit_name ?>.getAt(index).get('<?php echo strtolower($tableName).'['.$foreign_key.']'?>');;305 record_data['<?php echo $pk ?>'] = ds_<?php echo $edit_name ?>.getAt(index).get('<?php echo $relatedTableFKs ?>');; 363 306 <?php 364 307 // iterate through all requested columns of current class 365 308 foreach ($relatedClass['columns'] as $group => $columnsFromGroup): 366 309 foreach ($columnsFromGroup as $column): 367 $columnName = strtolower($column->getTableName().'/'.$column->getPhpName()); 368 369 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 370 list($class, $checkName) = explode('/', $columnName, 2); 371 $tableMap = $this->getTableMap(); 372 $tableName = $tableMap->getName(); 373 374 if (strtolower($class) != strtolower($tableName)) 375 { 376 $checkName = $columnName; 377 $columnName = $tableName.'/'.$columnName; 378 } 310 //correction for key 311 $column->key = strtolower($column->getTableName().'/'.$column->key); 379 312 380 $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials');313 $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 381 314 ?> 382 315 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 383 316 [?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?] 384 317 <?php endif; ?> 385 record_data['<?php echo str_replace('/', $tableDelimiter, $c heckName) ?>'] = ds_<?php echo $edit_name ?>.getAt(index).get('<?php echo $tableName.'['.str_replace('/', $tableDelimiter, $checkName).']'?>');318 record_data['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'] = ds_<?php echo $edit_name ?>.getAt(index).get('<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'); 386 319 <?php 387 320 //don't add it twice 388 $hs[] = $c heckName;321 $hs[] = $column->key; 389 322 ?> 390 323 <?php if ($credentials): ?> plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__json_td.php
r7411 r7468 39 39 40 40 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 41 list($class, $checkName) = explode('/', $columnName, 2);42 43 if (strtolower($class) != strtolower($tableName))44 {45 $checkName = $columnName;46 }41 // list($class, $checkName) = explode('/', $columnName, 2); 42 // 43 // if (strtolower($class) != strtolower($tableName)) 44 // { 45 // $checkName = $columnName; 46 // } 47 47 48 48 // want to see in the datastore still 49 49 //if (in_array($checkName, $hs)) continue; 50 50 51 $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials');51 $credentials = $this->getParameterValue('list.fields.'.$columnName.'.credentials'); 52 52 53 53 ?> … … 67 67 // 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) 68 68 // Due to this hack the column looses all info (like type, length, etc and keys (like isPartial, isLink, isComponent ) 69 $column = $this->getAdminColumnForField($c heckName);69 $column = $this->getAdminColumnForField($columnName); 70 70 } 71 71 … … 74 74 75 75 //don't add it twice 76 $hs[] = $c heckName;76 $hs[] = $columnName; 77 77 78 78 $i++; plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_autocomplete_td.php
r7179 r7468 18 18 { 19 19 $pkr = clone($relatedGroupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 20 $pkr->key = strtolower($pk->getTableName().'/'.$pkr->getTableName().'/'.$pkr->getName()); 20 //correction of key 21 $pkr->key = strtolower($pkr->getTableName().'/'.$pkr->getName()); 21 22 22 23 $columns[] = $pkr; // add related primary key … … 32 33 33 34 foreach ($columns as $column) : 34 $columnName = $column->key;35 // $columnName = $column->key; 35 36 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 36 list($class, $checkName) = explode('/', $columnName, 2);37 38 if (strtolower($class) != strtolower($tableName))39 {40 $checkName = $columnName;41 }37 // list($class, $checkName) = explode('/', $columnName, 2); 38 // 39 // if (strtolower($class) != strtolower($tableName)) 40 // { 41 // $checkName = $columnName; 42 // } 42 43 43 44 // skip local fields 44 if (false === strpos($c heckName, '/')) continue;45 if (false === strpos($column->key, '/')) continue; 45 46 46 list($relatedTableName, $relatedColumnName) = explode('/', $checkName, 2); 47 list($relatedTableName, $relatedColumnName) = explode('/', $column->key, 2); 48 $relatedTableName = $column->getTable()->getName(); 47 49 48 50 // skip foreign related fields … … 50 52 51 53 // check if hidden 52 if (in_array($c heckName, $hs)) continue;54 if (in_array($column->key, $hs)) continue; 53 55 54 $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials');56 $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 55 57 ?> 56 58 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> … … 63 65 // TODO: to make it work with componentents and partials, check the method getColumnAjaxDefinition instead of processColumnAutocompleteName (which can than get private) 64 66 ?> 65 "<?php echo str_replace('/',$tableDelimiter, $checkName) ?>": "[?php echo str_replace('"', '\"', $results->get<?php echo sfInflector::camelize($relatedColumnName) ?>() ) ?]"67 "<?php echo $relatedTableName.$tableDelimiter.$column->getName() ?>": "[?php echo str_replace('"', '\"', $results->get<?php echo sfInflector::camelize($relatedColumnName) ?>() ) ?]" 66 68 [?php $i++; ?] 67 69 [?php endif; ?] 68 70 <?php 69 71 //don't add it twice 70 $hs[] = $c heckName;72 $hs[] = $column->key; 71 73 ?> 72 74 <?php if ($credentials): ?> plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_columnmodel.php
r7237 r7468 37 37 38 38 foreach ($columns as $column) : 39 $columnName = $column->key;39 // $columnName = $column->key; 40 40 41 41 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 42 list($class, $checkName) = explode('/', $columnName, 2);43 44 if (strtolower($class) != strtolower($tableName))45 {46 $checkName = $columnName;47 }42 // list($class, $checkName) = explode('/', $columnName, 2); 43 // 44 // if (strtolower($class) != strtolower($tableName)) 45 // { 46 // $checkName = $columnName; 47 // } 48 48 49 49 if(count($this->getParameterValue('list.expander')) != 0) … … 53 53 } 54 54 55 if (in_array($c heckName, $hs)) continue;55 if (in_array($column->key, $hs)) continue; 56 56 57 $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials');57 $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 58 58 59 59 ?> … … 64 64 <?php 65 65 66 $id = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$c heckName.'.params.id'));66 $id = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->key.'.params.id')); 67 67 68 $header = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$checkName.'.name')); 68 $header = str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$column->key.'.name')); 69 70 $dataIndex = str_replace('/', $tableDelimiter, $column->key); 69 71 70 $dataIndex = str_replace('/', $tableDelimiter, $columnName); 71 72 $width = $this->getParameterValue('list.fields.'.$checkName.'.params.width'); 72 $width = $this->getParameterValue('list.fields.'.$column->key.'.params.width'); 73 73 74 74 ?> plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_filter.php
r6892 r7468 33 33 34 34 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 35 list($class, $checkName) = explode('/', $columnName, 2);36 37 if (strtolower($class) != strtolower($tableName))38 {39 $checkName = $columnName;40 }35 // list($class, $checkName) = explode('/', $columnName, 2); 36 // 37 // if (strtolower($class) != strtolower($tableName)) 38 // { 39 // $checkName = $columnName; 40 // } 41 41 ?> 42 <?php $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials') ?>42 <?php $credentials = $this->getParameterValue('list.fields.'.$columnName.'.credentials') ?> 43 43 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 44 44 [?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?] … … 46 46 <?php 47 47 //TODO, change this so drop-down columnboxes and checkboxes appear... 48 $formFields[] = array('fieldLabel' => str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$c heckName.'.name')), 'name' => 'filters['.str_replace('/', $tableDelimiter, $columnName).']');48 $formFields[] = array('fieldLabel' => str_replace("'", "\\'", $this->getParameterValue('list.fields.'.$columnName.'.name')), 'name' => 'filters['.str_replace('/', $tableDelimiter, $columnName).']'); 49 49 ?> 50 50 <?php if ($credentials): ?> plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_layout.php
r7412 r7468 9 9 $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 10 10 11 $tableName = $this->getTableName();12 $prefix = $tableName;11 //$tableName = $this->getTableName(); 12 //$prefix = $tableName; 13 13 14 14 $limit = $this->getParameterValue('list.max_per_page', sfConfig::get('app_sf_extjs_theme_plugin_list_max_per_page', 20)); … … 54 54 ( 55 55 'parameters' => 'row, index', 56 'source' => "if (!row.data['".$p refix.$tableDelimiter.$pkn."']) return 'x-grid-group-body-hide';"56 'source' => "if (!row.data['".$pkn."']) return 'x-grid-group-body-hide';" //$prefix.$tableDelimiter. 57 57 )); 58 58 plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_renderer.php
r7087 r7468 41 41 42 42 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 43 list($class, $checkName) = explode('/', $columnName, 2);44 45 if (strtolower($class) != strtolower($tableName))46 {47 $checkName = $columnName;48 }43 // list($class, $checkName) = explode('/', $columnName, 2); 44 // 45 // if (strtolower($class) != strtolower($tableName)) 46 // { 47 // $checkName = $columnName; 48 // } 49 49 50 50 //check if field is foreign 51 if (false !== strpos($c heckName, '/'))51 if (false !== strpos($column->key, '/')) 52 52 { 53 $last = strrpos($checkName, '/'); 54 $relatedTableName = substr($checkName, 0, $last); 55 $key_name = $this->getForeignKeyToTable($relatedTableName, $groupedColumns); 53 $last = strrpos($column->key, '/'); 54 $relatedTableFK = substr($column->key, 0, $last); 55 $record_pkn = $relatedTableFK; 56 //$key_name = str_replace('/', $tableDelimiter, $column->key);//$this->getForeignKeyToTable($relatedTableName, $groupedColumns); 56 57 57 $subGroupedColumn = $this->getSubGroupedColumns($relatedTable Name,$groupedColumns);58 $subGroupedColumn = $this->getSubGroupedColumns($relatedTableFK,$groupedColumns); 58 59 $relatedTablePK = $subGroupedColumn['pk']; 59 60 } 60 61 else 61 62 { 62 $ key_name = $tableName.'/'.$pkn;63 $record_pkn = $pkn; //$tableName.'/'. 63 64 } 64 65 65 66 //header values 66 67 // $pieces = explode('/', $key_name); 67 $url_pkn = $relatedTablePK->getName();68 $record_pkn = str_replace('/', $tableDelimiter, $key_name);68 // $url_pkn = $relatedTablePK->getName(); 69 // $record_pkn = str_replace('/', $tableDelimiter, $key_name); 69 70 70 $ h_tableName = $relatedTableName;71 $h_moduleName = $ h_tableName; //TODO: this probably is not always the same!71 $relatedTableName = $relatedTablePK->getTableName(); 72 $h_moduleName = $relatedTableName; //TODO: table-name not always the same as moduleName, need extra user-defined translation (alread implemented/used elsewhere, with extra info from generator.yml file!) 72 73 73 $params = $this->getParameterValue('list.fields.'.$c heckName.'.params');74 $params = $this->getParameterValue('list.fields.'.$column->key.'.params'); 74 75 $params = is_array($params) ? $params : sfToolkit::stringToArray($params); 75 76 $h_valuePrefix = isset($params['header_valuePrefix']) ? $params['header_valuePrefix'] : ''; … … 82 83 $default_collapse = false; 83 84 //TODO remove hardcoded tag for underline, add option to set stylesheet-class, don't forget to remove the closing tag as well... 84 $headerText .= "<u><a href=\'".$controller->genUrl($h_moduleName."/edit?".$ url_pkn."=")."/'+record.data['".$record_pkn."']+'\' id=\'".$h_moduleName."'+record.data['".$record_pkn."']+'\'>";85 $headerText .= "<u><a href=\'".$controller->genUrl($h_moduleName."/edit?".$relatedTablePK->getName()."=")."/'+record.data['".$record_pkn."']+'\' id=\'".$h_moduleName."'+record.data['".$record_pkn."']+'\'>"; 85 86 } 86 87 $headerText .= $h_valuePrefix."'+record.data['".str_replace('/', $tableDelimiter, $columnName)."']+'".$h_valueSuffix; … … 131 132 132 133 <?php 133 $key = $p refix.$pkn;134 $key = $pkn; //$prefix. 134 135 ?> 135 136 // TODO: remove hardcoded html-tags, set css plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_related_ajax_renderer.php
r7356 r7468 13 13 $groupedColumns = $this->getColumnsGrouped($for, true); 14 14 $columns = $this->getListRelatedColumns($groupedColumns, false); 15 //$tableName = strtolower($groupedColumns['pk']->getTableName());16 $tableName = $this->getTableName();17 15 18 16 //iterate through all related columns 19 17 foreach ($columns as $column) : 20 $columnName = $column->key; 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 24 if (strtolower($class) != strtolower($tableName)) 25 { 26 $checkName = $columnName; 27 } 28 18 $last = strrpos($column->key, '/'); 19 $relatedTableFKs = substr($column->key, 0, $last); 20 29 21 // can we skip it? 30 if (in_array($c heckName, $hs)) continue;22 if (in_array($column->key, $hs)) continue; 31 23 if ($column->isPrimaryKey()) continue; 32 24 if ($column->isForeignKey()) continue; 33 25 34 26 // or are we looking for it? Columns defined as 'table/field' 35 if (false === strpos($c heckName, '/'))27 if (false === strpos($column->key, '/')) 36 28 { 37 29 continue; 38 30 } 39 else40 {41 $last = strrpos($checkName, '/');42 $relatedTableName = substr($checkName, 0, $last);43 $key_name = $this->getForeignKeyToTable($relatedTableName, $groupedColumns);44 31 45 $subGroupedColumn = $this->getSubGroupedColumns($relatedTableName,$groupedColumns); 46 $relatedTablePK = $subGroupedColumn['pk']; 47 } 48 49 $credentials = $this->getParameterValue('list.fields.'.$checkName.'.credentials'); 32 $credentials = $this->getParameterValue('list.fields.'.$column->key.'.credentials'); 50 33 ?> 51 34 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> … … 54 37 <?php 55 38 56 //get last related table 57 if (strrpos($relatedTableName, '/')) 58 { 59 $tables = explode('/', $relatedTableName); 60 $relatedTableName = $tables[count($tables)-1]; 61 } 39 $relatedTableName = $column->getTable()->getName(); 62 40 63 41 //TODO: maybe rendername should contain all related-tablenames, not only last related-table 64 $rendererName = ucfirst($relatedTableName).ucfirst($column->getName())42 $rendererName = sfInflector::camelize(str_replace('/', '_', $column->key));//ucfirst($relatedTableName).ucfirst($column->getName()) 65 43 ?> 66 44 function render<?php echo $rendererName ?>Field(value) { … … 68 46 <?php 69 47 //set name (from column of related JSON-DataStore) 70 if (false !== strpos($checkName, '/'))71 {72 $name = $column->getName();73 }74 48 $foreign_ds = sfInflector::underscore($relatedTableName)."_ds"; 49 50 $name = $column->getName(); 51 $last = strrpos($column->key, '/'); 52 $relatedTableFKs = substr($column->key, 0, $last); 75 53 ?> 76 54 // if value in foreign datastore, return this value 77 55 if (<?php echo $foreign_ds ?>.getById(value)) { 78 return <?php echo $foreign_ds ?>.getById(value).get('<?php echo $ relatedTableName.$tableDelimiter.$name ?>');56 return <?php echo $foreign_ds ?>.getById(value).get('<?php echo $name ?>'); 79 57 // if not in foreign datastore, test if it is preloaded (this can be out-dated therefor do it after checking datastore) 80 } else if ((index = ds_list.find('<?php echo str_replace('/', $tableDelimiter, $ key_name) ?>', value)) != -1) {58 } else if ((index = ds_list.find('<?php echo str_replace('/', $tableDelimiter, $relatedTableFKs) ?>', value)) != -1) { 81 59 // foreign-ID not known in foreign-store yet, add preloaded data from the main-store 82 <?php echo $ foreign_ds ?>_add_preloaded_from_index(index, value);60 <?php echo $rendererName?>AddPreloadedFromIndex(index, value); 83 61 84 return ds_list.getAt(index).get('<?php echo str_replace('/', $tableDelimiter, $column Name) ?>');62 return ds_list.getAt(index).get('<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'); 85 63 } else { 86 64 //TODO if value still not found the foreign-data-store should get it from the server! (but I don't think this will be necesarry occur) … … 89 67 } 90 68 } 69 70 71 72 // Define related renderer-helpers to show preloaded data; prevent loading all related data stores 73 function <?php echo $rendererName ?>AddPreloadedFromIndex(index, value) { 91 74 <?php 92 //don't add it twice 93 $hs[] = $checkName; 94 ?> 95 <?php if ($credentials): ?> 96 [?php endif; ?] 97 <?php endif; ?> 98 <?php endforeach; ?> 75 $hs2 = array(); 99 76 100 // Define related renderer-helpers to show preloaded data; prevent loading all related data stores 101 <?php if(array_key_exists('related', $groupedColumns)): ?> 102 <?php foreach ($groupedColumns['related'] as $relatedTableName => $relatedClass): ?> 103 function <?php echo strtolower($relatedTableName) ?>_ds_add_preloaded_from_index(index, value) { 104 105 <?php 77 $relatedClass = $groupedColumns['related'][$relatedTableName]; 78 106 79 $pk = $relatedTableName.$tableDelimiter.$relatedClass['pk']->getName(); 80 $listDisplay = array(array('name' => $pk, 'mapping' => $pk)); 107 81 108 $listDisplay = array(array('name' => $pk, 'mapping' => $pk));109 82 foreach ($relatedClass['columns'] as $group => $columnsFromGroup) 110 83 { 111 foreach ($columnsFromGroup as $column )84 foreach ($columnsFromGroup as $column2) 112 85 { 113 $columnName = $column->getTableName().'/'.$column->getName(); 114 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 115 list($relatedTableName, $checkName) = explode('/', $columnName, 2); 116 117 if (strtolower($relatedTableName) != strtolower($tableName)) 118 { 119 $checkName = $columnName; 120 } 121 122 $listDisplay[] = array('name' => str_replace('/', $tableDelimiter, $checkName), 'mapping' => str_replace('/', $tableDelimiter, $checkName)); 86 $columnName2 = $column2->getTableName().'/'.$column2->getName(); 87 88 if (in_array($columnName2, $hs2)) continue; 89 90 $listDisplay[] = array('name' => str_replace('/', $tableDelimiter, $columnName2), 'mapping' => str_replace('/', $tableDelimiter, $columnName2)); 91 92 $hs2[] = $columnName2; 123 93 } 124 } 94 } 125 95 ?> 126 96 var Record = Ext.data.Record.create(<?php echo _extjs_property_encode($listDisplay) ?>); … … 131 101 record_data['<?php echo $pk ?>'] = value; 132 102 <?php 103 $hs2 = array(); 133 104 // iterate through all requested columns of current class 134 105 foreach ($relatedClass['columns'] as $group => $columnsFromGroup): 135 foreach ($columnsFromGroup as $column ):136 $columnName = strtolower($column->getTableName().'/'.$column->getPhpName());106 foreach ($columnsFromGroup as $column2): 107 $columnName2 = $column->getTableName().'/'.$column2->getName(); 137 108 138 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 139 list($relatedTableName, $checkName) = explode('/', $columnName, 2); 140 141 if (strtolower($relatedTableName) != strtolower($tableName)) 142 { 143 $checkName = $columnName; 144 $columnName = strtolower($tableName).'/'.$columnName; 145 } 109 if (in_array($columnName2, $hs2)) continue; 146 110 147 $credentials = $this->getParameterValue('list.fields.'.$c heckName.'.credentials');111 $credentials = $this->getParameterValue('list.fields.'.$columnName2.'.credentials'); 148 112 ?> 149 113 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 150 114 [?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?] 151 115 <?php endif; ?> 152 record_data['<?php echo str_replace('/', $tableDelimiter, $checkName) ?>'] = ds_list.getAt(index).get('<?php echo str_replace('/', $tableDelimiter, $columnName) ?>'); 153 <?php 154 //don't add it twice 155 $hs[] = $checkName; 156 ?> 116 record_data['<?php echo str_replace('/', $tableDelimiter, $columnName2) ?>'] = ds_list.getAt(index).get('<?php echo str_replace('/', $tableDelimiter, $relatedTableFKs).$tableDelimiter.$column2->getName() ?>'); 157 117 <?php if ($credentials): ?> 158 118 [?php endif; ?] 159 119 <?php endif; ?> 120 <?php 121 //don't add it twice 122 $hs2[] = $columnName2; 123 ?> 160 124 <?php endforeach; ?> 161 125 <?php endforeach; ?> … … 164 128 <?php echo strtolower($relatedTableName) ?>_ds.add(r); 165 129 } 130 131 <?php 132 //don't add it twice 133 $hs[] = $column->key; 134 ?> 135 <?php if ($credentials): ?> 136 [?php endif; ?] 137 <?php endif; ?> 166 138 <?php endforeach; ?> 167 <?php endif; ?> 139 plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php
r7413 r7468 312 312 $pk = $pks[0]->getPhpName(); 313 313 314 // TODO: check if this is the new method (see below) 315 return $this->getAdminColumnForField($pk); 314 return new sfAdminColumn($pk, $pks[0], null); 316 315 } 317 316 … … 343 342 { 344 343 // create and catch exception caused by model classes starting with a lower case character 345 try346 {344 // try 345 // { 347 346 $tableMap = @call_user_func(array($peerName, 'getTableMap')); 348 if(!$tableMap) throw new Exception();349 }350 catch(Exception $e)351 {352 $tableMap = call_user_func(array(strtolower(substr($peerName, 0, 1)) . substr($peerName, 1), 'getTableMap'));353 }347 // if(!$tableMap) throw new Exception(); 348 // } 349 // catch(Exception $e) 350 // { 351 // $tableMap = call_user_func(array(strtolower(substr($peerName, 0, 1)) . substr($peerName, 1), 'getTableMap')); 352 // } 354 353 355 354 foreach ($tableMap->getColumns() as $col) … … 357 356 if ($col->isPrimaryKey()) 358 357 { 359 $column = $this->getAdminColumnForField($col->getPhpName(), null, $peerName);358 $column = new sfAdminColumn($col->getPhpName(), $col, null); 360 359 $groupedColumns['pk'] = $column; 361 360 break; // end foreach when found … … 381 380 { 382 381 $columnPhpName = $column->getPhpName(); 383 list($related SingularClassName, $none) = explode('::', $columnPhpName, 2);382 list($relatedTablePhpName, $none) = explode('::', $columnPhpName, 2); 384 383 list($none, $relatedColumnName) = explode('/', $columnName, 2); 385 384 386 $relatedPeerName = $related SingularClassName.'Peer';387 $relatedTableName = sfInflector::underscore($relatedSingularClassName);385 $relatedPeerName = $relatedTablePhpName.'Peer'; 386 // $relatedTableName = sfInflector::underscore($relatedTablePhpName); 388 387 // $relatedColumnName = str_replace('::', '/', $relatedColumnName); // Change back :: to / for relatedColumnName 389 388 … … 394 393 { 395 394 // Search for ForeignKey 396 if ($col->getRelatedTableName() == $relatedTableName)395 if ($col->getRelatedTableName() != '') 397 396 { 398 // Add ForeignKey to current columns (needed for drop-down boxes) 399 $colFKName = $col->getPhpName(); 400 $colFKUnderscore = sfInflector::underscore($colFKName); 401 $column = $this->getAdminColumnForField($colFKName, null, $peerName); 402 // add an option to which tells to hide this field (for iteration in grid and edit views) 403 // this way it CAN be used for en/de-coding in json-data 404 $column->visible = false; 405 $column->key = $colFKUnderscore; 406 $column->index = $i++; 407 $groupedColumns['columns'][$group][] = $column; 408 409 break; // stop foreach 397 $colRelatedTable = $this->getMap()->getDatabaseMap()->getTable($col->getRelatedTableName()); 398 if ($colRelatedTable->getPhpName() == $relatedTablePhpName) 399 { 400 // Add ForeignKey to current columns (needed for drop-down boxes) 401 $colFKName = $col->getPhpName(); 402 $colFKUnderscore = strtolower($col->getColumnName()); 403 $column = new sfAdminColumn($colFKName, $col, null); 404 // add an option to which tells to hide this field (for iteration in grid and edit views) 405 // this way it CAN be used for en/de-coding in json-data 406 $column->visible = false; 407 $column->key = $colFKUnderscore; 408 $column->index = $i++; 409 $groupedColumns['columns'][$group][] = $column; 410 411 $relatedTableName = $colRelatedTable->getName(); 412 break; // stop foreach 413 } 410 414 } 411 415 } … … 560 564 * Returns a sub selection of columnsGrouped 561 565 * 562 * @param string $relatedTable Name the relatedTable (start with the base-table-name)566 * @param string $relatedTableFKs the ForeignKey(s) to the relatedTable 563 567 * @param array() $groupedColumns Hierarchically arranged array with columns 564 568 * @return subSelection of $groupedColumns 565 569 */ 566 public function getSubGroupedColumns($relatedTable Name, $groupedColumns)567 { 568 $currentTable Name = sfInflector::underscore($groupedColumns['pk']->getTable()->getPhpName());569 570 public function getSubGroupedColumns($relatedTableFKs, $groupedColumns) 571 { 572 $currentTableFK = $relatedTableFKs; 573 $nextTableFKs = null; 570 574 // test if relatedTableName contains mainTable name at begin, if so remove it 571 if (false !== strpos($relatedTableName, '/')) 572 { 573 list($firstTableName, $nextTableNames) = explode('/', $relatedTableName, 2); 574 575 if ($currentTableName == $firstTableName) 576 { 577 $relatedTableName = $nextTableNames; 578 } 579 } 580 581 // test if relatedTableName contains mainTable name at begin, if so remove it 582 if (false !== strpos($relatedTableName, '/')) 583 { 584 list($firstTableName, $nextTableNames) = explode('/', $relatedTableName, 2); 585 return $this->getSubGroupedColumns($nextTableNames, $groupedColumns['related'][$firstTableName]); 575 if (false !== strpos($relatedTableFKs, '/')) 576 { 577 list($currentTableFK, $nextTableFKs) = explode('/', $relatedTableFKs, 2); 578 } 579 580 //translate foreign-key-name to table-name 581 $ColFK = $this->getColumnForFieldName($currentTableFK, $groupedColumns['pk']->getTable()->getPhpName().'Peer'); 582 $relatedTableName = $ColFK->getRelatedTableName(); 583 584 // recursion if remaining foreign-keys 585 if ($nextTableFKs) 586 { 587 return $this->getSubGroupedColumns($nextTableFKs, $groupedColumns['related'][$relatedTableName]); 586 588 } 587 589 else … … 599 601 * @return string the FK-name 600 602 */ 601 public function get ForeignKeyToTable($relatedTableName, $groupedColumns)603 public function getOBSOLETEForeignKeyToTable($relatedTableName, $groupedColumns) // WARNING: this is can give wrong results when there are multiple foreign-keys to the same table!!! 602 604 { 603 605 //undefined variable notice thrown in dev environment without this … … 622 624 list($relatedTableName, $relatedRelatedTableName) = explode('/', $relatedTableName, 2); 623 625 //recursion 624 $field = $ currentTableName.'/'.$this->getForeignKeyToTable($relatedRelatedTableName, $groupedColumns['related'][$relatedTableName]);626 $field = $this->getOBSOLETEForeignKeyToTable($relatedRelatedTableName, $groupedColumns['related'][$relatedTableName]); 625 627 } 626 628 else // is directly related to current table … … 750 752 } 751 753 752 $prefix_org = $prefix;753 $prefix .= sfInflector::underscore($groupedColumns['pk']->getTable()->getPhpName()).'/';754 // $prefix_org = $prefix; 755 // $prefix .= sfInflector::underscore($groupedColumns['pk']->getTable()->getPhpName()).'/'; 754 756 755 757 if ($addPK && $returnInvisible) … … 784 786 } 785 787 // Iterate through all its related tables recursively 786 $relatedColumnList = $this->getListRelatedColumns($groupedColumns, $returnInvisible, $groups, $prefix _org);788 $relatedColumnList = $this->getListRelatedColumns($groupedColumns, $returnInvisible, $groups, $prefix); 787 789 $columnList = array_merge($columnList, $relatedColumnList); 788 790 … … 807 809 808 810 // TODO: maybe filter this pk, if there is no matching group in this table, AND in any related tables 809 $prefix .= sfInflector::underscore($groupedColumns['pk']->getTable()->getPhpName()).'/';811 // $prefix .= sfInflector::underscore($groupedColumns['pk']->getTable()->getPhpName()).'/'; 810 812 811 813 … … 813 815 foreach($groupedColumns['related'] as $relatedName => $relatedTable) 814 816 { 815 $relatedColumnList = $this->getListColumns($relatedTable, $returnInvisible, $groups, $prefix, false); 817 //search foreign-key 818 $found = false; 819 $foreign_col = null; 820 foreach($groupedColumns['columns'] as $group) 821 { 822 foreach($group as $adminCol) 823 { 824 if ($adminCol->getRelatedTableName() == $relatedName) 825 { 826 $foreign_col = $adminCol; 827 $found = true; 828 break 2; 829 } 830 } 831 } 832 if (!$found) 833 { 834 throw new Exception("Foreign key not found to table ".$relatedName); 835 } 836 $related_prefix = $prefix.strtolower($foreign_col->getColumnName()).'/'; 837 $relatedColumnList = $this->getListColumns($relatedTable, $returnInvisible, $groups, $related_prefix, false); 816 838 $columnList = array_merge($columnList, $relatedColumnList); 817 839 } … … 960 982 $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 961 983 962 $columnName = $column->key;984 // $checkName = $column->key; 963 985 964 986 // remove base classname for checks (This way you can check on fields like name, instead of product/name) 965 list($class, $checkName) = explode('/', $columnName, 2); 966 if ($class != sfInflector::underscore($this->getClassName())) 967 { 968 $checkName = $columnName; 969 } 970 971 $user_params = $this->getParameterValue($for.'.fields.'.$checkName.'.params'); 987 // list($foreignKey) = explode('/', $columnName, 2); 988 989 $user_params = $this->getParameterValue($for.'.fields.'.$column->key.'.params'); 972 990 $params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params); 973 991 //$params = $user_params ? array_merge($params, $user_params) : $params; 974 992 975 993 // if hidden in edit-pages 976 if (($for == 'edit') && (strtolower($this->getParameterValue('edit.fields.'.$c heckName.'.class', null))=='hidden'))994 if (($for == 'edit') && (strtolower($this->getParameterValue('edit.fields.'.$column->key.'.class', null))=='hidden')) 977 995 { 978 996 return array( 979 997 'class' => 'Hidden', 980 998 'options' => array( 981 'name' => $class.'['.str_replace('/', $tableDelimiter, $checkName).']'999 'name' => str_replace('/', $tableDelimiter, $column->key) 982 1000 ) 983 1001 ); … … 985 1003 986 1004 $groupBy = false; 987 if ($c heckName== $this->getParameterValue('list.grouping.field', null))1005 if ($column->key == $this->getParameterValue('list.grouping.field', null)) 988 1006 { 989 1007 $groupBy = true; … … 1038 1056 // this column contains drop-down Combo-Boxes 1039 1057 // improve like this: http://extjs.com/deploy/dev/examples/form/forum-search.html So you are able to add new values! (although it would be nice to keep the drop-down button at the right, so don't hide the trigger) 1040 if ((false !== strpos($checkName, '/')) && ($groupedColumns!=Array())) 1041 { 1042 $last = strrpos($checkName, '/'); 1043 $relatedTableName = substr($checkName, 0, $last); 1044 $relatedTable = $this->getSubGroupedColumns($relatedTableName, $groupedColumns); 1045 $relatedColumn = $this->getForeignKeyColumnToTable($relatedTableName, $groupedColumns); 1046 $comboName = $class.'['.sfInflector::underscore($relatedTable['pk']->getPhpName()).']'; 1047 1048 //get last related table 1049 if (strrpos($relatedTableName, '/')) 1050 { 1051 $tables = explode('/', $relatedTableName); 1052 $relatedTableName = $tables[count($tables)-1]; 1053 } 1054 1055 $valueFieldCombo = sfInflector::underscore($relatedTableName).$tableDelimiter.sfInflector::underscore($relatedTable['pk']->getPhpName()); 1056 1057 $store = sfInflector::underscore($relatedTableName).'_ds'; 1058 1059 $cbOptions = array('hiddenName' => sfInflector::underscore($relatedTableName).'_'.$column->getName().'_combo', 1060 'name' => sfInflector::underscore($relatedTableName).'_'.$column->getName().'_combo', 1058 if ((false !== strpos($column->key, '/')) && ($groupedColumns!=Array())) 1059 { 1060 // $relatedTable = $this->getSubGroupedColumns($relatedTableFKs, $groupedColumns); 1061 // $relatedFKColumn = $groupedColumns['columns'][$relatedTableFK]; //TODO: groups... 1062 $fields = explode('/', $column->key); 1063 1064 $last = strrpos($column->key, '/'); 1065 $relatedTableFKs = substr($column->key, 0, $last); 1066 $relatedTableGrouped = $this->getSubGroupedColumns($relatedTableFKs, $groupedColumns); 1067 $relatedTablePK = $relatedTableGrouped['pk']; 1068 // $relatedTableName = $this->getTableFromFK($relatedTableFKs); 1069 // $relatedFKColumn = $this->getForeignKeyColumnToTable($relatedTableName, $groupedColumns); 1070 $relatedFKColumn = $this->getColumnForFieldName($fields[0]); 1071 1072 // $comboName = sfInflector::underscore($relatedTable['pk']->getPhpName()); //TODO, don't know if this is desired 1073 1074 // //get last related table 1075 // if (strrpos($relatedTableName, '/')) 1076 // { 1077 // $tables = explode('/', $relatedTableName); 1078 // $relatedTableName = $tables[count($tables)-1]; 1079 // } 1080 1081 //valuefield is the primary-key for the related table 1082 $valueFieldCombo = $relatedTablePK->getTableName().$tableDelimiter.$relatedTablePK->getName(); //sfInflector::underscore($relatedTableName).$tableDelimiter.sfInflector::underscore($relatedTable['pk']->getPhpName()); 1083 $displayFieldCombo = $column->getTableName().$tableDelimiter.$column->getName(); 1084 1085 $store = sfInflector::underscore($column->getTableName()).'_ds'; 1086 1087 $cbOptions = array('hiddenName' => $column->getTableName().'_'.$column->getName().'_combo', 1088 'name' => $column->getTableName().'_'.$column->getName().'_combo', 1061 1089 'valueField' => $valueFieldCombo, 1062 'displayField' => str_replace('/', $tableDelimiter, $checkName),1090 'displayField' => $displayFieldCombo, 1063 1091 'queryParam' => 'filters['.str_replace('/', $tableDelimiter, $column->key).']', 1064 1092 'store' => $store, … … 1066 1094 'lazyRender' => 'true', 1067 1095 1068 'baseTable' => $class.'-',1096 // 'baseTable' => $class.'-', 1069 1097 1070 1098 'showEditor' => 'function(){ 1071 1099 var fields = new Array(); 1072 fields[\''.str_replace('/', $tableDelimiter, $c heckName).'\'] = this.getRawValue();1073 show'.sfInflector::camelize($ relatedTableName).'Editor(fields, this);1100 fields[\''.str_replace('/', $tableDelimiter, $column->getName()).'\'] = this.getRawValue(); 1101 show'.sfInflector::camelize($column->getTableName()).'Editor(fields, this); 1074 1102 }' 1075 1103 … … 1078 1106 1079 1107 //override required check 1080 if ($related Column->isNotNull())1108 if ($relatedFKColumn->isNotNull()) 1081 1109 { 1082 1110 $cbOptions['allowBlank'] = 'false'; … … 1090 1118 { 1091 1119 $cbOptions['allowBlank'] = 'true'; 1092 $cbOptions['blankText'] = '';1120 unset($cbOptions['blankText']); 1093 1121 1094 1122 //reset $option as well 1095 1123 $options['allowBlank'] = 'true'; 1096 $options['blankText'] = ''; 1097 } 1124 unset($options['blankText']); 1125 } 1126 1127 1098 1128 1099 $jsComboBox = extjs_form_combobox($cbOptions);1100 1101 1129 if ($for == 'edit') 1102 1130 { 1103 list($class, $field) = explode('/', $this->getForeignKeyToTable($relatedTableName, $groupedColumns), 2); 1104 $comboName = $class.'['.str_replace('/', $tableDelimiter, $field).']'; 1131 //list($class, $field) = explode('/', $this->getForeignKeyToTable($relatedTableName, $groupedColumns), 2); 1132 $field = str_replace('/', $tableDelimiter, $column->key);//$this->getForeignKeyToTable($relatedTableName, $groupedColumns); 1133 $comboName = $groupedColumns['pk']->getTableName().'['.str_replace('/', $tableDelimiter, $relatedTableFKs).']'; 1105 1134 1106 1135 //add/overwrite some data … … 1118 1147 if ( (isset($params['editable']) && $params['editable']) || (!isset($params['editable']) && sfConfig::get('app_sf_extjs_theme_plugin_list_editable', false)) ) 1119 1148 { 1120 $valueField = str_replace('/', $tableDelimiter, $ this->getForeignKeyToTable($relatedTableName, $groupedColumns));1149 $valueField = str_replace('/', $tableDelimiter, $column->key); //$this->getForeignKeyToTable($column->getTableName(), $groupedColumns) 1121 1150 1122 $definition['dataIndexNew'] = $valueField; 1151 $definition['dataIndexNew'] = str_replace('/', $tableDelimiter, $relatedTableFKs); 1152 1153 $jsComboBox = extjs_form_combobox($cbOptions); 1154 1123 1155 $definition['editor'] = $jsComboBox; 1124 1156 } 1125 $rendererName = ucfirst(str_replace('/', $tableDelimiter, $relatedTableName)).ucfirst($column->getName());1157 $rendererName = sfInflector::camelize(str_replace('/', '_', $column->key)); 1126 1158 $definition['renderer'] = 'render'.$rendererName.'Field'; 1127 1159 } … … 1241 1273 else if ($column->isPartial() && ($for =='edit')) 1242 1274 { 1243 $options['partname'] = $c heckName;1244 return array('class' => 'Partial', 'options' => $options, 'partname' => $c heckName);1275 $options['partname'] = $column->key; 1276 return array('class' => 'Partial', 'options' => $options, 'partname' => $column->key); 1245 1277 } 1246 1278 else … … 1289 1321 } 1290 1322 1291 /* This method overwrites the original method and adds the argument $peerName to it 1292 */ 1293 public function getAdminColumnForField($field, $flag = null, $peerName = null) 1294 { 1295 $phpName = sfInflector::camelize($field); 1296 1297 //not working 1298 /*$fields = explode('/', $field); 1299 $pointer = count($fields) - 1; 1300 1301 $phpName = sfInflector::camelize($fields[$pointer--]); 1302 while ($pointer >= 0 ) 1303 { 1304 $phpName = $this->getTableMap()->getDatabaseMap()->getTable($fields[$pointer--])->getPhpName().'::'.$phpName; 1305 }*/ 1306 1307 return new sfAdminColumn($phpName, $this->getColumnForPhpName($phpName, $peerName), $flag); 1308 } 1309 1310 /* This method overwrites the original method and adds the argument $peerName to it 1323 /* This method overwrites the original method so it can handle foreign-keys in the fieldname 1324 */ 1325 public function getAdminColumnForField($field, $flag = array(), $peerName = null) 1326 { 1327 1328 //re-disabled ;) 1329 //$phpName = sfInflector::camelize($field); 1330 1331 //Re-enabled 1332 $fields = explode('/', $field); 1333 1334 $lastPeerClassName = $this->getPeerClassName(); 1335 if ($peerName) 1336 { 1337 $lastPeerClassName = $peerName; 1338 } 1339 $phpName = ""; 1340 1341 if (!in_array('_', $flag)) // no-partial 1342 { 1343 //get PHP-name for (all) foreign tables (from foreign-key) 1344 for ($i = 0; $i < count($fields); $i++) 1345 { 1346 $currentField = $fields[$i]; 1347 $tableMap = call_user_func(array($lastPeerClassName, 'getTableMap')); 1348 // search the matching column for this key 1349 $found = false; 1350 foreach ($tableMap->getColumns() as $column) 1351 { 1352 if ($column->getColumnName() == strtoupper($currentField)) // TODO not tested if strtoupper is always correct, maybe both strtoupper... 1353 { 1354 $found = true; 1355 break; 1356 } 1357 } 1358 1359 if (!$found) 1360 { 1361 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)); 1362 } 1363 1364 if ($i != count($fields) - 1) 1365 { 1366 $relatedTableName = $column->getRelatedTableName(); 1367 $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 1368 1369 $phpName .= $relatedTable->getPhpName().'::'; 1370 1371 $lastPeerClassName = $relatedTable->getPhpName().'Peer'; 1372 } 1373 else 1374 { 1375 $phpName .= $column->getPhpName(); 1376 } 1377 } 1378 } 1379 else //partial 1380 { 1381 $phpName .= sfInflector::camelize($field); 1382 } 1383 1384 return new sfAdminColumn($phpName, $this->getColumnForPhpName($phpName, $lastPeerClassName), $flag); 1385 } 1386 1387 /* This method overwrites the original method, so it can handle phpNames containing classNames 1311 1388 * 1312 1389 * returns a column phpName or null if none was found … … 1314 1391 public function getColumnForPhpName($phpName, $peerName = null) 1315 1392 { 1316 // the base peerName will be this->PeerName 1393 //strip 1394 $fields = explode('::', $phpName); 1395 $phpName = $fields[count($fields) - 1]; 1396 1317 1397 if ($peerName == null) 1318 1398 { … … 1320 1400 } 1321 1401 1322 $tableMap = call_user_func(array($peerName, 'getTableMap')); 1323 1324 // search the matching column for this column name 1325 1402 if (count($fields)>1) 1403 { 1404 $className = $fields[count($fields) - 2]; 1405 $peerName = $className."Peer"; 1406 } 1407 1408 $tableMap = call_user_func(array($peerName, 'getTableMap')); 1409 1410 // search the matching column for this PHPname 1326 1411 foreach ($tableMap->getColumns() as $column) 1327 1412 { 1328 1413 if ($column->getPhpName() == $phpName) 1329 1414 { 1330 $found = true;1331 1332 1415 return $column; 1333 1416 } 1334 1417 } 1335 1418 1336 // not a "real" column, so we will simulate one1419 // not a "real" column, so we return null 1337 1420 return null; 1338 1421 } 1339 1422 1423 /* This method returns the column from its (relative) fieldname 1424 * relative by providing foreign-keys 1425 * 1426 * returns the column from this (relative) fieldname 1427 */ 1428 public function getColumnForFieldName($fieldName, $peerName = null) 1429 { 1430 if ($peerName == null) 1431 { 1432 $peerName = $this->getPeerClassName(); 1433 } 1434 $tableMap = call_user_func(array($peerName, 'getTableMap')); 1435 1436 // recursion needed? 1437 if (false !== strpos($fieldName, '/')) 1438 { 1439 list($firstFieldName, $nextFieldNames) = explode('/', $fieldName, 2); 1440 1441 foreach ($tableMap->getColumns() as $column) 1442 { 1443 if ($column->getColumnName() == strtoupper($firstFieldName)) 1444 { 1445 $relatedTableName = $column->getRelatedTableName(); 1446 $relatedTable = $this->getMap()->getDatabaseMap()->getTable($relatedTableName); 1447 1448 $peerName = $relatedTable->getPhpName().'Peer'; 1449 return $this->getColumnForFieldName($nextFieldNames, $peerName); 1450 } 1451 } 1452 } 1453 // find and return column form current table 1454 else 1455 { 1456 // search the matching column for this PHPname 1457 foreach ($tableMap->getColumns() as $column) 1458 { 1459 if ($column->getColumnName() == strtoupper($fieldName)) 1460 { 1461 return $column; 1462 } 1463 } 1464 } 1465 1466 // column not found in this table, so we return null 1467 throw new Exception('field "'.$fieldName.'" not found in Peer "'.$peerName.'"'); 1468 return null; 1469 } 1470 1340 1471 public function getTableName($underscore = true) 1341 1472 {

