Changeset 6882
- Timestamp:
- 01/02/08 09:27:53 (10 months ago)
- Files:
-
- branches/1.1/lib/generator/sfAdminGenerator.class.php (modified) (1 diff)
- branches/1.1/lib/generator/sfCrudGenerator.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/skeleton/config/generator.yml (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/actions/actions.class.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/editSuccess.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/indexSuccess.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/listSuccess.php (deleted)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/showSuccess.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateCrudTask.class.php (modified) (5 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/lib/task/sfPropelInitCrudTask.class.php (deleted)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/browseTest.php (modified) (4 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud1Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud2Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud3Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud4Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud5Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud6Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud7Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud8Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crud9Test.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crud/crudBrowser.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/crudTest.php (deleted)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/crud/modules/simple (deleted)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema.xml (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema.yml (deleted)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/ArticleForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/AuthorArticleForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/AuthorForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/BaseFormPropel.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/BookForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/CategoryForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php (added)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Book.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Category.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/ArticleMapBuilder.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticle.php (modified) (5 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticlePeer.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthor.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorPeer.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseBook.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseBookPeer.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseCategory.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseCategoryPeer.php (modified) (2 diffs)
- branches/1.1/test/bin/prove.php (modified) (1 diff)
- branches/1.1/test/other/fixtures/test/functional/result-harness.txt (modified) (2 diffs)
- branches/1.1/test/other/fixtures/test/result-harness.txt (modified) (2 diffs)
- branches/1.1/test/other/tasksTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/generator/sfAdminGenerator.class.php
r5102 r6882 709 709 } 710 710 711 public function getFormObject() 712 { 713 $class = $this->getClassName().'Form'; 714 715 return new $class(); 716 } 717 718 public function getHiddenFields() 719 { 720 $form = $this->getFormObject(); 721 $hiddenFields = array(); 722 foreach ($form->getWidgetSchema()->getPositions() as $name) 723 { 724 if ($form[$name]->isHidden()) 725 { 726 $hiddenFields[] = $name; 727 } 728 } 729 730 return $hiddenFields; 731 } 732 733 public function getHiddenFieldsAsString() 734 { 735 $hiddenFields = ''; 736 foreach ($this->getHiddenFields() as $name) 737 { 738 $hiddenFields .= ' [?php echo $form[\''.$name.'\'] ?]'."\n"; 739 } 740 741 return "\n".$hiddenFields; 742 } 743 744 public function getLastNonHiddenField() 745 { 746 $form = $this->getFormObject(); 747 $positions = $form->getWidgetSchema()->getPositions(); 748 $last = count($positions) - 1; 749 for ($i = count($positions) - 1; $i >= 0; $i--) 750 { 751 if ($form[$positions[$i]]->isHidden()) 752 { 753 $last = $i - 1; 754 } 755 else 756 { 757 break; 758 } 759 } 760 761 return $last; 762 } 763 711 764 /** 712 765 * Escapes a string. branches/1.1/lib/generator/sfCrudGenerator.class.php
r5098 r6882 96 96 * @return string The PHP code 97 97 */ 98 public function getRetrieveByPkParamsForAction($indent )98 public function getRetrieveByPkParamsForAction($indent, $callee = '$this->getRequestParameter') 99 99 { 100 100 $params = array(); 101 101 foreach ($this->getPrimaryKey() as $pk) 102 102 { 103 $params[] = "\$this->getRequestParameter('".sfInflector::underscore($pk->getPhpName())."')"; 103 $params[] = "$callee('".sfInflector::underscore($pk->getPhpName())."')"; 104 } 105 106 return implode(",\n".str_repeat(' ', max(0, $indent - strlen($this->singularName.$this->className))), $params); 107 } 108 109 /** 110 * Returns PHP code for primary keys parameters. 111 * 112 * @param integer The indentation value 113 * 114 * @return string The PHP code 115 */ 116 public function getRetrieveByPkParamsForEdit($indent, $prefix) 117 { 118 $params = array(); 119 foreach ($this->getPrimaryKey() as $pk) 120 { 121 $name = sfInflector::underscore($pk->getPhpName()); 122 // $params[] = sprintf("\$request->getParameter('%s', \$request->getParameter('%s'))", sprintf('%s[%s]', $prefix, $name), $name); 123 $params[] = sprintf("\$request->getParameter('%s')", $name); 104 124 } 105 125 branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/skeleton/config/generator.yml
r500 r6882 4 4 model_class: ##MODEL_CLASS## 5 5 theme: default 6 7 ##CONFIG## branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/actions/actions.class.php
r4334 r6882 2 2 3 3 /** 4 * <?php echo $this->get GeneratedModuleName() ?> actions.4 * <?php echo $this->getModuleName() ?> actions. 5 5 * 6 6 * @package ##PROJECT_NAME## 7 * @subpackage <?php echo $this->get GeneratedModuleName() ?>7 * @subpackage <?php echo $this->getModuleName() ?> 8 8 9 9 * @author ##AUTHOR_NAME## … … 14 14 public function executeIndex() 15 15 { 16 return $this->forward('<?php echo $this->getModuleName() ?>', 'list');16 $this-><?php echo $this->getSingularName() ?>List = <?php echo $this->getClassName() ?>Peer::doSelect(new Criteria()); 17 17 } 18 18 19 public function executeList() 19 <?php if (isset($this->params['with_show']) && $this->params['with_show']): ?> 20 public function executeShow($request) 20 21 { 21 $this-><?php echo $this->getPluralName() ?> = <?php echo $this->getClassName() ?>Peer::doSelect(new Criteria()); 22 } 23 24 public function executeShow() 25 { 26 $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(49) ?>); 22 $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(49, '$request->getParameter') ?>); 27 23 $this->forward404Unless($this-><?php echo $this->getSingularName() ?>); 28 24 } 29 25 26 <?php endif; ?> 27 <?php if (isset($this->params['non_atomic_actions']) && $this->params['non_atomic_actions']): ?> 28 public function executeEdit($request) 29 { 30 $this->form = new <?php echo $this->getClassName() ?>Form(<?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForEdit(49, $this->getSingularName()) ?>)); 31 32 if ($request->isMethod('post')) 33 { 34 $this->form->bind($request->getParameter('<?php echo $this->getSingularName() ?>')); 35 if ($this->form->isValid()) 36 { 37 $<?php echo $this->getSingularName() ?> = $this->form->save(); 38 39 $this->redirect('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>); 40 } 41 } 42 } 43 <?php else: ?> 30 44 public function executeCreate() 31 45 { 32 $this-> <?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>();46 $this->form = new <?php echo $this->getClassName() ?>Form(); 33 47 34 48 $this->setTemplate('edit'); 35 49 } 36 50 37 public function executeEdit( )51 public function executeEdit($request) 38 52 { 39 $this-><?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(49) ?>); 40 $this->forward404Unless($this-><?php echo $this->getSingularName() ?>); 53 $this->form = new <?php echo $this->getClassName() ?>Form(<?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(49, '$request->getParameter') ?>)); 41 54 } 42 55 43 public function executeUpdate( )56 public function executeUpdate($request) 44 57 { 45 if (<?php echo $this->getTestPksForGetOrCreate(false) ?>) 58 $this->forward404Unless($request->isMethod('post')); 59 60 $this->form = new <?php echo $this->getClassName() ?>Form(<?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(49, '$request->getParameter') ?>)); 61 62 $this->form->bind($this->getRequestParameter('<?php echo $this->getSingularName() ?>')); 63 if ($this->form->isValid()) 46 64 { 47 $<?php echo $this->getSingularName() ?> = new <?php echo $this->getClassName() ?>(); 48 } 49 else 50 { 51 $<?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(45) ?>); 52 $this->forward404Unless($<?php echo $this->getSingularName() ?>); 65 $<?php echo $this->getSingularName() ?> = $this->form->save(); 66 67 $this->redirect('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>); 53 68 } 54 69 55 <?php foreach ($this->getTableMap()->getColumns() as $name => $column): $type = $column->getCreoleType(); ?> 56 <?php if ($name == 'CREATED_AT' || $name == 'UPDATED_AT') continue ?> 57 <?php $name = sfInflector::underscore($column->getPhpName()) ?> 58 <?php if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP): ?> 59 if ($this->getRequestParameter('<?php echo $name ?>')) 60 { 61 list($d, $m, $y) = $this->getContext()->getI18N()->getDateForCulture($this->getRequestParameter('<?php echo $name ?>'), $this->getUser()->getCulture()); 62 $<?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>("$y-$m-$d"); 63 } 64 <?php elseif ($type == CreoleTypes::BOOLEAN): ?> 65 $<?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($this->getRequestParameter('<?php echo $name ?>', 0)); 66 <?php elseif ($column->isForeignKey()): ?> 67 $<?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($this->getRequestParameter('<?php echo $name ?>') ? $this->getRequestParameter('<?php echo $name ?>') : null); 68 <?php else: ?> 69 $<?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($this->getRequestParameter('<?php echo $name ?>')); 70 $this->setTemplate('edit'); 71 } 70 72 <?php endif; ?> 71 <?php endforeach; ?>72 73 73 $<?php echo $this->getSingularName() ?>->save(); 74 75 return $this->redirect('<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>); 76 <?php //' ?> 77 } 78 79 public function executeDelete() 74 public function executeDelete($request) 80 75 { 81 $<?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(43) ?>); 82 83 $this->forward404Unless($<?php echo $this->getSingularName() ?>); 76 $this->forward404Unless($<?php echo $this->getSingularName() ?> = <?php echo $this->getClassName() ?>Peer::retrieveByPk(<?php echo $this->getRetrieveByPkParamsForAction(43, '$request->getParameter') ?>)); 84 77 85 78 $<?php echo $this->getSingularName() ?>->delete(); 86 79 87 return $this->redirect('<?php echo $this->getModuleName() ?>/list');80 $this->redirect('<?php echo $this->getModuleName() ?>/index'); 88 81 } 89 82 } branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/editSuccess.php
r2726 r6882 1 [?php use_helper('Object') ?] 1 <?php $form = $this->getFormObject() ?> 2 [?php $<?php echo $this->getSingularName() ?> = $form->getObject() ?] 3 <h1>[?php echo $<?php echo $this->getSingularName() ?>->isNew() ? 'New' : 'Edit' ?] <?php echo sfInflector::humanize($this->getModuleName()) ?></h1> 2 4 3 [?php echo form_tag('<?php echo $this->getModuleName() ?>/update') ?] 5 <form action="[?php echo url_for('<?php echo $this->getModuleName() ?>/<?php echo isset($this->params['non_atomic_actions']) && $this->params['non_atomic_actions'] ? 'edit' : 'update' ?>'.(!$<?php echo $this->getSingularName() ?>->isNew() ? '?<?php echo $this->getPrimaryKeyUrlParams() ?> : '')) ?]" method="post" [?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?]> 6 <table> 7 <tfoot> 8 <tr> 9 <td colspan="2"> 10 <a href="[?php echo url_for('<?php echo $this->getModuleName() ?>/index') ?]">Cancel</a> 11 [?php if (!$<?php echo $this->getSingularName() ?>->isNew()): ?] 12 [?php echo link_to('Delete', '<?php echo $this->getModuleName() ?>/delete?<?php echo $this->getPrimaryKeyUrlParams() ?>, array('post' => true, 'confirm' => 'Are you sure?')) ?] 13 [?php endif; ?] 14 <input type="submit" value="Save" /> 15 </td> 16 </tr> 17 </tfoot> 18 <tbody> 19 <?php if (isset($this->params['non_verbose_templates']) && $this->params['non_verbose_templates']): ?> 20 [?php echo $this->getAttributeHolder()->isEscaped() ? $form->render(ESC_RAW) : $form ?] 21 <?php else: ?> 4 22 5 <?php foreach ($this->getPrimaryKey() as $pk): ?> 6 [?php echo object_input_hidden_tag($<?php echo $this->getSingularName() ?>, 'get<?php echo $pk->getPhpName() ?>') ?] 23 <?php foreach ($form->getWidgetSchema()->getPositions() as $i => $name): ?> 24 <?php if ($form[$name]->isHidden()) continue ?> 25 <tr> 26 <th><?php echo $form[$name]->renderLabel() ?></th> 27 <td> 28 [?php echo $form['<?php echo $name ?>']->renderError() ?] 29 [?php echo $form['<?php echo $name ?>'] ?] 30 <?php $i == $this->getLastNonHiddenField() and print $this->getHiddenFieldsAsString() ?> 31 </td> 32 </tr> 7 33 <?php endforeach; ?> 8 9 <table> 10 <tbody> 11 <?php foreach ($this->getTableMap()->getColumns() as $name => $column): ?> 12 <?php if ($column->isPrimaryKey()) continue ?> 13 <?php if ($name == 'CREATED_AT' || $name == 'UPDATED_AT') continue ?> 14 <tr> 15 <th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?><?php if ($column->isNotNull()): ?>*<?php endif; ?>:</th> 16 <td>[?php echo <?php echo $this->getCrudColumnEditTag($column) ?> ?]</td> 17 </tr> 18 <?php endforeach; ?> 19 </tbody> 20 </table> 21 <hr /> 22 [?php echo submit_tag('save') ?] 23 [?php if (<?php echo $this->getPrimaryKeyIsSet() ?>): ?] 24 [?php echo link_to('delete', '<?php echo $this->getModuleName() ?>/delete?<?php echo $this->getPrimaryKeyUrlParams() ?>, 'post=true&confirm=Are you sure?') ?] 25 [?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/show?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?] 26 [?php else: ?] 27 [?php echo link_to('cancel', '<?php echo $this->getModuleName() ?>/list') ?] 28 [?php endif; ?] 34 <?php endif; ?> 35 </tbody> 36 </table> 29 37 </form> branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelCrud/default/template/templates/showSuccess.php
r1228 r6882 1 1 <table> 2 <tbody>2 <tbody> 3 3 <?php foreach ($this->getTableMap()->getColumns() as $column): ?> 4 <tr>5 <th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>:</th>6 <td>[?= $<?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>() ?]</td>7 </tr>4 <tr> 5 <th><?php echo sfInflector::humanize(sfInflector::underscore($column->getPhpName())) ?>:</th> 6 <td>[?= $<?php echo $this->getSingularName() ?>->get<?php echo $column->getPhpName() ?>() ?]</td> 7 </tr> 8 8 <?php endforeach; ?> 9 </tbody>9 </tbody> 10 10 </table> 11 11 12 <hr /> 12 [?php echo link_to('edit', '<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?] 13 [?php echo link_to('list', '<?php echo $this->getModuleName() ?>/list') ?] 13 14 <a href="[?php echo url_for('<?php echo $this->getModuleName() ?>/edit?<?php echo $this->getPrimaryKeyUrlParams() ?>) ?]">Edit</a> 15 16 <a href="[?php echo url_for('<?php echo $this->getModuleName() ?>/index') ?]">List</a> branches/1.1/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateCrudTask.class.php
r6097 r6882 32 32 $this->addOptions(array( 33 33 new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'default'), 34 new sfCommandOption('generate-in-cache', null, sfCommandOption::PARAMETER_NONE, 'Generate the module in cache'), 35 new sfCommandOption('non-atomic-actions', null, sfCommandOption::PARAMETER_NONE, 'Generate non atomic actions'), 36 new sfCommandOption('non-verbose-templates', null, sfCommandOption::PARAMETER_NONE, 'Generate non verbose templates'), 37 new sfCommandOption('with-show', null, sfCommandOption::PARAMETER_NONE, 'Generate a show method'), 38 new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), 34 39 )); 35 40 … … 46 51 The task creates a [%module%|COMMENT] module in the [%application%|COMMENT] application 47 52 for the model class [%model%|COMMENT]. 53 54 You can also create an empty module that inherits its actions and templates from 55 a runtime generated module in [%sf_app_cache_dir%/modules/auto%module%|COMMENT] by 56 using the [--generate-in-cache|COMMENT] option: 57 58 [./symfony propel:generate-crud --generate-in-cache frontend article Article|INFO] 48 59 49 60 The generator can use a customized theme by using the [--theme|COMMENT] option: … … 62 73 $properties = parse_ini_file(sfConfig::get('sf_config_dir').'/properties.ini', true); 63 74 64 // generate module 65 $tmpDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true)); 66 sfConfig::set('sf_module_cache_dir', $tmpDir); 67 $generatorManager = new sfGeneratorManager(); 68 $generatorManager->generate('sfPropelCrudGenerator', array('model_class' => $arguments['model'], 'moduleName' => $arguments['module'], 'theme' => $options['theme'])); 69 70 $moduleDir = sfConfig::get('sf_root_dir').'/'.sfConfig::get('sf_apps_dir_name').'/'.$arguments['application'].'/'.sfConfig::get('sf_app_module_dir_name').'/'.$arguments['module']; 71 72 // copy our generated module 73 $this->filesystem->mirror($tmpDir.'/auto'.ucfirst($arguments['module']), $moduleDir, sfFinder::type('any')); 74 75 // change module name 76 $this->filesystem->replaceTokens($moduleDir.'/actions/actions.class.php', '', '', array('auto'.ucfirst($arguments['module']) => $arguments['module'])); 77 78 $constants = array( 75 $this->constants = array( 79 76 'PROJECT_NAME' => isset($properties['symfony']['name']) ? $properties['symfony']['name'] : 'symfony', 80 77 'APP_NAME' => $arguments['application'], … … 84 81 ); 85 82 83 $method = $options['generate-in-cache'] ? 'executeInit' : 'executeGenerate'; 84 85 $this->$method($arguments, $options); 86 } 87 88 protected function executeGenerate($arguments = array(), $options = array()) 89 { 90 $this->bootstrapSymfony($arguments['application'], $options['env'], true); 91 92 sfSimpleAutoload::getInstance()->unregister(); 93 sfSimpleAutoload::getInstance()->register(); 94 95 $databaseManager = new sfDatabaseManager(); 96 97 // generate module 98 $tmpDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true)); 99 sfConfig::set('sf_module_cache_dir', $tmpDir); 100 $generatorManager = new sfGeneratorManager(); 101 $generatorManager->generate('sfPropelCrudGenerator', array( 102 'model_class' => $arguments['model'], 103 'moduleName' => $arguments['module'], 104 'theme' => $options['theme'], 105 'non_atomic_actions' => $options['non-atomic-actions'], 106 'non_verbose_templates' => $options['non-verbose-templates'], 107 'with_show' => $options['with-show'], 108 )); 109 110 $moduleDir = sfConfig::get('sf_root_dir').'/'.sfConfig::get('sf_apps_dir_name').'/'.$arguments['application'].'/'.sfConfig::get('sf_app_module_dir_name').'/'.$arguments['module']; 111 112 // copy our generated module 113 $this->filesystem->mirror($tmpDir.'/auto'.ucfirst($arguments['module']), $moduleDir, sfFinder::type('any')); 114 115 if (!$options['with-show']) 116 { 117 $this->filesystem->remove($moduleDir.'/templates/showSuccess.php'); 118 } 119 120 // change module name 121 $this->filesystem->replaceTokens($moduleDir.'/actions/actions.class.php', '', '', array('auto'.ucfirst($arguments['module']) => $arguments['module'])); 122 86 123 // customize php and yml files 87 124 $finder = sfFinder::type('file')->name('*.php', '*.yml'); 88 $this->filesystem->replaceTokens($finder->in($moduleDir), '##', '##', $ constants);125 $this->filesystem->replaceTokens($finder->in($moduleDir), '##', '##', $this->constants); 89 126 90 127 // create basic test … … 92 129 93 130 // customize test file 94 $this->filesystem->replaceTokens(sfConfig::get('sf_root_dir').'/test/functional/'.$arguments['application'].DIRECTORY_SEPARATOR.$arguments['module'].'ActionsTest.php', '##', '##', $ constants);131 $this->filesystem->replaceTokens(sfConfig::get('sf_root_dir').'/test/functional/'.$arguments['application'].DIRECTORY_SEPARATOR.$arguments['module'].'ActionsTest.php', '##', '##', $this->constants); 95 132 96 133 // delete temp files 97 134 $this->filesystem->remove(sfFinder::type('any')->in($tmpDir)); 98 135 } 136 137 protected function executeInit($arguments = array(), $options = array()) 138 { 139 $moduleDir = sfConfig::get('sf_root_dir').'/'.sfConfig::get('sf_apps_dir_name').'/'.$arguments['application'].'/'.sfConfig::get('sf_app_module_dir_name').'/'.$arguments['module']; 140 141 // create basic application structure 142 $finder = sfFinder::type('any')->ignore_version_control()->discard('.sf'); 143 $dirs = sfLoader::getGeneratorSkeletonDirs('sfPropelCrud', $options['theme']); 144 foreach ($dirs as $dir) 145 { 146 if (is_dir($dir)) 147 { 148 $this->filesystem->mirror($dir, $moduleDir, $finder); 149 break; 150 } 151 } 152 153 // create basic test 154 $this->filesystem->copy(sfConfig::get('sf_symfony_data_dir').'/skeleton/module/test/actionsTest.php', sfConfig::get('sf_root_dir').'/test/functional/'.$arguments['application'].'/'.$arguments['module'].'ActionsTest.php'); 155 156 // customize test file 157 $this->filesystem->replaceTokens(sfConfig::get('sf_root_dir').'/test/functional/'.$arguments['application'].DIRECTORY_SEPARATOR.$arguments['module'].'ActionsTest.php', '##', '##', $this->constants); 158 159 // customize php and yml files 160 $finder = sfFinder::type('file')->name('*.php', '*.yml'); 161 $this->constants['CONFIG'] = sprintf(" non_atomic_actions: %s\n non_verbose_templates: %s\n with_show: %s", 162 $options['non-atomic-actions'] ? 'true' : 'false', 163 $options['non-verbose-templates'] ? 'true' : 'false', 164 $options['with-show'] ? 'true' : 'false' 165 ); 166 $this->filesystem->replaceTokens($finder->in($moduleDir), '##', '##', $this->constants); 167 } 99 168 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/browseTest.php
r6482 r6882 66 66 67 67 // first line 68 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td ', '1', array('position' => 0))->69 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td ', 'foo title', array('position' => 1))->70 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td ', 'bar body', array('position' => 2))->71 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td img', true, array('position' => 3))->72 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td ', '1', array('position' => 4))->68 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(0)', '1')-> 69 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(1)', 'foo title')-> 70 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(2)', 'bar body')-> 71 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(3) img', true)-> 72 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td:nth(4)', '1')-> 73 73 checkResponseElement('body table tbody tr[class="sf_admin_row_0"] td a[href$="/article/edit/id/1"]', '1')-> // clickable 74 74 75 75 // second line 76 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td ', '2', array('position' => 0))->77 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td ', 'foo foo title', array('position' => 1))->78 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td ', 'bar bar body', array('position' => 2))->79 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td img', false, array('position' => 3))->80 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td ', '2', array('position' => 4))->76 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(0)', '2')-> 77 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(1)', 'foo foo title')-> 78 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(2)', 'bar bar body')-> 79 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(3) img', false)-> 80 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(4)', '2')-> 81 81 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td a[href$="/article/edit/id/2"]', '2')-> 82 82 … … 158 158 checkResponseElement('body form#sf_admin_edit_form input[name="article[online]"][id="article_online"][type="checkbox"][checked="checked"]', true)-> 159 159 checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"]', true)-> 160 checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="1"]', ' 1')->161 checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="2"]', ' 2')->160 checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="1"]', 'Category 1')-> 161 checkResponseElement('body form#sf_admin_edit_form select[name="article[category_id]"][id="article_category_id"] option[value="2"]', 'Category 2')-> 162 162 checkResponseElement('body form#sf_admin_edit_form input[name="article[created_at]"][id="article_created_at"][value*="-"]')-> 163 163 … … 187 187 checkResponseElement('#article_body', 'my body')-> 188 188 checkResponseElement('input[id="article_online"][checked="checked"]', true)-> 189 checkResponseElement('#article_category_id option[selected="selected"]', ' 2')189 checkResponseElement('#article_category_id option[selected="selected"]', 'Category 2') 190 190 ; 191 191 … … 229 229 checkResponseElement('input[id="article_title"][value="new title"]')-> 230 230 checkResponseElement('#article_body', 'new body')-> 231 checkResponseElement('#article_category_id option[selected="selected"]', ' 2')->231 checkResponseElement('#article_category_id option[selected="selected"]', 'Category 2')-> 232 232 233 233 // check list 234 234 getAndCheck('article', 'list')-> 235 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td ', '', array('position' => 7))->235 checkResponseElement('body table tbody tr[class="sf_admin_row_1"] td:nth(7)', '')-> 236 236 237 237 // nb lines branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema.xml
r5103 r6882 4 4 <table name="article"> 5 5 <column name="id" type="integer" required="true" primaryKey="true" autoincrement="true" /> 6 <column name="title" type="varchar" size="255" />6 <column name="title" type="varchar" size="255" required="true" /> 7 7 <column name="body" type="longvarchar" /> 8 8 <column name="online" type="boolean" /> branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Book.php
r5103 r6882 10 10 class Book extends BaseBook 11 11 { 12 public function __toString() 13 { 14 return $this->getName(); 15 } 12 16 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/Category.php
r5103 r6882 10 10 class Category extends BaseCategory 11 11 { 12 public function __toString() 13 { 14 return $this->getName(); 15 } 12 16 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/ArticleMapBuilder.php
r5103 r6882 35 35 $tMap->addPrimaryKey('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null); 36 36 37 $tMap->addColumn('TITLE', 'Title', 'string', CreoleTypes::VARCHAR, false, 255);37 $tMap->addColumn('TITLE', 'Title', 'string', CreoleTypes::VARCHAR, true, 255); 38 38 39 39 $tMap->addColumn('BODY', 'Body', 'string', CreoleTypes::LONGVARCHAR, false, null); branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticle.php
r5103 r6882 676 676 public function getCategory($con = null) 677 677 { 678 include_once 'lib/model/om/BaseCategoryPeer.php';679 680 678 if ($this->aCategory === null && ($this->category_id !== null)) { 681 682 $this->aCategory = CategoryPeer::retrieveByPK($this->category_id, $con); 679 $this->aCategory = CategoryPeer::retrieveByPK($this->category_id, $con); 683 680 684 681 … … 706 703 public function getBook($con = null) 707 704 { 708 include_once 'lib/model/om/BaseBookPeer.php';709 710 705 if ($this->aBook === null && ($this->book_id !== null)) { 711 712 $this->aBook = BookPeer::retrieveByPK($this->book_id, $con); 706 $this->aBook = BookPeer::retrieveByPK($this->book_id, $con); 713 707 714 708 … … 728 722 public function getAuthorArticles($criteria = null, $con = null) 729 723 { 730 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 731 if ($criteria === null) { 724 if ($criteria === null) { 732 725 $criteria = new Criteria(); 733 726 } … … 766 759 public function countAuthorArticles($criteria = null, $distinct = false, $con = null) 767 760 { 768 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 769 if ($criteria === null) { 761 if ($criteria === null) { 770 762 $criteria = new Criteria(); 771 763 } … … 791 783 public function getAuthorArticlesJoinAuthor($criteria = null, $con = null) 792 784 { 793 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 794 if ($criteria === null) { 785 if ($criteria === null) { 795 786 $criteria = new Criteria(); 796 787 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticlePeer.php
r5103 r6882 67 67 public static function getMapBuilder() 68 68 { 69 include_once 'lib/model/map/ArticleMapBuilder.php';70 69 return BasePeer::getMapBuilder('lib.model.map.ArticleMapBuilder'); 71 70 } … … 830 829 } 831 830 } else { 832 require_once 'lib/model/map/ArticleMapBuilder.php'; 833 Propel::registerMapBuilder('lib.model.map.ArticleMapBuilder'); 831 Propel::registerMapBuilder('lib.model.map.ArticleMapBuilder'); 834 832 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthor.php
r5103 r6882 359 359 public function getAuthorArticles($criteria = null, $con = null) 360 360 { 361 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 362 if ($criteria === null) { 361 if ($criteria === null) { 363 362 $criteria = new Criteria(); 364 363 } … … 397 396 public function countAuthorArticles($criteria = null, $distinct = false, $con = null) 398 397 { 399 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 400 if ($criteria === null) { 398 if ($criteria === null) { 401 399 $criteria = new Criteria(); 402 400 } … … 422 420 public function getAuthorArticlesJoinArticle($criteria = null, $con = null) 423 421 { 424 include_once 'lib/model/om/BaseAuthorArticlePeer.php'; 425 if ($criteria === null) { 422 if ($criteria === null) { 426 423 $criteria = new Criteria(); 427 424 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php
r5103 r6882 418 418 public function getAuthor($con = null) 419 419 { 420 include_once 'lib/model/om/BaseAuthorPeer.php';421 422 420 if ($this->aAuthor === null && ($this->author_id !== null)) { 423 424 $this->aAuthor = AuthorPeer::retrieveByPK($this->author_id, $con); 421 $this->aAuthor = AuthorPeer::retrieveByPK($this->author_id, $con); 425 422 426 423 … … 448 445 public function getArticle($con = null) 449 446 { 450 include_once 'lib/model/om/BaseArticlePeer.php';451 452 447 if ($this->aArticle === null && ($this->article_id !== null)) { 453 454 $this->aArticle = ArticlePeer::retrieveByPK($this->article_id, $con); 448 $this->aArticle = ArticlePeer::retrieveByPK($this->article_id, $con); 455 449 456 450 branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php
r5103 r6882 52 52 public static function getMapBuilder() 53 53 { 54 include_once 'lib/model/map/AuthorArticleMapBuilder.php';55 54 return BasePeer::getMapBuilder('lib.model.map.AuthorArticleMapBuilder'); 56 55 } … … 805 804 } 806 805 } else { 807 require_once 'lib/model/map/AuthorArticleMapBuilder.php'; 808 Propel::registerMapBuilder('lib.model.map.AuthorArticleMapBuilder'); 806 Propel::registerMapBuilder('lib.model.map.AuthorArticleMapBuilder'); 809 807 } branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorPeer.php
r5103 r6882 49 49 public static function getMapBuilder() 50 50 { 51 include_once 'lib/model/map/AuthorMapBuilder.php';52 51 return BasePeer::getMapBuilder('lib.model.map.AuthorMapBuilder'); 53 52 } … … 364 363 } 365 364 } else { 366 require_once 'lib/model/map/AuthorMapBuilder.php'; 367 Propel::registerMapBuilder('lib.model.map.AuthorMapBuilder'); 365 Propel::registerMapBuilder('lib.model.map.AuthorMapBuilder'); 368 366 } branches/1.1/lib/plugins/sfPropel