Changeset 71

Show
Ignore:
Timestamp:
08/02/08 22:23:55 (2 years ago)
Author:
nperriault
Message:

[1.1] Application connection forms, enhanced tests and SymfoniansTestBrowser?

Files:

Legend:

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

    r68 r71  
    140140application_edit_company_connection: 
    141141  url:   /application/:slug/connection/:id/company/edit 
    142   param: { module: applications, action: editCompanyConnection
     142  param: { module: applications, action: connectAsCompany
    143143 
    144144application_connect_as_developer: 
     
    148148application_edit_developer_connection: 
    149149  url:   /application/:slug/connection/:id/person/edit 
    150   param: { module: applications, action: editDeveloperConnection
     150  param: { module: applications, action: connectAsDeveloper
    151151 
    152152application_tags: 
  • trunk/apps/main/modules/applications/actions/actions.class.php

    r70 r71  
    88class applicationsActions extends myActions 
    99{ 
    10  
     10  /** 
     11   * Lists applications countries 
     12   * 
     13   * @param sfWebRequest $request 
     14   */ 
    1115  public function executeCountries(sfWebRequest $request) 
    1216  { 
    1317    $this->countries = ApplicationPeer::retrieveCountriesWithCount(); 
    1418  } 
    15    
     19 
     20  /** 
     21   * Application creation or edition 
     22   * 
     23   * @param  sfWebRequest $request 
     24   */ 
    1625  public function executeEdit(sfWebRequest $request) 
    1726  { 
     
    1928    { 
    2029      $application = $this->getFromSlug(); 
    21        
     30 
    2231      $this->forward404If(is_null($application), sprintf('App with slug "%s" not found', $request->getParameter('slug'))); 
    23        
     32 
    2433      if (!$this->getUser()->isAdmin() && $application->getSubmitterId() != $this->getUser()->getId()) 
    2534      { 
     
    2736        $this->redirect('@application_page?slug='.$application->getSlug()); 
    2837      } 
    29        
     38 
    3039      $this->form = new ApplicationForm($application); 
    3140      $this->setTemplate('edit'); 
     
    4352      $creation = true; 
    4453    } 
    45      
     54 
    4655    $this->form->setDefault('tags', $application->getTagsString()); 
    4756    $this->application = $application; 
    48      
     57 
    4958    if ($request->isMethod('post')) 
    5059    { 
    5160      // Set the submitter id from the session 
    5261      $submitter_id = $this->getUser()->isAdmin() && $application->getSubmitterId() ? $application->getSubmitterId() : $this->getUser()->getId(); 
    53       $params = array_merge($request->getParameter('application'),  
     62      $params = array_merge($request->getParameter('application'), 
    5463                            array('submitter_id' => $submitter_id)); 
    5564      $this->form->bind($params, $request->getFiles('application')); 
    56        
     65 
    5766      /* @var $application Application */ 
    5867      if (!$this->form->isValid() or is_null($application = $this->form->save())) 
     
    6069        return sfView::SUCCESS; 
    6170      } 
    62        
     71 
    6372      /* @var $thumb sfValidatedThumb */ 
    6473      if (!is_null($thumb = $this->form->getValue('screenshot_file'))) 
     
    6675        $thumb->saveThumb('applications', $application, 'setScreenshotPath'); 
    6776      } 
    68        
     77 
    6978      parent::purgeObjectRelatedCache($application); 
    70        
     79 
    7180      $this->getUser()->setFlash('notice', $message); 
    7281      $this->getUser()->setAttribute('from_app_creation', is_null($request->getParameter('slug')), 'symfonians'); 
     
    7584  } 
    7685 
    77   public function executeEditCompanyConnection(sfWebRequest $request) 
    78   { 
    79     $this->application = $this->getFromSlug(); 
    80     $this->connection = ApplicationCompanyPeer::retrieveByPK($this->getRequestParameter('id')); 
    81     $this->forward404Unless($this->connection, 'ApplicationCompany not found'); 
    82  
    83     if ($request->isMethod('post')) 
    84     { 
    85       $this->updateCompanyConnectionFromRequest(); 
    86       parent::purgeObjectRelatedCache($this->connection); 
    87       $this->getUser()->setFlash('notice', $this->__('Connection updated')); 
    88       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    89     } 
    90  
    91     $this->setTemplate('connectAsCompany'); 
    92     $this->form_action = sprintf('@application_edit_company_connection?slug=%s&id=%d', 
    93                                  $this->application->getSlug(), 
    94                                  $this->connection->getId()); 
    95   } 
    96  
    97   public function executeEditDeveloperConnection(sfWebRequest $request) 
    98   { 
    99     $this->application = $this->getFromSlug(); 
    100     $this->connection = ApplicationDeveloperPeer::retrieveByPK($this->getRequestParameter('id')); 
    101     $this->forward404Unless($this->connection, 'ApplicationDeveloper not found'); 
    102     $this->form = new ApplicationDeveloperForm($this->connection); 
    103  
    104     if ($request->isMethod('post')) 
    105     { 
    106       $this->updateDeveloperConnectionFromRequest(); 
    107       parent::purgeObjectRelatedCache($this->connection); 
    108       $this->getUser()->setFlash('notice', $this->__('Connection updated')); 
    109       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    110     } 
    111  
    112     $this->setTemplate('connectAsDeveloper'); 
    113     $this->form_action = sprintf('@application_edit_developer_connection?slug=%s&id=%d', 
    114                                  $this->application->getSlug(), 
    115                                  $this->connection->getId()); 
    116   } 
    117  
     86  /** 
     87   * Connects a company 
     88   * 
     89   * @param sfWebRequest $request 
     90   */ 
    11891  public function executeConnectAsCompany(sfWebRequest $request) 
    11992  { 
    120     $this->connection = new ApplicationCompany(); 
    121     $this->application = $this->getFromSlug(); 
     93    $this->application = $this->getFromSlug() or $this->forward404(); 
     94 
     95    /* $var $connection ApplicationCompany */ 
     96    if (is_numeric($request->getParameter('id'))) // Connection edition 
     97    { 
     98      $this->forward404Unless($connection = ApplicationCompanyPeer::retrieveByPK($request->getParameter('id'))); 
     99 
     100      if ($connection->getSubmitterId() != $this->getUser()->getId()) 
     101      { 
     102        $this->getUser()->setFlash('warning', $this->__('You cannot edit this connection')); 
     103        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     104      } 
     105 
     106      $creation = false; 
     107      $this->form_action = sprintf('@application_edit_company_connection?slug=%s&id=%d', 
     108                                   $this->application->getSlug(), 
     109                                   $connection->getId()); 
     110    } 
     111    else // Connection creation 
     112    { 
     113      $connection = new ApplicationCompany(); 
     114      $connection->setApplication($this->application); 
     115 
     116      $creation = true; 
     117      $this->form_action = '@application_connect_as_company?slug='.$this->application->getSlug(); 
     118    } 
     119 
     120    $companies = $this->getUser()->getGuardUser()->getCompaniesArray($this->getUser()->isAdmin() ? 'all' : 'related'); 
     121    $this->form = new ApplicationCompanyForm($connection, array('companies' => $companies)); 
    122122 
    123123    // Checks if a relation already exists for this company 
    124     $connection_data = $this->getRequestParameter('connection'); 
    125     if ($connection_data && $this->application->hasCompanyConnected($connection_data['company_id'])) 
    126     { 
    127       $this->getUser()->setFlash('warning', $this->__('The company you entered is already related to this application')); 
    128       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    129     } 
     124    $connection_data = array_merge($this->getRequestParameter('connection', array()), 
     125                                   array('submitter_id'   => $this->getUser()->getId(), 
     126                                         'application_id' => $this->application->getId())); 
    130127 
    131128    // Form has been submitted 
    132129    if ($request->isMethod('post')) 
    133130    { 
    134       $this->updateCompanyConnectionFromRequest(); 
    135       parent::purgeObjectRelatedCache($this->connection); 
    136  
    137       $this->getUser()->setFlash('notice', $this->__('The company has been marked as connected to this application')); 
    138       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    139     } 
    140  
    141     $this->form_action = '@application_connect_as_company?slug='.$this->application->getSlug(); 
    142   } 
    143  
     131      // If it's a new connection, checks if the company is already connected to the application 
     132      if ($connection->isNew() && $this->application->hasCompanyConnected($connection_data['company_id'])) 
     133      { 
     134        $this->getUser()->setFlash('warning', $this->__('The company you entered is already related to this application')); 
     135        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     136      } 
     137 
     138      $this->form->bind($connection_data); 
     139 
     140      if ($this->form->isValid()) 
     141      { 
     142        $this->form->save(); 
     143        parent::purgeObjectRelatedCache($connection); 
     144        $this->getUser()->setFlash('notice', $this->__('The company has been marked as connected to this application')); 
     145        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     146      } 
     147    } 
     148  } 
     149 
     150  /** 
     151   * Connects a developer 
     152   * 
     153   * @param sfWebRequest $request 
     154   */ 
    144155  public function executeConnectAsDeveloper(sfWebRequest $request) 
    145156  { 
    146     $this->connection = new ApplicationDeveloper(); 
    147     $this->application = $this->getFromSlug(); 
    148     $this->form = new ApplicationDeveloperForm($this->connection); 
    149  
    150     // Checks if a relation already exists for this person 
    151     if ($this->application->hasDeveloper($this->getUser()->getId())) 
    152     { 
    153       $this->getUser()->setFlash('warning', $this->__('This person is already related to this application')); 
    154       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    155     } 
    156  
    157     // Where do we come from ? 
    158     $this->from_app_creation = $this->getUser()->getAttribute('from_app_creation', false, 'symfonians'); 
    159     $this->getUser()->getAttributeHolder()->remove('from_app_creation', 'symfonians'); 
     157    $this->application = $this->getFromSlug() or $this->forward404(); 
     158 
     159    /* $var $connection ApplicationDeveloper */ 
     160    if (is_numeric($request->getParameter('id'))) // Connection edition 
     161    { 
     162      $connection = ApplicationDeveloperPeer::retrieveByPK($request->getParameter('id')); 
     163      $this->forward404If(is_null($connection)); 
     164 
     165      if ($connection->getDeveloperId() != $this->getUser()->getId()) 
     166      { 
     167        $this->getUser()->setFlash('warning', $this->__('You cannot edit this connection')); 
     168        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     169      } 
     170 
     171      $this->from_app_creation = true; 
     172      $this->form_action = sprintf('@application_edit_developer_connection?slug=%s&id=%d', 
     173                                   $this->application->getSlug(), 
     174                                   $connection->getId()); 
     175    } 
     176    else // Connection creation 
     177    { 
     178      $connection = new ApplicationDeveloper(); 
     179      $connection->setApplication($this->application); 
     180      $connection->setsfGuardUser($this->getUser()->getGuardUser()); 
     181 
     182      // Checks if a relation already exists for this person 
     183      if ($this->application->hasDeveloper($this->getUser()->getId())) 
     184      { 
     185        $this->getUser()->setFlash('warning', $this->__('You are already connected with this application')); 
     186        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     187      } 
     188 
     189      $this->from_app_creation = true; 
     190      $this->form_action = '@application_connect_as_developer?slug='.$this->application->getSlug(); 
     191    } 
     192 
     193    $this->form = new ApplicationDeveloperForm($connection); 
    160194 
    161195    // Form has been submitted 
    162196    if ($request->isMethod('post')) 
    163197    { 
    164       $params = array_merge($request->getParameter('connection'),  
     198      $params = array_merge($request->getParameter('connection', array()), 
    165199                            array('application_id' => $this->application->getId(), 
    166200                                  'developer_id'   => $this->getUser()->getId())); 
     
    169203      { 
    170204        $this->form->save(); 
    171         parent::purgeObjectRelatedCache($this->connection); 
     205        parent::purgeObjectRelatedCache($connection); 
    172206        $this->getUser()->setFlash('notice', $this->__('You have been marked as implied with this application')); 
    173207        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    174208      } 
    175209    } 
    176  
    177     $this->form_action = '@application_connect_as_developer?slug='.$this->application->getSlug(); 
    178   } 
    179  
     210  } 
     211 
     212  /** 
     213   * Deletes an application 
     214   * 
     215   * @param sfWebRequest $request 
     216   */ 
    180217  public function executeDelete(sfWebRequest $request) 
    181218  { 
     
    194231  } 
    195232 
     233  /** 
     234   * Shows application details 
     235   * 
     236   * @param sfWebRequest $request 
     237   */ 
    196238  public function executeDetails(sfWebRequest $request) 
    197239  { 
     
    219261  } 
    220262 
     263  /** 
     264   * Applications homepage 
     265   * 
     266   * @param sfWebRequest $request 
     267   */ 
    221268  public function executeHome(sfWebRequest $request) 
    222269  { 
     
    271318  } 
    272319 
     320  /** 
     321   * Promotes an application to the homepage 
     322   * 
     323   * @param sfWebRequest $request 
     324   */ 
    273325  public function executePromote(sfWebRequest $request) 
    274326  { 
     
    286338  } 
    287339 
     340  /** 
     341   * Show all applications tags 
     342   * 
     343   * @param sfWebRequest $request 
     344   */ 
    288345  public function executeTags(sfWebRequest $request) 
    289346  { 
     
    293350    $this->tags = TagPeer::getPopulars($c); 
    294351  } 
    295    
     352 
    296353  /** 
    297354   * Retrieves an Application object from the "slug" parameter, if exists 
    298355   * 
    299    * @param  Criteria|null  $c  Optional Propel Criteria  
     356   * @param  Criteria|null  $c  Optional Propel Criteria 
    300357   * @return Application|null 
    301358   */ 
     
    306363      return null; 
    307364    } 
    308      
     365 
    309366    if (!$c instanceof Criteria) 
    310367    { 
    311368      $c = new Criteria(); 
    312369    } 
    313      
     370 
    314371    $c->addJoin(ApplicationPeer::SUBMITTER_ID, sfGuardUserPeer::ID, Criteria::LEFT_JOIN); 
    315372    $c->add(ApplicationPeer::SLUG, $this->getRequestParameter('slug')); 
    316      
     373 
    317374    return ApplicationPeer::doSelectOne($c); 
    318375  } 
    319  
    320376} 
  • trunk/apps/main/modules/applications/templates/connectAsCompanySuccess.php

    r50 r71  
    22 
    33<?php slot('page_title') ?> 
    4   <?php $page_title = __('Connect a company to the %application% application',  
     4  <?php $page_title = __('Connect a company 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(),  
     11    <?php $image = image_tag($application->getFullScreenshotPath(), 
    1212                             'class=app_screenshot alt='.$application->getName().' preview') ?> 
    1313    <?php if ($application->getHomepage()): ?> 
     
    1919<?php end_slot() ?> 
    2020 
    21 <?php echo breadcrumb(array(array(__('Applications'), '@application_home'),  
     21<?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 
    2222                            array($application->getName(), '@application_page?slug='.$application->getSlug()), 
    2323                            $page_title)) ?> 
     
    3737      <legend><?php echo __('Connection informations') ?></legend> 
    3838      <div class="form-row required"> 
    39         <label for="company_id"><?php echo __('Company') ?></label> 
    40         <?php echo select_tag('connection[company_id]', 
    41                               options_for_select($sf_user->getGuardUser()->getCompaniesArray($sf_user->isAdmin() ? 'all' : 'related'), 
    42                                                  $sf_request->getParameter('connection[company_id]', $connection->getCompanyId()), 
    43                                                  'include_custom='.__('Select a company'))) ?> 
    44         <?php echo form_error('connection[company_id]') ?> 
     39        <?php echo $form['company_id']->renderLabel(__('Company')) ?> 
     40        <?php echo $form['company_id']->render() ?> 
     41        <?php echo $form['company_id']->renderError() ?> 
    4542        <div class="form_help"> 
    4643          <?php echo __('You must have already connected to companies to see them appearing in the select box below') ?> 
     
    4845      </div> 
    4946      <div class="form-row required"> 
    50         <label for="role"><?php echo __('The company role in this project') ?></label
    51         <?php echo object_input_tag($connection, 'getRole', 'name=connection[role]', $sf_params->get('connection[role]')) ?> 
    52         <?php echo form_error('connection[role]') ?> 
     47        <?php echo $form['role']->renderLabel(__('The company role in this project')) ?
     48        <?php echo $form['role']->render() ?> 
     49        <?php echo $form['role']->renderError() ?> 
    5350      </div> 
    5451      <div class="form-row"> 
    55         <label for="description"><?php echo __('Description of the company mission') ?></label
    56         <?php echo object_textarea_tag($connection, 'getDescription', 'name=connection[description]', $sf_params->get('connection[description]')) ?> 
    57         <?php echo form_error('connection[description]') ?> 
     52        <?php echo $form['description']->renderLabel(__('Description of the company mission')) ?
     53        <?php echo $form['description']->render() ?> 
     54        <?php echo $form['description']->renderError() ?> 
    5855      </div> 
    5956    </fieldset> 
     
    6259    <fieldset> 
    6360      <legend><?php echo __('Timeline') ?></legend> 
    64       <div class="form-row"> 
    65         <label for="started_at"><?php echo __('Start date of activity (yyyy-mm-dd)') ?></label> 
    66         <?php echo object_input_date_tag($connection, 'getStartedAt', 'name=connection[started_at] format=Y-MM-dd rich=true class=date_select', $sf_params->get('connection[started_at]')) ?> 
    67         <?php echo form_error('connection[started_at]') ?> 
    68       </div> 
    69       <div class="form-row"> 
    70         <label for="ended_at"><?php echo __('End date of activity (yyyy-mm-dd)') ?></label> 
    71         <?php echo object_input_date_tag($connection, 'getEndedAt', 'name=connection[ended_at] format=Y-MM-dd rich=true class=date_select', $sf_params->get('connection[ended_at]')) ?> 
    72         <?php echo form_error('connection[ended_at]') ?> 
     61      <div class="date_select"> 
     62        <div class="form-row"> 
     63          <?php echo $form['started_at']->renderLabel(__('Start date of activity')) ?> 
     64          <?php echo $form['started_at']->render() ?> 
     65          <?php echo $form['started_at']->renderError() ?> 
     66        </div> 
     67        <div class="form-row"> 
     68          <?php echo $form['ended_at']->renderLabel(__('End date of activity')) ?> 
     69          <?php echo $form['ended_at']->render() ?> 
     70          <?php echo $form['ended_at']->renderError() ?> 
     71        </div> 
    7372      </div> 
    7473    </fieldset> 
     
    7675  <div class="form-row" style="text-align:center;clear:left;"> 
    7776    <p> 
     77      <?php echo $form['_csrf_token'] ?> 
    7878      <?php echo button_to(__('Cancel'), '@application_page?slug='.$application->getSlug()) ?>&nbsp; 
    79       <?php echo submit_tag(__('Connect the company to this application')) ?
     79      <input type="submit" value="<?php echo __('Connect the company to this application') ?>"/
    8080    </p> 
    8181  </div> 
  • trunk/apps/main/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php

    r53 r71  
    11<?php 
    22/** 
    3  * Base sfGuardAuth actions 
    4  *  
     3 * Base sfGuardAuth actions, overriden here just to have the myActions features 
     4 * 
    55 * @package    symfony 
    66 * @subpackage plugin 
     
    2121    { 
    2222      $this->form->bind($request->getParameter('signin')); 
    23        
     23 
    2424      if ($this->form->isValid()) 
    2525      { 
     
    2727        $this->getUser()->signin($values['user'], 'on' === $values['remember']); 
    2828 
    29         $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer($request->getReferer())); 
    30  
     29        $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $request->getReferer()); 
    3130        return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage'); 
    3231      } 
  • trunk/lib/form/ActivationForm.class.php

    r68 r71  
    66 * @package    form 
    77 * @subpackage activation 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    98 */ 
    109class ActivationForm extends BaseActivationForm 
  • trunk/lib/form/ApplicationCompanyForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * ApplicationCompany form. 
     
    65 * @package    form 
    76 * @subpackage application_company 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class ApplicationCompanyForm extends BaseApplicationCompanyForm 
     
    1210  public function configure() 
    1311  { 
     12    if (!is_array($this->getOption('companies')) || array() === $this->getOption('companies')) 
     13    { 
     14      $this->setOption('companies', array()); 
     15    } 
     16 
     17    unset($this['id']); 
     18 
     19    $this->widgetSchema['company_id'] = new sfWidgetFormSelect(array('choices' => $this->getOption('companies'))); 
     20    $this->validatorSchema['company_id'] = new sfValidatorChoice(array('choices' => array_keys($this->getOption('companies')))); 
     21 
     22    $this->mergeForm(new BaseConnectionForm()); 
     23 
     24    $this->widgetSchema->setNameFormat('connection[%s]'); 
    1425  } 
    1526} 
  • trunk/lib/form/ApplicationDeveloperForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * ApplicationDeveloper form. 
     
    65 * @package    form 
    76 * @subpackage application_developer 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class ApplicationDeveloperForm extends BaseApplicationDeveloperForm 
     
    1210  public function configure() 
    1311  { 
    14     $context = sfContext::getInstance(); 
    15     $culture = $context->getUser()->getCulture(); 
    16      
    1712    unset($this['id']); 
    18      
    19     // Widgets 
    20     $this->widgetSchema['started_at']     = new sfWidgetFormI18nDate(array('culture' => $culture)); 
    21     $this->widgetSchema['ended_at']    = new sfWidgetFormI18nDate(array('culture' => $culture)); 
    22      
    23     // Validators 
    24     $this->validatorSchema['started_at']  = new sfValidatorDate(array('required' => false)); 
    25     $this->validatorSchema['ended_at'] = new sfValidatorDate(array('required' => false)); 
    26     $this->validatorSchema['role'] = new sfValidatorString(array('max_length' => 255, 'required' => true)); 
    27      
     13 
     14    $this->mergeForm(new BaseConnectionForm()); 
     15 
    2816    $this->widgetSchema->setNameFormat('connection[%s]'); 
    2917  } 
  • trunk/lib/form/ApplicationForm.class.php

    r70 r71  
    55 * @package    form 
    66 * @subpackage application 
    7  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    87 */ 
    98class ApplicationForm extends BaseApplicationForm 
    109{ 
     10  protected $culture = null; 
     11 
    1112  public function configure() 
    1213  { 
    1314    sfLoader::loadHelpers('I18n'); 
    1415    $context = sfContext::getInstance(); 
    15     $culture = $context->getUser()->getCulture(); 
    16      
     16    $this->culture = $context->getUser()->getCulture(); 
     17 
    1718    // Unset unused widgets 
    1819    unset($this['id'], 
    19           $this['created_at'],  
     20          $this['created_at'], 
    2021          $this['updated_at'], 
    21           $this['slug'],  
     22          $this['slug'], 
    2223          $this['is_featured'], 
    2324          $this['screenshot_path']); 
    24      
    25     // Overriding widgets 
    26     $this->widgetSchema['tags']               = new sfWidgetFormInput(); 
    27     $this->widgetSchema['country']            = new ExtendedWidgetFormI18nSelectCountry(array('culture' => $culture, 'add_label_option' => __('Select a country'))); 
    28     $this->widgetSchema['started_at']         = new sfWidgetFormI18nDate(array('culture' => $culture)); 
    29     $this->widgetSchema['released_at']        = new sfWidgetFormI18nDate(array('culture' => $culture)); 
    30     $this->widgetSchema['screenshot_file']    = new sfWidgetFormInputFile(); 
    31      
    32     // Overriding validators 
    33     $this->validatorSchema['tags']            = new sfValidatorTags(array('separator' => ',', 'required' => false)); 
    34     $this->validatorSchema['country']         = new sfValidatorI18nChoiceCountry(array('culture' => $culture, 'required' => false)); 
    35     $this->validatorSchema['started_at']      = new sfValidatorDate(array('required' => false)); 
    36     $this->validatorSchema['ended_at']        = new sfValidatorDate(array('required' => false)); 
    37     $this->validatorSchema['screenshot_file'] = new sfValidatorFile(array('max_size' => 512000,  
    38                                                                           'mime_types' => 'web_images', 
    39                                                                           'validated_file_class' => 'sfValidatedThumb',  
    40                                                                           'required' => false)); 
    41      
    42     // Redefined validators 
    43     $this->validatorSchema['homepage'] = new sfValidatorOr(array( 
    44       new sfValidatorUrl(), 
    45       new sfValidatorChoice(array('choices' => array('http://', ''))), 
    46     )); 
    47     $this->validatorSchema['feed_url'] = new sfValidatorOr(array( 
    48       new sfValidatorUrl(), 
    49       new sfValidatorChoice(array('choices' => array('http://', ''))), 
    50     )); 
    51      
    52     // Post validators 
    53     /*$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( 
    54         new sfValidatorPropelUnique(array('model' => 'Application', 'column' => array('homepage'))), 
    55         new sfValidatorSchemaLicence(),  
    56     )));*/ 
    57      
     25 
     26    $this->initWidgets(); 
     27    $this->initValidators(); 
     28 
    5829    // Defaults 
    5930    $this->setDefaults(array('homepage'      => 'http://', 
     
    6334                             'is_opensource' => null)); 
    6435  } 
     36 
     37  /** 
     38   * Intitialize widgets 
     39   * 
     40   */ 
     41  public function initWidgets() 
     42  { 
     43    $this->widgetSchema['tags']               = new sfWidgetFormInput(); 
     44    $this->widgetSchema['country']            = new ExtendedWidgetFormI18nSelectCountry(array('culture' => $this->culture, 'add_label_option' => __('Select a country'))); 
     45    $this->widgetSchema['started_at']         = new sfWidgetFormI18nDate(array('culture' => $this->culture)); 
     46    $this->widgetSchema['released_at']        = new sfWidgetFormI18nDate(array('culture' => $this->culture)); 
     47    $this->widgetSchema['screenshot_file']    = new sfWidgetFormInputFile(); 
     48  } 
     49 
     50  /** 
     51   * Initialize validators 
     52   * 
     53   */ 
     54  public function initValidators() 
     55  { 
     56    $this->validatorSchema['tags']            = new sfValidatorTags(array('separator' => ',', 'required' => false)); 
     57    $this->validatorSchema['country']         = new sfValidatorI18nChoiceCountry(array('culture' => $this->culture, 'required' => false)); 
     58    $this->validatorSchema['started_at']      = new sfValidatorDate(array('required' => false)); 
     59    $this->validatorSchema['ended_at']        = new sfValidatorDate(array('required' => false)); 
     60    $this->validatorSchema['screenshot_file'] = new sfValidatorFile(array('max_size' => 512000, 
     61                                                                          'mime_types' => 'web_images', 
     62                                                                          'validated_file_class' => 'sfValidatedThumb', 
     63                                                                          'required' => false)); 
     64    $this->validatorSchema['homepage'] = new sfValidatorOr(array( 
     65      new sfValidatorUrl(), 
     66      new sfValidatorChoice(array('choices' => array('http://', ''))), 
     67    )); 
     68 
     69    $this->validatorSchema['feed_url'] = new sfValidatorOr(array( 
     70      new sfValidatorUrl(), 
     71      new sfValidatorChoice(array('choices' => array('http://', ''))), 
     72    )); 
     73 
     74    // Post validators 
     75    /*$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( 
     76        new sfValidatorPropelUnique(array('model' => 'Application', 'column' => array('homepage'))), 
     77        new sfValidatorSchemaLicence(), 
     78    )));*/ 
     79  } 
    6580} 
  • trunk/lib/form/BaseFormPropel.class.php

    r56 r71  
    44 * 
    55 * @package    form 
    6  * @version    SVN: $Id: sfPropelFormBaseTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    76 */ 
    87abstract class BaseFormPropel extends sfFormPropel 
  • trunk/lib/form/BlogPostForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * BlogPost form. 
     
    65 * @package    form 
    76 * @subpackage blog_posts 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class BlogPostForm extends BaseBlogPostForm 
  • trunk/lib/form/CompanyForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * Company form. 
     
    65 * @package    form 
    76 * @subpackage company 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class CompanyForm extends BaseCompanyForm 
  • trunk/lib/form/CompanyPersonForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * CompanyPerson form. 
     
    65 * @package    form 
    76 * @subpackage company_people 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class CompanyPersonForm extends BaseCompanyPersonForm 
  • trunk/lib/form/EventForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * Event form. 
     
    65 * @package    form 
    76 * @subpackage event 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class EventForm extends BaseEventForm 
  • trunk/lib/form/JobForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * Job form. 
     
    65 * @package    form 
    76 * @subpackage jobs 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class JobForm extends BaseJobForm 
  • trunk/lib/form/LocalEventForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * LocalEvent form. 
     
    65 * @package    form 
    76 * @subpackage local_event 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class LocalEventForm extends BaseLocalEventForm 
  • trunk/lib/form/RecommendationForm.class.php

    r68 r71  
    11<?php 
    2  
    32/** 
    43 * Recommendation form. 
     
    65 * @package    form 
    76 * @subpackage recommendation 
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ 
    97 */ 
    108class RecommendationForm extends BaseRecommendationForm 
  • trunk/lib/form/sfFormReCaptcha.class.php

    r56 r71  
    11<?php 
    2  
    32/* 
    43 * This file is part of the symfony package. 
     
    109 
    1110/** 
    12  * sfFormReCatcha is a base form embedding a recaptcha widget and validator, it  
    13  * can also bind submitted parameters directly from the request using the  
     11 * sfFormReCatcha is a base form embedding a recaptcha widget and validator, it 
     12 * can also bind submitted parameters directly from the request using the 
    1413 * bindFromRequest() method. 
    15  *  
    16  * You must define a private and a public recaptcha key in order to use this  
     14 * 
     15 * You must define a private and a public recaptcha key in order to use this 
    1716 * form. You can do so passing options to the constructor of the class, eg: 
    18  *  
     17 * 
    1918 *     $form = new sfFormReCaptcha(array(), array('recaptcha_public_key'  => '12345', 
    2019 *                                                'recaptcha_private_key' => '54321')); 
    21  *  
     20 * 
    2221 * You can use symfony environements to configure if you want to use recaptcha 
    2322 * for certain environment only 
     
    3635  { 
    3736    parent::__construct($defaults, $options, $CSRFSecret); 
    38      
    39     // We setup the captcha now, because the configure() method has just been  
     37 
     38    // We setup the captcha now, because the configure() method has just been 
    4039    // called in __construct() so we can append the captcha field to the whole form. 
    4140    $this->setupCaptcha(); 
    4241  } 
    43    
     42 
    4443  /** 
    4544   * Bind parameters, including the captcha ones, from a sfRequest object instance 
     
    5251  { 
    5352    $nameFormat = $this->widgetSchema->getNameFormat(); 
    54      
     53 
    5554    if ('%s' == $nameFormat) 
    5655    { 
    5756      throw new LogicException('You must define a name format using setNameFormat() in order to use the bindFromRequest() method'); 
    5857    } 
    59      
     58 
    6059    $nameFormat = substr($nameFormat, 0, strpos($nameFormat, ('['))); 
    61      
     60 
    6261    $params = $request->getParameter($nameFormat, array()); 
    6362    if (true === sfConfig::get('app_recaptcha_enabled')) 
     
    7473 
    7574  /** 
    76    * Setup captcha for current form  
    77    *  
     75   * Setup captcha for current form 
     76   * 
    7877   */ 
    7978  protected function setupCaptcha() 
  • trunk/lib/model/Application.php

    r62 r71  
    1717    return $this->getName(); 
    1818  } 
    19    
     19 
    2020  /** 
    2121   * Fills current Application with array parameters, including tags 
     
    2727  { 
    2828    parent::fromArray($arr, $keyType); 
    29      
     29 
    3030    foreach (array('tags', 'Tags') as $tagField) 
    3131    { 
     
    3636    } 
    3737  } 
    38    
     38 
    3939  /** 
    4040   * Converts current Application to an associative array 
     
    4646  { 
    4747    $arr = parent::toArray($keyType); 
    48      
     48 
    4949    if (BasePeer::TYPE_FIELDNAME == $keyType) 
    5050    { 
     
    5555      $arr['Tags'] = $this->getTagsString(); 
    5656    } 
    57      
     57 
    5858    return $arr; 
    5959  } 
     
    216216  public function hasCompanyConnected($company) 
    217217  { 
     218    if (!$company) 
     219    { 
     220      return false; 
     221    } 
     222 
    218223    if ($company instanceof BaseCompany) 
    219224    { 
     
    224229      $company_id = $company; 
    225230    } 
     231 
    226232    $c = new Criteria; 
    227233    $c->add(ApplicationCompanyPeer::COMPANY_ID, $company_id); 
     234 
    228235    return ($this->countApplicationCompanys($c) > 0); 
    229236  } 
    230    
     237 
    231238  /** 
    232239   * Checks if an application is owned by a given user 
     
    240247      $user_id = $user_id->getId(); 
    241248    } 
    242      
     249 
    243250    return ($this->getSubmitterId() === $user_id); 
    244251  } 
     
    293300    return $save; 
    294301  } 
    295    
     302 
    296303  /** 
    297304   * Sets the feed url value 
     
    305312      $v = null; 
    306313    } 
    307      
     314 
    308315    return parent::setFeedUrl($v); 
    309316  } 
    310    
     317 
    311318  /** 
    312319   * Sets the homepage url value 
     
    320327      $v = null; 
    321328    } 
    322      
     329 
    323330    return parent::setHomepage($v); 
    324331  } 
    325    
     332 
    326333  /** 
    327334   * Sets is_featured field and update according relations 
     
    340347    parent::setIsFeatured($flag); 
    341348  } 
    342    
     349 
    343350  /** 
    344351   * Sets application tags, only if application has already been saved 
     
    352359      return; 
    353360    } 
    354      
     361 
    355362    $this->removeAllTags(); 
    356363    $this->addTag($tags); 
  • trunk/lib/utils/SymfoniansTestBrowser.class.php

    r66 r71  
    22/** 
    33 * Symfonians functional tests browser: 
    4  *   
     4 * 
    55 *   - initializes database manager automatically 
    66 *   - provides session testing utilities 
     
    99 * @subpackage test 
    1010 */ 
    11 class SymfoniansTestBrowser extends sfTestBrowser  
     11class SymfoniansTestBrowser extends sfTestBrowser 
    1212{ 
    13    
     13 
    1414  /** 
    1515   * Database manager 
     
    1717   */ 
    1818  protected static $db = null; 
    19    
     19 
    2020  /** 
    2121   * Admin test user 
     
    2323   */ 
    2424  protected static $adminUser = null; 
    25    
     25 
    2626  /** 
    2727   * Standard test user 
     
    2929   */ 
    3030  protected static $standardUser = null; 
    31    
     31 
    3232  /** 
    3333   * Application configuration 
     
    3535   */ 
    3636  protected static $configuration = null; 
    37    
     37 
    3838  /** 
    3939   * Public constructor, and initialize database manager 
    4040   * 
    41    * @param  sfApplicationConfiguration  $configuration   
     41   * @param  sfApplicationConfiguration  $configuration 
    4242   * @see    sfTestBrowser 
    4343   */ 
     
    4848    return parent::__construct($hostname, $remote, $options); 
    4949  } 
    50    
     50 
     51  /** 
     52   * Simulates a click on a link or button. 
     53   * 
     54   * @param string $name       The link or button text 
     55   * @param array  $arguments 
     56   * 
     57   * @return sfBrowser 
     58   */ 
     59  public function click($name, $arguments = array()) 
     60  { 
     61    self::$test->comment(sprintf('Click "%s"', $name)); 
     62 
     63    try 
     64    { 
     65      $click = parent::click($name, $arguments); 
     66      return $click; 
     67    } 
     68    catch (sfException $e) 
     69    { 
     70      self::$test->fail(sprintf('%s in "%s"', $e->getMessage(), $this->getResponse()->getContent())); 
     71      return $this; 
     72    } 
     73  } 
     74 
    5175  /** 
    5276   * Sign in a test user 
     
    6892      $pass = 'testpass1'; 
    6993    } 
    70      
     94 
    7195    self::$test->comment('Login user'); 
    72      
    73     return $this->  
     96 
     97    return $this-> 
    7498      click('Sign in')-> 
    7599      setField('signin[username]', $user->getUsername())-> 
     
    79103      get($goto); 
    80104  } 
    81    
     105 
    82106  /** 
    83107   * Generates and returns a test user 
     
    91115      self::$standardUser = usersFactory::createTestUser('testuser', 'testpass1', 'testuser@gmail.com'); 
    92116    } 
    93      
     117 
    94118    return self::$standardUser; 
    95119  } 
    96    
     120 
    97121  /** 
    98122   * Generates and returns a test admin user 
     
    106130      self::$adminUser = usersFactory::createTestUser('testadmin', 'testpass2', 'testadmin@gmail.com', true); 
    107131    } 
    108      
     132 
    109133    return self::$adminUser; 
    110134  } 
    111    
     135 
    112136  /** 
    113137   * Loads project default fixtures 
     
    117141  { 
    118142    self::$test->comment('Loading fixtures...'); 
    119      
     143 
    120144    $t = new sfPropelLoadDataTask(self::$configuration->getEventDispatcher(), new sfAnsiColorFormatter()); 
    121145    $t->run(array('application' => self::$configuration->getApplication())); 
    122      
     146 
    123147    self::$test->comment('Fixtures loaded.'); 
    124148  } 
    125    
     149 
     150  /** 
     151   * Sets a form field in the browser. 
     152   * 
     153   * @param string $name   The field name 
     154   * @param string $value  The field value 
     155   * 
     156   * @return sfBrowser 
     157   */ 
     158  public function setField($name, $value) 
     159  { 
     160    self::$test->diag(sprintf('setting field "%s" value to "%s"', $name, $value)); 
     161 
     162    return parent::setField($name, $value); 
     163  } 
     164 
    126165  /** 
    127166   * Retrieve the current user session 
     
    133172    return $this->getContext()->getUser(); 
    134173  } 
    135    
     174 
    136175  /** 
    137176   * Sets the value of a session attribute 
     
    148187    return $this; 
    149188  } 
    150    
     189 
    151190  /** 
    152191   * Checks if a session attribute matches a value 
     
    162201    return $this; 
    163202  } 
    164    
     203 
    165204  /** 
    166205   * Forces current user to be authenticated 
     
    174213    return $this; 
    175214  } 
    176    
     215 
    177216} 
    178217 
  • trunk/test/functional/main/applicationsActionsTest.php

    r70 r71  
    88 
    99$browser-> 
    10    
     10 
    1111  // Check application home 
    1212  get('/logout')-> // Forces the purge of the session 
     
    3939  signInUser('/application/add')-> 
    4040  isStatusCode(200)-> 
    41    
     41 
    4242  // Checking app form defaults 
    4343  responseContains('<input type="checkbox" name="application[is_opensource]" id="application_is_opensource" />')-> 
    44    
     44 
    4545  // Create a new application 
    4646  setField('application[name]', 'My test app')-> 
     
    5050  isRequestParameter('action', 'edit')-> 
    5151  followRedirect()-> 
    52    
     52 
    5353  // Connect as developer 
    5454  isRequestParameter('module', 'applications')-> 
     
    6363  isStatusCode(302)-> 
    6464  followRedirect()-> 
    65    
     65 
    6666  // Check application details page 
    6767  isRequestParameter('module', 'applications')-> 
     
    6969  isRequestParameter('slug', 'my-test-app')-> 
    7070  checkResponseElement('p.notice', '/You have been marked as implied with this application/', array('position' => 0))-> 
    71    
     71 
     72  // Connect a company 
     73  click('Connect a company!')-> 
     74  isRequestParameter('module', 'applications')-> 
     75  isRequestParameter('action', 'connectAsCompany')-> 
     76  isStatusCode(200)-> 
     77  setField('connection[role]', 'My company role')-> 
     78  click('Connect the company to this application')-> 
     79  isRequestParameter('module', 'applications')-> 
     80  isRequestParameter('action', 'connectAsCompany')-> 
     81  // FIXME: current testuser doesn't have any companies! 
     82  isStatusCode(302)-> 
     83  followRedirect()-> 
     84  isRequestParameter('module', 'applications')-> 
     85  isRequestParameter('action', 'details')-> 
     86  isRequestParameter('slug', 'my-test-app')-> 
     87  checkResponseElement('p.notice', '/The company has been marked as connected to this application/', array('position' => 0))-> 
     88 
    7289  // Edit application 
    7390  click('Edit this application informations')-> 
     
    7996  isStatusCode(302)-> 
    8097  followRedirect()-> 
    81    
     98 
    8299  // Check application details page 
    83100  isRequestParameter('module', 'applications')-> 
     
    89106  checkResponseElement('table.related_people_list tr', '/My role/', array('position' => 0))-> 
    90107  checkResponseElement('table.related_people_list tr', '/Mostly sleeping/', array('position' => 0))-> 
    91    
     108 
    92109  shutdown() 
    93110;