Changeset 36

Show
Ignore:
Timestamp:
04/20/08 21:27:37
Author:
jtexier
Message:

added Profile unit test & userTools class, made some fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/jtexier/apps/main/modules/sfGuardAuth/actions/actions.class.php

    r30 r36  
    238238      $user = new sfGuardUser(); 
    239239      $user->setUsername($this->getRequestParameter('username')); 
    240       $user->setEmail($this->getRequestParameter('email')); 
    241240      $user->setPassword($this->getRequestParameter('password')); 
    242241      $user->setIsActive(false); 
    243242      $user->save(); 
     243 
     244      $user_profile = $user->getProfile(); 
     245      $user_profile->setEmail($this->getRequestParameter('email')); 
     246      $user_profile->save(); 
    244247       
    245248      $activation = new Activation(); 
     
    252255       
    253256      $mailSent = $this->sendSwiftSmtpPlainMail('mail', 'register', 
    254                                                 $user->getEmail(), 
     257                                                $user_profile->getEmail(), 
    255258                                                $this->__('Please confirm your Symfonians account creation request')); 
    256259       
     
    264267      $this->setFlash('notice', sfContext::getInstance()->getI18N() 
    265268                      ->__('A confirmation mail has been sent to %mail%', 
    266                            array('%mail%' => $user->getEmail()))); 
     269                           array('%mail%' => $user_profile->getEmail()))); 
    267270      $this->forward('sfGuardAuth', 'registerDone'); 
    268271    } 
  • branches/jtexier/apps/main/modules/sfGuardAuth/validate/register.yml

    r2 r36  
    3838      domain_error:    The domain provided in the email address does not seem to be correct 
    3939    sfPropelUniqueValidator: 
    40       class:           sfGuardUser 
     40      class:           UserProfile 
    4141      column:          email 
    4242      unique_error:    This email address already exists in the database 
  • branches/jtexier/config/search.yml

    r30 r36  
    8686      description:          summary 
    8787      validator:            getIsActive 
    88     #sfGuardUser: 
    89     UserProfile: 
     88    sfGuardUser: 
    9089      fields: 
    91         #username:           text 
     90        username:           text 
    9291        displayName: 
    9392          boost:            1.5 
  • branches/jtexier/lib/model/PluginsfGuardUser.php

    r30 r36  
    7575 
    7676  /** 
     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  /** 
    77139   * Retrieves mail sender address, in the form "Firstname Lastname" <name@isp.tld> 
    78140   * 
     
    276338 
    277339 
     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   
    278397  /** 
    279398   * Retrieves all recommendations received by current user. Mainly a proxy to 
     
    320439  { 
    321440    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()); 
    322451  } 
    323452 
     
    650779  } 
    651780 
    652   /*** Mapping of profile basic getters  ******/ 
     781  /*** Proxy getters to profile data  ******/ 
    653782   
    654783   /** 
     
    700829  public function getPhpAt() 
    701830  { 
    702     return $this->getProfile()->getBirthDate(); 
     831    return $this->getProfile()->getPhpAt(); 
    703832  } 
    704833     
    705834  public function getSymfonyAt() 
    706835  { 
     836    return $this->getProfile()->getSymfonyAt(); 
     837  } 
     838 
     839  public function getBirthDate() 
     840  { 
    707841    return $this->getProfile()->getBirthDate(); 
    708842  } 
    709  
    710   public function getBirthDate() 
    711   { 
    712     return $this->getProfile()->getBirthDate(); 
    713   } 
    714843   
    715844  public function getAddress() 
     
    744873  { 
    745874 
    746     return $this->getProfile()->getSummary(); 
     875    return $this->getProfile()->getCountry(); 
    747876  } 
    748877 
     
    782911   
    783912} 
     913 
     914sfLucenePropelBehavior::getInitializer()->setupModel('sfGuardUser');   
  • branches/jtexier/lib/model/PluginsfGuardUserPeer.php

    r30 r36  
    4747  { 
    4848    $c = new Criteria; 
    49     $c->add(self::EMAIL, $email); 
     49    $c->addJoin(self::ID,UserProfilePeer::USER_ID); 
     50    $c->add(UserProfilePeer::EMAIL, $email); 
    5051    return self::doSelectOne($c); 
    5152  } 
     
    124125    $c = new Criteria(); 
    125126    $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); 
    128130    $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); 
    131133    $rs = self::doSelectRS($c); 
    132134    while ($rs->next()) 
  • branches/jtexier/lib/model/UserProfile.php

    r30 r36  
    1010class UserProfile extends BaseUserProfile 
    1111{ 
    12    
    13  
    1412  /** 
    15    * Retrieves companies associated with current user 
    16    * 
    17    * @param  string  $type  Filter type (submitted, related, all) 
    18    * @return array 
    19    */ 
    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 select 
    45    * html tag 
    46    * 
    47    * @param  string  $type  Filter type (submitted, related, all) 
    48    * @return array 
    49    */ 
    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 string 
    62    * 
    63    * @param  string  $separator 
    64    * @return string 
    65    */ 
    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 applications 
    78    * 
    79    * @param  Criteria  $c 
    80    * @return array 
    81    */ 
    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 string 
    96    * 
    97    * @param  string  $separator 
    98    * @return string 
    99    */ 
    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 companies 
    116    * 
    117    * @param  Criteria  $c 
    118    * @return array 
    119    */ 
    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     /** 
    13413   * Get user skill tags 
    13514   * 
     
    14019    return $this->getTags(); 
    14120  } 
    142    
    143    
    144     /** 
    145    * Get user skill tags string 
    146    * 
    147    * @return string 
    148    */ 
    149   public function getSkillsString($separator = ', ') 
    150   { 
    151     return implode($separator, $this->getSkills()); 
    152   } 
    153    
    15421   
    15522  /** 
     
    293160                            'sfPropelActAsTaggableBehavior')); 
    294161 
    295 sfLucenePropelBehavior::getInitializer()->setupModel('UserProfile');   
     162 
    296163   
    297164 
  • branches/jtexier/test/unit/KarmaTest.php

    r30 r36  
    1313$niko = sfGuardUserPeer::retrieveByUsername('niko'); 
    1414 
    15 $t = new lime_test(6, new lime_output_color()); 
     15$t = new lime_test(8, new lime_output_color()); 
    1616$t->isa_ok($niko, 'sfGuardUser', 'User is an instance of sfGuardUser'); 
    1717$t->is($niko->getUsername(), 'niko', 'getUsermame() retrieves correct username');