Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //******Model***************************************************************************************************
- <?php
- /**
- * This is the model class for table "h_lpu_register".
- *
- * The followings are the available columns in table 'h_lpu_register':
- * @property integer $id
- * @property string $reg_id
- * @property string $name
- * @property string $name_s
- * @property string $name_f
- * @property string $inn
- * @property string $ogrn
- * @property string $kpp
- * @property string $post_index_u
- * @property string $address_u
- * @property string $okopf
- * @property double $id_ved
- * @property double $org_lvl
- * @property string $gv_fam
- * @property string $gv_im
- * @property string $gv_ot
- * @property string $phone
- * @property string $fax
- * @property string $email
- * @property string $www
- * @property string $mp
- * @property string $last_update
- * @property string $okato_reg
- * @property integer $parent_id
- * @property string $gv_initials_r
- * @property string $usl_set
- * @property double $uet_usl
- * @property string $name_work
- * @property integer $is_hc
- *
- * The followings are the available model relations:
- * @property KsgPlan[] $ksgPlans
- * @property HLpuDoc[] $hLpuDocs
- * @property Rpn[] $rpns
- * @property HLpuRegInfo[] $hLpuRegInfos
- * @property RpnFileData[] $rpnFileDatas
- * @property HMesLpu[] $hMesLpus
- */
- class HLpuRegister extends CActiveRecord
- {
- public $dateInput;
- public function getDbConnection() {
- return Yii::app()->db2;
- }
- /**
- * @return string the associated database table name
- */
- public function tableName()
- {
- return 'h_lpu_register';
- }
- /**
- * @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('dateInput', 'required'),
- array('dateInput','date','format'=>'dd.MM.yyyy','message'=>'tyrtyrtyr".'),
- array('id, parent_id, is_hc', 'numerical', 'integerOnly'=>true),
- array('id_ved, org_lvl, uet_usl', 'numerical'),
- array('reg_id, post_index_u', 'length', 'max'=>6),
- array('name, www', 'length', 'max'=>100),
- array('name_s, name_f, address_u, name_work', 'length', 'max'=>250),
- array('inn, kpp', 'length', 'max'=>12),
- array('ogrn', 'length', 'max'=>15),
- array('okopf', 'length', 'max'=>2),
- array('gv_fam, gv_im, gv_ot, phone, fax, gv_initials_r', 'length', 'max'=>40),
- array('email', 'length', 'max'=>50),
- array('mp, usl_set', 'length', 'max'=>10),
- array('last_update', 'length', 'max'=>4),
- array('okato_reg', 'length', 'max'=>5),
- // The following rule is used by search().
- // @todo Please remove those attributes that should not be searched.
- array('reg_id, name, name_s, name_f, inn, ogrn, kpp, post_index_u, address_u, okopf, id_ved, org_lvl, gv_fam, gv_im, gv_ot, phone, fax, email, www, mp, last_update, okato_reg, parent_id, gv_initials_r, usl_set, uet_usl, name_work, is_hc', '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(
- /*'ksgPlans' => array(self::HAS_MANY, 'KsgPlan', 'mo_id'),*/
- 'hLpuDocs' => array(self::HAS_MANY, 'HLpuDoc', 'lpu'),
- /*'rpns' => array(self::HAS_MANY, 'Rpn', 'mo_id'),*/
- 'hLpuRegInfos' => array(self::HAS_MANY, 'HLpuRegInfo', 'lpu'),
- /*'rpnFileDatas' => array(self::HAS_MANY, 'RpnFileData', 'mo_id'),
- 'hMesLpus' => array(self::HAS_MANY, 'HMesLpu', 'lpu'),*/
- 'medHealth'=>array(self::HAS_MANY,'HV008','mp')
- );
- }
- /**
- * @return array customized attribute labels (name=>label)
- */
- public function attributeLabels()
- {
- return array(
- 'id' => '#',
- 'reg_id' => 'Код',
- 'name' => 'Наименование',
- 'name_s' => 'Краткое наименование',
- 'name_f' => 'Полное наименование',
- 'inn' => 'ИНН',
- 'ogrn' => 'ОГРН',
- 'kpp' => 'КПП',
- 'post_index_u' => 'Post Index U',
- 'address_u' => 'Address U',
- 'okopf' => 'Okopf',
- 'id_ved' => 'Id Ved',
- 'org_lvl' => 'Org Lvl',
- 'gv_fam' => 'Gv Fam',
- 'gv_im' => 'Gv Im',
- 'gv_ot' => 'Gv Ot',
- 'phone' => 'Телефон',
- 'fax' => 'Факс',
- 'email' => 'Email',
- 'www' => 'Www',
- 'mp' => 'Mp',
- 'last_update' => 'Last Update',
- 'okato_reg' => 'Okato Reg',
- 'parent_id' => 'Parent',
- 'gv_initials_r' => 'Gv Initials R',
- 'usl_set' => 'Usl Set',
- 'uet_usl' => 'Uet Usl',
- 'name_work' => 'Name Work',
- 'is_hc' => 'Is Hc',
- 'dateInput'=>'Фильтр по дате',
- );
- }
- /**
- * 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('reg_id',$this->reg_id,true);
- $criteria->compare('name',$this->name,true);
- $criteria->compare('name_s',$this->name_s,true);
- $criteria->compare('name_f',$this->name_f,true);
- $criteria->compare('inn',$this->inn,true);
- $criteria->compare('ogrn',$this->ogrn,true);
- $criteria->compare('kpp',$this->kpp,true);
- $criteria->compare('post_index_u',$this->post_index_u,true);
- $criteria->compare('address_u',$this->address_u,true);
- $criteria->compare('okopf',$this->okopf,true);
- $criteria->compare('id_ved',$this->id_ved);
- $criteria->compare('org_lvl',$this->org_lvl);
- $criteria->compare('gv_fam',$this->gv_fam,true);
- $criteria->compare('gv_im',$this->gv_im,true);
- $criteria->compare('gv_ot',$this->gv_ot,true);
- $criteria->compare('phone',$this->phone,true);
- $criteria->compare('fax',$this->fax,true);
- $criteria->compare('email',$this->email,true);
- $criteria->compare('www',$this->www,true);
- //$criteria->compare('mp',$this->mp,true);
- $criteria->compare('last_update',$this->last_update,true);
- $criteria->compare('okato_reg',$this->okato_reg,true);
- $criteria->compare('parent_id',$this->parent_id);
- $criteria->compare('gv_initials_r',$this->gv_initials_r,true);
- $criteria->compare('usl_set',$this->usl_set,true);
- $criteria->compare('uet_usl',$this->uet_usl);
- $criteria->compare('name_work',$this->name_work,true);
- $criteria->compare('is_hc',$this->is_hc);
- //$criteria->compare('dateInput',$this->dateInput);
- $criteria->together = true;
- $criteria->with = array('hLpuRegInfos');
- $criteria->condition = ':now BETWEEN hLpuRegInfos.date_1 AND hLpuRegInfos.date_2';
- //$criteria->condition = ':now BETWEEN hLpuDocs.date_1 AND hLpuDocs.date_2';
- //$criteria->params = array(':now'=>isset($this->dateInput)?$this->dateInput:date('d.m.Y'));
- $criteria->params = array(':now'=>$this->dateInput);
- return new CActiveDataProvider($this, array(
- 'criteria'=>$criteria,
- 'pagination'=> array(
- 'pageSize'=>50
- )
- ));
- }
- public function getDocLpu()
- {
- foreach ($this->hLpuDocs as $value) {
- $array[]=$value->doc_num;
- }
- if(!isset($value->doc_num)){
- $array[]='нет';
- }
- //$array=isset($array)?$array:'нет';
- $result = implode(', ',$array);
- return $result;
- }
- public function getMedPom()
- {
- $mp = is_null($this->mp)?'1':chop($this->mp, ',');
- $array = explode(',',$mp);
- foreach ($array as $value) {
- $name[]=HV008::model()->find('code=:value',array(':value'=>$value))->name;
- }
- $result = implode(', ',$name);
- return $result;
- }
- public function coalesce() {
- $args = func_get_args();
- foreach ($args as $arg) {
- if (!empty($arg)) {
- return $arg;
- }
- }
- return null;
- }
- /**
- * 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 HLpuRegister the static model class
- */
- public static function model($className=__CLASS__)
- {
- return parent::model($className);
- }
- }
- //******Controller*************************************************************************************************
- public function actionIndex()
- {
- //$this->layout = '//layouts/main';
- $model=new HLpuRegister;
- $model->unsetAttributes(); // clear any default values
- if(isset($_GET['HLpuRegister'])){
- $model->attributes=$_GET['HLpuRegister'];
- $model->dateInput = $_GET['HLpuRegister']['dateInput'];
- $model->validate();
- //$this->refresh();
- }
- $this->render('index',array(
- 'model'=>$model,
- ));
- /*
- $dataProvider=new CActiveDataProvider('HLpuRegister');
- $this->render('index',array(
- 'dataProvider'=>$dataProvider,
- ));*/
- }
Advertisement
Add Comment
Please, Sign In to add comment