Changeset 70
- Timestamp:
- 07/14/08 22:52:55 (4 months ago)
- Files:
-
- trunk/apps/main/modules/applications/actions/actions.class.php (modified) (1 diff)
- trunk/apps/main/modules/applications/templates/_form.php (modified) (1 diff)
- trunk/lib/form/ApplicationForm.class.php (modified) (5 diffs)
- trunk/lib/utils/sfValidatedThumb.class.php (modified) (6 diffs)
- trunk/lib/validator/sfValidatorSchemaLicence.class.php (added)
- trunk/lib/validator/sfValidatorTags.class.php (added)
- trunk/lib/widget/ExtendedWidgetFormI18nSelectCountry.class.php (added)
- trunk/test/functional/main/applicationsActionsTest.php (modified) (4 diffs)
- trunk/test/unit/ExtendedWidgetFormI18nSelectCountryTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/apps/main/modules/applications/actions/actions.class.php
r69 r70 318 318 } 319 319 320 /**321 * Process uploaded image file and updates passed Application object with the322 * thumb path field updated323 *324 * @param sfValidatedFile|null $file The uploaded file325 * @param Application $application The Application object instance326 */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 351 320 } trunk/apps/main/modules/applications/templates/_form.php
r69 r70 14 14 <fieldset> 15 15 <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' : '' ?>"> 17 17 <?php echo $form['name']->renderLabel() ?> 18 18 <?php echo $form['name']->render() ?> trunk/lib/form/ApplicationForm.class.php
r69 r70 11 11 public function configure() 12 12 { 13 sfLoader::loadHelpers('I18n'); 13 14 $context = sfContext::getInstance(); 14 15 $culture = $context->getUser()->getCulture(); … … 24 25 // Overriding widgets 25 26 $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'))); 27 28 $this->widgetSchema['started_at'] = new sfWidgetFormI18nDate(array('culture' => $culture)); 28 29 $this->widgetSchema['released_at'] = new sfWidgetFormI18nDate(array('culture' => $culture)); … … 30 31 31 32 // Overriding validators 32 $this->validatorSchema['tags'] = new sfValidator Regex(array('pattern' => '/[0-9\w.-_, ]/i', 'required' => false));33 $this->validatorSchema['tags'] = new sfValidatorTags(array('separator' => ',', 'required' => false)); 33 34 $this->validatorSchema['country'] = new sfValidatorI18nChoiceCountry(array('culture' => $culture, 'required' => false)); 34 35 $this->validatorSchema['started_at'] = new sfValidatorDate(array('required' => false)); … … 40 41 41 42 // 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 )); 43 47 $this->validatorSchema['feed_url'] = new sfValidatorOr(array( 44 48 new sfValidatorUrl(), 45 49 new sfValidatorChoice(array('choices' => array('http://', ''))), 46 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 )));*/ 47 57 48 58 // Defaults … … 51 61 'released_at' => 'today', // thanks strtotime() 52 62 'is_featured' => null, 53 'is_opensource' => false));63 'is_opensource' => null)); 54 64 } 55 65 } trunk/lib/utils/sfValidatedThumb.class.php
r69 r70 2 2 /** 3 3 * 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. 5 5 * 6 6 * This class aims to be used as the one to use with the sfValidatorFile … … 9 9 * new sfValidatorFile(array('validated_file_class' => 'sfValidatedThumb')); 10 10 * 11 * You must use the saveThumb() method to save the thumb on your filesystem: 12 * 13 * $thumb->saveThumb('applications', $application, 'setThumbnail') 14 * 11 15 * @package symfonians 12 16 * @subpackage validator … … 14 18 class sfValidatedThumb extends sfValidatedFile 15 19 { 20 21 /** 22 * Allowed types 23 * @var array 24 */ 25 protected static $allowedTypes = array('applications', 'people', 'companies'); 16 26 17 27 /** … … 26 36 public function saveThumb($type, BaseObject $object, $thumbSetter = 'setThumbPath', $fileMode = 0666, $create = true, $dirMode = 0777) 27 37 { 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)) 29 44 { 30 45 throw new InvalidArgumentException(sprintf('Type "%s" is invalid', $type)); … … 37 52 } 38 53 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); 43 57 44 58 $fileName = md5($object->__toString()).'.jpg'; … … 48 62 $fileName; 49 63 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; 54 68 55 69 $object->$thumbSetter($fileName); 56 $ok = $object->save();57 $this->savedName = $file;58 70 59 return ($o k> 0);71 return ($object->save() > 0); 60 72 } 61 73 trunk/test/functional/main/applicationsActionsTest.php
r68 r70 10 10 11 11 // Check application home 12 get('/logout')-> // Forces the purge of the session 12 13 get('/applications')-> 13 14 isStatusCode(200)-> … … 39 40 isStatusCode(200)-> 40 41 42 // Checking app form defaults 43 responseContains('<input type="checkbox" name="application[is_opensource]" id="application_is_opensource" />')-> 44 41 45 // Create a new application 42 46 setField('application[name]', 'My test app')-> … … 44 48 isStatusCode(302)-> 45 49 isRequestParameter('module', 'applications')-> 46 isRequestParameter('action', ' add')->50 isRequestParameter('action', 'edit')-> 47 51 followRedirect()-> 48 52 … … 75 79 isStatusCode(302)-> 76 80 followRedirect()-> 81 82 // Check application details page 77 83 isRequestParameter('module', 'applications')-> 78 84 isRequestParameter('action', 'details')-> 79 85 isRequestParameter('slug', 'my-test-app')-> 80 86 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() 82 93 ;
