
<?php

/**
 * This is the model class for table "{{customers}}".
 *
 * The followings are the available columns in table '{{customers}}':
 * @property integer $id
 * @property string $customer_name
 * @property string $phone_no
 * @property string $isActive
 * @property integer $created_by
 * @property integer $updated_by
 * @property string $created_datetime
 * @property string $updated_datetime
 * @property string $email
 * @property string $Address
 * @property string $image
 */
class Customers extends CActiveRecord
{
	public function tableName()
	{
		return '{{customers}}';
	}

	public function rules()
	{
		return array(
			array('customer_name, phone_no, email, Address', 'required'),
			array('created_by, updated_by', 'numerical', 'integerOnly'=>true),
      array('country_id, state_id', 'numerical', 'integerOnly' => true),
      array('country_id, state_id', 'numerical', 'integerOnly' => true),
			array('customer_name, email', 'length', 'max'=>100),
			array('phone_no', 'length', 'max'=>20),
			array('isActive', 'length', 'max'=>1),
			array('Address', 'length', 'max'=>500),
			array('image', 'safe'),
			array('isActive, created_by, created_datetime, updated_by, updated_datetime', 'safe'),
			array('location_id', 'safe'),
      array('country_id, state_id', 'safe'),
			array('id, customer_name, phone_no, isActive, created_by, updated_by, created_datetime, updated_datetime, email, Address', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array('location' => array(self::BELONGS_TO, 'Locations', 'location_id'),
    'country' => array(self::BELONGS_TO, 'Country', 'country_id'),
    'state'   => array(self::BELONGS_TO, 'States', 'state_id'),
  );
	}

	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'customer_name' => 'Customer Name',
			'phone_no' => 'Phone No',
			'isActive' => 'Is Active',
			'created_by' => 'Created By',
			'updated_by' => 'Updated By',
			'created_datetime' => 'Created Datetime',
			'updated_datetime' => 'Updated Datetime',
			'email' => 'Email',
			'Address' => 'Address',
			'image' => 'Image',
      'country_id' => 'Country',
      'state_id'   => 'State',  
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('customer_name',$this->customer_name,true);
		$criteria->compare('phone_no',$this->phone_no,true);
		$criteria->compare('isActive',$this->isActive,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('created_datetime',$this->created_datetime,true);
		$criteria->compare('updated_datetime',$this->updated_datetime,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('Address',$this->Address,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
