Changeset 74

Show
Ignore:
Timestamp:
08/22/08 11:07:16 (2 years ago)
Author:
nperriault
Message:

Forthport of r73: Fixed user model class incorrectly calculates the age of a member (thanks to Russ)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/model/PluginsfGuardUser.php

    r53 r74  
    5252  { 
    5353    $age = null; 
     54 
    5455    if ($this->getBirthdate()) 
    5556    { 
    56       $age = date("Y") - (int) $this->getBirthdate('Y'); 
    57       $month_diff = date("m") - (int) $this->getBirthdate('m'); 
    58       $day_diff = date("d") - (int) $this->getBirthdate('d'); 
    59       $age -= $day_diff < 0 || $month_diff < 0 ? 1 : 0; 
    60     } 
     57      $age   = date("Y") - (int) $this->getBirthdate('Y'); 
     58      $month = (int) $this->getBirthdate('m'); 
     59      $day   = (int) $this->getBirthdate('d'); 
     60 
     61      if (date("m") < $month || (date("m") == $month && date("d") < $day)) 
     62      { 
     63        --$age; 
     64      } 
     65    } 
     66 
    6167    return $age; 
    6268  } 
    63    
     69 
    6470  /** 
    6571   * Check if user allow to be contacted. If he published a job offer in its own 
     
    7278  { 
    7379    $allow = parent::getAllowContact(); 
    74      
     80 
    7581    if ($check_jobs && $this->countJobs(new Criteria) > 0) 
    7682    { 
    7783      $allow = true; 
    7884    } 
    79      
     85 
    8086    return $allow; 
    8187  } 
     
    278284 
    279285  /** 
    280    * Return full avatar path 
    281    * 
    282    * @param string $format 
    283    * @return string 
    284    */ 
    285   public function getFullAvatarPath($format = 'standard') 
    286   { 
    287     if (!$this->getAvatarPath()) 
    288     { 
    289       return sfConfig::get('app_people_default_avatar'); 
    290     } 
    291     return sprintf('/%s/%s/%s/%s', 
    292                    sfConfig::get('sf_upload_dir_name'), 
    293                    sfConfig::get('app_people_upload_dir', 'people'), 
    294                    $format, 
    295                    $this->getAvatarPath()); 
     286   * Return avatar path, with optional stored format 
     287   * 
     288   * @param  string  $format (small16, small48, standard) 
     289   * @return string 
     290   */ 
     291  public function getAvatarPath($format = 'standard') 
     292  { 
     293    if (!parent::getAvatarPath()) 
     294    { 
     295      return null; 
     296    } 
     297 
     298    return sprintf('/%s/%s', $format, parent::getAvatarPath()); 
    296299  } 
    297300 
     
    318321      $user = $user->getRawValue(); 
    319322    } 
     323 
    320324    if ($user instanceof sfGuardUser) 
    321325    { 
    322326      $user = $user->getId(); 
    323327    } 
     328 
    324329    $c = new Criteria(); 
    325330    $c->add(RecommendationPeer::RECOMMENDED_ID, $this->getId()); 
    326331    $c->add(RecommendationPeer::RECOMMENDER_ID, $user); 
     332 
    327333    return (RecommendationPeer::doCount($c) > 0); 
    328334  } 
     
    367373  { 
    368374  } 
    369    
     375 
    370376  public function setPasswordHash($v) 
    371377  { 
     
    409415  { 
    410416    $algorithm = $this->getAlgorithm(); 
    411      
     417 
    412418    if (false !== $pos = strpos($algorithm, '::')) 
    413419    { 
    414420      $algorithm = array(substr($algorithm, 0, $pos), substr($algorithm, $pos + 2)); 
    415421    } 
    416      
     422 
    417423    if (!is_callable($algorithm)) 
    418424    { 
    419425      throw new sfException(sprintf('The algorithm callable "%s" is not callable.', $algorithm)); 
    420426    } 
    421      
     427 
    422428    return $this->getPassword() == call_user_func_array($algorithm, array($this->getSalt().$password)); 
    423429  }