Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is the model class for table "{{merchant_batch_code}}".
- *
- * The followings are the available columns in table '{{merchant_batch_code}}':
- * @property integer $id
- * @property string $merchant_id
- * @property string $merchant_code
- * @property string $merchant_gentime
- * @property integer $merchant_code_exp
- * @property string $merchant_code_redeem_date
- */
- class MerchantBatchCode extends CActiveRecord
- {
- /**
- * @return string the associated database table name
- */
- public $_relmerchantname;
- public $_relmerchanttype;
- public function tableName()
- {
- return '{{merchant_batch_code}}';
- }
- /**
- * @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('merchant_id, merchant_code, merchant_gentime', 'required'),
- array('merchant_code_exp', 'numerical', 'integerOnly'=>true),
- array('merchant_id, merchant_code', 'length', 'max'=>30),
- array('merchant_code_redeem_date', 'safe'),
- // The following rule is used by search().
- // @todo Please remove those attributes that should not be searched.
- array('id, merchant_id, merchant_code, merchant_gentime, merchant_code_exp, merchant_code_redeem_date', 'safe', 'on'=>'search'),
- );
- }
- /**
- * @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(
- 'merchantId' => array(self::BELONGS_TO, 'Merchant', 'merchant_id'),
- );
- }
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'id' => 'ID',
- 'merchant_id' => 'Merchant ID',
- 'merchant_code' => 'Merchant Code',
- 'merchant_gentime' => 'Merchant Generate Time',
- 'merchant_code_exp' => 'Merchant Code Expire',
- 'merchant_code_redeem_date' => 'Merchant Code Redeem Time',
- '_relmerchantname' => 'Merchant Name',
- '_relmerchanttype' => 'Merchant Type',
- );
- }
- /**
- * Retrieves a list of models based on the current search/filter conditions.
- *
- * Typical usecase:
- * - Initialize the model fields with values from filter form.
- * - Execute this method to get CActiveDataProvider instance which will filter
- * models according to data in model fields.
- * - Pass data provider to CGridView, CListView or any similar widget.
- *
- * @return CActiveDataProvider the data provider that can return the models
- * based on the search/filter conditions.
- */
- public function search()
- {
- // @todo Please modify the following code to remove attributes that should not be searched.
- $criteria=new CDbCriteria;
- $criteria->compare('id',$this->id);
- $criteria->compare('merchant_id',$this->merchant_id,true);
- $criteria->compare('merchant_code',$this->merchant_code,true);
- $criteria->compare('merchant_gentime',$this->merchant_gentime,true);
- $criteria->compare('merchant_code_exp',$this->merchant_code_exp);
- $criteria->compare('merchant_code_redeem_date',$this->merchant_code_redeem_date,true);
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- ));
- }
- protected function afterFind()
- {
- $dataRel = Merchant::model()->findByAttributes(array('merchant_id' =>$this->merchant_id));
- if(is_null($this->merchant_code_redeem_date) || $this->merchant_code_redeem_date = '') {
- $this->merchant_code_redeem_date = '-';
- } else {
- $this->merchant_code_redeem_date = $this->merchant_code_redeem_date;
- }
- $this->_relmerchantname = $dataRel['merchant_name'];
- $this->_relmerchanttype = $dataRel['merchant_type'];
- parent::afterFind();
- }
- /**
- * Returns the static model of the specified AR class.
- * Please note that you should have this exact method in all your CActiveRecord descendants!
- * @param string $className active record class name.
- * @return MerchantBatchCode the static model class
- */
- public static function model($className=__CLASS__)
- {
- return parent::model($className);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement