Development

Changeset 12758

You must first sign up to be able to contribute.

Changeset 12758

Show
Ignore:
Timestamp:
11/08/08 11:35:24 (1 year ago)
Author:
fabien
Message:

[1.2] added automatic route creation to propel:generate-admin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_filters.php

    r12647 r12758  
    44  [?php endif; ?] 
    55 
    6   <form action="[?php echo url_for('@<?php echo $this->getUrlForAction('filter') ?>') ?]" method="post"> 
     6  <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'filter')) ?]" method="post"> 
    77    <table cellspacing="0"> 
    88      <tfoot> 
     
    1010          <td colspan="2"> 
    1111            [?php echo $form->renderHiddenFields() ?] 
    12             [?php echo link_to(__('Reset', array(), 'sf_admin'), '@<?php echo $this->getUrlForAction('filter') ?>', array('method' => 'post', 'query_string' => '_reset')) ?] 
     12            [?php echo link_to(__('Reset', array(), 'sf_admin'), '<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'filter'), array('query_string' => '_reset', 'method' => 'post')) ?] 
    1313            <input type="submit" value="[?php echo __('Filter', array(), 'sf_admin') ?]" /> 
    1414          </td> 
  • plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/_list_th_tabular.php

    r12474 r12758  
    44<?php if ($field->isReal()): ?> 
    55  [?php if ('<?php echo $name ?>' == $sort[0]): ?] 
    6     [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getModuleName() ?>/index?sort=<?php echo $name ?>&sort_type='.($sort[1] == 'asc' ? 'desc' : 'asc')) ?] 
     6    [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getUrlForAction('list') ?>', array(), array('query_string' => 'sort=<?php echo $name ?>&sort_type='.($sort[1] == 'asc' ? 'desc' : 'asc'))) ?] 
    77    <img src="[?php echo sfConfig::get('sf_admin_module_web_dir').'/images/'.$sort[1].'.png' ?]" alt="[?php echo __($sort[1], array(), 'sf_admin') ?]" /> 
    88  [?php else: ?] 
    9     [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getModuleName() ?>/index?sort=<?php echo $name ?>&sort_type=asc') ?] 
     9    [?php echo link_to(__('<?php echo $field->getConfig('label') ?>', array(), '<?php echo $this->getI18nCatalogue() ?>'), '<?php echo $this->getUrlForAction('list') ?>', array(), array('query_string' => 'sort=<?php echo $name ?>&sort_type=asc')) ?] 
    1010  [?php endif; ?] 
    1111<?php else: ?> 
  • plugins/sfPropelPlugin/trunk/data/generator/sfPropelModule/admin/template/templates/indexSuccess.php

    r12493 r12758  
    1919  <div id="sf_admin_content"> 
    2020<?php if ($this->configuration->getValue('list.batch_actions')): ?> 
    21     <form action="[?php echo url_for('<?php echo $this->getUrlForAction('batch') ?>') ?]" method="post"> 
     21    <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection') ?>', array('action' => 'batch')) ?]" method="post"> 
    2222<?php endif; ?> 
    2323    [?php include_partial('<?php echo $this->getModuleName() ?>/list', array('pager' => $pager, 'sort' => $sort, 'helper' => $helper)) ?] 
  • plugins/sfPropelPlugin/trunk/lib/task/sfPropelGenerateAdminTask.class.php

    r12474 r12758  
    2828    $this->addArguments(array( 
    2929      new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name'), 
    30       new sfCommandArgument('route', sfCommandArgument::REQUIRED, 'The route name'), 
     30      new sfCommandArgument('route_or_model', sfCommandArgument::REQUIRED, 'The route name or the model class'), 
    3131    )); 
    3232 
    3333    $this->addOptions(array( 
     34      new sfCommandOption('module', null, sfCommandOption::PARAMETER_REQUIRED, 'The module name', null), 
    3435      new sfCommandOption('theme', null, sfCommandOption::PARAMETER_REQUIRED, 'The theme name', 'admin'), 
    3536      new sfCommandOption('singular', null, sfCommandOption::PARAMETER_REQUIRED, 'The singular name', null), 
     
    4546The [propel:generate-admin|INFO] task generates a Propel admin module: 
    4647 
     48  [./symfony propel:generate-admin frontend Article|INFO] 
     49 
     50The task creates a module in the [%frontend%|COMMENT] application for the 
     51[%Article%|COMMENT] model. 
     52 
     53The task creates a route for you in the application [routing.yml|COMMENT]. 
     54 
     55You can also generate a Propel admin module by passing a route name: 
     56 
    4757  [./symfony propel:generate-admin frontend article|INFO] 
    4858 
     
    5060[%article%|COMMENT] route definition found in [routing.yml|COMMENT]. 
    5161 
    52 For the filters to work properly, you need to add a collection route for it: 
     62For the filters and batch actions to work properly, you need to add 
     63collection routes for them: 
    5364 
    54   articles
     65  article
    5566    class: sfPropelRouteCollection 
    5667    options: 
    5768      model:              Article 
    58       module:             article 
    59       collection_actions: { filter: post } 
    60  
     69      collection_actions: { filter: post, batch: post } 
    6170EOF; 
    6271  } 
     
    6877  { 
    6978    // get configuration for the given route 
    70     $config = new sfRoutingConfigHandler(); 
    71     $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 
     79    if (false !== $this->getRouteFromName($arguments['route_or_model'])) 
     80    { 
     81      $arguments['route'] = $routes[$arguments['route_or_model']]; 
     82      $arguments['route_name'] = $arguments['route_or_model']; 
    7283 
    73     if (!isset($routes[$arguments['route']])) 
    74     { 
    75       throw new sfCommandException(sprintf('The route "%s" does not exist.', $arguments['route'])); 
     84      return $this->generateForRoute($arguments, $options); 
    7685    } 
    7786 
    78     $routeOptions = $routes[$arguments['route']]->getOptions(); 
     87    // is it a model class name 
     88    if (!class_exists($arguments['route_or_model'])) 
     89    { 
     90      throw new sfCommandException(sprintf('The route "%s" does not exist and there is no "%s" class.', $arguments['route_or_model'])); 
     91    } 
    7992 
    80     if (!$routes[$arguments['route']] instanceof sfPropelRouteCollection) 
     93    $r = new ReflectionClass($arguments['route_or_model']); 
     94    if (!$r->isSubclassOf('BaseObject')) 
    8195    { 
    82       throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route'])); 
     96      throw new sfCommandException(sprintf('"%s" is not a Propel class.', $arguments['route_or_model'])); 
     97    } 
     98 
     99    // create a route 
     100    $model = $arguments['route_or_model']; 
     101    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 
     102 
     103    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 
     104    $content = file_get_contents($routing); 
     105    $routesArray = sfYaml::load($content); 
     106 
     107    if (!isset($routesArray[$name])) 
     108    { 
     109      $module = $options['module'] ? $options['module'] : $name; 
     110      $content = sprintf(<<<EOF 
     111%s: 
     112  class: sfPropelRouteCollection 
     113  options: 
     114    model:               %s 
     115    module:              %s 
     116    prefix_path:         %s 
     117    with_wilcard_routes: true 
     118 
     119 
     120EOF 
     121      , $name, $model, $module, $module).$content; 
     122 
     123      file_put_contents($routing, $content); 
     124    } 
     125 
     126    $arguments['route'] = $this->getRouteFromName($name); 
     127    $arguments['route_name'] = $name; 
     128 
     129    return $this->generateForRoute($arguments, $options); 
     130  } 
     131 
     132  protected function generateForRoute($arguments, $options) 
     133  { 
     134    $routeOptions = $arguments['route']->getOptions(); 
     135 
     136    if (!$arguments['route'] instanceof sfPropelRouteCollection) 
     137    { 
     138      throw new sfCommandException(sprintf('The route "%s" is not a Propel collection route.', $arguments['route_name'])); 
    83139    } 
    84140 
     
    113169    return $task->run(array($arguments['application'], $module, $model), $taskOptions); 
    114170  } 
     171 
     172  protected function getRouteFromName($name) 
     173  { 
     174    $config = new sfRoutingConfigHandler(); 
     175    $routes = $config->evaluate($this->configuration->getConfigPaths('config/routing.yml')); 
     176 
     177    if (isset($routes[$name])) 
     178    { 
     179      return $routes[$name]; 
     180    } 
     181 
     182    return false; 
     183  } 
    115184} 

The Sensio Labs Network

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