Changeset 70

Show
Ignore:
Timestamp:
07/14/08 22:52:55 (4 months ago)
Author:
nperriault
Message:

[1.1] application form post validators

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/main/modules/applications/actions/actions.class.php

    r69 r70  
    318318  } 
    319319 
    320   /** 
    321    * Process uploaded image file and updates passed Application object with the 
    322    * thumb path field updated 
    323    * 
    324    * @param  sfValidatedFile|null  $file         The uploaded file 
    325    * @param  Application           $application  The Application object instance 
    326    */ 
    327   protected function processUploadedImage($file, Application $application) 
    328   { 
    329     if (is_null($file)) 
    330     { 
    331       return null; 
    332     } 
    333  
    334     $thumb = ImagesTools::createThumb ( 
    335       $file, 
    336       sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.sfConfig::get('app_applications_upload_dir', 'applications'), 
    337       md5($application->getName()).'.jpg', 
    338       sfConfig::get('app_applications_screenshot_width', 200), 
    339       sfConfig::get('app_applications_screenshot_height', 140), 
    340       sfConfig::get('app_applications_screenshot_mime', 'image/jpeg'), 
    341       sfConfig::get('app_applications_screenshot_quality', 90) 
    342     ); 
    343      
    344     if ($thumb) 
    345     { 
    346       $application->setScreenshotPath($thumb); 
    347       $application->save(); 
    348     } 
    349   } 
    350  
    351320} 
  • trunk/apps/main/modules/applications/templates/_form.php

    r69 r70  
    1414    <fieldset> 
    1515      <legend><?php echo __('Application informations') ?></legend> 
    16       <div class="form-row required"> 
     16      <div class="form-row required <?php echo $form['name']->hasError() ? 'field_error' : '' ?>"> 
    1717        <?php echo $form['name']->renderLabel() ?> 
    1818        <?php echo $form['name']->render() ?> 
  • trunk/lib/form/ApplicationForm.class.php

    r69 r70  
    1111  public function configure() 
    1212  { 
     13    sfLoader::loadHelpers('I18n'); 
    1314    $context = sfContext::getInstance(); 
    1415    $culture = $context->getUser()->getCulture(); 
     
    2425    // Overriding widgets 
    2526    $this->widgetSchema['tags']               = new sfWidgetFormInput(); 
    26     $this->widgetSchema['country']            = new sfWidgetFormI18nSelectCountry(array('culture' => $culture)); 
     27    $this->widgetSchema['country']            = new ExtendedWidgetFormI18nSelectCountry(array('culture' => $culture, 'add_label_option' => __('Select a country'))); 
    2728    $this->widgetSchema['started_at']         = new sfWidgetFormI18nDate(array('culture' => $culture)); 
    2829    $this->widgetSchema['released_at']        = new sfWidgetFormI18nDate(array('culture' => $culture)); 
     
    3031     
    3132    // Overriding validators 
    32     $this->validatorSchema['tags']            = new sfValidatorRegex(array('pattern' => '/[0-9\w.-_, ]/i', 'required' => false)); 
     33    $this->validatorSchema['tags']            = new sfValidatorTags(array('separator' => ',', 'required' => false)); 
    3334    $this->validatorSchema['country']         = new sfValidatorI18nChoiceCountry(array('culture' => $culture, 'required' => false)); 
    3435    $this->validatorSchema['started_at']      = new sfValidatorDate(array('required' => false)); 
     
    4041     
    4142    // Redefined validators 
    42     $this->validatorSchema['homepage'] = new sfValidatorUrl(array('required' => false)); 
     43    $this->validatorSchema['homepage'] = new sfValidatorOr(array( 
     44      new sfValidatorUrl(), 
     45      new sfValidatorChoice(array('choices' => array('http://', ''))), 
     46    )); 
    4347    $this->validatorSchema['feed_url'] = new sfValidatorOr(array( 
    4448      new sfValidatorUrl(), 
    4549      new sfValidatorChoice(array('choices' => array('http://', ''))), 
    4650    )); 
     51     
     52    // Post validators 
     53    /*$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( 
     54        new sfValidatorPropelUnique(array('model' => 'Application', 'column' => array('homepage'))), 
     55        new sfValidatorSchemaLicence(),  
     56    )));*/ 
    4757     
    4858    // Defaults 
     
    5161                             'released_at'   => 'today',   // thanks strtotime() 
    5262                             'is_featured'   => null, 
    53                              'is_opensource' => false)); 
     63                             'is_opensource' => null)); 
    5464  } 
    5565} 
  • trunk/lib/utils/sfValidatedThumb.class.php

    r69 r70  
    22/** 
    33 * Saves an uploaded image file as a web thumb and updates a Propel object  
    4  * accordingly. 
     4 * accordingly. The thumbnail generation depends on the sfThumbnail plugin. 
    55 *   
    66 * This class aims to be used as the one to use with the sfValidatorFile  
     
    99 *     new sfValidatorFile(array('validated_file_class' => 'sfValidatedThumb')); 
    1010 * 
     11 * You must use the saveThumb() method to save the thumb on your filesystem: 
     12 *  
     13 *     $thumb->saveThumb('applications', $application, 'setThumbnail') 
     14 *  
    1115 * @package    symfonians 
    1216 * @subpackage validator 
     
    1418class sfValidatedThumb extends sfValidatedFile 
    1519{ 
     20   
     21  /** 
     22   * Allowed types 
     23   * @var array 
     24   */ 
     25  protected static $allowedTypes = array('applications', 'people', 'companies'); 
    1626   
    1727  /** 
     
    2636  public function saveThumb($type, BaseObject $object, $thumbSetter = 'setThumbPath', $fileMode = 0666, $create = true, $dirMode = 0777) 
    2737  { 
    28     if (!in_array($type, array('applications', 'people', 'companies'))) 
     38    if (!class_exists('sfThumbnail', true)) 
     39    { 
     40      throw new sfConfigurationException('The sfThumbnailPlugin must be installed'); 
     41    } 
     42     
     43    if (!in_array($type, self::$allowedTypes)) 
    2944    { 
    3045      throw new InvalidArgumentException(sprintf('Type "%s" is invalid', $type)); 
     
    3752    } 
    3853     
    39     $width    = sfConfig::get(sprintf('app_%s_screenshot_width', $type), 200); 
    40     $height   = sfConfig::get(sprintf('app_%s_screenshot_height', $type), 140); 
    41     $mime     = sfConfig::get(sprintf('app_%s_screenshot_mime', $type), 'image/jpeg'); 
    42     $quality  = sfConfig::get(sprintf('app_%s_screenshot_quality', $type), 90); 
     54    $width    = sfConfig::get(sprintf('app_%s_thumb.width', $type), 200); 
     55    $height   = sfConfig::get(sprintf('app_%s_thumb.height', $type), 140); 
     56    $quality  = sfConfig::get(sprintf('app_%s_thumb.quality', $type), 90); 
    4357     
    4458    $fileName = md5($object->__toString()).'.jpg'; 
     
    4862            $fileName; 
    4963     
    50     if (!$saved = parent::save($file, $fileMode, $create, $dirMode)) 
    51     { 
    52       return false
    53     } 
     64    $thumbnail = new sfThumbnail($width, $height, true, true, $quality, null); 
     65    $thumbnail->loadFile($this->getTempName()); 
     66    $thumbnail->save($file, 'image/jpeg')
     67    $this->savedName = $file; 
    5468     
    5569    $object->$thumbSetter($fileName); 
    56     $ok = $object->save(); 
    57     $this->savedName = $file; 
    5870     
    59     return ($ok > 0); 
     71    return ($object->save() > 0); 
    6072  } 
    6173   
  • trunk/test/functional/main/applicationsActionsTest.php

    r68 r70  
    1010   
    1111  // Check application home 
     12  get('/logout')-> // Forces the purge of the session 
    1213  get('/applications')-> 
    1314  isStatusCode(200)-> 
     
    3940  isStatusCode(200)-> 
    4041   
     42  // Checking app form defaults 
     43  responseContains('<input type="checkbox" name="application[is_opensource]" id="application_is_opensource" />')-> 
     44   
    4145  // Create a new application 
    4246  setField('application[name]', 'My test app')-> 
     
    4448  isStatusCode(302)-> 
    4549  isRequestParameter('module', 'applications')-> 
    46   isRequestParameter('action', 'add')-> 
     50  isRequestParameter('action', 'edit')-> 
    4751  followRedirect()-> 
    4852   
     
    7579  isStatusCode(302)-> 
    7680  followRedirect()-> 
     81   
     82  // Check application details page 
    7783  isRequestParameter('module', 'applications')-> 
    7884  isRequestParameter('action', 'details')-> 
    7985  isRequestParameter('slug', 'my-test-app')-> 
    8086  checkResponseElement('p.notice', '/Application updated/', array('position' => 0))-> 
    81   checkResponseElement('h2', '/My edited test app/', array('position' => 0)) 
     87  checkResponseElement('h2', '/My edited test app/', array('position' => 0))-> 
     88  checkResponseElement('table.related_people_list tr', '/testuser/', array('position' => 0))-> 
     89  checkResponseElement('table.related_people_list tr', '/My role/', array('position' => 0))-> 
     90  checkResponseElement('table.related_people_list tr', '/Mostly sleeping/', array('position' => 0))-> 
     91   
     92  shutdown() 
    8293;