Changeset 71
- Timestamp:
- 08/02/08 22:23:55 (2 years ago)
- Files:
-
- trunk/apps/main/config/routing.yml (modified) (2 diffs)
- trunk/apps/main/modules/applications/actions/actions.class.php (modified) (14 diffs)
- trunk/apps/main/modules/applications/templates/connectAsCompanySuccess.php (modified) (7 diffs)
- trunk/apps/main/modules/applications/validate (deleted)
- trunk/apps/main/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php (modified) (3 diffs)
- trunk/lib/form/ActivationForm.class.php (modified) (1 diff)
- trunk/lib/form/ApplicationCompanyForm.class.php (modified) (3 diffs)
- trunk/lib/form/ApplicationDeveloperForm.class.php (modified) (3 diffs)
- trunk/lib/form/ApplicationForm.class.php (modified) (2 diffs)
- trunk/lib/form/BaseFormPropel.class.php (modified) (1 diff)
- trunk/lib/form/BlogPostForm.class.php (modified) (2 diffs)
- trunk/lib/form/CompanyForm.class.php (modified) (2 diffs)
- trunk/lib/form/CompanyPersonForm.class.php (modified) (2 diffs)
- trunk/lib/form/EventForm.class.php (modified) (2 diffs)
- trunk/lib/form/JobForm.class.php (modified) (2 diffs)
- trunk/lib/form/LocalEventForm.class.php (modified) (2 diffs)
- trunk/lib/form/RecommendationForm.class.php (modified) (2 diffs)
- trunk/lib/form/sfFormReCaptcha.class.php (modified) (5 diffs)
- trunk/lib/model/Application.php (modified) (13 diffs)
- trunk/lib/utils/SymfoniansTestBrowser.class.php (modified) (16 diffs)
- trunk/test/functional/main/applicationsActionsTest.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/apps/main/config/routing.yml
r68 r71 140 140 application_edit_company_connection: 141 141 url: /application/:slug/connection/:id/company/edit 142 param: { module: applications, action: editCompanyConnection}142 param: { module: applications, action: connectAsCompany } 143 143 144 144 application_connect_as_developer: … … 148 148 application_edit_developer_connection: 149 149 url: /application/:slug/connection/:id/person/edit 150 param: { module: applications, action: editDeveloperConnection}150 param: { module: applications, action: connectAsDeveloper } 151 151 152 152 application_tags: trunk/apps/main/modules/applications/actions/actions.class.php
r70 r71 8 8 class applicationsActions extends myActions 9 9 { 10 10 /** 11 * Lists applications countries 12 * 13 * @param sfWebRequest $request 14 */ 11 15 public function executeCountries(sfWebRequest $request) 12 16 { 13 17 $this->countries = ApplicationPeer::retrieveCountriesWithCount(); 14 18 } 15 19 20 /** 21 * Application creation or edition 22 * 23 * @param sfWebRequest $request 24 */ 16 25 public function executeEdit(sfWebRequest $request) 17 26 { … … 19 28 { 20 29 $application = $this->getFromSlug(); 21 30 22 31 $this->forward404If(is_null($application), sprintf('App with slug "%s" not found', $request->getParameter('slug'))); 23 32 24 33 if (!$this->getUser()->isAdmin() && $application->getSubmitterId() != $this->getUser()->getId()) 25 34 { … … 27 36 $this->redirect('@application_page?slug='.$application->getSlug()); 28 37 } 29 38 30 39 $this->form = new ApplicationForm($application); 31 40 $this->setTemplate('edit'); … … 43 52 $creation = true; 44 53 } 45 54 46 55 $this->form->setDefault('tags', $application->getTagsString()); 47 56 $this->application = $application; 48 57 49 58 if ($request->isMethod('post')) 50 59 { 51 60 // Set the submitter id from the session 52 61 $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'), 54 63 array('submitter_id' => $submitter_id)); 55 64 $this->form->bind($params, $request->getFiles('application')); 56 65 57 66 /* @var $application Application */ 58 67 if (!$this->form->isValid() or is_null($application = $this->form->save())) … … 60 69 return sfView::SUCCESS; 61 70 } 62 71 63 72 /* @var $thumb sfValidatedThumb */ 64 73 if (!is_null($thumb = $this->form->getValue('screenshot_file'))) … … 66 75 $thumb->saveThumb('applications', $application, 'setScreenshotPath'); 67 76 } 68 77 69 78 parent::purgeObjectRelatedCache($application); 70 79 71 80 $this->getUser()->setFlash('notice', $message); 72 81 $this->getUser()->setAttribute('from_app_creation', is_null($request->getParameter('slug')), 'symfonians'); … … 75 84 } 76 85 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 */ 118 91 public function executeConnectAsCompany(sfWebRequest $request) 119 92 { 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)); 122 122 123 123 // 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())); 130 127 131 128 // Form has been submitted 132 129 if ($request->isMethod('post')) 133 130 { 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 */ 144 155 public function executeConnectAsDeveloper(sfWebRequest $request) 145 156 { 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); 160 194 161 195 // Form has been submitted 162 196 if ($request->isMethod('post')) 163 197 { 164 $params = array_merge($request->getParameter('connection' ),198 $params = array_merge($request->getParameter('connection', array()), 165 199 array('application_id' => $this->application->getId(), 166 200 'developer_id' => $this->getUser()->getId())); … … 169 203 { 170 204 $this->form->save(); 171 parent::purgeObjectRelatedCache($ this->connection);205 parent::purgeObjectRelatedCache($connection); 172 206 $this->getUser()->setFlash('notice', $this->__('You have been marked as implied with this application')); 173 207 $this->redirect('@application_page?slug='.$this->application->getSlug()); 174 208 } 175 209 } 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 */ 180 217 public function executeDelete(sfWebRequest $request) 181 218 { … … 194 231 } 195 232 233 /** 234 * Shows application details 235 * 236 * @param sfWebRequest $request 237 */ 196 238 public function executeDetails(sfWebRequest $request) 197 239 { … … 219 261 } 220 262 263 /** 264 * Applications homepage 265 * 266 * @param sfWebRequest $request 267 */ 221 268 public function executeHome(sfWebRequest $request) 222 269 { … … 271 318 } 272 319 320 /** 321 * Promotes an application to the homepage 322 * 323 * @param sfWebRequest $request 324 */ 273 325 public function executePromote(sfWebRequest $request) 274 326 { … … 286 338 } 287 339 340 /** 341 * Show all applications tags 342 * 343 * @param sfWebRequest $request 344 */ 288 345 public function executeTags(sfWebRequest $request) 289 346 { … … 293 350 $this->tags = TagPeer::getPopulars($c); 294 351 } 295 352 296 353 /** 297 354 * Retrieves an Application object from the "slug" parameter, if exists 298 355 * 299 * @param Criteria|null $c Optional Propel Criteria 356 * @param Criteria|null $c Optional Propel Criteria 300 357 * @return Application|null 301 358 */ … … 306 363 return null; 307 364 } 308 365 309 366 if (!$c instanceof Criteria) 310 367 { 311 368 $c = new Criteria(); 312 369 } 313 370 314 371 $c->addJoin(ApplicationPeer::SUBMITTER_ID, sfGuardUserPeer::ID, Criteria::LEFT_JOIN); 315 372 $c->add(ApplicationPeer::SLUG, $this->getRequestParameter('slug')); 316 373 317 374 return ApplicationPeer::doSelectOne($c); 318 375 } 319 320 376 } trunk/apps/main/modules/applications/templates/connectAsCompanySuccess.php
r50 r71 2 2 3 3 <?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', 5 5 array('%application%' => $application->getName())) ?> 6 6 <?php echo $page_title ?> … … 9 9 <?php slot('sidebar') ?> 10 10 <?php if ($application->getScreenshotPath()): ?> 11 <?php $image = image_tag($application->getFullScreenshotPath(), 11 <?php $image = image_tag($application->getFullScreenshotPath(), 12 12 'class=app_screenshot alt='.$application->getName().' preview') ?> 13 13 <?php if ($application->getHomepage()): ?> … … 19 19 <?php end_slot() ?> 20 20 21 <?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 21 <?php echo breadcrumb(array(array(__('Applications'), '@application_home'), 22 22 array($application->getName(), '@application_page?slug='.$application->getSlug()), 23 23 $page_title)) ?> … … 37 37 <legend><?php echo __('Connection informations') ?></legend> 38 38 <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() ?> 45 42 <div class="form_help"> 46 43 <?php echo __('You must have already connected to companies to see them appearing in the select box below') ?> … … 48 45 </div> 49 46 <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() ?> 53 50 </div> 54 51 <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() ?> 58 55 </div> 59 56 </fieldset> … … 62 59 <fieldset> 63 60 <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> 73 72 </div> 74 73 </fieldset> … … 76 75 <div class="form-row" style="text-align:center;clear:left;"> 77 76 <p> 77 <?php echo $form['_csrf_token'] ?> 78 78 <?php echo button_to(__('Cancel'), '@application_page?slug='.$application->getSlug()) ?> 79 < ?php echo submit_tag(__('Connect the company to this application')) ?>79 <input type="submit" value="<?php echo __('Connect the company to this application') ?>"/> 80 80 </p> 81 81 </div> trunk/apps/main/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php
r53 r71 1 1 <?php 2 2 /** 3 * Base sfGuardAuth actions 4 * 3 * Base sfGuardAuth actions, overriden here just to have the myActions features 4 * 5 5 * @package symfony 6 6 * @subpackage plugin … … 21 21 { 22 22 $this->form->bind($request->getParameter('signin')); 23 23 24 24 if ($this->form->isValid()) 25 25 { … … 27 27 $this->getUser()->signin($values['user'], 'on' === $values['remember']); 28 28 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()); 31 30 return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage'); 32 31 } trunk/lib/form/ActivationForm.class.php
r68 r71 6 6 * @package form 7 7 * @subpackage activation 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 8 */ 10 9 class ActivationForm extends BaseActivationForm trunk/lib/form/ApplicationCompanyForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * ApplicationCompany form. … … 6 5 * @package form 7 6 * @subpackage application_company 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class ApplicationCompanyForm extends BaseApplicationCompanyForm … … 12 10 public function configure() 13 11 { 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]'); 14 25 } 15 26 } trunk/lib/form/ApplicationDeveloperForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * ApplicationDeveloper form. … … 6 5 * @package form 7 6 * @subpackage application_developer 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class ApplicationDeveloperForm extends BaseApplicationDeveloperForm … … 12 10 public function configure() 13 11 { 14 $context = sfContext::getInstance();15 $culture = $context->getUser()->getCulture();16 17 12 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 28 16 $this->widgetSchema->setNameFormat('connection[%s]'); 29 17 } trunk/lib/form/ApplicationForm.class.php
r70 r71 5 5 * @package form 6 6 * @subpackage application 7 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $8 7 */ 9 8 class ApplicationForm extends BaseApplicationForm 10 9 { 10 protected $culture = null; 11 11 12 public function configure() 12 13 { 13 14 sfLoader::loadHelpers('I18n'); 14 15 $context = sfContext::getInstance(); 15 $ culture = $context->getUser()->getCulture();16 16 $this->culture = $context->getUser()->getCulture(); 17 17 18 // Unset unused widgets 18 19 unset($this['id'], 19 $this['created_at'], 20 $this['created_at'], 20 21 $this['updated_at'], 21 $this['slug'], 22 $this['slug'], 22 23 $this['is_featured'], 23 24 $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 58 29 // Defaults 59 30 $this->setDefaults(array('homepage' => 'http://', … … 63 34 'is_opensource' => null)); 64 35 } 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 } 65 80 } trunk/lib/form/BaseFormPropel.class.php
r56 r71 4 4 * 5 5 * @package form 6 * @version SVN: $Id: sfPropelFormBaseTemplate.php 6174 2007-11-27 06:22:40Z fabien $7 6 */ 8 7 abstract class BaseFormPropel extends sfFormPropel trunk/lib/form/BlogPostForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * BlogPost form. … … 6 5 * @package form 7 6 * @subpackage blog_posts 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class BlogPostForm extends BaseBlogPostForm trunk/lib/form/CompanyForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * Company form. … … 6 5 * @package form 7 6 * @subpackage company 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class CompanyForm extends BaseCompanyForm trunk/lib/form/CompanyPersonForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * CompanyPerson form. … … 6 5 * @package form 7 6 * @subpackage company_people 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class CompanyPersonForm extends BaseCompanyPersonForm trunk/lib/form/EventForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * Event form. … … 6 5 * @package form 7 6 * @subpackage event 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class EventForm extends BaseEventForm trunk/lib/form/JobForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * Job form. … … 6 5 * @package form 7 6 * @subpackage jobs 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class JobForm extends BaseJobForm trunk/lib/form/LocalEventForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * LocalEvent form. … … 6 5 * @package form 7 6 * @subpackage local_event 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class LocalEventForm extends BaseLocalEventForm trunk/lib/form/RecommendationForm.class.php
r68 r71 1 1 <?php 2 3 2 /** 4 3 * Recommendation form. … … 6 5 * @package form 7 6 * @subpackage recommendation 8 * @version SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $9 7 */ 10 8 class RecommendationForm extends BaseRecommendationForm trunk/lib/form/sfFormReCaptcha.class.php
r56 r71 1 1 <?php 2 3 2 /* 4 3 * This file is part of the symfony package. … … 10 9 11 10 /** 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 14 13 * 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 17 16 * form. You can do so passing options to the constructor of the class, eg: 18 * 17 * 19 18 * $form = new sfFormReCaptcha(array(), array('recaptcha_public_key' => '12345', 20 19 * 'recaptcha_private_key' => '54321')); 21 * 20 * 22 21 * You can use symfony environements to configure if you want to use recaptcha 23 22 * for certain environment only … … 36 35 { 37 36 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 40 39 // called in __construct() so we can append the captcha field to the whole form. 41 40 $this->setupCaptcha(); 42 41 } 43 42 44 43 /** 45 44 * Bind parameters, including the captcha ones, from a sfRequest object instance … … 52 51 { 53 52 $nameFormat = $this->widgetSchema->getNameFormat(); 54 53 55 54 if ('%s' == $nameFormat) 56 55 { 57 56 throw new LogicException('You must define a name format using setNameFormat() in order to use the bindFromRequest() method'); 58 57 } 59 58 60 59 $nameFormat = substr($nameFormat, 0, strpos($nameFormat, ('['))); 61 60 62 61 $params = $request->getParameter($nameFormat, array()); 63 62 if (true === sfConfig::get('app_recaptcha_enabled')) … … 74 73 75 74 /** 76 * Setup captcha for current form 77 * 75 * Setup captcha for current form 76 * 78 77 */ 79 78 protected function setupCaptcha() trunk/lib/model/Application.php
r62 r71 17 17 return $this->getName(); 18 18 } 19 19 20 20 /** 21 21 * Fills current Application with array parameters, including tags … … 27 27 { 28 28 parent::fromArray($arr, $keyType); 29 29 30 30 foreach (array('tags', 'Tags') as $tagField) 31 31 { … … 36 36 } 37 37 } 38 38 39 39 /** 40 40 * Converts current Application to an associative array … … 46 46 { 47 47 $arr = parent::toArray($keyType); 48 48 49 49 if (BasePeer::TYPE_FIELDNAME == $keyType) 50 50 { … … 55 55 $arr['Tags'] = $this->getTagsString(); 56 56 } 57 57 58 58 return $arr; 59 59 } … … 216 216 public function hasCompanyConnected($company) 217 217 { 218 if (!$company) 219 { 220 return false; 221 } 222 218 223 if ($company instanceof BaseCompany) 219 224 { … … 224 229 $company_id = $company; 225 230 } 231 226 232 $c = new Criteria; 227 233 $c->add(ApplicationCompanyPeer::COMPANY_ID, $company_id); 234 228 235 return ($this->countApplicationCompanys($c) > 0); 229 236 } 230 237 231 238 /** 232 239 * Checks if an application is owned by a given user … … 240 247 $user_id = $user_id->getId(); 241 248 } 242 249 243 250 return ($this->getSubmitterId() === $user_id); 244 251 } … … 293 300 return $save; 294 301 } 295 302 296 303 /** 297 304 * Sets the feed url value … … 305 312 $v = null; 306 313 } 307 314 308 315 return parent::setFeedUrl($v); 309 316 } 310 317 311 318 /** 312 319 * Sets the homepage url value … … 320 327 $v = null; 321 328 } 322 329 323 330 return parent::setHomepage($v); 324 331 } 325 332 326 333 /** 327 334 * Sets is_featured field and update according relations … … 340 347 parent::setIsFeatured($flag); 341 348 } 342 349 343 350 /** 344 351 * Sets application tags, only if application has already been saved … … 352 359 return; 353 360 } 354 361 355 362 $this->removeAllTags(); 356 363 $this->addTag($tags); trunk/lib/utils/SymfoniansTestBrowser.class.php
r66 r71 2 2 /** 3 3 * Symfonians functional tests browser: 4 * 4 * 5 5 * - initializes database manager automatically 6 6 * - provides session testing utilities … … 9 9 * @subpackage test 10 10 */ 11 class SymfoniansTestBrowser extends sfTestBrowser 11 class SymfoniansTestBrowser extends sfTestBrowser 12 12 { 13 13 14 14 /** 15 15 * Database manager … … 17 17 */ 18 18 protected static $db = null; 19 19 20 20 /** 21 21 * Admin test user … … 23 23 */ 24 24 protected static $adminUser = null; 25 25 26 26 /** 27 27 * Standard test user … … 29 29 */ 30 30 protected static $standardUser = null; 31 31 32 32 /** 33 33 * Application configuration … … 35 35 */ 36 36 protected static $configuration = null; 37 37 38 38 /** 39 39 * Public constructor, and initialize database manager 40 40 * 41 * @param sfApplicationConfiguration $configuration 41 * @param sfApplicationConfiguration $configuration 42 42 * @see sfTestBrowser 43 43 */ … … 48 48 return parent::__construct($hostname, $remote, $options); 49 49 } 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 51 75 /** 52 76 * Sign in a test user … … 68 92 $pass = 'testpass1'; 69 93 } 70 94 71 95 self::$test->comment('Login user'); 72 73 return $this-> 96 97 return $this-> 74 98 click('Sign in')-> 75 99 setField('signin[username]', $user->getUsername())-> … … 79 103 get($goto); 80 104 } 81 105 82 106 /** 83 107 * Generates and returns a test user … … 91 115 self::$standardUser = usersFactory::createTestUser('testuser', 'testpass1', 'testuser@gmail.com'); 92 116 } 93 117 94 118 return self::$standardUser; 95 119 } 96 120 97 121 /** 98 122 * Generates and returns a test admin user … … 106 130 self::$adminUser = usersFactory::createTestUser('testadmin', 'testpass2', 'testadmin@gmail.com', true); 107 131 } 108 132 109 133 return self::$adminUser; 110 134 } 111 135 112 136 /** 113 137 * Loads project default fixtures … … 117 141 { 118 142 self::$test->comment('Loading fixtures...'); 119 143 120 144 $t = new sfPropelLoadDataTask(self::$configuration->getEventDispatcher(), new sfAnsiColorFormatter()); 121 145 $t->run(array('application' => self::$configuration->getApplication())); 122 146 123 147 self::$test->comment('Fixtures loaded.'); 124 148 } 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 126 165 /** 127 166 * Retrieve the current user session … … 133 172 return $this->getContext()->getUser(); 134 173 } 135 174 136 175 /** 137 176 * Sets the value of a session attribute … … 148 187 return $this; 149 188 } 150 189 151 190 /** 152 191 * Checks if a session attribute matches a value … … 162 201 return $this; 163 202 } 164 203 165 204 /** 166 205 * Forces current user to be authenticated … … 174 213 return $this; 175 214 } 176 215 177 216 } 178 217 trunk/test/functional/main/applicationsActionsTest.php
r70 r71 8 8 9 9 $browser-> 10 10 11 11 // Check application home 12 12 get('/logout')-> // Forces the purge of the session … … 39 39 signInUser('/application/add')-> 40 40 isStatusCode(200)-> 41 41 42 42 // Checking app form defaults 43 43 responseContains('<input type="checkbox" name="application[is_opensource]" id="application_is_opensource" />')-> 44 44 45 45 // Create a new application 46 46 setField('application[name]', 'My test app')-> … … 50 50 isRequestParameter('action', 'edit')-> 51 51 followRedirect()-> 52 52 53 53 // Connect as developer 54 54 isRequestParameter('module', 'applications')-> … … 63 63 isStatusCode(302)-> 64 64 followRedirect()-> 65 65 66 66 // Check application details page 67 67 isRequestParameter('module', 'applications')-> … … 69 69 isRequestParameter('slug', 'my-test-app')-> 70 70 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 72 89 // Edit application 73 90 click('Edit this application informations')-> … … 79 96 isStatusCode(302)-> 80 97 followRedirect()-> 81 98 82 99 // Check application details page 83 100 isRequestParameter('module', 'applications')-> … … 89 106 checkResponseElement('table.related_people_list tr', '/My role/', array('position' => 0))-> 90 107 checkResponseElement('table.related_people_list tr', '/Mostly sleeping/', array('position' => 0))-> 91 108 92 109 shutdown() 93 110 ;
