Changeset 75

Show
Ignore:
Timestamp:
08/22/08 14:03:33 (10 months ago)
Author:
nperriault
Message:

[1.1]:

  • Companies and people modules migrated, with according form classes and templates, and functional test suite
  • Enhanced SymfoniansTestBrowser?
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/main/config/routing.yml

    r71 r75  
    111111 
    112112# Applications 
    113 applications_test: 
    114   url: /applications/test 
    115   param: { module: applications, action: test } 
    116113applications_countries: 
    117114  url:   /applications/countries 
     
    169166company_add: 
    170167  url:   /company/add 
    171   param: { module: companies, action: add
     168  param: { module: companies, action: edit
    172169 
    173170company_edit: 
     
    185182company_edit_connection: 
    186183  url:   /company/:slug/connection/:id/edit 
    187   param: { module: companies, action: editConnection
     184  param: { module: companies, action: connect
    188185 
    189186company_contact: 
  • trunk/apps/main/i18n/fr/messages.xml

    r38 r75  
    315315<trans-unit id="69"> 
    316316<source>Fields marked with a &lt;span class="left-star"&gt;star&lt;/span&gt; are mandatory.</source> 
    317 <target>Les champs marqués d'une &lt;span class="left-star"&gt;star&lt;/span&gt; sont obligatoires</target> 
     317<target>Les champs marqués d'une &lt;span class="left-star"&gt;étoile&lt;/span&gt; sont obligatoires</target> 
    318318</trans-unit> 
    319319 
     
    615615<trans-unit id="129"> 
    616616<source>Update %name% application informations</source> 
    617 <target>Mettre à jour les informations concernant l'application %application%</target> 
     617<target>Mettre à jour les informations concernant l'application %name%</target> 
    618618</trans-unit> 
    619619 
  • trunk/apps/main/lib/myActions.class.php

    r62 r75  
    11<?php 
    22/** 
    3  * Shared actions stub 
     3 * Shared actions stub for all actions 
    44 * 
    55 */ 
     
    2929  protected function buildPagerRoute($route_name, $params = array()) 
    3030  { 
    31     $query_string = http_build_query($params, '', '&'); 
    32     if ($query_string) 
     31    if ($query_string = http_build_query($params, '', '&')) 
    3332    { 
    3433      $route = sprintf('%s?%s&page=', $route_name, $query_string); 
     
    3837      $route = sprintf('%s?page=', $route_name); 
    3938    } 
     39 
    4040    return $route; 
    4141  } 
     
    6464   * Returns the rendered value of a partial 
    6565   * 
    66    * @param  string $module   Module name 
    67    * @param  string $partial  Partial name (including the underscore prefix) 
    68    * @param  array  $vars     Var to pass to the partial (optional) 
     66   * @param  string $module   Module name 
     67   * @param  string $partial  Partial name (including the underscore prefix) 
     68   * @param  array  $vars     Var to pass to the partial (optional) 
    6969   * @return string 
    7070   */ 
    7171  protected function getRenderedPartial($module, $partial, $vars = array()) 
    7272  { 
    73     $view = new sfPartialView(); 
    74     $view->initialize(sfContext::getInstance(), $module, $partial, null); 
    75     return $view->render($vars); 
    76   } 
    77  
     73    $view = new sfPartialView(sfContext::getInstance(), $module, $partial, null); 
     74    $view->setPartialVars($vars); 
     75    return $view->render(); 
     76  } 
     77 
     78  /** 
     79   * Get the current view cache manager, if any (it does not exist in dev env) 
     80   * 
     81   * @return sfViewCacheManager|null 
     82   */ 
    7883  protected function getViewCacheManager() 
    7984  { 
     
    8186  } 
    8287 
     88  /** 
     89   * Purges the cache related to a given object 
     90   * 
     91   * @param  object  $object 
     92   * @return mixed 
     93   */ 
    8394  protected function purgeObjectRelatedCache($object) 
    8495  { 
    8596    $purge_method = sprintf('purge%sRelatedCache', ucfirst(get_class($object))); 
     97 
    8698    if (method_exists($this, $purge_method)) 
    8799    { 
     
    90102  } 
    91103 
     104  /** 
     105   * Purges the homepage cache related assets 
     106   * 
     107   */ 
    92108  protected function purgeHomepage() 
    93109  { 
     
    98114  } 
    99115 
     116  /** 
     117   * Purges the sections homepages cache related assets 
     118   * 
     119   */ 
    100120  protected function purgeHomepages() 
    101121  { 
     
    112132  } 
    113133 
     134  /** 
     135   * Purges an application cache related assets 
     136   * 
     137   * @param Application $application 
     138   */ 
    114139  protected function purgeApplicationRelatedCache(Application $application) 
    115140  { 
     
    127152  } 
    128153 
     154  /** 
     155   * Purges a company cache related assets 
     156   * 
     157   * @param Company $company 
     158   */ 
    129159  protected function purgeCompanyRelatedCache(Company $company) 
    130160  { 
     
    142172  } 
    143173 
     174  /** 
     175   * Purges a job cache related assets 
     176   * 
     177   * @param Job $job 
     178   */ 
    144179  protected function purgeJobRelatedCache(Job $job) 
    145180  { 
     
    157192  } 
    158193 
     194  /** 
     195   * Purges a user cache related assets 
     196   * 
     197   * @param sfGuardUser $person 
     198   */ 
    159199  protected function purgePersonRelatedCache(sfGuardUser $person) 
    160200  { 
     
    168208  } 
    169209 
     210  /** 
     211   * Purges a recommendation cache related assets 
     212   * 
     213   * @param Recommendation $recommendation 
     214   */ 
    170215  protected function purgeRecommendationRelatedCache(Recommendation $recommendation) 
    171216  { 
     
    179224  } 
    180225 
     226  /** 
     227   * Purges an application company relation cache 
     228   * 
     229   * @param ApplicationCompany $app_company 
     230   */ 
    181231  protected function purgeApplicationCompanyRelatedCache(ApplicationCompany $app_company) 
    182232  { 
     
    190240  } 
    191241 
     242  /** 
     243   * Purges an application developer related cache 
     244   * 
     245   * @param ApplicationDeveloper $app_person 
     246   */ 
    192247  protected function purgeApplicationDeveloperRelatedCache(ApplicationDeveloper $app_person) 
    193248  { 
     
    201256  } 
    202257 
     258  /** 
     259   * Purges a company person related cache 
     260   * 
     261   * @param CompanyPerson $company_person 
     262   */ 
    203263  protected function purgeCompanyPersonRelatedCache(CompanyPerson $company_person) 
    204264  { 
     
    298358    } 
    299359    $mailer->disconnect(); 
    300      
     360 
    301361    // Add mailSent timestamp 
    302362    $this->getUser()->setAttribute('lastMailAt', time()); 
    303      
     363 
    304364    return ($sent > 0); 
    305365  } 
     
    342402    return $address; 
    343403  } 
    344    
     404 
    345405  /** 
    346406   * Checks for mail flooding (die, dirty spammers) 
     
    352412  { 
    353413    $user = $this->getUser(); 
    354      
     414 
    355415    if (!$user) 
    356416    { 
    357417      throw new sfException($this->__('Mail sending use the session, please allow cookies')); 
    358418    } 
    359      
     419 
    360420    $lastMailAt = $user->getAttribute('lastMailAt', null); 
    361      
     421 
    362422    if (is_null($lastMailAt)) 
    363423    { 
    364424      return; 
    365425    } 
    366      
     426 
    367427    $ttl = sfConfig::get('app_mail_mail_flood_time', 300); 
    368      
    369     if (time() - $lastMailAt < $ttl)  
     428 
     429    if (time() - $lastMailAt < $ttl) 
    370430    { 
    371431      throw new sfException(sprintf($this->__('You must wait at least %d seconds between two mail send, please try again later'), $ttl)); 
    372432    } 
    373433  } 
    374    
    375   /** 
    376    * Post execution: if a form has been set, we put it in sfContext to be able  
     434 
     435  /** 
     436   * Post execution: if a form has been set, we put it in sfContext to be able 
    377437   * to reference it in the layout or partials 
    378438   * 
  • trunk/apps/main/modules/applications/actions/actions.class.php

    r71 r75  
    3838 
    3939      $this->form = new ApplicationForm($application); 
     40      $this->form->setDefault('tags', $application->getTagsString()); 
    4041      $this->setTemplate('edit'); 
    4142      $message = $this->__('Application updated'); 
     
    5354    } 
    5455 
    55     $this->form->setDefault('tags', $application->getTagsString()); 
    56     $this->application = $application; 
    57  
    5856    if ($request->isMethod('post')) 
    5957    { 
     
    7977 
    8078      $this->getUser()->setFlash('notice', $message); 
    81       $this->getUser()->setAttribute('from_app_creation', is_null($request->getParameter('slug')), 'symfonians'); 
    8279      $this->redirect(sprintf($redirect, $application->getSlug())); 
    8380    } 
     
    161158    { 
    162159      $connection = ApplicationDeveloperPeer::retrieveByPK($request->getParameter('id')); 
     160 
    163161      $this->forward404If(is_null($connection)); 
    164162 
     
    200198                                  'developer_id'   => $this->getUser()->getId())); 
    201199      $this->form->bind($params); 
     200 
    202201      if ($this->form->isValid()) 
    203202      { 
  • trunk/apps/main/modules/applications/actions/components.class.php

    r2 r75  
    77{ 
    88 
     9  /** 
     10   * Filter form component 
     11   * 
     12   */ 
    913  public function executeFilterForm() 
    1014  { 
    11     $this->countries = ApplicationPeer::retrieveCountries(); 
     15    $this->form = new CountrySelectorForm(ApplicationPeer::retrieveCountries()); 
     16    $this->form->setDefault('country', $this->getRequestParameter('country')); 
    1217  } 
    1318 
     19  /** 
     20   * Popular tags component 
     21   * 
     22   */ 
    1423  public function executePopularTags() 
    1524  { 
     
    2029  } 
    2130 
     31  /** 
     32   * Recently added apps component 
     33   * 
     34   */ 
    2235  public function executeRecentlyAdded() 
    2336  { 
     
    2841  } 
    2942 
     43  /** 
     44   * Recently updated apps component 
     45   * 
     46   */ 
    3047  public function executeRecentlyUpdated() 
    3148  { 
     
    3653  } 
    3754 
     55  /** 
     56   * Related tags component 
     57   * 
     58   */ 
    3859  public function executeRelatedTags() 
    3960  { 
    40     $this->related_tags = TagPeer::getRelatedTags($this->tag, 
    41                               array('model' => 'Application')); 
     61    $this->related_tags = TagPeer::getRelatedTags($this->tag, array('model' => 'Application')); 
    4262  } 
    4363 
     64  /** 
     65   * User applications 
     66   * 
     67   */ 
    4468  public function executeUserApplications() 
    4569  { 
  • trunk/apps/main/modules/applications/templates/_filterForm.php

    r56 r75  
    11<form action="<?php echo url_for('@application_home') ?>" method="get" id="country_form"> 
    2   <?php /* 
     2  <?php echo $form['country']->renderLabel() ?> 
     3  <?php echo $form['country']->render() ?> 
    34  <p> 
    4     <label for="country"><?php echo __('Filter by country') ?></label> 
    5     <?php echo select_tag('country', 
    6                           options_for_select($countries, 
    7                                              $sf_request->getParameter('country'), 
    8                                              array('include_custom' => __('All countries')))) ?> 
     5    <input type="checkbox" value="1" <?php echo $sf_request->hasParameter('opensource') ? 'checked="checked"' : '' ?> name="opensource" id="opensource"> 
     6    <label for="opensource" class="left"><?php echo __('Only open source applications') ?></label> 
    97  </p> 
    108  <p> 
    11     <?php echo checkbox_tag('opensource', 1, $sf_request->hasParameter('opensource'), 'id=opensource') ?> 
    12     <?php echo label_for('opensource', __('Only open source applications'), 'class=left') ?> 
     9    <input type="submit" value="<?php echo __('Filter') ?>" name="commit"/> 
    1310  </p> 
    14   <p> 
    15     <?php echo submit_tag(__('Filter')) ?> 
    16   </p> 
    17   */ ?> 
    1811</form> 
  • trunk/apps/main/modules/applications/templates/_form.php

    r70 r75  
    1515      <legend><?php echo __('Application informations') ?></legend> 
    1616      <div class="form-row required <?php echo $form['name']->hasError() ? 'field_error' : '' ?>"> 
    17         <?php echo $form['name']->renderLabel() ?> 
     17        <?php echo $form['name']->renderLabel(__('Application name')) ?> 
    1818        <?php echo $form['name']->render() ?> 
    1919        <?php echo $form['name']->renderError() ?> 
     
    2828      <legend><?php echo __('Other informations') ?></legend> 
    2929      <?php echo $form['country']->renderRow() ?> 
    30       <?php echo $form['screenshot_file']->renderRow() ?> 
     30      <?php echo $form['screenshot_file']->renderRow(array(), __('Screenshot')) ?> 
    3131      <div class="form-row"> 
    3232        <?php echo $form['is_opensource'] ?> 
    33         <?php echo $form['is_opensource']->renderLabel(__('Is this application open source?'), array('class' => 'inline')) ?> 
     33        <?php echo $form['is_opensource']->renderLabel(__('This application is open source'), array('class' => 'inline')) ?> 
    3434      </div> 
    35       <?php echo $form['licence']->renderRow(array(), __('If application is open source, how is it licensed?')) ?> 
     35      <?php echo $form['licence']->renderRow(array(), __('Licence informations')) ?> 
    3636      <?php echo $form['feed_url']->renderRow() ?> 
    3737      <div class="date_select"> 
     
    4343  <div class="form-row" style="text-align:center;clear:left;"> 
    4444    <p> 
     45      <?php echo $form['id'] ?> 
    4546      <?php echo $form['_csrf_token'] ?> 
    4647      <input type="submit" value="<?php echo $submit_label ?>" /> 
  • trunk/apps/main/modules/applications/templates/_popularTags.php

    r2 r75  
    22<h3><?php echo __('Tags') ?></h3> 
    33<div class="tags_cloud"> 
    4   <?php echo tag_cloud($tags, '@application_tag?tag=') ?> 
     4  <?php echo tag_cloud($tags->getRawValue(), '@application_tag?tag=%s') ?> 
    55</div> 
    66<p class="more"> 
  • trunk/apps/main/modules/applications/templates/_relatedTags.php

    r2 r75  
    33                  array('%tag%' => tags_string($tag))) ?></h3> 
    44<div class="tags_cloud"> 
    5   <?php echo more_related_tag_cloud($related_tags, '@application_home?tag=', $tag)?> 
     5  <?php echo more_related_tag_cloud($related_tags, '@application_home?tag=%s', $tag)?> 
    66</div> 
    77<p class="more"> 
  • trunk/apps/main/modules/applications/templates/addSuccess.php

    r56 r75  
    55 
    66<?php include_partial('applications/form', 
    7                       array('application'  => $application
     7                      array('application'  => $form->getObject()
    88                            'form'         => $form, 
    99                            'title'        => $page_title, 
  • trunk/apps/main/modules/applications/templates/connectAsCompanySuccess.php

    r71 r75  
    99<?php slot('sidebar') ?> 
    1010  <?php if ($application->getScreenshotPath()): ?> 
    11     <?php $image = image_tag($application->getFullScreenshotPath(), 
    12                              'class=app_screenshot alt='.$application->getName().' preview') ?> 
     11    <?php $image = application_image_tag($application, 'class=app_screenshot alt='.$application->getName().' preview') ?> 
    1312    <?php if ($application->getHomepage()): ?> 
    1413      <?php echo link_to($image, $application->getHomepage()) ?> 
  • trunk/apps/main/modules/applications/templates/connectAsDeveloperSuccess.php

    r68 r75  
    22 
    33<?php slot('page_title') ?> 
    4   <?php $page_title = __('Connect yourself to the %application% application',  
     4  <?php $page_title = __('Connect yourself to the %application% application', 
    55                         array('%application%' => $application->getName())) ?> 
    66  <?php echo $page_title ?> 
     
    99<?php slot('sidebar') ?> 
    1010  <?php if ($application->getScreenshotPath()): ?> 
    11     <?php $image = image_tag($application->getFullScreenshotPath(),  
    12                              'class=app_screenshot alt='.$application->getName().' preview') ?> 
     11    <?php $image = image_tag($application, 'class=app_screenshot alt='.$application->getName().' preview') ?> 
    1312    <?php if ($application->getHomepage()): ?> 
    1413      <?php echo link_to($image, $application->getHomepage()) ?> 
     
    1918<?php end_slot() ?> 
    2019 
    21 <?php echo breadcrumb(array(array(__('Applications'), '@application_home'),  
     20<?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 
    2221                            array($application->getName(), '@application_page?slug='.$application->getSlug()), 
    2322                            $page_title)) ?> 
     
    2524<h2><?php echo $page_title ?><span class="gradient">&nbsp;</span></h2> 
    2625 
    27 <?php if (isset($from_app_creation) && $from_app_creation): ?> 
    28   <p><?php echo __('Now that your app has been added, please provide some informations on how you\'ve been implied with it :-)') ?></p> 
    29 <?php else: ?> 
    30   <p><?php echo __('If you have worked on the %application% application, please fill and submit the form below.', 
    31                    array('%application%' => $application->getName())) ?></p> 
    32 <?php endif; ?> 
     26<p><?php echo __('If you have worked on the %application% application, please fill and submit the form below.', 
     27                 array('%application%' => $application->getName())) ?></p> 
    3328 
    3429<p class="form-info"> 
     
    4035    <fieldset> 
    4136      <legend><?php echo __('Connection informations') ?></legend> 
    42       <div class="form-row required"> 
     37      <div class="form-row required <?php echo $form['role']->hasError() ? 'field_error' : '' ?>"> 
    4338        <?php echo $form['role']->renderLabel(__('Your role in this project')) ?> 
    4439        <?php echo $form['role']->render() ?> 
  • trunk/apps/main/modules/applications/templates/detailsSuccess.php

    r2 r75  
    88<?php slot('sidebar') ?> 
    99  <?php if ($application->getScreenshotPath()): ?> 
    10     <?php $image = image_tag($application->getFullScreenshotPath(),  
    11                              'class=app_screenshot alt='.$application->getName().' preview') ?> 
     10    <?php $image = application_image_tag($application, 'class=app_screenshot alt='.$application->getName().' preview') ?> 
    1211    <?php if ($application->getHomepage()): ?> 
    1312      <?php echo link_to($image, $application->getHomepage()) ?> 
     
    2625    <ul class="admin_actions"> 
    2726      <li> 
    28         <?php echo link_to(__('Edit this application informations'),  
     27        <?php echo link_to(__('Edit this application informations'), 
    2928                         '@application_edit?slug='.$application->getSlug(), 
    3029                         'class=bigedit') ?></li> 
    3130      <li> 
    32         <?php echo link_to(__('Delete this application'),  
     31        <?php echo link_to(__('Delete this application'), 
    3332                         '@application_delete?slug='.$application->getSlug(), 
    3433                         'class=bigdelete confirm='.__('Are you sure?')) ?></li> 
    3534      <?php if ($sf_user->isAdmin()): ?> 
    3635      <li> 
    37         <?php echo link_to(__('Promote as featured on homepage'),  
     36        <?php echo link_to(__('Promote as featured on homepage'), 
    3837                         '@application_promote?slug='.$application->getSlug(), 
    3938                         'class=promote confirm='.__('Are you sure?')) ?></li> 
     
    4241  <?php endif; ?> 
    4342  <h3><?php echo __('Have a nice symfony app?') ?></h3> 
    44   <?php echo big_button_to(__('Add an application'),  
     43  <?php echo big_button_to(__('Add an application'), 
    4544                           '@application_add', 'id=bt_addapp') ?> 
    4645<?php end_slot() ?> 
    4746 
    4847<div class="fiftypercent"> 
    49    
    50   <?php echo breadcrumb(array(array(__('Applications'), '@application_home'),  
     48 
     49  <?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 
    5150                              $page_title)) ?> 
    52    
     51 
    5352  <h2> 
    5453    <?php echo $page_title ?> 
     
    6160    <span class="gradient">&nbsp;</span> 
    6261  </h2> 
    63    
     62 
    6463  <?php include_partial('applications/entry', 
    6564                        array('application' => $application)) ?> 
    66    
     65 
    6766</div> 
    6867 
     
    8685          <?php endif; ?> 
    8786          <?php if ($sf_user->getId() == $app_person->getDeveloperId()): ?> 
    88             <?php echo link_to(image_tag('page_edit.png', 'alt=Edit'), 
     87            <?php echo link_to(image_tag('page_edit.png', 'alt=Edit person connection'), 
    8988                               '@application_edit_developer_connection?slug='.$application->getSlug().'&id='.$app_person->getId(), 
    9089                               'title='.__('Edit your connection with ').$app_person->getApplication()->getName().' rel=nofollow class=edit') ?> 
     
    116115    <?php endif; ?> 
    117116  </div> 
    118    
     117 
    119118  <div class="related_companies"> 
    120119    <h3><?php echo __('Companies related to this application') ?></h3> 
     
    125124        <tr class="<?php echo $i % 2 == 0 ? 'row' : 'row odd' ?>"> 
    126125          <td class="mini_thumb_cell"> 
    127             <?php echo link_to(image_tag($company_application->getCompany()->getFullLogoPath(), 
     126            <?php echo link_to(company_image_tag($company_application->getCompany(), 
    128127                                         'class=mini_thumb'), 
    129128                               '@company_page?slug='.$company_application->getCompany()->getSlug(), 
     
    137136            <?php endif; ?> 
    138137            <?php if ($sf_user->getId() == $company_application->getSubmitterId()): ?> 
    139               <?php echo link_to(image_tag('page_edit.png', 'alt=Edit'), 
     138              <?php echo link_to(image_tag('page_edit.png', 'alt=Edit company connection'), 
    140139                                 '@application_edit_company_connection?slug='.$application->getSlug().'&id='.$company_application->getId(), 
    141140                                 'title='.__('Edit this connection to ').$company_application->getCompany()->getName().' rel=nofollow class=edit') ?> 
     
    161160    <?php endif; ?> 
    162161    <p class="more"> 
    163       <?php echo link_to(__('Connect a company!'),  
     162      <?php echo link_to(__('Connect a company!'), 
    164163                         '@application_connect_as_company?slug='.$application->getSlug()) ?> 
    165164    </p> 
    166165  </div> 
    167    
     166 
    168167</div> 
  • trunk/apps/main/modules/applications/templates/homeSuccess.php

    r11 r75  
    6262      <?php endif; ?> 
    6363      <?php echo link_to($application->getName(), 
    64                            '@application_page?slug='.$application->getSlug()) ?> 
     64                         '@application_page?slug='.$application->getSlug()) ?> 
    6565      <?php if ($application->getCountry()): ?> 
    6666        <?php echo flag_image_tag($application->getCountry()) ?> 
     
    6969    <div class="thumb_area"> 
    7070      <p><?php if ($application->getScreenshotPath()): ?> 
    71       <?php echo link_to(image_tag($application->getFullScreenshotPath(), 
    72                                    'alt=screenshot'), 
     71      <?php echo link_to(application_image_tag($application, 'alt=screenshot'), 
    7372                         '@application_page?slug='.$application->getSlug(), 
    7473                         'class=thumb_link') ?> 
  • trunk/apps/main/modules/applications/templates/tagsSuccess.php

    r2 r75  
    1010<?php end_slot() ?> 
    1111 
    12 <?php echo breadcrumb(array(array(__('Applications'), '@application_home'),  
     12<?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 
    1313                            $page_title)) ?> 
    1414 
     
    1919 
    2020<div class="tags_cloud big_cloud"> 
    21   <?php echo tag_cloud($tags, '@application_home?tag=') ?> 
     21  <?php echo tag_cloud($tags, '@application_home?tag=%s') ?> 
    2222</div> 
  • trunk/apps/main/modules/companies/actions/actions.class.php

    r48 r75  
    99{ 
    1010 
    11   public function executeAdd() 
    12   { 
    13     $this->company = new Company(); 
    14     if ($this->getRequest()->getMethod() == sfRequest::POST) 
    15     { 
    16       $this->updateFromRequest(); 
    17       parent::purgeObjectRelatedCache($this->company); 
    18       $this->getUser()->setFlash('notice', $this->__('Company added')); 
    19       $this->getUser()->setAttribute('from_company_creation', true, 'symfonians'); 
    20       $this->redirect('@company_connect_as_member?slug='.$this->company->getSlug()); 
    21     } 
    22   } 
    23  
    24   public function executeEdit() 
     11  /** 
     12   * Adds or edit a Company 
     13   * 
     14   * @param sfWebRequest $request 
     15   */ 
     16  public function executeEdit(sfWebRequest $request) 
     17  { 
     18    if (!is_null($request->getParameter('slug'))) 
     19    { 
     20      $company = $this->getFromSlug(); 
     21 
     22      $this->forward404If(is_null($company), sprintf('Company with slug "%s" not found', $request->getParameter('slug'))); 
     23 
     24      if (!$this->getUser()->isAdmin() && $company->getSubmitterId() != $this->getUser()->getId()) 
     25      { 
     26        $this->getUser()->setFlash('warning', $this->__('You are not allowed to edit this record')); 
     27        $this->redirect('@company_page?slug='.$company->getSlug()); 
     28      } 
     29 
     30      $this->form = new CompanyForm($company); 
     31      $this->setTemplate('edit'); 
     32      $message = $this->__('Company updated'); 
     33      $redirect = '@company_page?slug=%s'; 
     34      $creation = false; 
     35    } 
     36    else 
     37    { 
     38      $company = new Company(); 
     39      $this->form = new CompanyForm(); 
     40      $this->setTemplate('add'); 
     41      $message = $this->__('Company added'); 
     42      $redirect = '@company_connect_as_member?slug=%s'; 
     43      $creation = true; 
     44    } 
     45 
     46    if ($request->isMethod('post')) 
     47    { 
     48      $submitter_id = $this->getUser()->isAdmin() && $company->getSubmitterId() ? $company->getSubmitterId() : $this->getUser()->getId(); 
     49      $params = array_merge($request->getParameter('company'), 
     50                            array('submitter_id' => $submitter_id)); 
     51      $this->form->bind($params, $request->getFiles('company')); 
     52 
     53      if (!$this->form->isValid() or is_null($company = $this->form->save())) 
     54      { 
     55        return sfView::SUCCESS; 
     56      } 
     57 
     58      /* @var $thumb sfValidatedThumb */ 
     59      if (!is_null($thumb = $this->form->getValue('logo_file'))) 
     60      { 
     61        $thumb->saveThumb('companies', $company, 'setLogoPath'); 
     62      } 
     63 
     64      parent::purgeObjectRelatedCache($company); 
     65 
     66      $this->getUser()->setFlash('notice', $this->__('Company updated')); 
     67      $this->redirect(sprintf($redirect, $company->getSlug())); 
     68    } 
     69