예제 #1
0
 public function actionSelect()
 {
     $select = new ProductSelectForm();
     //var_dump($_POST['ProductSelectForm']);
     if (isset($_POST['ProductSelectForm'])) {
         $select->attributes = $_POST['ProductSelectForm'];
         $select->producer = $_POST['ProductSelectForm']['producer'];
         $_GET['kindparent'] = $select->kindparent;
         $_GET['inkind'] = $select->inkind;
         $_GET['producer'] = $select->producer;
         $_GET['min'] = $select->min;
         $_GET['max'] = $select->max;
         //$_GET['count']=count($_POST['ProductSelectForm']);
         //var_dump($_GET);
     } else {
         $select->kindparent = $_GET['kindparent'];
         $select->inkind = $_GET['inkind'];
         $select->producer = $_GET['producer'];
         $select->min = $_GET['min'];
         $select->max = $_GET['max'];
         //var_dump($_GET);
     }
     //var_dump($select->producer);
     if ($select->validate()) {
         $kindparent = '=tbl_kindparent.kindparent';
         $inkind = '=tbl_inkind.inkind';
         $producer = '=tbl_producer.producer';
         //$producer1='Wilmar';
         //$producer2='Марко';
         //var_dump($producer1);
         $min = '0';
         $max = '100000';
         $empty = 0;
         $c = $select->kindparent;
         if ($select->kindparent != 'unselectValue') {
             $kindparent = "='{$select->kindparent}'";
         } else {
             $empty = $empty + 1;
         }
         //var_dump($c!='unselectValue');
         if ($select->inkind != 'unselectValue') {
             $inkind = "='{$select->inkind}'";
         } else {
             $empty = $empty + 1;
         }
         if (!empty($select->producer)) {
             $a = $select->producer;
             $producer = " in ('";
             for ($i = 0; $i < count($select->producer); $i++) {
                 if ($i + 1 == count($select->producer)) {
                     $producer .= "{$a[$i]}')";
                 } else {
                     $producer .= "{$a[$i]}','";
                 }
             }
             //var_dump($producer);
         } else {
             $empty = $empty + 1;
         }
         //If (!empty($select->producer)) $producer=$select->producer;
         if (!empty($select->min)) {
             $min = $select->min;
         } else {
             $empty = $empty + 1;
         }
         if (!empty($select->max)) {
             $max = $select->max;
         } else {
             $empty = $empty + 1;
         }
         //var_dump($kindparent);
         //var_dump($inkind);
         //var_dump($producer);
         //var_dump($min);
         //var_dump( $kindparent);
         //var_dump($_POST['ProductSelectForm']);
         //var_dump($empty);
         //var_dump($select->kindparent);
         if ($empty == 5) {
             //throw new CHttpException(404, 'The requested page does not exist.');
             ///$this->redirect(array('site/index'));
         } else {
             $criteria = new CDbCriteria(array('condition' => "tbl_kindparent.kindparent {$kindparent} and tbl_inkind.inkind {$inkind} and tbl_producer.producer {$producer} and t.cost>=:min and t.cost<=:max", 'join' => ' INNER JOIN tbl_inkind on t.id_inkind=tbl_inkind.id_inkind INNER  JOIN tbl_kindparent on tbl_kindparent.id_parent=tbl_inkind.id_parent INNER JOIN tbl_producer on t.id_producer=tbl_producer.id_producer ', 'params' => array(':min' => $min, ':max' => $max)));
             //var_dump($criteria);
             $dataProvider = new CActiveDataProvider('Product', array('pagination' => array('pageSize' => 6), 'criteria' => $criteria));
             $this->render('index', array('dataProvider' => $dataProvider));
         }
         //$productCount = Product::model()->count($criteria);
         //	var_dump($productCount);
         //$pages = new CPagination($productCount);
         //$pages->pageSize = 5;
         //$pages->applyLimit($criteria);
         //$product = Product::model()->findAll($criteria);
         //var_dump($product);
         //$this->render('select', array(
         //	'product' => $product,
         //	'pages' => $pages
         //));
     } else {
         //$error=$search->addError('jkhjh');
         //$z=$search->addError('password','Incorrect username or password.');
         //$search->getErrors();
         //var_dump($z);
         //$this->addError('password','Incorrect username or password.');
         //var_dump($_POST['ProductSelectForm']);
         throw new CHttpException(404, 'The requested page does not exist.');
     }
 }
예제 #2
0
 public function run()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'inkind';
     $criteria->distinct = true;
     $t['unselectValue'] = NULL;
     $this->inkind = Inkind::model()->findAll($criteria);
     //var_dump($this->inkind);
     for ($i = 0; $i < count($this->inkind); $i++) {
         $t[$this->inkind[$i]->inkind] = $this->inkind[$i]->inkind;
     }
     $t['unselectValue'] = '';
     $this->inkind = $t;
     $t = [];
     // var_dump($this->inkind);
     $criteria = new CDbCriteria();
     $criteria->select = 'kindparent';
     $criteria->distinct = true;
     $t['unselectValue'] = NULL;
     $this->kindparent = Kindparent::model()->findAll($criteria);
     //var_dump($this->inkind);
     for ($i = 0; $i < count($this->kindparent); $i++) {
         $t[$this->kindparent[$i]->kindparent] = $this->kindparent[$i]->kindparent;
     }
     $this->kindparent = $t;
     $t = [];
     // var_dump($this->kindparent);
     $criteria = new CDbCriteria();
     $criteria->select = 'producer';
     $criteria->distinct = true;
     //$t['uncheckValue']=NULL;
     $this->producer = Producer::model()->findAll($criteria);
     //var_dump($this->inkind);
     for ($i = 0; $i < count($this->producer); $i++) {
         $t[$this->producer[$i]->producer] = $this->producer[$i]->producer;
     }
     $this->producer = $t;
     $t = [];
     $form = new ProductSelectForm();
     $form->clearErrors();
     if (isset($_POST['ProductSelectForm'])) {
         $form->attributes = $_POST['ProductSelectForm'];
     }
     // if (isset($_POST['ProductSelectForm'])) {
     //   $form->kindparent=$_POST['ProductSelectForm']['kindparent'];
     // $form->inkind=$_POST['ProductSelectForm']['inkind'];
     //    $form->producer=$_POST['ProductSelectForm']['producer'];}
     //$form->min=$_POST['ProductSelectForm']['min'];
     //$form->max=$_POST['ProductSelectForm']['max'];
     // var_dump($_POST['ProductSelectForm']);
     // }
     //var_dump($_POST);
     //  var_dump($form->validate());
     //    if (isset($_POST['ProductSelectForm'])&&(!$form->validate())) {
     //  unset($_POST['SiteSearchForm']);
     //   $form->clearErrors();
     // $form->addError('ProductSelectForm','Задайте условия поиска');
     //  $z=$form->getErrors();
     // var_dump($z);
     // }
     // }
     // var_dump($_GET);
     $this->render('productSelect', array('form' => $form, 'inkind' => $this->inkind, 'kindparent' => $this->kindparent, 'producer' => $this->producer));
     $form->clearErrors();
 }