Advertisement
joris

MerchantBatchCode

Sep 23rd, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.13 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "{{merchant_batch_code}}".
  5.  *
  6.  * The followings are the available columns in table '{{merchant_batch_code}}':
  7.  * @property integer $id
  8.  * @property string $merchant_id
  9.  * @property string $merchant_code
  10.  * @property string $merchant_gentime
  11.  * @property integer $merchant_code_exp
  12.  * @property string $merchant_code_redeem_date
  13.  */
  14. class MerchantBatchCode extends CActiveRecord
  15. {
  16.     /**
  17.      * @return string the associated database table name
  18.      */
  19.  
  20.     public $_relmerchantname;
  21.     public $_relmerchanttype;
  22.  
  23.     public function tableName()
  24.     {
  25.         return '{{merchant_batch_code}}';
  26.     }
  27.  
  28.     /**
  29.      * @return array validation rules for model attributes.
  30.      */
  31.     public function rules()
  32.     {
  33.         // NOTE: you should only define rules for those attributes that
  34.         // will receive user inputs.
  35.         return array(
  36.             array('merchant_id, merchant_code, merchant_gentime', 'required'),
  37.             array('merchant_code_exp', 'numerical', 'integerOnly'=>true),
  38.             array('merchant_id, merchant_code', 'length', 'max'=>30),
  39.             array('merchant_code_redeem_date', 'safe'),
  40.             // The following rule is used by search().
  41.             // @todo Please remove those attributes that should not be searched.
  42.             array('id, merchant_id, merchant_code, merchant_gentime, merchant_code_exp, merchant_code_redeem_date', 'safe', 'on'=>'search'),
  43.         );
  44.     }
  45.  
  46.     /**
  47.      * @return array relational rules.
  48.      */
  49.     public function relations()
  50.     {
  51.         // NOTE: you may need to adjust the relation name and the related
  52.         // class name for the relations automatically generated below.
  53.         return array(
  54.             'merchantId' => array(self::BELONGS_TO, 'Merchant', 'merchant_id'),
  55.         );
  56.     }
  57.  
  58.     /**
  59.      * @return array customized attribute labels (name=>label)
  60.      */
  61.     public function attributeLabels()
  62.     {
  63.         return array(
  64.             'id' => 'ID',
  65.             'merchant_id' => 'Merchant ID',
  66.             'merchant_code' => 'Merchant Code',
  67.             'merchant_gentime' => 'Merchant Generate Time',
  68.             'merchant_code_exp' => 'Merchant Code Expire',
  69.             'merchant_code_redeem_date' => 'Merchant Code Redeem Time',
  70.             '_relmerchantname' => 'Merchant Name',
  71.             '_relmerchanttype' => 'Merchant Type',
  72.         );
  73.     }
  74.  
  75.     /**
  76.      * Retrieves a list of models based on the current search/filter conditions.
  77.      *
  78.      * Typical usecase:
  79.      * - Initialize the model fields with values from filter form.
  80.      * - Execute this method to get CActiveDataProvider instance which will filter
  81.      * models according to data in model fields.
  82.      * - Pass data provider to CGridView, CListView or any similar widget.
  83.      *
  84.      * @return CActiveDataProvider the data provider that can return the models
  85.      * based on the search/filter conditions.
  86.      */
  87.     public function search()
  88.     {
  89.         // @todo Please modify the following code to remove attributes that should not be searched.
  90.  
  91.         $criteria=new CDbCriteria;
  92.  
  93.         $criteria->compare('id',$this->id);
  94.         $criteria->compare('merchant_id',$this->merchant_id,true);
  95.         $criteria->compare('merchant_code',$this->merchant_code,true);
  96.         $criteria->compare('merchant_gentime',$this->merchant_gentime,true);
  97.         $criteria->compare('merchant_code_exp',$this->merchant_code_exp);
  98.         $criteria->compare('merchant_code_redeem_date',$this->merchant_code_redeem_date,true);
  99.  
  100.         return new CActiveDataProvider($this, array(
  101.             'criteria'=>$criteria,
  102.         ));
  103.     }
  104.  
  105.     protected function afterFind()
  106.     {
  107.             $dataRel = Merchant::model()->findByAttributes(array('merchant_id' =>$this->merchant_id));
  108.  
  109.             if(is_null($this->merchant_code_redeem_date) || $this->merchant_code_redeem_date = '') {
  110.                     $this->merchant_code_redeem_date = '-';
  111.             } else {
  112.                     $this->merchant_code_redeem_date = $this->merchant_code_redeem_date;
  113.             }
  114.  
  115.             $this->_relmerchantname = $dataRel['merchant_name'];
  116.             $this->_relmerchanttype = $dataRel['merchant_type'];
  117.  
  118.             parent::afterFind();
  119.     }
  120.  
  121.     /**
  122.      * Returns the static model of the specified AR class.
  123.      * Please note that you should have this exact method in all your CActiveRecord descendants!
  124.      * @param string $className active record class name.
  125.      * @return MerchantBatchCode the static model class
  126.      */
  127.     public static function model($className=__CLASS__)
  128.     {
  129.         return parent::model($className);
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement