public function run()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['producer_id'])) {
         $producer_id = Yii::app()->request->getParam('producer_id');
         // 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->condition = "producer_id = :sterm";
         $criteria->params = array(":sterm" => $producer_id);
         $criteria->limit = $limit;
         $criteria->order = 'title';
         echo CJavaScript::jsonEncode(CHtml::listData(Disk::model()->findAll($criteria), 'id', 'title'));
     }
 }
 private function showDisksByModel($alias, $construct = null)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'disk.alias = :alias';
     $criteria->params = array(':alias' => $alias);
     if (!($model = Disk::model()->find('alias = :alias', array(':alias' => $alias)))) {
         throw new CHttpException(400, 'Такой страницы нет');
     }
     // Сезонность
     if ($construct && L::r_item('diskConstructionType', $construct)) {
         $criteria->addCondition('disk.diskConstructionType = ' . L::r_item('diskConstructionType', $construct));
     }
     $criteria->addCondition('t.rest <> "0"');
     $criteria->with = array('disk');
     $dataProvider = new CActiveDataProvider('DiskSizes', array('criteria' => $criteria));
     $this->addComment($model);
     $this->render('disks/sizes', array('dataProvider' => $dataProvider, 'construct' => $construct, 'model' => $model));
 }
 /**
  * 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 = Disk::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'Запрашиваемая страница не существует.');
     }
     return $model;
 }
Exemplo n.º 4
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->disk->producer->title', 'filter' => CHtml::listData(DiskProducers::model()->findAll(), 'id', 'title')), array('name' => 'disk_id', 'value' => '$data->disk->title', 'filter' => CHtml::listData(Disk::model()->findAll('producer_id=:id', array(':id' => $model->producer)), 'id', 'title')), 'width', 'diameter', 'PCD_screws', 'PCD_diameter', 'ET', 'DIA', 'price', 'rest', array('class' => 'CButtonColumn'))));
 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()) {
             # Вот тут начинается импорт
             $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 = 1;
             $rowcount = $data->rowcount($sheet);
             #$colcount = $data->colcount();
             #$rowcount = 10;
             $r = 2;
             while ($r <= $rowcount) {
                 $cai = $data->val($r, 1);
                 if (empty($cai)) {
                     $r++;
                     continue;
                 }
                 $producer_alias = EString::strtolower(EString::sanitize($data->val($r, 2)));
                 if (!($producer = DiskProducers::model()->find('alias=:alias', array(':alias' => $producer_alias)))) {
                     $producer = new DiskProducers();
                     @($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;
                 }
                 $disk_alias = EString::strtolower(EString::sanitize($data->val($r, 3)));
                 if (!($disk = Disk::model()->find('alias=:alias', array(':alias' => $disk_alias)))) {
                     $disk = new Disk();
                     @($result['new_disks'] += 1);
                 } else {
                     @($result['old_disks'] += 1);
                 }
                 $disk->producer_id = $producer->id;
                 $disk->title = $data->val($r, 3);
                 $disk->alias = $disk_alias;
                 $disk->color = 1;
                 $disk->construction_type = L::r_item('diskConstructionType', 'alloy');
                 if ($data->val($r, 5)) {
                     $disk->construction_type = L::r_item('diskConstructionType', 'forged');
                 }
                 /*
                 if($data->val($r, 4) && $data->val($r,5))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'scratched');
                 if(!($data->val($r, 4)) && !($data->val($r,5)) ))
                 	$disk->construction_type = L::r_item('diskConstructionType', 'stamped');
                 */
                 // загрузка картинок...
                 $alias = EString::sanitize($producer_alias . '_' . $disk_alias);
                 $path0 = Yii::getPathOfAlias('webroot.files.' . EString::strtolower('Disk') . '.' . 'photo') . DIRECTORY_SEPARATOR;
                 $f = false;
                 $tmp_image = str_replace('.jpg', '.png', $data->val($r, 12));
                 if (!empty($tmp_image) && empty($disk->photo)) {
                     #d($tmp_image);
                     #d($tyre->photo);
                     foreach (Disk::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/disk/photo/::size::/' . $alias . '.jpg')))) {
                             $image = new Image();
                         }
                         $image->created = date('Y-m-d H:i:s', strtotime($row['add_date']));
                         $image->filename = '/files/disk/photo/::size::/' . $alias . '.jpg';
                         $image->title = $producer->title . ' ' . $disk->title;
                         $image->alt = $producer->title . ' ' . $disk->title;
                         $image->save();
                         $disk->photo = '/files/disk/photo/::size::/' . $alias . '.jpg';
                     } else {
                         $disk->photo = null;
                     }
                 }
                 if (!$disk->save()) {
                     $result['errors']['disk:' . $data->val($r, 1)] = $disk->errors;
                 }
                 if (!($size = DiskSizes::model()->find('code=:code', array(':code' => $cai)))) {
                     $size = new DiskSizes();
                     $size->alias = uniqid();
                     $size->save(false);
                     @($result['new_size'] += 1);
                 } else {
                     @($result['old_size'] += 1);
                 }
                 $size->disk_id = $disk->id;
                 $size->code = $cai;
                 /*
                  * 1. cae	
                  * 2. producer.name
                  * 3. model.name
                  * 4. lit
                  * 5. kov
                  * 6. sh
                  * 7. d	
                  * 8. pcd
                  * 9. pcd2
                  * 10.vil
                  * 11.dia
                  */
                 $width_fl_point = preg_replace("/,/", ".", $data->val($r, 6));
                 $width_c = floatval(preg_replace("/^[^0-9\\.]/", "", $width_fl_point));
                 $size->width = $width_c;
                 $size->diameter = $data->val($r, 7);
                 $ET_fl_point = preg_replace("/,/", ".", $data->val($r, 10));
                 $ET_c = floatval(preg_replace("/^[^0-9\\.\\-]/", "", $ET_fl_point));
                 $size->ET = floatval($ET_c);
                 list($size->PCD_screws, $PCD_diameter_fl_point) = preg_split('/[^\\d,\\.]+/i', $data->val($r, 8));
                 $PCD_diameter_fl_point = preg_replace("/,/", ".", $PCD_diameter_fl_point);
                 $PCD_diameter_c = floatval(preg_replace("/^[^0-9\\.]/", "", $PCD_diameter_fl_point));
                 $size->PCD_diameter = $PCD_diameter_c;
                 $DIA_fl_point = preg_replace("/,/", ".", $data->val($r, 11));
                 $DIA_c = floatval(preg_replace("/^[^0-9\\.]/", "", $DIA_fl_point));
                 $size->DIA = $DIA_c;
                 $size->price = 0;
                 $size->rest = 0;
                 $size->alias = $size->id . '-' . $size->width . '-' . $size->diameter . '-' . $size->PCD_screws . '-' . $size->PCD_diameter . '-ET' . $size->ET . '-' . $size->DIA;
                 if (!$size->save()) {
                     $size->delete();
                     $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));
 }
Exemplo n.º 6
0
	<div class="row">
		<?php 
Yii::app()->clientScript->registerScriptFile($this->assets . '/js/jquery.selectboxes.min.js');
?>
		<?php 
echo $form->labelEx($model, 'disk_id');
?>
		<div class='input'>
			<div>Производитель<br />
			<?php 
echo CHtml::dropDownList(null, $model->isNewRecord ? null : $model->disk->producer_id, CHtml::listData(DiskProducers::model()->findAll(), 'id', 'title'), array('id' => 'diskProducersList', 'ajax' => array('url' => CHtml::normalizeUrl(array('disks/sizes/ajaxDisks')), 'dataType' => 'json', 'data' => 'js:"producer_id="+$(this).val()', 'success' => 'function(data){ jQuery(\'#' . get_class($model) . '_disk_id\').html("").addOption(data, false); }')));
?>
			</div>
			<div>Диск<br />
			<?php 
echo $form->dropDownList($model, 'disk_id', $model->isNewRecord ? array() : CHtml::listData(Disk::model()->findAll('producer_id=' . $model->disk->producer_id), 'id', 'title'));
?>
			</div>
			<?php 
if ($model->isNewRecord) {
    Yii::app()->clientScript->registerScript(get_class($model) . '#diskProducersList', '$("#' . get_class($model) . '_disk_id").ajaxAddOption("' . CHtml::normalizeUrl(array('disks/sizes/ajaxDisks')) . '", {producer_id: $("#diskProducersList").val()});');
}
?>
		</div>
		<?php 
echo $form->error($model, 'disk_id');
?>
	</div>

	<div class="row">
		<?php 
