Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.38 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "user".
  5.  *
  6.  * The followings are the available columns in table 'user':
  7.  * @property integer $id
  8.  * @property integer $fb_id
  9.  * @property string $nickname
  10.  * @property string $email
  11.  * @property string $first_name
  12.  * @property string $last_name
  13.  * @property string $gender
  14.  * @property integer $country
  15.  * @property string $locale
  16.  * @property string $birthday
  17.  * @property string $show_birthday
  18.  * @property string $url_name
  19.  * @property string $friends_only
  20.  */
  21. class User extends CActiveRecord
  22. {
  23.         const BIRTHYEAR_MIN = 1950;
  24.         const BIRTHYEAR_MAX = 2010;
  25.  
  26.         public $birthD;
  27.         public $birthYear;
  28.         public $birthMonth;
  29.         /**
  30.          * Returns the static model of the specified AR class.
  31.          * @return User the static model class
  32.          */
  33.         public static function model($className=__CLASS__)
  34.         {
  35.                 return parent::model($className);
  36.         }
  37.  
  38.         /**
  39.          * @return string the associated database table name
  40.          */
  41.         public function tableName()
  42.         {
  43.                 return 'user';
  44.         }
  45.  
  46.         /**
  47.          * @return array validation rules for model attributes.
  48.          */
  49.         public function rules()
  50.         {
  51.                 // NOTE: you should only define rules for those attributes that
  52.                 // will receive user inputs.
  53.                 return array(
  54.                         array('nickname, email, first_name, last_name, locale, birthday, gender, locale, country',
  55.                         'safe',
  56.                         'on'=>'Register'),
  57.  
  58.                         array('nickname, email, first_name, last_name, locale, birthday, birthyear, birthmonth, birthd, info_closet, info_never_without, info_brands, gender, country, locale',
  59.                         'required',
  60.                         'on'=>'AccountSettings'),
  61.  
  62.                         array('nickname, first_name, last_name, url_name',
  63.                         'length',
  64.                         'on'=>'AccountSettings',
  65.                         'max'=>30),
  66.  
  67.                         array('email,info_closet,info_never_without,info_brands',
  68.                         'length',
  69.                         'on'=>'AccountSettings',
  70.                         'max'=>50),
  71.  
  72.                         array('email',
  73.                         'on'=>'AccountSettings',
  74.                         'email'),
  75.  
  76.                         array('gender',
  77.                         'on'=>'AccountSettings',
  78.                         'in',
  79.                         'range'=>array('f','m')),
  80.  
  81.                         array('birthyear',
  82.                         'on'=>'AccountSettings',
  83.                         'numerical',
  84.                         'integerOnly'=>true,
  85.                         'min'=>1950,
  86.                         'max'=>2010),
  87.  
  88.                         array('birthd',
  89.                         'on'=>'AccountSettings',
  90.                         'numerical',
  91.                         'integerOnly'=>true,
  92.                         'min'=>1,
  93.                         'max'=>31),
  94.  
  95.                         array('birthmonth',
  96.                         'on'=>'AccountSettings',
  97.                         'numerical',
  98.                         'integerOnly'=>true,
  99.                         'min'=>1,
  100.                         'max'=>12),
  101.  
  102.                         array('gender',
  103.                         'on'=>'AccountSettings',
  104.                         'length',
  105.                         'max'=>1),
  106.  
  107.                         array('locale',
  108.                         'on'=>'AccountSettings',
  109.                         'length',
  110.                         'max'=>5),
  111.                         // The following rule is used by search().
  112.                         // Please remove those attributes that should not be searched.
  113.  
  114.                         array('url_name',
  115.                         'safe',
  116.                         'on'=>'AccountSettings'),
  117.                 );
  118.         }
  119.  
  120.         /**
  121.          * @return array relational rules.
  122.          */
  123.         public function relations()
  124.         {
  125.                 // NOTE: you may need to adjust the relation name and the related
  126.                 // class name for the relations automatically generated below.
  127.                 return array(
  128.                         );
  129.         }
  130.  
  131.         /**
  132.          * @return array customized attribute labels (name=>label)
  133.          */
  134.         public function attributeLabels()
  135.         {
  136.                 return array(
  137.                         'id' => 'Id',
  138.                         'fb_id' => 'Fb',
  139.                         'nickname' => 'Nickname',
  140.                         'email' => 'Email',
  141.                         'first_name' => 'First Name',
  142.                         'last_name' => 'Last Name',
  143.                         'gender' => 'Gender',
  144.                         'country' => 'Country',
  145.                         'locale' => 'Language',
  146.                         'birthday' => 'Birthday',
  147.                         'show_birthday' => 'Show Birthday',
  148.                         'url_name' => 'Url Name',
  149.                         'friends_only' => 'Who can view my profile',
  150.                         'birthd' => 'Day',
  151.                         'birthyear' => 'Year',
  152.                         'birthmonth' => 'Month',
  153.                         'info_never_without' => 'I never leave home without',
  154.                         'info_brands' => 'My favorite brands',
  155.                         'info_closet' => 'Whats really in my closet'
  156.                 );
  157.         }
  158.  
  159.         /**
  160.          * Retrieves a list of models based on the current search/filter conditions.
  161.          * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  162.          */
  163.         public function search()
  164.         {
  165.                 // Warning: Please modify the following code to remove attributes that
  166.                 // should not be searched.
  167.  
  168.                 $criteria=new CDbCriteria;
  169.  
  170.                 $criteria->compare('id',$this->id);
  171.  
  172.                 $criteria->compare('fb_id',$this->fb_id);
  173.  
  174.                 $criteria->compare('nickname',$this->nickname,true);
  175.  
  176.                 $criteria->compare('email',$this->email,true);
  177.  
  178.                 $criteria->compare('first_name',$this->first_name,true);
  179.  
  180.                 $criteria->compare('last_name',$this->last_name,true);
  181.  
  182.                 $criteria->compare('gender',$this->gender,true);
  183.  
  184.                 $criteria->compare('country',$this->country);
  185.  
  186.                 $criteria->compare('locale',$this->locale,true);
  187.  
  188.                 $criteria->compare('birthday',$this->birthday,true);
  189.  
  190.                 $criteria->compare('show_birthday',$this->show_birthday,true);
  191.  
  192.                 $criteria->compare('url_name',$this->url_name,true);
  193.  
  194.                 $criteria->compare('friends_only',$this->friends_only,true);
  195.  
  196.                 return new CActiveDataProvider('User', array(
  197.                         'criteria'=>$criteria,
  198.                 ));
  199.         }
  200.  
  201.         /*
  202.          * Get current age of user
  203.          */
  204.         public function getAge() {
  205.  
  206.                 $diff = date_diff(new DateTime($this->birthday),new DateTime('now'));
  207.                 return $diff->y;
  208.         }
  209.  
  210.         public function getBirthYear() {
  211.  
  212.                 $birth = explode('-',$this->birthday);
  213.                 return $birth[0];
  214.         }
  215.  
  216.         public function setBirthYear($value) {
  217.  
  218.                 $this->birthyear = $value;
  219.         }
  220.  
  221.         public function getBirthMonth() {
  222.  
  223.                 $birth = explode('-',$this->birthday);
  224.                 return preg_replace('/^0/','',$birth[1]);
  225.         }
  226.         public function setBirthMonth($value) {
  227.  
  228.                 $this->birthmonth = $value;
  229.         }
  230.         public function getBirthD() {
  231.  
  232.                 $birth = explode('-',$this->birthday);
  233.                 return preg_replace('/^0/','',$birth[2]);
  234.         }
  235.         public function setBirthD($value) {
  236.  
  237.                 $this->birthd=$value;
  238.         }
  239.  
  240.         public function getYears() {
  241.  
  242.                 return array_combine(self::$years,self::$years);
  243.         }
  244.         public function getDays() {
  245.  
  246.                 return array_combine(self::$days,self::$days);
  247.         }
  248.         public function beforeSave() {
  249.  
  250.                 if($this->isNewRecord) return true;
  251.                 $this->birthday = $this->birthyear.'-'.$this->birthmonth.'-'.$this->birthd;
  252.                 return true;
  253.         }
  254.  
  255.         public function dropDownRange($min,$max) {
  256.  
  257.                 return array_combine($x = range($min,$max),$x);
  258.         }
  259.  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement