public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         // this was set with the "max" attribute of the CAutoComplete widget
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->limit = $limit;
         $criteria->order = 'title';
         echo CJavaScript::jsonEncode(CHtml::listData(TyreProducers::model()->findAll($criteria), 'id', 'title'));
     }
 }
Example #2
0
	<div class="row">
		<?php 
echo $form->label($model, 'id');
?>
		<?php 
echo $form->textField($model, 'id');
?>
	</div>
	
	<div class="row">
		<?php 
echo $form->label($model, 'producer');
?>
		<?php 
echo $form->dropDownList($model, 'producer', CHtml::listData(TyreProducers::model()->findAll(), 'id', 'title'));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'code');
?>
		<?php 
echo $form->textField($model, 'code', array('size' => 45, 'maxlength' => 45));
?>
	</div>

	<div class="row">
		<?php 
echo $form->label($model, 'width');
 public function actionNomenclature()
 {
     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()) {
             # Вот тут начинается импорт
             Yii::import('ext.markdown.*');
             Yii::import('ext.markdownify.*');
             Yii::import('webroot.helpers.*');
             #$tyresForm->file = CUploadedFile::getInstance($tyresForm, 'file');
             /* Первая страница
              * 1. CAI
              * 2. Производитель
              * 3. Модель
              * 4. Сезон
              * 5. Применяемость
              * 6. Тип протектора
              * 7. Шипованность
              * 8. Ширина профиля(мм)
              * 9. Высота профиля (%)
              * 10. Диаметр (,R)
              * 11. Индекс скорости
              * 12. Индекс нагрузки
              * 13. Цена
              * 14. Фото, большое
              * 15. Фото, мелкое
             */
             $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);
             $rowcount = $data->rowcount();
             #$colcount = $data->colcount();
             #$rowcount = 3;
             $r = 2;
             while ($r <= $rowcount) {
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = TyreProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new TyreProducers();
                     @($result['new_producers'] += 1);
                 } else {
                     @($result['old_producers'] += 1);
                 }
                 $producer->title = $data->val($r, 2);
                 $producer->alias = $producer_alias;
                 if (!$producer->save()) {
                     $result['errors']['producer:' . $data->val($r, 1)] = $producer->errors;
                 }
                 $tyre_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($tyre = Tyre::model()->find('alias=:alias', array(':alias' => $tyre_alias)))) {
                     $tyre = new Tyre();
                     @($result['new_tyres'] += 1);
                 } else {
                     @($result['old_tyres'] += 1);
                 }
                 $tyre->producer_id = $producer->id;
                 $tyre->title = $data->val($r, 3);
                 $tyre->alias = $tyre_alias;
                 $tyre->new = true;
                 $tyre->currency = L::r_item('tyreCurrency', $data->val($r, 5)) ? L::r_item('tyreCurrency', $data->val($r, 5)) : 0;
                 if ($data->val($r, 4) == 'зимние') {
                     $tyre->season = L::r_item('tyreSeason', 'winter');
                 }
                 if ($data->val($r, 4) == 'летние') {
                     $tyre->season = L::r_item('tyreSeason', 'summer');
                 }
                 if ($data->val($r, 4) == 'всесезонные') {
                     $tyre->season = L::r_item('tyreSeason', 'yearround');
                 }
                 $tyre->stud = $data->val($r, 7) ? 1 : 0;
                 $tyre->construction_type = 1;
                 $tyre->runflat_type = 0;
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $tyre_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Tyre') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 14));
                 if (!empty($tmp_image) && empty($tyre->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Tyre::model()->images['photo']['sizes'] as $key => $size) {
                         $pic = null;
                         // папка в которой будет хранится картинка
                         $path = $path0 . $key . DIRECTORY_SEPARATOR;
                         // создаю папку если ее не было
                         EFile::set($path)->createDir();
                         $pic = @file_get_contents('http://www.4tochki.ru' . $tmp_image);
                         $info = pathinfo($tmp_image);
                         #$row['pic_file'] - 117*(65-88) (лента слева)
                         if (empty($pic)) {
                             continue;
                         }
                         $fullpath = $path . $alias . '.jpg';
                         file_put_contents($fullpath, $pic);
                         $pic = Yii::app()->image->load($fullpath);
                         $pic->thumb(isset($size[0]) ? $size[0] : 0, isset($size[1]) ? $size[1] : 0, true, '#FFFFFF');
                         if ($key == 'big') {
                             $pic->watermark(Yii::getPathOfAlias('webroot') . Yii::app()->params['watermark'], 5);
                         }
                         $pic->save($fullpath);
                         $f = true;
                     }
                     if ($f) {
                         if (!($image = Image::model()->find('filename=:alias', array(':alias' => '/files/tyre/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $tyre->title;
                         $image->alt = $producer->title . ' ' . $tyre->title;
                         $image->save();
                         $tyre->photo = '/files/tyre/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $tyre->photo = null;
                     }
                 }
                 if (!$tyre->save()) {
                     $result['errors']['tyre:' . $data->val($r, 1)] = $tyre->errors;
                 }
                 $cai = $data->val($r, 1);
                 if (!($size = TyreSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new TyreSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->tyre_id = $tyre->id;
                 $size->code = $cai;
                 $size->width = $data->val($r, 8);
                 $size->height = $data->val($r, 9);
                 $size->diameter = $data->val($r, 10);
                 $size->speed_rating = preg_replace('/[0-9]/isU', '', $data->val($r, 11));
                 $size->load_index = preg_replace('/[a-z]/isU', '', $data->val($r, 12));
                 $size->price = 0;
                 $size->rest = 0;
                 #d($size->attributes);
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->height . '-' . $size->diameter . '-' . $size->speed_rating . $size->load_index;
                 # Сохраняю...
                 if (!$size->save()) {
                     $result['errors']['size:' . $data->val($r, 1)] = $size->errors;
                 }
                 $r++;
             }
             #$this->redirect(array('view','id'=>$model->id));
         }
     }
     $this->render('nomenclature', array('model' => $tyresForm, 'results' => $result));
 }
?>
 руб.
		
		<?php 
echo $form->error($tyreSelection, 'price_until');
?>
		
		<?php 
echo $form->error($tyreSelection, 'price_from');
?>
	</div>

	<div class="row producers">
		<label><b>Производители шин</b> <i class='control'>все</i></label>
		<?php 
echo $form->checkBoxList($tyreSelection, 'producers', CHtml::listData(TyreProducers::model()->alphabetically()->with('tyres.sizes:inSight')->findAll(), 'alias', 'title'), array('template' => '<span>{input} {label}</span>', 'separator' => ''));
?>
		<?php 
echo $form->error($tyreSelection, 'producers');
?>
		<div class='clear'></div>
	</div>
	
	<div class="row">
		<?php 
echo $form->labelEx($tyreSelection, 'width');
?>
		<?php 
echo $form->dropDownList($tyreSelection, 'width', CHtml::listData(TyreSizes::model()->inSight()->findAll(array('group' => 'width')), 'width', 'width'), array('empty' => ''));
?>
		<?php 
Example #5
0
<?php

$this->breadcrumbs = array('Шины' => array('index'), 'Управление шинами');
$this->menu = array(array('label' => 'Обзор шин', 'url' => array('index')), array('label' => 'Добавить шину', 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('tyre-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1>Управление шинами</h1>

<p>
Можно использовать операторы сравнения (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
или <b>=</b>) в начале запроса.
</p>

<?php 
echo CHtml::link('Расширенный поиск', '#', array('class' => 'search-button'));
?>
<div class="search-form" style="display:none">
<?php 
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'tyre-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', array('name' => 'producer_id', 'value' => '$data->producer->title', 'filter' => CHtml::listData(TyreProducers::model()->findAll(), 'id', 'title')), 'title', 'alias', array('name' => 'new', 'value' => 'L::ruitem(\'boolean\', $data->new)', 'filter' => L::ruitems('boolean')), array('name' => 'sale', 'value' => 'L::ruitem(\'boolean\', $data->sale)', 'filter' => L::ruitems('boolean')), array('name' => 'currency', 'value' => 'L::item(\'tyreCurrency\', $data->currency)', 'filter' => L::items('tyreCurrency')), array('name' => 'season', 'value' => 'L::item(\'tyreSeason\', $data->season)', 'filter' => L::items('tyreSeason')), array('name' => 'stud', 'value' => 'L::ruitem(\'boolean\', $data->stud)', 'filter' => L::ruitems('boolean')), array('name' => 'construction_type', 'value' => 'EString::substr(L::item(\'tyreConstructionType\', $data->construction_type), 0, 1)', 'filter' => L::items('tyreConstructionType')), array('name' => 'runflat_type', 'value' => 'L::ruitem(\'boolean\', $data->runflat_type)', 'filter' => L::ruitems('boolean')), array('class' => 'CButtonColumn'))));
 /**
  * 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 = TyreProducers::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'Запрашиваемая страница не существует.');
     }
     return $model;
 }
Example #7
0
<?php

$this->breadcrumbs = array('Типоразмеры' => array('index'), 'Управление типоразмерами');
$this->menu = array(array('label' => 'Обзор типоразмеров', 'url' => array('index')), array('label' => 'Добавить типоразмер', 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('tyre-sizes-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<h1>Управление типоразмерами</h1>

<p>
Можно использовать операторы сравнения (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
или <b>=</b>) в начале запроса.
</p>

<?php 
echo CHtml::link('Расширенный поиск', '#', array('class' => 'search-button'));
?>
<div class="search-form" style="display:none">
<?php 
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->

<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'tyre-sizes-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('code', array('name' => 'producer', 'value' => '$data->tyre->producer->title', 'filter' => CHtml::listData(TyreProducers::model()->findAll(), 'id', 'title')), array('name' => 'tyre_id', 'value' => '$data->tyre->title', 'filter' => CHtml::listData(Tyre::model()->findAll('producer_id=:id', array(':id' => $model->producer)), 'id', 'title')), 'width', 'height', 'diameter', 'load_index', 'speed_rating', 'price', 'rest', array('class' => 'CButtonColumn'))));
Example #8
0
	<?php 
echo $form->errorSummary($model);
?>

	<div class="row">
		<?php 
Yii::app()->clientScript->registerScriptFile($this->assets . '/js/jquery.selectboxes.min.js');
?>
		<?php 
echo $form->labelEx($model, 'tyre_id');
?>
		<div class='input'>
			<div>Производитель<br />
			<?php 
echo CHtml::dropDownList(null, $model->isNewRecord ? null : $model->tyre->producer_id, CHtml::listData(TyreProducers::model()->findAll(), 'id', 'title'), array('id' => 'tyreProducersList', 'ajax' => array('url' => CHtml::normalizeUrl(array('tyres/sizes/ajaxTyres')), 'dataType' => 'json', 'data' => 'js:"producer_id="+$(this).val()', 'success' => 'function(data){ jQuery(\'#' . get_class($model) . '_tyre_id\').html("").addOption(data, false); }')));
?>
			</div>
			<div>Шина<br />
			<?php 
echo $form->dropDownList($model, 'tyre_id', $model->isNewRecord ? array() : CHtml::listData(Tyre::model()->findAll('producer_id=' . $model->tyre->producer_id), 'id', 'title'));
?>
			</div>
			<?php 
if ($model->isNewRecord) {
    Yii::app()->clientScript->registerScript(get_class($model) . '#tyreProducersList', '$("#' . get_class($model) . '_tyre_id").ajaxAddOption("' . CHtml::normalizeUrl(array('tyres/sizes/ajaxTyres')) . '", {producer_id: $("#tyreProducersList").val()});');
}
?>
		</div>
		<?php 
echo $form->error($model, 'tyre_id');