public function actionTyres()
 {
     $sizes = array();
     $form = $_GET;
     $selection = new TyreSelectionForm();
     $pages = null;
     if (!empty($form)) {
         $selection->attributes = $form;
         if ($selection->validate()) {
             $criteria = new CDbCriteria();
             $criteria->with = array('tyre');
             if (!empty($selection->producers)) {
                 $crit0 = new CDbCriteria();
                 $crit0->with = array('producer');
                 $crit0->compare('producer.alias', $selection->producers);
                 // Собираю шины производителей подходящих под условия фильтра
                 $tyres = CHtml::listData(Tyre::model()->findAll($crit0), 'id', 'id');
                 $criteria->compare('tyre_id', $tyres);
             }
             #$criteria->compare('code',$this->code,true);
             $criteria->compare('width', $selection->width, true);
             $criteria->compare('height', $selection->height, true);
             $criteria->compare('diameter', $selection->diameter, true);
             $criteria->compare('tyre.season', $selection->season);
             $criteria->compare('tyre.stud', $selection->puncture);
             $criteria->compare('price', '>=' . $selection->price_from, false);
             $criteria->compare('price', '<=' . $selection->price_until, false);
             $criteria->compare('price', '<>0');
             $criteria->mergeWith(TyreSizes::model()->inSight()->getDbCriteria());
             $data = new CActiveDataProvider('TyreSizes', array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->params['selection.resultsPerPage'])));
         }
     }
     $this->render('tyres', array('selection' => $selection, 'data' => $data));
 }
 private function showTyresBySize($id, $season = null, $stud = null)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 't.id = :id';
     $criteria->params = array(':id' => $id);
     $model = TyreSizes::model()->find($criteria);
     $this->addComment($model->tyre);
     #throw new CHttpException(400,'Такой страницы нет');
     $this->render('tyres/size', array('model' => $model, 'season' => $season, 'stud' => $stud));
 }
 public function actionIndex()
 {
     ini_set('memory_limit', '650M');
     set_time_limit(0);
     $tyresForm = new ImportForm();
     $result = array();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ImportForm'])) {
         $tyresForm->attributes = $_POST['ImportForm'];
         if ($tyresForm->validate()) {
             # Вот тут начинается импорт
             /* вторая страница
              * 1. CAI
              * 2. Профиль(мм)
              * 3. Высота (%)
              * 4. Диаметр (,R)
              * 5. Индекс
              * 6. Модель
              * 7. Производитель
              * 8. Сезон
              * 9. Кол-во (ОПТ)
              * 10. Цена (ОПТ)
              * 11. Кол-во (ИМ)
              * 12. Цена (ИМ) 
             */
             TyreSizes::model()->updateAll(array('rest' => 0, 'price' => 0));
             $uploaded = Yii::app()->file->set('ImportForm[file]');
             Yii::app()->file->set(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id))->createDir();
             $newfile = $uploaded->copy(strtolower(Yii::getPathOfAlias('webroot.files.' . $this->id . '.' . $this->action->id)) . '/' . $uploaded->basename);
             $newfile->filename = $newfile->filename . '.' . date('YmdHis');
             Yii::import('ext.phpexcelreader.EPhpExcelReader');
             $data = new EPhpExcelReader($newfile->realpath, false);
             $sheet = 0;
             $rowcount = $data->rowcount($sheet);
             $result['rowcount'] = $rowcount;
             $result['count'] = 0;
             #$colcount = $data->colcount();
             #$rowcount = 5;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1, $sheet);
                 if ($size = TyreSizes::model()->find('code=:code', array(':code' => $cai))) {
                     $size->price = $data->val($r, 12, $sheet);
                     if (!empty($tyresForm->margin)) {
                         $size->price += $size->price * ($tyresForm->margin / 100);
                     }
                     $rest11 = $data->val($r, 11, $sheet);
                     $rest9 = $data->val($r, 9, $sheet);
                     if (is_int($rest11) && is_int($rest9)) {
                         if ($rest11 > $rest9) {
                             $size->rest = $rest11;
                         } else {
                             $size->rest = $rest9;
                         }
                     } elseif (!is_int($rest11) && is_int($rest9)) {
                         $size->rest = 10;
                     } elseif (is_int($rest11) && !is_int($rest9)) {
                         $size->rest = 20;
                     } else {
                         $size->rest = 20;
                     }
                     if (!$size->save()) {
                         $result['errors']['size:' . $data->val($r, 1, $sheet)] = $size->errors;
                     }
                     $result['count']++;
                 } else {
                     echo '<p>' . $cai . ' ' . $data->val($r, 7, $sheet) . ' ' . $data->val($r, 6, $sheet) . ' not found</p>';
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('index', array('model' => $tyresForm, 'results' => $result));
 }
echo $form->labelEx($tyreSelection, 'height');
?>
		<?php 
echo $form->dropDownList($tyreSelection, 'height', CHtml::listData(TyreSizes::model()->inSight()->findAll(array('group' => 'height')), 'height', 'height'), array('empty' => ''));
?>
		<?php 
echo $form->error($tyreSelection, 'height');
?>
	</div>
	
	<div class="row">
		<?php 
echo $form->labelEx($tyreSelection, 'diameter');
?>
		<?php 
echo $form->dropDownList($tyreSelection, 'diameter', CHtml::listData(TyreSizes::model()->inSight()->findAll(array('group' => 'diameter')), 'diameter', 'diameter'), array('empty' => ''));
?>
		<?php 
echo $form->error($tyreSelection, 'diameter');
?>
	</div>
	
	<div class="row">
		<?php 
echo $form->labelEx($tyreSelection, 'season');
?>
		<?php 
echo $form->dropDownList($tyreSelection, 'season', L::ruitems('tyreSeason'), array('empty' => 'Неважно'));
?>
		<?php 
echo $form->error($tyreSelection, 'season');
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = TyreSizes::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'Запрашиваемая страница не существует.');
     }
     return $model;
 }