Ejemplo n.º 1
0
 public function run()
 {
     $moduleModel = SiteModule::model()->findByPk(4);
     if (!empty($moduleModel)) {
         $root = CatalogRubrics::getRoot();
         $categories = $root->descendants()->findAll($root->id);
         $tree = '';
         $level = 0;
         foreach ($categories as $n => $category) {
             if ($category->status == 1) {
                 if ($category->level == $level) {
                     $tree .= CHtml::closeTag('li') . "\r\n";
                 } else {
                     if ($category->level > $level) {
                         $tree .= CHtml::openTag('ul') . "\r\n";
                     } else {
                         $tree .= CHtml::closeTag('li') . "\r\n";
                         for ($i = $level - $category->level; $i; $i--) {
                             $tree .= CHtml::closeTag('ul') . "\r\n";
                             $tree .= CHtml::closeTag('li') . "\r\n";
                         }
                     }
                 }
                 $tree .= CHtml::openTag('li');
                 $tree .= CHtml::link($category->name, Yii::app()->urlManager->createUrl($moduleModel->url_to_controller . '/element', array('param' => $category->url)));
                 $level = $category->level;
             }
         }
         $tree .= CHtml::closeTag('li') . "\r\n";
         $tree .= CHtml::closeTag('ul') . "\r\n";
         $data['tree'] = $tree;
         $this->render('view_Categories', $data);
     }
 }
Ejemplo n.º 2
0
    public function run()
    {
        $root = CatalogRubrics::model()->roots()->find();
        $all = CatalogRubrics::model()->findByPk($root->id)->findAll();
        $ret = '';
        foreach ($all as $item) {
            $item_attributes = $item->getAttributes();
            if ($item_attributes['parent_id'] == 4890) {
                $ret .= '<li class="lmenu_item_' . $item_attributes['id'] . '">
				<a href="/catalog/' . $item_attributes['url'] . '">' . $item_attributes['name'] . '</a>
				<div class="div_arrow moreheight down" idx="' . $item_attributes['id'] . '"></div>
				';
                $subitems = '';
                foreach ($all as $item2) {
                    $item2_attributes = $item2->getAttributes();
                    if ($item2_attributes['parent_id'] == $item_attributes['id']) {
                        $subitems .= '<li  class="lmenu_item_' . $item2_attributes['id'] . '">

						<a href="/catalog/' . $item2_attributes['url'] . '">' . $item2_attributes['name'] . '</a>';
                        $subsubitems = '';
                        foreach ($all as $item3) {
                            $item3_attributes = $item3->getAttributes();
                            if ($item3_attributes['parent_id'] == $item2_attributes['id']) {
                                $subsubitems .= '<li class="lmenu_item_' . $item3_attributes['id'] . '">
											           <a href="/catalog/' . $item3_attributes['url'] . '">
											             ' . $item3_attributes['name'] . '
											           </a>
											         </li>';
                            }
                        }
                        if (strlen($subsubitems)) {
                            $subsubitems = '
							<div class="div_arrow" idx="' . $item2_attributes['id'] . '">
							</div>
							<ul class="parent_lmcontainer_' . $item2_attributes['id'] . '">' . $subsubitems . '</ul>';
                        }
                        $subitems .= $subsubitems . '</li>';
                    }
                }
                if (strlen($subitems)) {
                    $ret .= '<ul class="parent_lmcontainer_' . $item_attributes['id'] . '">' . $subitems . '</ul>';
                }
                $ret .= '</li>';
            }
        }
        $data['ret'] = $ret;
        $this->render('view_LeftMenu', $data);
    }
Ejemplo n.º 3
0
 private function getChaildCategory($model, $level = null)
 {
     $menu_top = array();
     foreach (CatalogRubrics::getCatalogList($model, $level) as $data) {
         $menu_top[$data->id]['name'] = $data->name;
         $menu_top[$data->id]['url'] = $data->url;
     }
     return $menu_top;
 }
Ejemplo n.º 4
0
 public function actionUploaddata($id)
 {
     set_time_limit(0);
     $model = $this->loadModel($id);
     $catalog = null;
     //Для модуля Каталог, Двигатели, Трансмисия
     if ($model->module == 1) {
         $catalog = CatalogRubrics::model()->getRootIdAndName();
     }
     if ($model->module == 2) {
         $catalog = CatalogengineRubrics::model()->getRootIdAndName();
     }
     if ($model->module == 3) {
         $catalog = CatalogtransmissionRubrics::model()->getRootIdAndName();
     }
     if (isset($_POST['LoadxmlRubrics'])) {
         $err = 0;
         //$model->attributes = $_POST['LoadxmlRubrics'];
         $filepatch = YiiBase::getPathOfAlias('webroot') . '/../uploads/filestorage/loadxml/';
         $model->testedfile = CUploadedFile::getInstance($model, 'testedfile');
         if (!empty($model->testedfile)) {
             $ext = pathinfo($model->testedfile);
             $ext = $ext['extension'];
             if ($model->ext != $ext) {
                 if (($model->ext == 'xls' || $model->ext == 'xlsx') && ($ext == 'xls' || $ext == 'xlsx')) {
                     $err = 0;
                 } else {
                     $err = 1;
                     Yii::app()->user->setFlash('error', "Файл должен быть в формате: " . $model->ext);
                 }
             }
         } else {
             $err = 1;
             Yii::app()->user->setFlash('error', "Вы не выбрали файл");
         }
         if ($err == 0) {
             //Загружаем файл
             $filename = $model->testedfile->getName();
             $model->testedfile->saveAs($filepatch . $filename);
             //xls и xlsx
             if (preg_match("/.xls/i", $filename) || preg_match("/.xlsx/i", $filename)) {
                 $exel = new Parsfile();
                 $exel->pars_exel($filepatch . $filename);
                 $output = $exel->OutArr;
             }
             //xml
             if (preg_match("/.xml/i", $filename)) {
                 $xml = new Parsfile();
                 $xml->pars_xml($filepatch . $filename, $model->tag);
                 $output = $xml->XmlFieldsHash;
             }
             //csv
             if (preg_match("/.csv/i", $filename)) {
                 $csv = new Parsfile();
                 $splitter = LoadxmlRubrics::model()->getSplitter((int) $model->splitter);
                 $csv->pars_csv($filepatch . $filename, $splitter);
                 $output = $csv->OutArr;
             }
             //модуль каталог
             if ($model->module == 1 || $model->module == 2 || $model->module == 3) {
                 $table_pref = "tbl_";
                 if ($model->module == 1) {
                     $table = "catalog_elements";
                 }
                 //Для модуля Каталог
                 if ($model->module == 2) {
                     $table = "catalogengine_elements";
                 }
                 //Для модуля Двигатели
                 if ($model->module == 3) {
                     $table = "catalogtransmission_elements";
                 }
                 //Для модуля Трансмисия
                 // Вычисляем, какие столбцы нужно обходить циклом для группировки значений
                 $groups_need = array();
                 if (!empty($model->groups)) {
                     $list_groups = unserialize($model->groups);
                     $cnt_list = count($list_groups);
                     $group_i = 0;
                     for ($i = 1; $i <= $cnt_list; ++$i) {
                         if ($list_groups[$i]) {
                             $groups_need[$group_i] = $i;
                             // создаем массив с номерами нужных столбцов
                             ++$group_i;
                         }
                     }
                 }
                 $count_need = count($groups_need);
                 // кол-во нужных столбов
                 $count_table = count($output);
                 // кол-во строк в таблице
                 $val_arr_group = array();
                 // массив значений для группировки
                 $val_arr_cnt = array();
                 // массив для хранения кол-ва записей группировки
                 $val_arr_group_r = array();
                 // массив значений для группировки
                 if ($count_need > 0) {
                     for ($j = 1; $j <= $count_table; ++$j) {
                         for ($i = 0; $i <= $count_need; ++$i) {
                             $group_id = $groups_need[$i];
                             $group_cnt = intval($val_arr_cnt[$group_id]);
                             $read_vars = trim($output[$j][$group_id]);
                             $read_vars_alt = $this->totranslit($read_vars);
                             if (!in_array($read_vars_alt, $val_arr_group[$group_id]) and $read_vars_alt) {
                                 $val_arr_group[$group_id][$group_cnt] = $read_vars_alt;
                                 // записываем в массив значение
                                 $val_arr_group_r[$group_id][$group_cnt]['name'] = $read_vars;
                                 $val_arr_group_r[$group_id][$group_cnt]['alt_name'] = $read_vars_alt;
                                 ++$group_cnt;
                                 $val_arr_cnt[$group_id] = $group_cnt;
                                 // записываем в массив кол-во записей
                             }
                         }
                     }
                 }
                 //надо очищать каталог перед импортом - сдеать вызов тут
                 if (isset($_POST['LoadxmlRubrics']['clearsect']) && (int) $_POST['LoadxmlRubrics']['clearsect'] == 1 && (int) $_POST['LoadxmlRubrics']['parent_id'] > 0) {
                     if ($model->module == 1) {
                         CatalogElements::model()->deleteAll("`parent_id` = :parent_id", array(':parent_id' => (int) $_POST['LoadxmlRubrics']['parent_id']));
                     }
                     if ($model->module == 2) {
                         CatalogengineElements::model()->deleteAll("`parent_id` = :parent_id", array(':parent_id' => (int) $_POST['LoadxmlRubrics']['parent_id']));
                     }
                     if ($model->module == 3) {
                         CatalogtransmissionElements::model()->deleteAll("`parent_id` = :parent_id", array(':parent_id' => (int) $_POST['LoadxmlRubrics']['parent_id']));
                     }
                 }
                 /*
                 foreach ($val_arr_group_r as $keys_in ) {
                     foreach ( $keys_in as $test ) {
                         $nde = array();
                         $nde['name'] = trim($test['name']);
                         $nde['page_name'] = $test['name'];
                         $nde['url'] = strtolower($test['alt_name']);
                         if ((int)$_POST['LoadxmlRubrics']['parent_id']>0){
                             $category = new CatalogRubrics;
                             $category->name = $nde['name'];
                             $category->page_name = $nde['page_name'];
                             $category->url = $nde['url'];
                             $category->parent_id = (int)$_POST['LoadxmlRubrics']['parent_id'];
                             $root = CatalogRubrics::model()->findByPk($category->parent_id);
                             $category->appendTo($root);
                         }
                     }
                 }
                 */
                 $MainFields = null;
                 $fields = explode('|', $model->content2);
                 $FieldCount = 0;
                 foreach ($fields as $k => $v) {
                     if (isset($v[0]) && !empty($v[0])) {
                         $subfields = explode('%', $v);
                         $MainFields2[$k] = $subfields;
                         if ($model->ext == 'xml') {
                             $subfields[1] = $xml->XmlAntiMap[$subfields[1]];
                         }
                         $MainFields[$k] = $subfields;
                         $FieldCount++;
                     }
                 }
                 $uniqKey = '';
                 foreach ($MainFields as $mk => $mv) {
                     if ($mv[0] == $model->unique && $model->unique != '') {
                         $uniqKey = $model->unique;
                     }
                 }
                 //Пишем данные в таблицы
                 foreach ($output as $k => $v) {
                     $sett = '';
                     $setv = '';
                     $UniqField = '';
                     $WriteFlag = 1;
                     foreach ($MainFields as $K => $V) {
                         $val = '';
                         if ($model->ext == 'xml') {
                             $xml_field = $MainFields2[$K][1];
                             $val = $xml->XmlFieldsHash[$k][$xml_field];
                             if ($V[1] == 3) {
                                 $val = preg_replace("/[^1234567890.,]/", '', $val);
                                 $vall = preg_replace("/\\,]/", '.', $val);
                             }
                             if ($V[1] == 2) {
                                 if (trim($xml->XmlFieldsHash[$k][$xml_field]) == '') {
                                     $val = '';
                                 } else {
                                     $val = 1;
                                 }
                             }
                         } else {
                             $val = $v[$V[1]];
                             if ($V[2] == 3) {
                                 $val = preg_replace("/[^1234567890.,]/", '', $val);
                                 $vall = preg_replace("/\\,]/", '.', $val);
                             }
                             if ($V[2] == 2) {
                                 if (trim($v[$V[2] - 1]) == '') {
                                     $val = '';
                                 } else {
                                     $val = 1;
                                 }
                             }
                         }
                         //print $val."||||<br/>";
                         if ($sett == '') {
                             $sett .= " `{$V['0']}` ";
                         } else {
                             $sett .= ", `{$V['0']}` ";
                         }
                         if ($setv == '') {
                             $setv .= " '" . $val . "' ";
                         } else {
                             $setv .= ", '" . addslashes($val) . "' ";
                         }
                         if ($V[0] == $uniqKey && $V[0] != '') {
                             $UniqField = $uniqKey;
                             $resultU = Yii::app()->db->createCommand()->select('*')->from('{{' . $table . '}}')->where(" `" . $UniqField . "` = '" . $val . "'")->queryAll();
                             foreach ($resultU as $rowU) {
                                 if ($rowU['id'] != '') {
                                     Yii::app()->db->createCommand()->delete("`" . $table . "`", 'id=:id', array(':id' => $rowU['id']));
                                 }
                             }
                         }
                         if ($V[3] != '') {
                             //if($val == ''){$WriteFlag = 0;}
                         }
                     }
                     $sett .= ',`parent_id` ';
                     $setv .= ", '" . (int) $_POST['LoadxmlRubrics']['parent_id'] . "' ";
                     if ($WriteFlag != '0') {
                         $sql = "INSERT INTO " . $table_pref . $table . " ({$sett}) VALUES ({$setv})";
                         Yii::app()->db->createCommand($sql)->execute();
                     } else {
                         print "0 <br/>";
                     }
                 }
             }
             Yii::app()->user->setFlash('success', "Данные загружены");
         }
     }
     $this->render('uploaddata', array('model' => $model, 'catalog' => $catalog));
 }
Ejemplo n.º 5
0
 public function actionSharechars($type_parent = 3)
 {
     $this->breadcrumbs = array('Группы товаров' => array('/catalog/catalog/listgroup'), 'Настройки' => array('/catalog/catalog/settings'), 'Список предопределенных характеристик' => array('/catalog/catalog/sharechars'));
     $model = new CatalogChars('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['CatalogChars'])) {
         $model->attributes = $_GET['CatalogChars'];
     }
     if (isset($_POST['CatalogChars'])) {
         //Добавляем новую предопределенную характеристику
         $model->attributes = $_POST['CatalogChars'];
         $model->type_parent = $type_parent;
         if ($model->save()) {
             //Если указано наследование - создаем это свойство для остальных элементов в этом объекте
             if ($model->inherits == 1) {
                 CatalogChars::model()->addInherits($model, $_POST['CatalogChars']);
             } else {
                 //Иначе - создаем только для указаного каталога это свойство
                 $model = new CatalogChars();
                 $model->attributes = $_POST['CatalogChars'];
                 $model->type_parent = 1;
                 $model->save();
             }
         }
         $model = new CatalogChars('search');
         $model->unsetAttributes();
         // clear any default values
     }
     $param = null;
     $param[] = 'type_parent = ' . $type_parent;
     $param[] = 'is_deleted = 0';
     $data['sort'] = array('defaultOrder' => 'id DESC');
     $data['Pagination'] = array('PageSize' => 100);
     $provider = new CActiveDataProvider('CatalogChars', $data);
     $param = implode(" AND ", $param);
     $provider->criteria = $model->search($param);
     $root = CatalogRubrics::getRoot();
     $catalog = CMap::mergeArray(array($root->id => $root->name), $root->getFormattedDescendants($root->id));
     $this->render('sharechars', array('model' => $model, 'provider' => $provider, 'catalog' => $catalog, 'root' => $root));
 }
