Changeset 68

Show
Ignore:
Timestamp:
07/14/08 09:25:04 (2 years ago)
Author:
nperriault
Message:

[1.1] everything is broken \o/

Files:

Legend:

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

    r50 r68  
    120120application_add: 
    121121  url:   /application/add 
    122   param: { module: applications, action: add
     122  param: { module: applications, action: edit
    123123 
    124124application_edit: 
  • trunk/apps/main/modules/applications/actions/actions.class.php

    r66 r68  
    99{ 
    1010 
    11   public function executeAdd(sfWebRequest $request) 
    12   { 
    13     $this->forward('applications', 'edit'); 
    14   } 
    15  
    1611  public function executeCountries(sfWebRequest $request) 
    1712  { 
     
    2116  public function executeEdit(sfWebRequest $request) 
    2217  { 
    23     $creation = false; 
    24      
    25     if (!$application = $this->getFromSlug()) 
     18    if (!is_null($request->getParameter('slug'))) 
     19    { 
     20      $application = $this->getFromSlug(); 
     21       
     22      $this->forward404If(is_null($application), sprintf('App with slug "%s" not found', $request->getParameter('slug'))); 
     23       
     24      if (!$this->getUser()->isAdmin() && $application->getSubmitterId() != $this->getUser()->getId()) 
     25      { 
     26        $this->getUser()->setFlash('warning', $this->__('You are not allowed to edit this record')); 
     27        $this->redirect('@application_page?slug='.$application->getSlug()); 
     28      } 
     29       
     30      $this->setTemplate('edit'); 
     31      $message = $this->__('Application updated'); 
     32      $redirect = '@application_page?slug=%s'; 
     33      $creation = false; 
     34    } 
     35    else 
    2636    { 
    2737      $application = new Application(); 
     38      $this->setTemplate('add'); 
     39      $message = $this->__('Application added'); 
     40      $redirect = '@application_connect_as_developer?slug=%s'; 
    2841      $creation = true; 
    29       $this->setTemplate('add'); 
    30     } 
    31      
    32     if (!$creation && !$this->getUser()->isAdmin() && $application->getSubmitterId() != $this->getUser()->getId()) 
    33     { 
    34       $this->getUser()->setFlash('warning', $this->__('You are not allowed to edit this record')); 
    35       $this->redirect('@application_page?slug='.$application->getSlug()); 
    3642    } 
    3743     
     
    5359      } 
    5460       
     61      /* @var $application Application */ 
    5562      $application = $this->form->getObject(); 
    5663       
    57       // Process uploaded image file 
    58       $this->processUploadedImage($this->form->getValue('screenshot_path'), $application); 
     64      /* @var $thumb sfValidatedThumb */ 
     65      $thumb = $this->form->getValue('screenshot_path'); 
     66      $thumb->makeThumb( 
     67        sfConfig::get('app_applications_screenshot_width', 200), 
     68        sfConfig::get('app_applications_screenshot_height', 140), 
     69        sfConfig::get('app_applications_screenshot_mime', 'image/jpeg'), 
     70        sfConfig::get('app_applications_screenshot_quality', 90) 
     71      ); 
     72      $thumb_name = md5($application->getName()).'.jpg'; 
     73      $thumb->save(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 
     74                   sfConfig::get('app_applications_upload_dir', 'applications') . DIRECTORY_SEPARATOR .  
     75                   $thumb_name); 
     76       
     77      $application->setScreenshotPath($thumb_name); 
     78      $application->save(); 
    5979       
    6080      parent::purgeObjectRelatedCache($application); 
    6181       
    62       if (isset($creation) && true === $creation) 
    63       { 
    64         $message = $this->__('Application added'); 
    65         $redirect = '@application_connect_as_developer?slug='.$application->getSlug(); 
    66       } 
    67       else 
    68       { 
    69         $message = $this->__('Application updated'); 
    70         $redirect = '@application_page?slug='.$application->getSlug(); 
    71       } 
    72        
    7382      $this->getUser()->setFlash('notice', $message); 
    74       $this->getUser()->setAttribute('from_app_creation', $creation, 'symfonians'); 
    75       $this->redirect($redirect); 
     83      $this->getUser()->setAttribute('from_app_creation', is_null($request->getParameter('slug')), 'symfonians'); 
     84      $this->redirect(sprintf($redirect, $application->getSlug())); 
    7685    } 
    7786  } 
     
    102111    $this->connection = ApplicationDeveloperPeer::retrieveByPK($this->getRequestParameter('id')); 
    103112    $this->forward404Unless($this->connection, 'ApplicationDeveloper not found'); 
     113    $this->form = new ApplicationDeveloperForm($this->connection); 
    104114 
    105115    if ($request->isMethod('post')) 
     
    147157    $this->connection = new ApplicationDeveloper(); 
    148158    $this->application = $this->getFromSlug(); 
     159    $this->form = new ApplicationDeveloperForm($this->connection); 
    149160 
    150161    // Checks if a relation already exists for this person 
     
    162173    if ($request->isMethod('post')) 
    163174    { 
    164       $this->updateDeveloperConnectionFromRequest(); 
    165       parent::purgeObjectRelatedCache($this->connection); 
    166  
    167       $this->getUser()->setFlash('notice', $this->__('You have been marked as implied with this application')); 
    168       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     175      $params = array_merge($request->getParameter('connection'),  
     176                            array('application_id' => $this->application->getId(), 
     177                                  'developer_id'   => $this->getUser()->getId())); 
     178      $this->form->bind($params); 
     179      if ($this->form->isValid()) 
     180      { 
     181        $this->form->save(); 
     182        parent::purgeObjectRelatedCache($this->connection); 
     183        $this->getUser()->setFlash('notice', $this->__('You have been marked as implied with this application')); 
     184        $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     185      } 
    169186    } 
    170187 
     
    312329  } 
    313330 
    314   public function handleErrorEdit() 
    315   { 
    316     $this->application = $this->getFromSlug(); 
    317     return sfView::SUCCESS; 
    318   } 
    319  
    320   public function handleErrorEditCompanyConnection() 
    321   { 
    322     $this->application = $this->getFromSlug(); 
    323     $this->connection = ApplicationCompanyPeer::retrieveByPK($this->getRequestParameter('id')); 
    324     $this->forward404Unless($this->connection, 'ApplicationCompany not found'); 
    325     $this->form_action = sprintf('@application_edit_company_connection?slug=%s&id=%d', 
    326                                  $this->application->getSlug(), 
    327                                  $this->connection->getId()); 
    328     $this->setTemplate('connectAsCompany'); 
    329     return sfView::SUCCESS; 
    330   } 
    331  
    332   public function handleErrorEditDeveloperConnection() 
    333   { 
    334     $this->application = $this->getFromSlug(); 
    335     $this->connection = ApplicationDeveloperPeer::retrieveByPK($this->getRequestParameter('id')); 
    336     $this->forward404Unless($this->connection, 'ApplicationDeveloper not found'); 
    337     $this->form_action = sprintf('@application_edit_developer_connection?slug=%s&id=%d', 
    338                                  $this->application->getSlug(), 
    339                                  $this->connection->getId()); 
    340     $this->setTemplate('connectAsDeveloper'); 
    341     return sfView::SUCCESS; 
    342   } 
    343    
    344331  /** 
    345332   * Process uploaded image file and updates passed Application object with the 
     
    373360  } 
    374361 
    375   public function handleErrorConnectAsCompany() 
    376   { 
    377     $this->connection = new ApplicationCompany(); 
    378     $this->application = $this->getFromSlug(); 
    379     $this->form_action = sprintf('@application_connect_as_company?slug=%s', 
    380                                  $this->application->getSlug()); 
    381     return sfView::SUCCESS; 
    382   } 
    383  
    384   public function handleErrorConnectAsDeveloper() 
    385   { 
    386     $this->connection = new ApplicationDeveloper(); 
    387     $this->application = $this->getFromSlug(); 
    388     $this->form_action = sprintf('@application_connect_as_developer?slug=%s', 
    389                                  $this->application->getSlug()); 
    390     return sfView::SUCCESS; 
    391   } 
    392  
    393   protected function updateCompanyConnectionFromRequest() 
    394   { 
    395     $connection_data = $this->getRequestParameter('connection', array()); 
    396  
    397     if (isset($connection_data['started_at']) && $connection_data['started_at'] == '') 
    398     { 
    399       unset($connection_data['started_at']); 
    400     } 
    401     if (isset($connection_data['ended_at']) && $connection_data['ended_at'] == '') 
    402     { 
    403       unset($connection_data['ended_at']); 
    404     } 
    405  
    406     try 
    407     { 
    408       $this->connection->fromArray($connection_data, BasePeer::TYPE_FIELDNAME); 
    409       $this->connection->setApplication($this->application); 
    410       $this->connection->setSubmitterId($this->getUser()->getId()); 
    411       $this->connection->save(); 
    412     } 
    413     catch (Exception $e) 
    414     { 
    415       $this->getRequest()->setError('errors', $this->__('Unable to save this relation')); 
    416       sfContext::getInstance()->getLogger()->err('Blocking error at ApplicationCompany save time: '.$e->getMessage()); 
    417     } 
    418   } 
    419  
    420   protected function updateDeveloperConnectionFromRequest() 
    421   { 
    422     $connection_data = $this->getRequestParameter('connection', array()); 
    423  
    424     if (isset($connection_data['started_at']) && $connection_data['started_at'] == '') 
    425     { 
    426       unset($connection_data['started_at']); 
    427     } 
    428     if (isset($connection_data['ended_at']) && $connection_data['ended_at'] == '') 
    429     { 
    430       unset($connection_data['ended_at']); 
    431     } 
    432  
    433     try 
    434     { 
    435       $this->connection->fromArray($connection_data, BasePeer::TYPE_FIELDNAME); 
    436       $this->connection->setDeveloperId($this->getUser()->getId()); 
    437       $this->connection->setApplication($this->application); 
    438       $this->connection->save(); 
    439     } 
    440     catch (Exception $e) 
    441     { 
    442       $this->getRequest()->setError('errors', $this->__('Unable to save this relation')); 
    443       sfContext::getInstance()->getLogger()->err('Blocking error at ApplicationDeveloper save time: '.$e->getMessage()); 
    444     } 
    445   } 
    446  
    447362} 
  • trunk/apps/main/modules/applications/templates/connectAsDeveloperSuccess.php

    r50 r68  
    4141      <legend><?php echo __('Connection informations') ?></legend> 
    4242      <div class="form-row required"> 
    43         <label for="role"><?php echo __('Your role in this project') ?></label
    44         <?php echo object_input_tag($connection, 'getRole', 'name=connection[role]', $sf_params->get('connection[role]')) ?> 
    45         <?php echo form_error('connection[role]') ?> 
     43        <?php echo $form['role']->renderLabel(__('Your role in this project')) ?
     44        <?php echo $form['role']->render() ?> 
     45        <?php echo $form['role']->renderError() ?> 
    4646      </div> 
    4747      <div class="form-row"> 
    48         <label for="description"><?php echo __('Description of your work') ?></label
    49         <?php echo object_textarea_tag($connection, 'getDescription', 'name=connection[description]', $sf_params->get('connection[description]')) ?> 
    50         <?php echo form_error('connection[description]') ?> 
     48        <?php echo $form['description']->renderLabel(__('Description of your work')) ?
     49        <?php echo $form['description']->render() ?> 
     50        <?php echo $form['description']->renderError() ?> 
    5151      </div> 
    5252    </fieldset> 
     
    5555    <fieldset> 
    5656      <legend><?php echo __('Timeline') ?></legend> 
    57       <div class="form-row"> 
    58         <label for="started_at"><?php echo __('Start date of activity (yyyy-mm-dd)') ?></label> 
    59         <?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]')) ?> 
    60         <?php echo form_error('connection[started_at]') ?> 
    61       </div> 
    62       <div class="form-row"> 
    63         <label for="ended_at"><?php echo __('End date of activity (yyyy-mm-dd)') ?></label> 
    64         <?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]')) ?> 
    65         <?php echo form_error('connection[ended_at]') ?> 
     57      <div class="date_select"> 
     58        <div class="form-row"> 
     59          <?php echo $form['started_at']->renderLabel(__('Start date of activity')) ?> 
     60          <?php echo $form['started_at']->render() ?> 
     61          <?php echo $form['started_at']->renderError() ?> 
     62        </div> 
     63        <div class="form-row"> 
     64          <?php echo $form['ended_at']->renderLabel(__('End date of activity')) ?> 
     65          <?php echo $form['ended_at']->render() ?> 
     66          <?php echo $form['ended_at']->renderError() ?> 
     67        </div> 
    6668      </div> 
    6769    </fieldset> 
     
    6971  <div class="form-row" style="text-align:center;clear:left;"> 
    7072    <p> 
    71       <?php echo button_to(__('Cancel'), '@application_page?slug='.$application->getSlug()) ?>&nbsp; 
    72       <?php echo submit_tag(__('Connect your profile to this application')) ?> 
     73      <?php echo $form['_csrf_token'] ?> 
     74      <input type="button" value="<?php echo __('Cancel') ?>" onclick="document.location='<?php echo url_for('@application_page?slug='.$application->getSlug()) ?>';return false"/> 
     75      <input type="submit" name="commit" value="<?php echo __('Connect your profile to this application') ?>"/> 
    7376    </p> 
    7477  </div> 
  • trunk/lib/form/ApplicationDeveloperForm.class.php

    r56 r68  
    1212  public function configure() 
    1313  { 
     14    $context = sfContext::getInstance(); 
     15    $culture = $context->getUser()->getCulture(); 
     16     
     17    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     
     28    $this->widgetSchema->setNameFormat('connection[%s]'); 
    1429  } 
    1530} 
  • trunk/lib/form/ApplicationForm.class.php

    r66 r68  
    1313    $context = sfContext::getInstance(); 
    1414    $culture = $context->getUser()->getCulture(); 
    15     //sfLoader::loadHelpers('I18n'); 
    1615     
    1716    // Unset unused widgets 
     
    3130    // Overriding validators 
    3231    $this->validatorSchema['tags']            = new sfValidatorRegex(array('pattern' => '/[0-9\w.-_, ]/i', 'required' => false)); 
    33     $this->validatorSchema['screenshot_path'] = new sfValidatorFile(array('max_size' => 512000, 'required' => false));  
     32    $this->validatorSchema['screenshot_path'] = new sfValidatorFile(array('max_size' => 512000,  
     33                                                                          'mime_types' => 'web_images', 
     34                                                                          'validated_file_class' => 'sfValidatedThumb',  
     35                                                                          'required' => false));  
    3436    $this->validatorSchema['country']         = new sfValidatorI18nChoiceCountry(array('culture' => $culture, 'required' => false)); 
    3537    $this->validatorSchema['started_at']      = new sfValidatorDate(array('required' => false)); 
  • trunk/plugins

    • Property svn:externals changed from
      sfPropelAlternativeSchemaPlugin http://svn.symfony-project.com/plugins/sfPropelAlternativeSchemaPlugin
      sfWebBrowserPlugin http://svn.symfony-project.com/plugins/sfWebBrowserPlugin
      sfPagerNavigationPlugin http://svn.symfony-project.com/plugins/sfPagerNavigationPlugin
      sfFeed2Plugin http://svn.symfony-project.com/plugins/sfFeed2Plugin
      sfPropelMigrationsLightPlugin -r7087 http://svn.symfony-project.com/plugins/sfPropelMigrationsLightPlugin/trunk/
      sfSwiftPlugin http://svn.symfony-project.com/plugins/sfSwiftPlugin/trunk
      sfLucenePlugin http://svn.symfony-project.com/plugins/sfLucenePlugin/branches/1.1
      sfGuardPlugin http://svn.symfony-project.com/plugins/sfGuardPlugin/branches/1.1
      sfFormExtraPlugin http://svn.symfony-project.com/plugins/sfFormExtraPlugin/
      to
      sfPropelAlternativeSchemaPlugin http://svn.symfony-project.com/plugins/sfPropelAlternativeSchemaPlugin
      sfWebBrowserPlugin http://svn.symfony-project.com/plugins/sfWebBrowserPlugin
      sfPagerNavigationPlugin http://svn.symfony-project.com/plugins/sfPagerNavigationPlugin
      sfFeed2Plugin http://svn.symfony-project.com/plugins/sfFeed2Plugin
      sfPropelMigrationsLightPlugin http://svn.symfony-project.com/plugins/sfPropelMigrationsLightPlugin/trunk/
      sfSwiftPlugin http://svn.symfony-project.com/plugins/sfSwiftPlugin/trunk
      sfLucenePlugin http://svn.symfony-project.com/plugins/sfLucenePlugin/branches/1.1
      sfGuardPlugin http://svn.symfony-project.com/plugins/sfGuardPlugin/branches/1.1
      sfFormExtraPlugin http://svn.symfony-project.com/plugins/sfFormExtraPlugin/
      sfPropelActAsTaggableBehaviorPlugin http://svn.symfony-project.com/plugins/sfPropelActAsTaggableBehaviorPlugin/trunk/
  • trunk/test/functional/main/applicationsActionsTest.php

    r66 r68  
    88 
    99$browser-> 
     10   
     11  // Check application home 
    1012  get('/applications')-> 
    1113  isStatusCode(200)-> 
     
    2224  checkResponseElement('.thumbs_list h4', '/Crédinoé/', array('position' => 5))-> 
    2325 
     26  // Check application page 
    2427  click('Splitgames')-> 
    2528  isStatusCode(200)-> 
     
    3538  signInUser('/application/add')-> 
    3639  isStatusCode(200)-> 
     40   
     41  // Create a new application 
    3742  setField('application[name]', 'My test app')-> 
    3843  click('Add this application')-> 
     
    4146  isRequestParameter('action', 'add')-> 
    4247  followRedirect()-> 
     48   
     49  // Connect as developer 
    4350  isRequestParameter('module', 'applications')-> 
    4451  isRequestParameter('action', 'connectAsDeveloper')-> 
    45   click('')->//TODO 
     52  checkResponseElement('p.notice', '/Application added/', array('position' => 0))-> 
     53  checkResponseElement('h2', '/Connect yourself to the My test app application/', array('position' => 0))-> 
     54  setField('connection[role]', 'My role')-> 
     55  setField('connection[description]', 'Mostly sleeping')-> 
     56  click('Connect your profile to this application')-> 
     57  isRequestParameter('module', 'applications')-> 
     58  isRequestParameter('action', 'connectAsDeveloper')-> 
     59  isStatusCode(302)-> 
     60  followRedirect()-> 
     61   
     62  // Check application details page 
    4663  isRequestParameter('module', 'applications')-> 
    4764  isRequestParameter('action', 'details')-> 
    4865  isRequestParameter('slug', 'my-test-app')-> 
    49   checkResponseElement('p.notice', '/Application updated/', array('position' => 0))-> 
     66  checkResponseElement('p.notice', '/You have been marked as implied with this application/', array('position' => 0))-> 
     67   
     68  // Edit application 
    5069  click('Edit this application informations')-> 
    5170  isRequestParameter('module', 'applications')-> 
     
    5978  isRequestParameter('action', 'details')-> 
    6079  isRequestParameter('slug', 'my-test-app')-> 
    61   checkResponseElement('p.notice', '/Application updated/', array('position' => 0)) 
     80  checkResponseElement('p.notice', '/Application updated/', array('position' => 0))-> 
     81  checkResponseElement('h2', '/My edited test app/', array('position' => 0)) 
    6282;