<?php

/**
 * This is the model class for table "re_building".
 *
 * The followings are the available columns in table 're_building':
 * @property integer $id
 * @property string $Building_name
 * @property string $makani
 * @property string $status
 * @property integer $created_by
 * @property string $created_date
 * @property integer $updated_by
 * @property string $updated_date
 */
class Building extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Building 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 're_building';
	}

	/**
	 * @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('building_name, makani', 'required'),
			array('created_by, updated_by', 'numerical', 'integerOnly'=>true),
			array('building_name,building_id, makani,emirate,location', 'length', 'max'=>50),
			array('status', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, building_name,building_id, makani, status, created_by, created_date, updated_by, updated_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(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'building_name' => 'Building Name',
                        'building_id' => 'Building Id',
			'makani' => 'Makani',
			'status' => 'Status',
			'created_by' => 'Created By',
			'created_date' => 'Created Date',
			'updated_by' => 'Updated By',
			'updated_date' => 'Updated Date',
		);
	}

	/**
	 * 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('building_name',$this->Building_name,true);
		$criteria->compare('makani',$this->makani,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('created_by',$this->created_by);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('updated_by',$this->updated_by);
		$criteria->compare('updated_date',$this->updated_date,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        public static function getList() {
        $model = self::model()->findAll(array('condition' =>'status="Y"'));
            $list =  CHtml::listData($model, 'id', 'building_name');
            return $list;
        }
        
        public static function getAllBuilding() {
        	$condition = 'status =  "Y"';
        	$model = self::model()->findAll(array('condition' => $condition));
        	return CHtml::listData($model, 'id', 'building_name');
        }
        
        public static function getBuildingName($id) {
        	$model = self::model()->findByPk($id);
        	return $model->building_name;
        }
}