Ejemplo n.º 6
0
 /**
  * Получение количества записей в категории
  *
  * @param $category
  * @return int|mixed
  */
 public static function getTotalCountElement($category)
 {
     $total = 0;
     if (is_int($category)) {
         $category = CatalogRubrics::model()->findByPk($category);
     }
     if (!empty($category)) {
         $branch = CatalogRubrics::getBranch($category->left_key, $category->right_key);
         foreach ($branch as $branchRow) {
             $ids[] = $branchRow->id;
         }
         if (!empty($ids)) {
             $total = Yii::app()->db->createCommand()->select('COUNT(*)')->from(CatalogElements::model()->tableName())->where(array('in', 'parent_id', $ids))->queryScalar();
         }
     }
     return $total;
 }
Ejemplo n.º 7
0
                -->
            </td>
        </tr>
        <?php 
}
?>
        </tbody>
    </table>

<div id="ajax_loader" style="display: none;"><img width="40px;" style="position:absolute; margin-top:10px; margin-left:-40px;" src="/images/admin/ajaxloader.gif"></div>
<div class="buttons">
    <?php 
if (isset($_GET['id']) && $_GET['id'] > 0) {
    ?>
<a class="btn" style="float:left; margin-top:14px" href="/admin/catalog/catalog/listgroup?id=<?php 
    echo CatalogRubrics::model()->findByPk((int) $_GET['id'])->parent_id;
    ?>
">&#9668; Назад</a><?php 
}
?>
    <a class="btn btn-primary" style="margin-top:14px; float:left; margin-left:15px" href="/admin/<?php 
