Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is the model class for table "user".
- *
- * The followings are the available columns in table 'user':
- * @property integer $id
- * @property integer $fb_id
- * @property string $nickname
- * @property string $email
- * @property string $first_name
- * @property string $last_name
- * @property string $gender
- * @property integer $country
- * @property string $locale
- * @property string $birthday
- * @property string $show_birthday
- * @property string $url_name
- * @property string $friends_only
- */
- class User extends CActiveRecord
- {
- const BIRTHYEAR_MIN = 1950;
- const BIRTHYEAR_MAX = 2010;
- public $birthD;
- public $birthYear;
- public $birthMonth;
- /**
- * Returns the static model of the specified AR class.
- * @return User the static model class
- */
- public static function model($className=__CLASS__)
- {
- return parent::model($className);
- }
- /**
- * @return string the associated database table name
- */
- public function tableName()
- {
- return 'user';
- }
- /**
- * @return array validation rules for model attributes.
- */
- public function rules()
- {
- // NOTE: you should only define rules for those attributes that
- // will receive user inputs.
- return array(
- array('nickname, email, first_name, last_name, locale, birthday, gender, locale, country',
- 'safe',
- 'on'=>'Register'),
- array('nickname, email, first_name, last_name, locale, birthday, birthyear, birthmonth, birthd, info_closet, info_never_without, info_brands, gender, country, locale',
- 'required',
- 'on'=>'AccountSettings'),
- array('nickname, first_name, last_name, url_name',
- 'length',
- 'on'=>'AccountSettings',
- 'max'=>30),
- array('email,info_closet,info_never_without,info_brands',
- 'length',
- 'on'=>'AccountSettings',
- 'max'=>50),
- array('email',
- 'on'=>'AccountSettings',
- 'email'),
- array('gender',
- 'on'=>'AccountSettings',
- 'in',
- 'range'=>array('f','m')),
- array('birthyear',
- 'on'=>'AccountSettings',
- 'numerical',
- 'integerOnly'=>true,
- 'min'=>1950,
- 'max'=>2010),
- array('birthd',
- 'on'=>'AccountSettings',
- 'numerical',
- 'integerOnly'=>true,
- 'min'=>1,
- 'max'=>31),
- array('birthmonth',
- 'on'=>'AccountSettings',
- 'numerical',
- 'integerOnly'=>true,
- 'min'=>1,
- 'max'=>12),
- array('gender',
- 'on'=>'AccountSettings',
- 'length',
- 'max'=>1),
- array('locale',
- 'on'=>'AccountSettings',
- 'length',
- 'max'=>5),
- // The following rule is used by search().
- // Please remove those attributes that should not be searched.
- array('url_name',
- 'safe',
- 'on'=>'AccountSettings'),
- );
- }
- /**
- * @return array relational rules.
- */
- public function relations()
- {
- // NOTE: you may need to adjust the relation name and the related
- // class name for the relations automatically generated below.
- return array(
- );
- }
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'id' => 'Id',
- 'fb_id' => 'Fb',
- 'nickname' => 'Nickname',
- 'email' => 'Email',
- 'first_name' => 'First Name',
- 'last_name' => 'Last Name',
- 'gender' => 'Gender',
- 'country' => 'Country',
- 'locale' => 'Language',
- 'birthday' => 'Birthday',
- 'show_birthday' => 'Show Birthday',
- 'url_name' => 'Url Name',
- 'friends_only' => 'Who can view my profile',
- 'birthd' => 'Day',
- 'birthyear' => 'Year',
- 'birthmonth' => 'Month',
- 'info_never_without' => 'I never leave home without',
- 'info_brands' => 'My favorite brands',
- 'info_closet' => 'Whats really in my closet'
- );
- }
- /**
- * Retrieves a list of models based on the current search/filter conditions.
- * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
- */
- public function search()
- {
- // Warning: Please modify the following code to remove attributes that
- // should not be searched.
- $criteria=new CDbCriteria;
- $criteria->compare('id',$this->id);
- $criteria->compare('fb_id',$this->fb_id);
- $criteria->compare('nickname',$this->nickname,true);
- $criteria->compare('email',$this->email,true);
- $criteria->compare('first_name',$this->first_name,true);
- $criteria->compare('last_name',$this->last_name,true);
- $criteria->compare('gender',$this->gender,true);
- $criteria->compare('country',$this->country);
- $criteria->compare('locale',$this->locale,true);
- $criteria->compare('birthday',$this->birthday,true);
- $criteria->compare('show_birthday',$this->show_birthday,true);
- $criteria->compare('url_name',$this->url_name,true);
- $criteria->compare('friends_only',$this->friends_only,true);
- return new CActiveDataProvider('User', array(
- 'criteria'=>$criteria,
- ));
- }
- /*
- * Get current age of user
- */
- public function getAge() {
- $diff = date_diff(new DateTime($this->birthday),new DateTime('now'));
- return $diff->y;
- }
- public function getBirthYear() {
- $birth = explode('-',$this->birthday);
- return $birth[0];
- }
- public function setBirthYear($value) {
- $this->birthyear = $value;
- }
- public function getBirthMonth() {
- $birth = explode('-',$this->birthday);
- return preg_replace('/^0/','',$birth[1]);
- }
- public function setBirthMonth($value) {
- $this->birthmonth = $value;
- }
- public function getBirthD() {
- $birth = explode('-',$this->birthday);
- return preg_replace('/^0/','',$birth[2]);
- }
- public function setBirthD($value) {
- $this->birthd=$value;
- }
- public function getYears() {
- return array_combine(self::$years,self::$years);
- }
- public function getDays() {
- return array_combine(self::$days,self::$days);
- }
- public function beforeSave() {
- if($this->isNewRecord) return true;
- $this->birthday = $this->birthyear.'-'.$this->birthmonth.'-'.$this->birthd;
- return true;
- }
- public function dropDownRange($min,$max) {
- return array_combine($x = range($min,$max),$x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement