public function loadModel($id)
 {
     if (($model = RealtyCategory::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('RealtyModule.realty', 'Page was not found!'));
     }
     return $model;
 }
Exemplo n.º 2
0
 /**
  * Action для вывода каталога объектов недвижимости
  *
  * @param string $category
  * @param string $type
  * @throws CHttpException
  */
 public function actionIndex($category, $type = '')
 {
     $realtyType = null;
     // Категория недвижимости
     $realtyCategory = RealtyCategory::model()->published()->with(['types:published'])->findByAlias($category);
     if (is_null($realtyCategory)) {
         throw new CHttpException(404);
     }
     // Тип недвижимости
     if (!empty($type)) {
         $realtyType = RealtyType::model()->published()->findByAlias($type);
         if (is_null($realtyType)) {
             throw new CHttpException(404);
         }
     }
     // Определение страницы для вывода мета-тегов страницы, заголовка и т.д.
     $page = !is_null($realtyType) ? $realtyType : $realtyCategory;
     // Инициализация поиска по объектам
     $model = new RealtyItem('user_search');
     $model->unsetAttributes();
     $model->category_id = $realtyCategory->id;
     $model->setCurrentCurrency($this->currentCurrency);
     if (!is_null($realtyType)) {
         // Подключаем EAV
         $model->attachEavSet($realtyType->eav_set_id);
         $model->type_id = $realtyType->id;
     } else {
         // Подключаем EAV
         $model->attachEavSet($realtyCategory->eav_set_id);
     }
     // Применение фильтра
     if (isset($_GET['filter'])) {
         $model->attributes = $_GET['filter'];
         $model->isSearch = true;
     }
     // Сохраняем ссылку для возврата
     Yii::app()->user->setState('realtyReturnUrl', $this->_constructReturnUrl('realty/realty/index'));
     $dataProvider = $model->user_search();
     // Вывод во view
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('catalog/_catalog', ['page' => $page, 'category' => $realtyCategory, 'type' => $realtyType, 'model' => $model, 'dataProvider' => $dataProvider], false, true);
     } else {
         $this->render('index', ['page' => $page, 'category' => $realtyCategory, 'type' => $realtyType, 'model' => $model, 'dataProvider' => $dataProvider]);
     }
 }
 public function actionFavorite()
 {
     $ids = array_reverse(Yii::app()->favorite->getPositions());
     $criteria = new CDbCriteria();
     $criteria->addInCondition('t.id', $ids);
     if (!empty($ids)) {
         $criteria->order = 'FIELD(t.id, ' . implode(',', $ids) . ')';
     }
     $categories = RealtyCategory::model()->published()->findAll(['order' => 't.sort ASC']);
     // Просматриваем все категории
     foreach ($categories as $key => &$category) {
         $category->items = RealtyItem::model()->withEavAttributes(true)->active()->category($category->id)->with(['category', 'type', 'currency'])->findAll($criteria);
         if (empty($category->items)) {
             unset($categories[$key]);
         }
     }
     $this->render('favorite', ['categories' => $categories]);
 }
Exemplo n.º 4
0
echo Yii::t('RealtyModule.realty', 'Fields with');
?>
    <span class="required">*</span>
    <?php 
echo Yii::t('RealtyModule.realty', 'are required.');
?>
</div>

<?php 
echo $form->errorSummary($model);
?>

<div class="row">
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'category_id', ['widgetOptions' => ['data' => RealtyCategory::model()->categoryList, 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('RealtyModule.realty', '--choose--'), 'data-original-title' => $model->getAttributeLabel('category_id'), 'data-content' => $model->getAttributeDescription('category_id'), 'data-container' => 'body']]]);
?>
    </div>
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'eav_set_id', ['widgetOptions' => ['data' => EavSetExtended::model()->list, 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('RealtyModule.realty', '--choose--'), 'data-original-title' => $model->getAttributeLabel('eav_set_id'), 'data-content' => $model->getAttributeDescription('eav_set_id'), 'data-container' => 'body']]]);
?>
    </div>
</div>

<div class="row">
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'status', ['widgetOptions' => ['data' => $model->statusList, 'htmlOptions' => ['class' => 'popover-help', 'empty' => Yii::t('RealtyModule.realty', '--choose--'), 'data-original-title' => $model->getAttributeLabel('status'), 'data-content' => $model->getAttributeDescription('status'), 'data-container' => 'body']]]);
?>
    </div>