echo Yii::app()->controller->module->id;
?>
/<?php 
echo Yii::app()->controller->id;
?>
/create?id=<?php 
echo isset($_GET['id']) ? (int) $_GET['id'] : 0;
?>
"> Добавить группу</a>
    <a class="btn btn-danger" style="float:left; margin-left:15px; margin-top:14px" href="javascript: deleteselected();">Удалить отмеченные</a>
Ejemplo n.º 8
0
 public function actionIndex()
 {
     $model = array();
     $data[] = array();
     $data['model_elements'] = array();
     if (isset($_GET['s']) && !empty($_GET['s']) && strlen(trim($_GET['s']))) {
         $pattern = trim($_GET['s']);
         $pattern_orig = $pattern;
         $pattern = '/' . $pattern . '/i';
         $page = isset($_GET['page']) ? intval($_GET['page']) : 0;
         $data['page'] = $page;
         //Ищем в каталоге
         $crubrics = CatalogRubrics::model()->findAll('status=1');
         $data['allow_rubrics'] = array();
         foreach ($crubrics as $datas) {
             if ($this->compares($pattern_orig, $datas->name)) {
                 $data['allow_rubrics'][] = $datas->id;
             }
         }
         foreach ($data['allow_rubrics'] as $allow_rubric) {
             $celements = CatalogElements::model()->findAll('status=1 AND parent_id = ' . intval($allow_rubric));
             foreach ($celements as $datas) {
                 if ($this->compares($pattern_orig, $datas->name) && !isset($data['model_elements'][$datas->id])) {
                     $data['model_elements'][$datas->id] = $datas;
                 }
             }
             foreach ($celements as $datas) {
                 if ($this->compares($pattern_orig, $datas->description) && !isset($data['model_elements'][$datas->id])) {
                     $data['model_elements'][$datas->id] = $datas;
                 }
             }
         }
         $celements = CatalogElements::model()->findAll('status=1');
         foreach ($celements as $datas) {
             if ($this->compares($pattern_orig, $datas->name) && !isset($data['model_elements'][$datas->id])) {
                 $data['model_elements'][$datas->id] = $datas;
             }
         }
         foreach ($celements as $datas) {
             if ($this->compares($pattern_orig, $datas->description) && !isset($data['model_elements'][$datas->id])) {
                 $data['model_elements'][$datas->id] = $datas;
             }
         }
         $count = count($data['model_elements']) - 12;
         $criteria = new CDbCriteria();
         $pages = new CPagination($count);
         $pages->pageSize = 12;
         $pages->applyLimit($criteria);
         $data['pages'] = $pages;
     }
     $this->render('index', $data);
 }
Ejemplo n.º 9
0
 /**
  * @param $model
  * @param $param
  * Добавляет наследование для категории
  */
 public function addInherits($model, $param)
 {
     if ($model->type_parent == 1 || $model->type_parent == 3) {
         //Для категорий
         $modelcatalog = CatalogRubrics::model()->findByPk($model->parent_id);
         foreach ($modelcatalog->descendants()->findAll() as $data) {
             $model_chars = new CatalogChars();
             $model_chars->attributes = $param;
             $model_chars->parent_id = $data->id;
             $model_chars->type_parent = 1;
             $model_chars->save();
         }
     }
     return true;
 }
Ejemplo n.º 10
0
                    </div>
-->
                    <div class="items-block-new">
                        <h1 class="lined">Новинки рынка</h1>
                        <div class="tovar_container">



<?php 
$model_CatalogElements = CatalogElements::model()->findAll('status = 1 ORDER BY order_id LIMIT 0,12');
foreach ($model_CatalogElements as $element_item) {
    $element = CatalogElements::model()->getProduct($element_item->id);
    if (isset($element['url'])) {
        $url = '/catalog' . $element['url'] . '/' . $element_item->id;
    }
    $modelRubric = CatalogRubrics::model()->find('id=' . $element_item->parent_id);
    $filename = '/uploads/filestorage/catalog/elements/' . $element_item->id . '.' . $element_item->image;
    $name_noqoutes = $element_item->name;
    $name_noqoutes = str_replace("'", '', $name_noqoutes);
    $name_noqoutes = str_replace('"', '', $name_noqoutes);
    $name_noqoutes = htmlspecialchars($name_noqoutes, ENT_QUOTES);
    $name_noqoutes = str_replace('&#039;', '', $name_noqoutes);
    ?>
	<div class="items-block-item">
		<div class="item-label new-product">new</div>
		<a href="<?php 
    echo $url;
    ?>
" class="items-block-item-img">
			<table>
				<tr><td></td></tr>