Changeset 7216
- Timestamp:
- 01/29/08 18:52:12 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/actions/actions.class.php
r7214 r7216 10 10 * @version SVN: $Id: actions.class.php 3501 2007-02-18 10:28:17Z fabien $ 11 11 */ 12 <?php 13 $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 14 ?> 15 12 16 class <?php echo $this->getGeneratedModuleName() ?>Actions extends sfActions 13 17 { … … 21 25 * this function does not affect the user-session, so sorting and your filters keep working 22 26 */ 23 public function executeJson ListAutocomplete()27 public function executeJsonAutocomplete() 24 28 { 25 29 // Require class 26 30 if (!$this->hasRequestParameter('class')) 27 31 { 28 throw new sfException(sprintf('Error, the Json ListAutocomplete page requires a class-name as argument'));32 throw new sfException(sprintf('Error, the JsonAutocomplete page requires a class-name as argument')); 29 33 } 30 34 $class = sfInflector::camelize($this->getRequestParameter('class')); … … 36 40 37 41 // filter, define namespace to autocomplete, to not disturb normal filters of this module 38 $this->processFilters("autocomplete"); 39 40 <?php if ($this->getParameterValue('list.filters')): ?> 42 $namespace = "autocomplete"; 43 $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 44 $this->processFilters($namespace); 45 41 46 $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/autocomplete/filters'); 42 <?php endif; ?>43 44 47 45 48 // pager … … 58 61 } 59 62 60 61 public function executeJsonList() 63 //seperate JSON-lists for every list, edit and edit.page -pages 64 <?php 65 $for = array('list'); 66 if ($this->getParameterValue('edit.display', null) || !$this->getParameterValue('edit.pages', null)) { 67 $for[] = 'edit'; 68 } 69 70 $edit_pages = $this->getParameterValue('edit.pages', array()); 71 72 foreach ($edit_pages as $pageName => $page) 73 { 74 $for[] = 'edit.pages.'.$pageName; 75 } 76 77 foreach($for as $page): 78 $page_name = ucFirst(sfInflector::camelize(str_replace('.','_', $page))); 79 ?> 80 public function executeJson<?php echo $page_name ?>() 62 81 { 63 82 $limit = $this->getRequestParameter('limit', <?php echo $this->getParameterValue('list.max_per_page', sfConfig::get('app_sf_extjs_theme_plugin_list_max_per_page', 20)) ?>); 64 83 $page = floor($this->getRequestParameter('start', 0) / $limit)+1; 84 85 $this->for = '<?php echo str_replace('.', '_', $page) ?>'; 65 86 66 87 $this->processSort(strtolower($this->getRequestParameter('dir'))); 67 88 68 $this->processFilters(); 69 70 <?php if ($this->getParameterValue('list.filters')): ?>89 $this->processFilters(); //TODO: maybe set namespace to pagename... 90 91 <?php //if ($this->getParameterValue('list.filters')): ?> 71 92 $this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/filters'); 72 <?php endif; ?>93 <?php //endif; ?> 73 94 74 95 // pager 75 96 $this->pager = new sfPropelPager('<?php echo $this->getClassName() ?>', $limit); 76 97 $c = new Criteria(); 77 <?php //if ($fields = $this->getParameterValue('list.fields')): ?> 78 <?php //foreach ($fields as $key => $field): ?> 79 <?php //if ($join_fields = $this->getParameterValue('list.fields.'.$key.'.join_fields')): ?> 80 //$c->addJoin(<?//=$join_fields[0]?>,<?//=$join_fields[1]?>); 81 <?php //endif; ?> 82 <?php //endforeach; ?> 83 <?php //endif; ?> 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]; 109 } 110 111 try 112 { 113 $fieldName = call_user_func(array($className.'Peer', 'translateFieldName'), $sortColumn, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME); 114 } 115 catch (Exception $e) 116 { 117 // sort column does not exist, throw error 118 throw new sfException(sprintf('Cannot sort on column "%s", the column does not exist. Clearing your cookies will (temporarily) fix this error.', $sortColumn)); 119 } 120 ?> 121 // first sort on group-by column 122 // TODO: this can be enhanced with options for the generator.yml file. 123 $c->addAscendingOrderByColumn('<?php echo $fieldName ?>'); 124 <?php endif; ?> 84 125 $this->addSortCriteria($c); 85 126 $this->addFiltersCriteria($c); … … 87 128 $this->pager->setPage($page); 88 129 <?php $peerMethod = $this->getParameterValue('list.peer_method') ? $this->getParameterValue('list.peer_method') : 'doSelectJoinAll'; 89 if (is_callable(array($this->get ClassName().'Peer', $peerMethod))): ?>130 if (is_callable(array($this->getPeerClassName(), $peerMethod))): ?> 90 131 $this->pager->setPeerMethod('<?php echo $peerMethod ?>'); 91 132 <?php endif; ?> 92 133 93 134 <?php $peerCountMethod = $this->getParameterValue('list.peer_count_method') ? $this->getParameterValue('list.peer_count_method') : 'doCountJoinAll'; 94 if (is_callable(array($this->get ClassName().'Peer', $peerCountMethod))): ?>135 if (is_callable(array($this->getPeerClassName(), $peerCountMethod))): ?> 95 136 $this->pager->setPeerCountMethod('<?php echo $peerCountMethod ?>'); 96 137 <?php endif; ?> 97 138 $this->pager->init(); 98 139 99 // $this->setLayout(false); 100 // sfConfig::set('sf_web_debug', false); 101 } 102 103 <?php 104 $columns = $this->getColumnsGroup(); 105 if (isset($columns['related'])): 106 foreach ($columns['related'] as $class => $relatedColumns): 107 $className = sfInflector::camelize($class); 108 ?> 109 public function executeJsonList<?php echo $class ?>() 110 { 111 //connect extjs to symfony 112 $limit = $this->getRequestParameter('limit', 10); 113 114 // pager 115 $this->pager = new sfPropelPager('<?php echo $className ?>', $limit); 116 $c = new Criteria(); 117 $this->pager->setCriteria($c); 118 $this->pager->setPage(1); 119 $this->pager->init(); 120 121 $this->setLayout(false); 122 sfConfig::set('sf_web_debug', false); 123 124 $render = ' 125 {totalCount:"'.$this->pager->getNbResults().'", data:[ 126 '; 127 $i = 0; 128 foreach ($this->pager->getResults() as $result) 129 { 130 if ($i > 0) $render .= ', '; 131 <?php 132 $pkName = $relatedColumns['pk']->getName(); 133 $pkMethod = 'get'.sfInflector::camelize($pkName); 134 ?> 135 $render .= '{ "<?php echo $pkName ?>": "'.$result-><?php echo $pkMethod ?>().'", '; 136 <?php $j = 0; foreach ($relatedColumns['columns'] as $col): 137 $colName = $col->getName(); 138 $colMethod = 'get'.sfInflector::camelize($colName); 139 ?> 140 <?php if ($j > 0): ?>$render .= ', ';<?php endif; ?> 141 $render .= ' "<?php echo $colName ?>": "'.$result-><?php echo $colMethod ?>().'"'; 142 <?php $j++; endforeach; ?> 143 $render .= ' }'; 144 $i++; 145 } 146 $render .= ' 147 ]}'; 148 149 return $this->renderText($render); 150 } 151 <?php endforeach; ?> 152 <?php endif; ?> 153 140 $this->setLayout(false); 141 sfConfig::set('sf_web_debug', false); 142 $this->setTemplate('json'); 143 } 144 <?php endforeach; ?> 145 146 public function executeListPrint() 147 { 148 $this->executeList(); 149 150 $this->print = true; 151 152 $this->setLayout(false); // TODO: set to a print layout... 153 sfConfig::set('sf_web_debug', false); 154 $this->setTemplate('list'); 155 } 154 156 155 157 public function executeList() … … 169 171 <?php foreach ($fields as $key => $field): ?> 170 172 <?php if ($join_fields = $this->getParameterValue('list.fields.'.$key.'.join_fields')): ?> 171 $c->addJoin(<? =$join_fields[0]?>,<?=$join_fields[1]?>);173 $c->addJoin(<?php echo $join_fields[0]?>,<?php echo $join_fields[1]?>); 172 174 <?php endif; ?> 173 175 <?php endforeach; ?> … … 184 186 <?php endif; ?> 185 187 $this->pager->init(); 188 189 190 <?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 191 $this->setTemplate('listAjax'); 192 <?php endif; ?> 193 186 194 } 187 195 … … 196 204 } 197 205 198 public function executeAjaxSave() 199 { 206 public function executeAjaxEdit() 207 { 208 // Check if retreiving instead of saving... 209 if ($this->getRequest()->hasParameter('filter')) 210 { 211 return $this->forward('<?php echo $this->getModuleName() ?>', 'jsonList'); 212 } 213 200 214 $this-><?php echo $this->getSingularName() ?> = $this->get<?php echo $this->getClassName() ?>OrCreate(); 201 215 202 $request = array(); 203 $fieldName = ''; 204 if ($field = $this->getRequestParameter('field')) 205 { 206 $fieldsName = $this->getFields(); 207 $fieldName = array_search($field, $fieldsName); 216 if ($fieldName = $this->getRequestParameter('field')) 217 { 208 218 $value = $this->getRequestParameter('value'); 209 219 … … 212 222 else 213 223 { 214 $this->update<?php echo $this->getClassName() ?>FromRequest( $request);224 $this->update<?php echo $this->getClassName() ?>FromRequest(); 215 225 } 216 226 217 227 $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 218 228 229 $this->setLayout(false); 230 sfConfig::set('sf_web_debug', false); 219 231 return $this->renderText('{ success: true, message: "Your modifications have been saved" }'); 220 232 } … … 251 263 252 264 <?php if ($this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?> 253 //if (!$this->getRequest()->isXmlHttpRequest())254 //{255 $this->setLayout(false); // TODO: maybe set to specific ajax layout256 //}257 sfConfig::set('sf_web_debug', false);265 if ($this->getRequest()->isXmlHttpRequest()) 266 { 267 $this->setLayout(false); 268 sfConfig::set('sf_web_debug', false); 269 } 258 270 return 'AjaxSuccess'; 259 271 <?php endif; ?> … … 263 275 public function executeDelete() 264 276 { 265 $this-><?php echo $this->getSingularName() ?> = <?php echo $this->get ClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>);277 $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(40) ?>); 266 278 $this->forward404Unless($this-><?php echo $this->getSingularName() ?>); 267 279 … … 291 303 <?php endforeach; ?> 292 304 <?php if(! ($deleteNotification = $this->getParameterValue('edit.delete_notification'))) $deleteNotification = 'The '.$this->getModuleName().' has been deleted' ?> 293 $this->setFlash('notice', '<?= $deleteNotification ?>'); 294 305 $this->setFlash('notice', '<?php echo $deleteNotification ?>'); 295 306 296 307 return $this->redirect('<?php echo $this->getModuleName() ?>/list'); … … 317 328 318 329 <?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 319 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> 330 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?> 331 <?php $type = $column->getCreoleType() ?> 320 332 <?php $name = $column->getName() ?> 321 333 <?php if ($column->isPrimaryKey()) continue ?> … … 380 392 protected function update<?php echo $this->getClassName() ?>ListFromRequest($columnName, $columnValue) 381 393 { 382 <?php $columns = $this->getColumns('list.display'); ?> 383 <?php foreach ($columns as $column): $type = $column->getCreoleType(); ?> 384 <?php $name = $column->getName(); ?> 385 <?php if ($column->isPrimaryKey()) continue ?> 386 <?php if (false !== strpos($name, '/')) continue; // TODO: at the moment cannot handle foreign fields ?> 387 388 if ($columnName == '<?php echo $column->getName() ?>') 389 { 390 <?php $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials') ?> 394 <?php 395 $groupedColumns = $this->getColumnsGrouped('list.display'); 396 $columns = $this->getListUniqueColumns($groupedColumns, true); 397 398 $tableName = $this->getTableName(); 399 $first = true; 400 401 foreach ($columns as $column): 402 403 $columnName = $column->key; 404 list($class, $checkName) = explode('/',$columnName, 2); 405 406 if (strtolower($class) != strtolower($tableName)) 407 { 408 $checkName = $columnName; 409 } 410 411 if ($column->isPrimaryKey()) continue; 412 if (false !== strpos($checkName, '/')) continue; // TODO: at the moment cannot handle foreign fields 413 414 $type = $column->getCreoleType(); 415 ?> 416 <?php echo !$first ? 'else' : '' ?>if ($columnName == '<?php echo str_replace('/', $tableDelimiter, $column->key) ?>') 417 { 418 <?php $credentials = $this->getParameterValue('list.fields.'.$checkName.'.credentials') ?> 391 419 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 392 420 if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) … … 394 422 <?php endif; ?> 395 423 <?php if ($type != CreoleTypes::BOOLEAN): ?> 396 if (isset($columnValue))397 {424 if (isset($columnValue)) 425 { 398 426 <?php endif; ?> 399 427 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 400 if ($columnValue) 401 { 402 try 403 { 404 $dateFormat = new sfDateFormat($this->getUser()->getCulture()); 405 <?php $inputPattern = $type == CreoleTypes::DATE ? 'd' : 'g'; ?> 406 <?php $outputPattern = $type == CreoleTypes::DATE ? 'i' : 'I'; ?> 407 if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'])) 428 if ($columnValue) 429 { 430 try 408 431 { 409 $value = $dateFormat->format($columnValue, '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>')); 432 $dateFormat = new sfDateFormat($this->getUser()->getCulture()); 433 <?php $inputPattern = $type == CreoleTypes::DATE ? 'd' : 'g'; ?> 434 <?php $outputPattern = $type == CreoleTypes::DATE ? 'i' : 'I'; ?> 435 //TODO : check $columnName below, this was $name, but this was obviously wrong! I don't know if $columnName is correct here.. 436 if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $columnName ?>'])) 437 { 438 $value = $dateFormat->format($columnValue, '<?php echo $outputPattern ?>', $dateFormat->getInputPattern('<?php echo $inputPattern ?>')); 439 } 440 else 441 { 442 $value_array = $columnValue; 443 $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : ''); 444 } 445 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($value); 410 446 } 411 else447 catch (sfException $e) 412 448 { 413 $value_array = $columnValue; 414 $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : ''); 449 // not a date 415 450 } 416 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($value); 417 } 418 catch (sfException $e) 419 { 420 // not a date 421 } 422 } 423 else 424 { 425 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(null); 426 } 451 } 452 else 453 { 454 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(null); 455 } 427 456 <?php elseif ($type == CreoleTypes::BOOLEAN): ?> 428 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0);457 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue == 'true' ? 1 : 0); 429 458 <?php elseif ($column->isForeignKey()): ?> 430 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null);431 <?php else: ?> 432 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue);459 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue); //save foreign-key 460 <?php else: ?> 461 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($columnValue); 433 462 <?php endif; ?> 434 463 <?php if ($type != CreoleTypes::BOOLEAN): ?> 435 }464 } 436 465 <?php endif; ?> 437 466 <?php if ($credentials): ?> 438 } 439 <?php endif; ?> 440 } 441 <?php endforeach; ?> 467 } 468 <?php endif; ?> 469 } 470 471 <?php $first = false; endforeach; ?> 442 472 } 443 473 … … 446 476 $<?php echo $this->getSingularName() ?> = $this->getRequestParameter('<?php echo $this->getSingularName() ?>'); 447 477 448 <?php foreach ($this->getColumnCategories('edit.display') as $category): ?> 449 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): $type = $column->getCreoleType(); ?> 450 <?php $name = $column->getName() ?> 451 <?php if ($column->isPrimaryKey()) continue ?> 452 <?php if (false !== strpos($name, '/')) continue; // TODO: at the moment cannot handle foreign fields ?> 453 454 <?php $credentials = $this->getParameterValue('edit.fields.'.$column->getName().'.credentials') ?> 455 <?php $input_type = $this->getParameterValue('edit.fields.'.$column->getName().'.type') ?> 456 <?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 478 <?php 479 $groupedColumns = $this->getColumnsGrouped('edit.display'); 480 $columns = $this->getListUniqueColumns($groupedColumns, true); 481 $tableName = $this->getTableName(); 482 483 foreach ($columns as $column): 484 list($class, $checkName) = explode('/', $column->key, 2); 485 486 if (strtolower($class) != strtolower($tableName)) 487 { 488 $checkName = $columnName; 489 } 490 491 if ($column->isPrimaryKey()) continue; 492 if (false !== strpos($checkName, '/')) continue; // TODO: at the moment cannot handle foreign fields 493 494 $type = $column->getCreoleType(); 495 $name = str_replace('/', $tableDelimiter, $checkName); 496 497 $credentials = $this->getParameterValue('edit.fields.'.$checkName.'.credentials'); 498 $input_type = $this->getParameterValue('edit.fields.'.$checkName.'.type'); 499 500 ?> 501 <?php 502 if ($credentials): 503 $credentials = str_replace("\n", ' ', var_export($credentials, true)) 504 ?> 457 505 if ($this->getUser()->hasCredential(<?php echo $credentials ?>)) 458 506 { 459 507 <?php endif; ?> 460 508 <?php if ($input_type == 'admin_input_file_tag'): ?> 461 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$c olumn->getName().'.upload_dir')) ?>509 <?php $upload_dir = $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.upload_dir')) ?> 462 510 $currentFile = sfConfig::get('sf_upload_dir')."/<?php echo $upload_dir ?>/".$this-><?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>(); 463 511 if (!$this->getRequest()->hasErrors() && isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>_remove'])) … … 477 525 <?php endif; ?> 478 526 <?php if ($input_type == 'admin_input_file_tag'): ?> 479 <?php if ($this->getParameterValue('edit.fields.'.$c olumn->getName().'.filename')): ?>480 $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$c olumn->getName().'.filename'))) ?>";527 <?php if ($this->getParameterValue('edit.fields.'.$checkName.'.filename')): ?> 528 $fileName = "<?php echo str_replace('"', '\\"', $this->replaceConstants($this->getParameterValue('edit.fields.'.$checkName.'.filename'))) ?>"; 481 529 <?php else: ?> 482 530 $fileName = md5($this->getRequest()->getFileName('<?php echo $this->getSingularName() ?>[<?php echo $name ?>]').time().rand(0, 99999)); … … 518 566 } 519 567 <?php elseif ($type == CreoleTypes::BOOLEAN): ?> 520 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']) ? ($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] == 'on' ? 1 : 0) : 0);568 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>(isset($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']) ? ($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] == 'on' ? 1 : 0) : 0); 521 569 <?php elseif ($column->isForeignKey()): ?> 522 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null); 523 <?php else: ?> 524 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 570 // $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] ? $<?php echo $this->getSingularName() ?>['<?php echo $name ?>'] : null); 571 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 572 <?php else: ?> 573 $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($<?php echo $this->getSingularName() ?>['<?php echo $name ?>']); 525 574 <?php endif; ?> 526 575 <?php if ($type != CreoleTypes::BOOLEAN): ?> … … 531 580 <?php endif; ?> 532 581 <?php endforeach; ?> 533 <?php endforeach; ?>534 582 } 535 583 … … 542 590 else 543 591 { 544 $<?php echo $this->getSingularName() ?> = <?php echo $this->get ClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>);592 $<?php echo $this->getSingularName() ?> = <?php echo $this->getPeerClassName() ?>::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForGetOrCreate() ?>); 545 593 546 594 $this->forward404Unless($<?php echo $this->getSingularName() ?>); … … 552 600 protected function processFilters($namespace = "<?php echo $this->getSingularName() ?>") 553 601 { 602 if ($this->getRequest()->hasParameter('filter')) 603 { 604 $filters = $this->getRequestParameter('filters'); 605 554 606 <?php if ($this->getParameterValue('list.filters')): ?> 555 if ($this->getRequest()->hasParameter('filter'))556 {557 $filters = $this->getRequestParameter('filters');558 607 <?php foreach ($this->getColumns('list.filters') as $column): $type = $column->getCreoleType() ?> 559 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?>608 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): //TODO replace $column->getName with $checkName ?> 560 609 if (isset($filters['<?php echo $column->getName() ?>']['from']) && $filters['<?php echo $column->getName() ?>']['from'] !== '') 561 610 { … … 568 617 <?php endif; ?> 569 618 <?php endforeach; ?> 619 <?php endif; ?> 570 620 571 621 /* reset Multi-sort // TODO, this should be done somewhere else, … … 586 636 $this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/'.$namespace.'/filters'); 587 637 } 588 <?php endif; ?>589 638 } 590 639 … … 648 697 protected function addFiltersCriteria($c, $namespace = '<?php echo $this->getSingularName() ?>') 649 698 { 650 <?php if ($this->getParameterValue('list.filters') || $this->getParameterValue('list.display')): ?> 651 <?php $columns = array_merge($this->getColumns('list.filters'), $this->getColumns('list.display')) ?> 699 <?php 700 // filtering is also used for drop-down combo-box filtering and retreiving json-data for edit-pages! 701 $for = array('list.filters', 'list.display', 'edit.display'); 702 $groupedColumns = $this->getColumnsGrouped($for, false); 703 704 $pk = clone($groupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 705 $pk->key = strtolower($pk->getTableName().'/'.$pk->getName()); 706 707 $columns = array(); 708 $columns[] = $pk; // add primary key 709 // add primary keys of related classes 710 foreach ($groupedColumns['related'] as $relatedTable => $relatedGroupedColumns) 711 { 712 $pkr = clone($relatedGroupedColumns['pk']); //copy by value, you don't want to add $pk->key to groupedColumns['pk'] 713 $pkr->key = strtolower($pk->getTableName().'/'.$pkr->getTableName().'/'.$pkr->getName()); 714 715 $columns[] = $pkr; // add related primary key 716 } 717 // add default keys below PKs 718 $columns = array_merge($columns, $this->getListUniqueColumns($groupedColumns, false)); 719 720 ?> 652 721 <?php foreach ($columns as $column):?> 653 722 <?php $type = $column->getCreoleType() ?> 654 <?php if (($column->isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue ?> 655 if (isset($this->filters['<?php echo $column->getName() ?>_is_empty'])) 656 { 657 $criterion = $c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, ''); 658 $criterion->addOr($c->getNewCriterion(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, null, Criteria::ISNULL)); 723 <?php 724 $peerClassName = $this->getPeerClassName(); 725 if (false !== strpos($column->key, '/')) 726 { 727 $parts = explode('/', $column->key); 728 $peer = $parts[count($parts)-2]; 729 $peerClassName = sfInflector::camelize($peer).'Peer'; 730 } 731 $columnName = strtoupper($column->getName()); 732 ?> 733 <?php if (($column->isPartial() || $column->isComponent()) && $this->getParameterValue('list.fields.'.$column->getName().'.filter_criteria_disabled')) continue; ?> 734 <?php if (!$column->isPrimaryKey()): ?> 735 if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>_is_empty'])) 736 { 737 $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, ''); 738 $criterion->addOr($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, null, Criteria::ISNULL)); 659 739 $c->add($criterion); 660 740 } 741 else 742 <?php endif; ?> 661 743 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 662 else if (isset($this->filters['<?php echo $column->getName() ?>']))663 { 664 if (isset($this->filters['<?php echo $column->getName() ?>']['from']) && $this->filters['<?php echo $column->getName() ?>']['from'] !== '')744 if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'])) 745 { 746 if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from'] !== '') 665 747 { 666 748 <?php if ($type == CreoleTypes::DATE): ?> 667 $criterion = $c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['from']), Criteria::GREATER_EQUAL);668 <?php else: ?> 669 $criterion = $c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['from'], Criteria::GREATER_EQUAL);670 <?php endif; ?> 671 } 672 if (isset($this->filters['<?php echo $column->getName() ?>']['to']) && $this->filters['<?php echo $column->getName() ?>']['to'] !== '')749 $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from']), Criteria::GREATER_EQUAL); 750 <?php else: ?> 751 $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['from'], Criteria::GREATER_EQUAL); 752 <?php endif; ?> 753 } 754 if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'] !== '') 673 755 { 674 756 if (isset($criterion)) 675 757 { 676 758 <?php if ($type == CreoleTypes::DATE): ?> 677 $criterion->addAnd($c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['to']), Criteria::LESS_EQUAL));678 <?php else: ?> 679 $criterion->addAnd($c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['to'], Criteria::LESS_EQUAL));759 $criterion->addAnd($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']), Criteria::LESS_EQUAL)); 760 <?php else: ?> 761 $criterion->addAnd($c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'], Criteria::LESS_EQUAL)); 680 762 <?php endif; ?> 681 763 } … … 683 765 { 684 766 <?php if ($type == CreoleTypes::DATE): ?> 685 $criterion = $c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, date('Y-m-d', $this->filters['<?php echo $column->getName() ?>']['to']), Criteria::LESS_EQUAL);686 <?php else: ?> 687 $criterion = $c->getNewCriterion(<?php echo $ this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, $this->filters['<?php echo $column->getName() ?>']['to'], Criteria::LESS_EQUAL);767 $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, date('Y-m-d', $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to']), Criteria::LESS_EQUAL); 768 <?php else: ?> 769 $criterion = $c->getNewCriterion(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']['to'], Criteria::LESS_EQUAL); 688 770 <?php endif; ?> 689 771 } … … 696 778 } 697 779 <?php else: ?> 698 else if (isset($this->filters['<?php echo $column->getName() ?>']) && $this->filters['<?php echo $column->getName() ?>'] !== '')780 if (isset($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']) && $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'] !== '') 699 781 { 700 782 <?php if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::LONGVARCHAR): ?> 701 783 $q = ''; 702 784 if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 703 $c->add(<?php echo $this->getPeerClassName() ?>::<?php echo strtoupper($column->getName()) ?>, strtr($this->filters['<?php echo $column->getName() ?>'].$q, '*', '%'), Criteria::LIKE); 704 <?php else: ?> 705 <?php 706 $columnName = $column->getName(); 707 $peer = $this->getPeerClassName(); 708 if (false !== strpos($columnName, '/')) 709 { 710 list($peer, $columnName) = explode('/', $columnName, 2); 711 } 712 ?> 785 $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, strtr($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'].$q, '*', '%'), Criteria::LIKE); 786 <?php else: ?> 787 <?php if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::LONGVARCHAR): ?> 713 788 $q = ''; 714 789 if ($this->getRequest()->getParameter('filter') == 'query') $q = '%'; 715 $c->add('<?php echo $peer ?>.<?php echo strtoupper($columnName) ?>', strtr($this->filters['<?php echo $column->getName() ?>'].$q, '*', '%'), Criteria::LIKE); 716 <?php endif; ?> 717 } 718 <?php endif; ?> 719 <?php endforeach; ?> 720 <?php endif; ?> 790 $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, strtr($this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>'].$q, '*', '%'), Criteria::LIKE); 791 <?php else: ?> 792 $c->add(<?php echo $peerClassName ?>::<?php echo $columnName ?>, $this->filters['<?php echo str_replace('/', $tableDelimiter, $column->key) ?>']); 793 <?php endif; ?> 794 <?php endif; ?> 795 } 796 <?php endif; ?> 797 <?php endforeach; ?> 721 798 } 722 799 … … 725 802 $sort_array = $this->getUser()->getAttributeHolder()->getAll('sf_admin/<?php echo $this->getSingularName() ?>/sort'); 726 803 $tableDelimiter = sfConfig::get('app_sf_extjs_theme_plugin_table_delimiter', '-'); 727 $fieldSufix = sfConfig::get('app_sf_extjs_theme_plugin_field_suffix', '');728 804 729 805 if ($sort_array) // if sort-columns are set … … 732 808 foreach($sort_array as $sort_column => $sort_type) 733 809 { 810 //strange construction!? AND Note there is also something like: $this->getPeerClassName() 734 811 $className = '<?php echo $this->getClassName() ?>'; 735 812 736 813 //fix for cookie error 814 $sortColumn = $sort_column; 737 815 if (false !== strpos($sort_column, $tableDelimiter)) 738 816 { 739 list($className, $sortColumn) = explode($tableDelimiter, $sort_column); 817 $elements = explode($tableDelimiter, $sort_column); 818 $className = $elements[count($elements)-2]; 819 $sortColumn = $elements[count($elements)-1]; 740 820 $className = sfInflector::camelize($className); 741 821 } 742 $sortColumn = str_replace(sfInflector::underscore($className).'-', '', $sort_column);822 //$sortColumn = str_replace(sfInflector::underscore($className).$tableDelimiter, '', $sort_column); 743 823 744 824 try … … 775 855 } 776 856 777 protected function get Fields()857 protected function getLabels() 778 858 { 779 859 return array( 780 <?php $fields = $this->getFieldsProperties(); 781 $fieldsName = $fields['names']; 782 foreach ($fieldsName as $name => $fieldName): ?> 783 '<?php echo $name ?>' => '<?php echo $fieldName ?>', 860 <?php 861 $groupedColumns = $this->getColumnsGrouped('edit.display'); 862 $columns = $this->getListUniqueColumns($groupedColumns, true); 863 $tableName = $this->getTableName(); 864 865 foreach ($columns as $columnName => $column) : 866 $columnName = $column->key; 867 868 list($class, $checkName) = explode('/', $columnName, 2); 869 870 if (strtolower($class) != strtolower($tableName)) 871 { 872 $class = strtolower($tableName); 873 $checkName = $columnName; 874 } 875 876 $fieldName = str_replace('/', $tableDelimiter, $columnName); 877 878 $labelName = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$checkName.'.name')); 879 ?> 880 '<?php echo $fieldName ?>' => '<?php echo $labelName ?>', 784 881 <?php endforeach; ?> 785 882 ); 786 883 } 787 788 protected function getLabels()789 {790 return array(791 <?php foreach ($this->getColumnCategories('edit.display') as $category): ?>792 <?php foreach ($this->getColumns('edit.display', $category) as $name => $column): ?>793 '<?php echo $this->getSingularName() ?>{<?php echo $column->getName() ?>}' => '<?php $label_name = str_replace("'", "\\'", $this->getParameterValue('edit.fields.'.$column->getName().'.name')); echo $label_name ?>',794 <?php endforeach; ?>795 <?php endforeach; ?>796 );797 }798 884 }