Changeset 36
- Timestamp:
- 04/20/08 21:27:37
- Files:
-
- branches/jtexier/apps/main/modules/sfGuardAuth/actions/actions.class.php (modified) (3 diffs)
- branches/jtexier/apps/main/modules/sfGuardAuth/validate/register.yml (modified) (1 diff)
- branches/jtexier/config/search.yml (modified) (1 diff)
- branches/jtexier/lib/model/PluginsfGuardUser.php (modified) (7 diffs)
- branches/jtexier/lib/model/PluginsfGuardUserPeer.php (modified) (2 diffs)
- branches/jtexier/lib/model/UserProfile.php (modified) (3 diffs)
- branches/jtexier/test/unit/KarmaTest.php (modified) (1 diff)
- branches/jtexier/test/unit/ProfileTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/jtexier/apps/main/modules/sfGuardAuth/actions/actions.class.php
r30 r36 238 238 $user = new sfGuardUser(); 239 239 $user->setUsername($this->getRequestParameter('username')); 240 $user->setEmail($this->getRequestParameter('email'));241 240 $user->setPassword($this->getRequestParameter('password')); 242 241 $user->setIsActive(false); 243 242 $user->save(); 243 244 $user_profile = $user->getProfile(); 245 $user_profile->setEmail($this->getRequestParameter('email')); 246 $user_profile->save(); 244 247 245 248 $activation = new Activation(); … … 252 255 253 256 $mailSent = $this->sendSwiftSmtpPlainMail('mail', 'register', 254 $user ->getEmail(),257 $user_profile->getEmail(), 255 258 $this->__('Please confirm your Symfonians account creation request')); 256 259 … … 264 267 $this->setFlash('notice', sfContext::getInstance()->getI18N() 265 268 ->__('A confirmation mail has been sent to %mail%', 266 array('%mail%' => $user ->getEmail())));269 array('%mail%' => $user_profile->getEmail()))); 267 270 $this->forward('sfGuardAuth', 'registerDone'); 268 271 } branches/jtexier/apps/main/modules/sfGuardAuth/validate/register.yml
r2 r36 38 38 domain_error: The domain provided in the email address does not seem to be correct 39 39 sfPropelUniqueValidator: 40 class: sfGuardUser40 class: UserProfile 41 41 column: email 42 42 unique_error: This email address already exists in the database branches/jtexier/config/search.yml
r30 r36 86 86 description: summary 87 87 validator: getIsActive 88 #sfGuardUser: 89 UserProfile: 88 sfGuardUser: 90 89 fields: 91 #username: text90 username: text 92 91 displayName: 93 92 boost: 1.5 branches/jtexier/lib/model/PluginsfGuardUser.php
r30 r36 75 75 76 76 /** 77 * Retrieves companies associated with current user 78 * 79 * @param string $type Filter type (submitted, related, all) 80 * @return array 81 */ 82 public function getCompanies($type = 'submitted') 83 { 84 $c = new Criteria(); 85 $c->add(CompanyPeer::IS_ACTIVE, true); 86 $c->addAscendingOrderByColumn(CompanyPeer::NAME); 87 switch ($type) 88 { 89 case 'all': 90 $companies = CompanyPeer::doSelect($c); 91 break; 92 case 'related': 93 $c->addJoin(CompanyPersonPeer::COMPANY_ID, CompanyPeer::ID); 94 $c->add(CompanyPersonPeer::USER_ID, $this->getId()); 95 $companies = CompanyPeer::doSelect($c); 96 break; 97 case 'submitted': 98 default: 99 $companies = $this->getCompanys($c); 100 break; 101 } 102 return $companies; 103 } 104 105 /** 106 * Retrieves simple hash of related companies. Useful for populating a select 107 * html tag 108 * 109 * @param string $type Filter type (submitted, related, all) 110 * @return array 111 */ 112 public function getCompaniesArray($type = 'submitted') 113 { 114 $companies = array(); 115 foreach ($this->getCompanies($type) as $company) 116 { 117 $companies[$company->getId()] = $company->getName(); 118 } 119 return $companies; 120 } 121 122 /** 123 * Returns related companies string 124 * 125 * @param string $separator 126 * @return string 127 */ 128 public function getCompaniesString($separator = ', ') 129 { 130 $companies = array(); 131 foreach ($this->getCompanies('related') as $company) 132 { 133 $companies[] = $company->getName(); 134 } 135 return implode($separator, $companies); 136 } 137 138 /** 77 139 * Retrieves mail sender address, in the form "Firstname Lastname" <name@isp.tld> 78 140 * … … 276 338 277 339 340 341 /** 342 * Retrieves related applications 343 * 344 * @param Criteria $c 345 * @return array 346 */ 347 public function getRelatedApplications(Criteria $c = null) 348 { 349 if (!$c instanceof Criteria) 350 { 351 $c = new Criteria; 352 } 353 $c->addJoin(ApplicationDeveloperPeer::APPLICATION_ID, ApplicationPeer::ID); 354 $c->addJoin(ApplicationDeveloperPeer::DEVELOPER_ID, sfGuardUserPeer::ID); 355 $c->add(sfGuardUserPeer::ID, $this->getId()); 356 return ApplicationPeer::doSelect($c); 357 } 358 359 /** 360 * Retrieves related applications and return their names in a string 361 * 362 * @param string $separator 363 * @return string 364 */ 365 public function getRelatedApplicationsString(Criteria $c = null, $separator = ', ') 366 { 367 if (!$c instanceof Criteria) 368 { 369 $c = new Criteria; 370 } 371 $applications = array(); 372 foreach ($this->getRelatedApplications($c) as $application) 373 { 374 $applications[] = $application->getName(); 375 } 376 return implode($separator, $applications); 377 } 378 379 /** 380 * Retrieves related companies 381 * 382 * @param Criteria $c 383 * @return array 384 */ 385 public function getRelatedCompanies(Criteria $c = null) 386 { 387 if (!$c instanceof Criteria) 388 { 389 $c = new Criteria; 390 } 391 $c->addJoin(CompanyPersonPeer::COMPANY_ID, CompanyPeer::ID); 392 $c->addJoin(CompanyPersonPeer::USER_ID, sfGuardUserPeer::ID); 393 $c->add(sfGuardUserPeer::ID, $this->getId()); 394 return CompanyPeer::doSelect($c); 395 } 396 278 397 /** 279 398 * Retrieves all recommendations received by current user. Mainly a proxy to … … 320 439 { 321 440 return $this->getProfile()->getSkills(); 441 } 442 443 /** 444 * Get user skill tags string 445 * 446 * @return string 447 */ 448 public function getSkillsString($separator = ', ') 449 { 450 return implode($separator, $this->getSkills()); 322 451 } 323 452 … … 650 779 } 651 780 652 /*** Mapping of profile basic getters******/781 /*** Proxy getters to profile data ******/ 653 782 654 783 /** … … 700 829 public function getPhpAt() 701 830 { 702 return $this->getProfile()->get BirthDate();831 return $this->getProfile()->getPhpAt(); 703 832 } 704 833 705 834 public function getSymfonyAt() 706 835 { 836 return $this->getProfile()->getSymfonyAt(); 837 } 838 839 public function getBirthDate() 840 { 707 841 return $this->getProfile()->getBirthDate(); 708 842 } 709 710 public function getBirthDate()711 {712 return $this->getProfile()->getBirthDate();713 }714 843 715 844 public function getAddress() … … 744 873 { 745 874 746 return $this->getProfile()->get Summary();875 return $this->getProfile()->getCountry(); 747 876 } 748 877 … … 782 911 783 912 } 913 914 sfLucenePropelBehavior::getInitializer()->setupModel('sfGuardUser'); branches/jtexier/lib/model/PluginsfGuardUserPeer.php
r30 r36 47 47 { 48 48 $c = new Criteria; 49 $c->add(self::EMAIL, $email); 49 $c->addJoin(self::ID,UserProfilePeer::USER_ID); 50 $c->add(UserProfilePeer::EMAIL, $email); 50 51 return self::doSelectOne($c); 51 52 } … … 124 125 $c = new Criteria(); 125 126 $c->clearSelectColumns(); 126 $c->addSelectColumn(self::CITY); 127 $c->add(self::COUNTRY, $country_code); 127 $c->addJoin(self::ID,UserProfilePeer::USER_ID); 128 $c->addSelectColumn(UserProfilePeer::CITY); 129 $c->add(UserProfilePeer::COUNTRY, $country_code); 128 130 $c->add(self::IS_ACTIVE, true); 129 $c->addGroupByColumn( self::CITY);130 $c->addAscendingOrderByColumn( self::CITY);131 $c->addGroupByColumn(UserProfilePeer::CITY); 132 $c->addAscendingOrderByColumn(UserProfilePeer::CITY); 131 133 $rs = self::doSelectRS($c); 132 134 while ($rs->next()) branches/jtexier/lib/model/UserProfile.php
r30 r36 10 10 class UserProfile extends BaseUserProfile 11 11 { 12 13 14 12 /** 15 * Retrieves companies associated with current user16 *17 * @param string $type Filter type (submitted, related, all)18 * @return array19 */20 public function getCompanies($type = 'submitted')21 {22 $c = new Criteria();23 $c->add(CompanyPeer::IS_ACTIVE, true);24 $c->addAscendingOrderByColumn(CompanyPeer::NAME);25 switch ($type)26 {27 case 'all':28 $companies = CompanyPeer::doSelect($c);29 break;30 case 'related':31 $c->addJoin(CompanyPersonPeer::COMPANY_ID, CompanyPeer::ID);32 $c->add(CompanyPersonPeer::USER_ID, $this->getUserId());33 $companies = CompanyPeer::doSelect($c);34 break;35 case 'submitted':36 default:37 $companies = $this->getCompanys($c);38 break;39 }40 return $companies;41 }42 43 /**44 * Retrieves simple hash of related companies. Useful for populating a select45 * html tag46 *47 * @param string $type Filter type (submitted, related, all)48 * @return array49 */50 public function getCompaniesArray($type = 'submitted')51 {52 $companies = array();53 foreach ($this->getCompanies($type) as $company)54 {55 $companies[$company->getId()] = $company->getName();56 }57 return $companies;58 }59 60 /**61 * Returns related companies string62 *63 * @param string $separator64 * @return string65 */66 public function getCompaniesString($separator = ', ')67 {68 $companies = array();69 foreach ($this->getCompanies('related') as $company)70 {71 $companies[] = $company->getName();72 }73 return implode($separator, $companies);74 }75 76 /**77 * Retrieves related applications78 *79 * @param Criteria $c80 * @return array81 */82 public function getRelatedApplications(Criteria $c = null)83 {84 if (!$c instanceof Criteria)85 {86 $c = new Criteria;87 }88 $c->addJoin(ApplicationDeveloperPeer::APPLICATION_ID, ApplicationPeer::ID);89 $c->addJoin(ApplicationDeveloperPeer::DEVELOPER_ID, sfGuardUserPeer::ID);90 $c->add(sfGuardUserPeer::ID, $this->getUserId());91 return ApplicationPeer::doSelect($c);92 }93 94 /**95 * Retrieves related applications and return their names in a string96 *97 * @param string $separator98 * @return string99 */100 public function getRelatedApplicationsString(Criteria $c = null, $separator = ', ')101 {102 if (!$c instanceof Criteria)103 {104 $c = new Criteria;105 }106 $applications = array();107 foreach ($this->getRelatedApplications($c) as $application)108 {109 $applications[] = $application->getName();110 }111 return implode($separator, $applications);112 }113 114 /**115 * Retrieves related companies116 *117 * @param Criteria $c118 * @return array119 */120 public function getRelatedCompanies(Criteria $c = null)121 {122 if (!$c instanceof Criteria)123 {124 $c = new Criteria;125 }126 $c->addJoin(CompanyPersonPeer::COMPANY_ID, CompanyPeer::ID);127 $c->addJoin(CompanyPersonPeer::USER_ID, sfGuardUserPeer::ID);128 $c->add(sfGuardUserPeer::ID, $this->getUserId());129 return CompanyPeer::doSelect($c);130 }131 132 133 /**134 13 * Get user skill tags 135 14 * … … 140 19 return $this->getTags(); 141 20 } 142 143 144 /**145 * Get user skill tags string146 *147 * @return string148 */149 public function getSkillsString($separator = ', ')150 {151 return implode($separator, $this->getSkills());152 }153 154 21 155 22 /** … … 293 160 'sfPropelActAsTaggableBehavior')); 294 161 295 sfLucenePropelBehavior::getInitializer()->setupModel('UserProfile'); 162 296 163 297 164 branches/jtexier/test/unit/KarmaTest.php
r30 r36 13 13 $niko = sfGuardUserPeer::retrieveByUsername('niko'); 14 14 15 $t = new lime_test( 6, new lime_output_color());15 $t = new lime_test(8, new lime_output_color()); 16 16 $t->isa_ok($niko, 'sfGuardUser', 'User is an instance of sfGuardUser'); 17 17 $t->is($niko->getUsername(), 'niko', 'getUsermame() retrieves correct username');