Exemplo n.º 7
0
 /**
  * @covers SysInfo\Linux\Disk::__construct
  * @covers SysInfo\Linux\Disk::getReads
  * @covers SysInfo\Linux\Disk::getWrites
  * @covers SysInfo\Linux\Disk::getTimeSpentReading
  * @covers SysInfo\Linux\Disk::getTimeSpentWriting
  * @covers SysInfo\Linux\Disk::sumField
  */
 public function testDiskWithSystemData()
 {
     $disk = new Disk();
     $this->assertInternalType('int', $disk->getReads());
     $this->assertInternalType('int', $disk->getReads('sda'));
     $this->assertInternalType('int', $disk->getReads(array('sda')));
     $this->assertInternalType('int', $disk->getReads('sda', 1));
     $this->assertInternalType('int', $disk->getReads('sda', array(1, 5)));
     $this->assertInternalType('int', $disk->getWrites());
     $this->assertInternalType('int', $disk->getWrites('sda'));
     $this->assertInternalType('int', $disk->getWrites(array('sda')));
     $this->assertInternalType('int', $disk->getWrites('sda', 1));
     $this->assertInternalType('int', $disk->getWrites('sda', array(1, 5)));
     $this->assertInternalType('int', $disk->getTimeSpentReading());
     $this->assertInternalType('int', $disk->getTimeSpentReading('sda'));
     $this->assertInternalType('int', $disk->getTimeSpentReading(array('sda')));
     $this->assertInternalType('int', $disk->getTimeSpentReading('sda', 1));
     $this->assertInternalType('int', $disk->getTimeSpentReading('sda', array(1, 5)));
     $this->assertInternalType('int', $disk->getTimeSpentWriting());
     $this->assertInternalType('int', $disk->getTimeSpentWriting('sda'));
     $this->assertInternalType('int', $disk->getTimeSpentWriting(array('sda')));
     $this->assertInternalType('int', $disk->getTimeSpentWriting('sda', 1));
     $this->assertInternalType('int', $disk->getTimeSpentWriting('sda', array(1, 5)));
 }
 public function actionDisks()
 {
     $sizes = array();
     $form = $_GET;
     $selection = new DiskSelectionForm();
     $pages = null;
     if (!empty($form)) {
         $selection->attributes = $form;
         if ($selection->validate()) {
             #d($tyreSelection->attributes);
             $criteria = new CDbCriteria();
             if (!empty($selection->producers)) {
                 $crit0 = new CDbCriteria();
                 $crit0->with = array('producer');
                 $crit0->compare('producer.alias', $selection->producers);
                 // Собираю шины производителей подходящих под условия фильтра
                 $disks = CHtml::listData(Disk::model()->findAll($crit0), 'id', 'id');
                 $criteria->compare('disk_id', $disks);
             }
             #$criteria->compare('code',$this->code,true);
             $criteria->compare('width', $selection->width);
             $criteria->compare('diameter', $selection->diameter);
             $criteria->compare('ET', $selection->ET, true);
             $pcd_screws = $pcd_diameter = null;
             if ($selection->PCD) {
                 list($pcd_screws, $pcd_diameter) = preg_split('/x/i', $selection->PCD);
             }
             $criteria->compare('PCD_screws', $pcd_screws);
             $criteria->compare('PCD_diameter', $pcd_diameter, true);
             $criteria->compare('price', '>=' . $selection->price_from, false);
             $criteria->compare('price', '<=' . $selection->price_until, false);
             $criteria->compare('price', '<>0');
             $criteria->mergeWith(DiskSizes::model()->inSight()->getDbCriteria());
             $data = new CActiveDataProvider('DiskSizes', array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->params['selection.resultsPerPage'])));
         }
     }
     $this->render('disks', array('selection' => $selection, 'data' => $data));
 }
Exemplo n.º 9
0
 /**
  * Builds a path from arguments and validates existence.
  *
  *      $_path = FileSystem::makePath(true,'path','to','my','stuff')
  *
  *      The result is "/path/to/my/stuff"
  *
  * @param bool         $createMissing If true,  and result path doesn't exist, it will be created
  * @param string|array $segments      One or more directory parts to assemble
  *
  * @return bool|string Returns the created path or false if non-existent
  *
  * @deprecated Use static::buildPath() or Disk::path() instead.
  */
 public static function makePath($createMissing = true, $segments = null)
 {
     $_parts = func_get_args();
     array_shift($_parts);
     return Disk::path($_parts, $createMissing);
 }
Exemplo n.º 10
0
 /**
  * Concatenate $parts into $separator delimited, trimmed, clean string.
  *
  * @param string|array $parts     The part or parts to join
  * @param bool         $leading   If true (default), a leading $separator will be added
  * @param string       $separator The delimiter to use
  *
  * @return null|string
  */
 public static function segment($parts = [], $leading = true, $separator = '/')
 {
     return Disk::segment($parts, $leading, $separator);
 }
Exemplo n.º 11
0
 /**
  * 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();
     if (Yii::app()->request->isAjaxRequest) {
         if ($model = Yii::app()->request->getParam('DiskSizes', false)) {
             // Обработка условий фильтра выбора производителя
             $this->producer = $model['producer'];
             // Собираю шины производителей подходящих под условия фильтра
             $disks = CHtml::listData(Disk::model()->findAll('producer_id=:producer_id', array(':producer_id' => $model['producer'])), 'id', 'id');
             // Подкидываю к фильтру новое условие
             $criteria->compare('disk_id', $disks);
         }
     }
     $criteria->compare('id', $this->id);
     $criteria->compare('disk_id', $this->disk_id, true);
     $criteria->compare('code', $this->code, true);
     $criteria->compare('width', $this->width);
     $criteria->compare('diameter', $this->diameter, true);
     $criteria->compare('ET', $this->ET);
     $criteria->compare('PCD_screws', $this->PCD_screws, true);
     $criteria->compare('PCD_diameter', $this->PCD_diameter);
     $criteria->compare('DIA', $this->DIA);
     $criteria->compare('price', $this->price, true);
     $criteria->compare('rest', $this->rest, true);
     return new CActiveDataProvider(get_class($this), array('criteria' => $criteria));
 }