Exemplo n.º 5
0
<?php

Yii::app()->getComponent('simpleBootstrap');
$model = new RealtyItem('user_search');
?>
<div class="filter filter-horizontal">
    <div class="container">
        <h2>Поиск</h2>
        <?php 
$form = $this->beginWidget('yupe\\widgets\\ActiveForm', ['id' => 'quick-search-form', 'action' => '', 'method' => 'get']);
?>
        
            <div class="row">
                <div class="form-group col-sm-3">
                    <?php 
$categories = RealtyCategory::model()->findAll(['scopes' => 'published']);
$options = [];
foreach ($categories as $value) {
    $options[$value->id] = ['data-url' => $value->getUrl()];
}
echo $form->dropDownListGroup($model, 'category_id', ['label' => false, 'widgetOptions' => ['data' => CHtml::listData($categories, 'id', 'title'), 'htmlOptions' => ['name' => "filter[category_id]", 'options' => $options, 'required' => true, 'id' => 'quick-search-category']]]);
?>
                </div><!-- /.form-group -->

                <div class="form-group col-sm-3">
                    <?php 
$attributeName = 'search_address';
$searchAddressAttributes = RealtyItem::$searchAddressAttributes;
foreach ($categories as $key => $cat) {
    $info = key_exists($cat->id, $searchAddressAttributes) ? $searchAddressAttributes[$cat->id] : $searchAddressAttributes[0];
    if (empty($info)) {
 public function actionIndex()
 {
     exit;
     $prefix = $_GET['prefix'];
     // prepare logger to dump logs every time one comes in
     Yii::getLogger()->autoFlush = 1;
     Yii::getLogger()->autoDump = true;
     function getNewFileName($fileName)
     {
         $ext = pathinfo($fileName, PATHINFO_EXTENSION);
         $oldName = pathinfo($fileName, PATHINFO_FILENAME);
         return md5(uniqid($fileName)) . '.' . $ext;
     }
     function logParse($message)
     {
         Yii::log($message, CLogger::LEVEL_TRACE, 'parse');
         Yii::getLogger()->flush(true);
     }
     //logParse("Begin");
     $begin = getmicrotime();
     // Начало
     $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->uploadPath . DIRECTORY_SEPARATOR . 'parse';
     $csvFile = $parsePath . DIRECTORY_SEPARATOR . "realty_{$prefix}.csv";
     $csvData = file_get_contents($csvFile);
     $csvData = mb_convert_encoding($csvData, 'utf-8', 'windows-1251');
     $csvData = explode("\r\n", $csvData);
     //var_dump($csvData);
     $categoryId = 1;
     //$typeId = 1;
     $category = RealtyCategory::model()->findByPK($categoryId);
     //$type = RealtyType::model()->findByPK($typeId);
     if (empty($category)) {
         throw new CHttpException(403, 'Incorrect category');
     }
     $realtyItems = [];
     $currencies = ['р.' => 1, '$' => 2, '€' => 3];
     $itemsCounter = 0;
     $galleriesList = CHtml::listData(RealtyGallery::model()->findAll(), 'xls_id', 'id');
     foreach ($csvData as $key => $row) {
         //if($key >= 20)
         //    break;
         $fields = str_getcsv($row, ";", '"');
         //$fields = explode(";", $row);
         //var_dump($fields);
         // Номер
         $num = (int) $fields[0];
         $imgFolderNum = $fields[1];
         if (empty($num)) {
             continue;
         }
         // Сделка
         $contractField = $fields[3];
         switch ($contractField) {
             case 'Продажа':
                 $contract = self::CONTRACT_SALE;
                 break;
             case 'Аренда':
                 $contract = self::CONTRACT_RENT;
                 break;
             default:
                 $contract = self::CONTRACT_SALE;
                 break;
         }
         // Тип недвижимости
         $typeField = $fields[2];
         switch ($typeField) {
             case 'Квартира':
                 $typeId = $contract == self::CONTRACT_RENT ? 4 : 1;
                 break;
             case 'Новостройка':
                 $typeId = 2;
                 break;
             default:
                 $typeId = 1;
                 break;
         }
         $type = RealtyType::model()->findByPK($typeId);
         if (empty($type)) {
             throw new CHttpException(403, 'Incorrect realty type');
         }
         $itemsCounter += 100;
         $realtyItem = new RealtyItem();
         if ($imgFolderNum == '-') {
             $realtyItem->status = 0;
         }
         // Направление недвижимости и тип
         $realtyItem->category_id = $categoryId;
         $realtyItem->type_id = $typeId;
         $realtyItem->attachEavSet($type->eav_set_id);
         $realtyItem->sort = $itemsCounter;
         $realtyItem->xls_id = $num;
         // Тип сделки
         $realtyItem->contract = $contract;
         // Район
         $district = trim($fields[4]);
         /*
                     $districtVariant = EavVariant::model()->find([
            'condition' => 't.attribute_id = :attribute_id AND LOWER(t.title) LIKE :title',
            'params' => [':attribute_id' => 10, ':title' => mb_strtolower($district)]
                     ]);
         */
         if ($district != '') {
             $district = $district == 'З' ? 'Запад' : $district;
             $districtVariant = EavVariant::model()->findByAttributes(['attribute_id' => 10, 'title' => $district]);
             $realtyItem->district = $districtVariant !== null ? $districtVariant->id : null;
         }
         // Метро
         $metro = trim($fields[5]);
         if ($metro != '') {
             $metro = mb_substr($metro, 2, mb_strlen($metro, 'utf-8') - 1, 'utf-8');
             $metro = trim($metro);
             $metroVariant = EavVariant::model()->findByAttributes(['attribute_id' => 28, 'title' => $metro]);
             if ($metroVariant !== null) {
                 $metroList = [$metroVariant->id];
             } else {
                 $criteria = new CDbCriteria();
                 $criteria->condition = 'attribute_id = :attribute_id AND title LIKE :title';
                 $criteria->params = [':attribute_id' => 28, ':title' => $metro . ' (%'];
                 $metroVariants = EavVariant::model()->findAll($criteria);
                 $metroList = [];
                 foreach ($metroVariants as $m) {
                     $metroList[] = $m->id;
                 }
             }
             $realtyItem->metro = $metroList;
         }
         // Адрес
         $realtyItem->name = trim($fields[6]);
         $realtyItem->address = trim($fields[6]);
         $realtyItem->itemAddress = 'Москва, ' . $realtyItem->address;
         // Жилой комплекс
         $realtyItem->residential_complex = trim($fields[7]);
         // Общая площадь
         $realtyItem->total_area = str_replace(',', '.', trim($fields[8]));
         // Этаж
         $storey = trim($fields[9]);
         $storey = preg_replace('~[^\\d\\-]+~', '', $storey);
         $realtyItem->storey = explode('-', trim($storey));
         // Этажность
         $storeysNum = preg_replace('~[^\\d]+~', '', $fields[10]);
         $realtyItem->storeys_number = trim($storeysNum);
         // Цена
         $realtyItem->price_per_sq_m = (double) preg_replace('~[^\\d]+~', '', $fields[11]);
         $realtyItem->price = (double) preg_replace('~[^\\d]+~', '', $fields[12]);
         $currency = preg_replace('~[\\d ]+~', '', $fields[11]);
         $realtyItem->currency_id = key_exists($currency, $currencies) ? $currencies[$currency] : reset($currencies);
         // Пентхаус
         $realtyItem->penthouse = trim($fields[13]) != '' ? 1 : 0;
         // Кол-во комнат
         $realtyItem->rooms_number = (int) trim($fields[14]);
         // Отделка
         $realtyItem->decoration = trim($fields[15]) != '' ? 1 : 0;
         // Паркинг
         $parkingPlacesNum = trim($fields[16]) != '' ? (int) $fields[16] : 0;
         $realtyItem->parking_places_num = $parkingPlacesNum;
         $realtyItem->parking = $parkingPlacesNum > 0 ? 1 : 0;
         // Описание
         $realtyItem->full_text = trim($fields[17], '"');
         // Изображения
         if ($imgFolderNum != '') {
             $imagesPath = $parsePath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $imgFolderNum;
             if (file_exists($imagesPath)) {
                 $realtyItem->gallery_xls_id = $imgFolderNum;
                 if (key_exists($imgFolderNum, $galleriesList)) {
                     $realtyItem->gallery_id = $galleriesList[$imgFolderNum];
                 }
             }
         }
         $realtyItems[] = $realtyItem;
         /*
                     var_dump($realtyItem->lotnum);
                     var_dump($realtyItem->district);
                     echo '<hr>';
         *
         */
     }
     echo 'Объектов: ' . count($realtyItems) . '<br />';
     echo '<hr>';
     //exit();
     // Сохраняем объекты и изображения в БД
     foreach ($realtyItems as $realtyItem) {
         //logParse($realtyItem->title);
         if ($realtyItem->saveWithEavAttributes()) {
             // Сохраняем номер лота
             $realtyItem->lotnum = implode('', [$realtyItem->category->id, $realtyItem->id]);
             $realtyItem->update(['lotnum']);
             //logParse('success');
         } else {
             //logParse('error');
             echo $realtyItem->title . ' - error<br />';
             var_dump($realtyItem->getErrors());
         }
     }
     $end = getmicrotime();
     $time = $end - $begin;
     echo "Время выполнения скрипта: " . $time . "с.";
     //logParse("Время выполнения скрипта: " . $time . "с.");
     echo '<hr>';
 }
Exemplo n.º 7
0
<?php

$this->widget('yupe\\widgets\\BackendGridView', ['id' => 'type-grid', 'type' => 'condensed', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => [['name' => 'category_id', 'type' => 'raw', 'value' => '$data->categoryTitle', 'filter' => RealtyCategory::model()->categoryList], ['class' => 'yupe.widgets.columns.CustomEditableColumn', 'name' => 'title'], ['class' => 'yupe.widgets.columns.CustomEditableColumn', 'name' => 'alias'], ['class' => 'yupe.widgets.columns.CustomEditableColumn', 'name' => 'icon'], ['name' => 'sort', 'class' => 'yupe.widgets.columns.CustomEditableColumn', 'htmlOptions' => ['style' => 'width:80px'], 'editable' => ['success' => 'js: function(response, newValue) {
                        $.fn.yiiGridView.update("category-grid");
                    }']], ['class' => 'yupe\\widgets\\columns\\EditableStatusColumn', 'name' => 'status', 'source' => $model->getStatusList(), 'options' => [RealtyCategory::STATUS_PUBLISHED => ['class' => 'label-success'], RealtyCategory::STATUS_DRAFT => ['class' => 'label-default']]], ['class' => 'yupe\\widgets\\columns\\CustomButtonColumn', 'template' => '{front_view} {update} {delete}']]]);
Exemplo n.º 8
0
        <?php 
echo $form->checkBoxGroup($model, 'is_special');
?>
    </div>
    <div class="col-sm-2">
        <label></label>
        <?php 
echo $form->checkBoxGroup($model, 'show_price');
?>
    </div>
</div>

<div class="row">
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'category_id', ['widgetOptions' => ['data' => RealtyCategory::model()->categoryList, 'htmlOptions' => ['empty' => Yii::t('RealtyModule.realty', '--choose--'), 'ajax' => ['type' => 'POST', 'url' => $this->createUrl('/realty/realtyItemBackend/dynamicType', !$model->isNewRecord ? ['id' => $model->id] : []), 'update' => $typeId, 'beforeSend' => "function () {\n                                \$('" . $typeId . "').attr('disabled', true);\n                                if (\$('" . $categoryId . " option:selected').val() == '')\n                                    return false;\n                            }", 'complete' => "function () {\n                                \$('" . $typeId . "').attr('disabled', false);\n                            }"]]]]);
?>
    </div>
    <div class="col-sm-3">
        <?php 
echo $form->dropDownListGroup($model, 'type_id', ['widgetOptions' => ['data' => $model->getCategoryTypeList(), 'htmlOptions' => ['disabled' => $model->category_id ? false : true, 'empty' => Yii::t('RealtyModule.realty', '--choose--')]]]);
?>
    </div>
    <div class="col-sm-2">
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <?php 
echo $form->dropDownListGroup($model, 'currency_id', ['widgetOptions' => ['data' => Currency::model()->currencyList, 'htmlOptions' => ['empty' => Yii::t('RealtyModule.realty', '--choose--')]]]);