public function run()
 {
     if (is_null($this->model)) {
         return;
     }
     $model = $this->model;
     // Условия выборки
     $criteria = new CDbCriteria();
     if ($this->limit > 0) {
         $criteria->limit = (int) $this->limit;
     }
     $criteria->order = 'RAND()';
     $criteria->scopes['type'] = $model->type->id;
     $criteria->compare('t.id', '<>' . $model->id);
     if ($model->category->id == RealtyCategory::ELITE_CATEGORY_ID) {
         $criteria->compare('::rooms_number::', $model->rooms_number);
         $criteria->addInCondition('::district::', $model->district);
     } elseif ($model->category->id == RealtyCategory::COUNTRY_CATEGORY_ID) {
         $criteria->addInCondition('::direction::', $model->direction);
     }
     if ($model->category->id == RealtyCategory::COMMERCIAL_CATEGORY_ID) {
         $criteria->addInCondition('::district::', $model->district);
     }
     // Выборка объектов
     $models = RealtyItem::model()->withEavAttributes(true)->active()->with(['category', 'type', 'currency'])->findAll($criteria);
     if (empty($models)) {
         return;
     }
     $this->render($this->view, ['models' => $models]);
 }
 public function actionCreate()
 {
     $model = $this->createModel();
     $modelName = get_class($model);
     $realtyItem = null;
     // Если указан объект недвижимости, для которого создается галерея изображений
     if (isset($_GET['realty_item_id'])) {
         if (($realtyItem = RealtyItem::model()->findByPk((int) $_GET['realty_item_id'])) === null) {
             throw new CHttpException(404, Yii::t('RealtyModule.realty', 'Page was not found!'));
         }
         $model->title = $realtyItem->name;
     }
     if (isset($_POST[$modelName])) {
         $model->attributes = $_POST[$modelName];
         if ($model->save()) {
             // Привязка галереи к объекту недвижимости
             if (!is_null($realtyItem)) {
                 $realtyItem->gallery_id = $model->id;
                 $realtyItem->update(['gallery_id']);
             }
             // Редирект на страницу управления изображениями галереи
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, 'Галерея создана!');
             $this->redirect(['/realty/realtyGalleryImageBackend/index/', 'item_id' => $model->id]);
         }
     }
     $this->render('create', ['model' => $model]);
 }
 public function actionIndex()
 {
     $dirPath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . Yii::app()->getModule('realty')->uploadPath . DIRECTORY_SEPARATOR . 'cian';
     $realtyTypes = ['flats_for_sale' => ['criteria' => ['order' => 't.sort ASC', 'condition' => 't.type_id IN (1,2)'], 'generator' => 'realty\\components\\cian\\FlatsForSaleCianXMLGenerator'], 'flats_rent' => ['criteria' => ['order' => 't.sort ASC', 'condition' => 't.type_id = 2'], 'generator' => 'realty\\components\\cian\\FlatsRentCianXMLGenerator']];
     // Просматриваем все категории
     foreach ($realtyTypes as $key => &$type) {
         $cianXMLGeneragor = new $type['generator']($dirPath);
         $models = RealtyItem::model()->withEavAttributes(true)->active()->with(['category', 'type', 'currency'])->findAll($type['criteria']);
         if (empty($models)) {
             continue;
         }
         foreach ($models as $model) {
             $cianXMLGeneragor->addItem($model);
         }
         $cianXMLGeneragor->write();
     }
 }
 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]);
 }
 public function run()
 {
     if ($this->title === false) {
         $this->title = Yii::t('RealtyModule.realty', 'Special offers');
     }
     $criteria = new CDbCriteria();
     $criteria->order = 't.update_time DESC';
     if ($this->limit > 0) {
         $criteria->limit = (int) $this->limit;
     }
     if (!is_null($this->category)) {
         $criteria->scopes['category'] = $this->category->id;
     }
     if (!is_null($this->type)) {
         $criteria->scopes['type'] = $this->type->id;
     }
     $models = RealtyItem::model()->withEavAttributes(true)->active()->specialOffer()->with(['category', 'type', 'currency'])->findAll($criteria);
     if (empty($models)) {
         return;
     }
     $this->render($this->view, ['models' => $models, 'title' => $this->title, 'category' => $this->category, 'type' => $this->type]);
 }
예제 #6
0
 /**
  * Action для получения описаний объектов, входящих в кластер, на карте
  *
  * @param string $id
  * @throws CHttpException
  */
 public function actionGetClusterDescription()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         throw new CHttpException(403, 'Invalid request');
     }
     $ids = explode(',', Yii::app()->getRequest()->getParam('ids', ''));
     if (empty($ids)) {
         Yii::app()->ajax->rawText('');
     }
     array_walk($ids, function ($item) {
         return (int) $item;
     });
     // Находим объекты недвижимости по ID
     $criteria = new CDbCriteria();
     $criteria->addInCondition('t.id', $ids);
     $models = RealtyItem::model()->withEavAttributes(true)->active()->with(['currency', 'category', 'type'])->findAll($criteria);
     if (empty($models)) {
         Yii::app()->ajax->rawText('');
     }
     // Генерируем ответ
     $currency = Yii::app()->getRequest()->getParam('currency', $this->getModule()->defaultCurrency);
     $result = [];
     foreach ($models as $model) {
         $model->setCurrentCurrency((int) $currency);
         $result[$model->id] = $this->renderPartial('catalog/_map_short_property_box', ['data' => $model], true);
     }
     Yii::app()->ajax->raw($result);
 }
 public function actionUpdate()
 {
     exit;
     $prefix = $_GET['prefix'];
     // prepare logger to dump logs every time one comes in
     Yii::getLogger()->autoFlush = 1;
     Yii::getLogger()->autoDump = true;
     $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);
     foreach ($csvData as $key => $row) {
         //if($key >= 20)
         //    break;
         $fields = str_getcsv($row, ";", '"');
         //var_dump($fields);
         // Номер
         $num = (int) $fields[0];
         $description = trim($fields[17], '"');
         if (empty($num)) {
             continue;
         }
         /*
                     if(mb_strpos($description, ';', 0, 'utf-8') === false) {
            continue;
                     }
         * 
         */
         $realtyItem = RealtyItem::model()->findByAttributes(['xls_id' => $num]);
         if (is_null($realtyItem)) {
             continue;
         }
         echo $num . '<br />';
         $realtyItem->full_text = $description;
         /*
                     if(!$realtyItem->update(['full_text']))
                     {
            echo $realtyItem->title . ' - '. $num . ' - error<br />';
            var_dump($realtyItem->getErrors());
                     }
         *
         */
         $realtyItem->year_built = (int) $fields[18];
         $realtyItem->number_of_apartments = (int) $fields[19];
         $realtyItem->apartment_number = (int) $fields[20];
         $realtyItem->housing = trim($fields[21], '"');
         if (!$realtyItem->saveWithEavAttributes()) {
             echo $realtyItem->title . ' - ' . $num . ' - error<br />';
             var_dump($realtyItem->getErrors());
         }
         echo '<hr>';
     }
     $end = getmicrotime();
     $time = $end - $begin;
     echo "Время выполнения скрипта: " . $time . "с.";
     echo '<hr>';
 }
예제 #8
0
 public function getItemsTotalList($onlyIds = false)
 {
     if ($this->_itemsTotalList == null) {
         $criteria = $this->_searchCriteria !== null ? $this->_constructSearchCriteria(true) : new CDbCriteria();
         $this->_itemsTotalList = RealtyItem::model()->findAll($criteria);
     }
     return $onlyIds ? array_keys(CHtml::listData($this->_itemsTotalList, 'id', 'id')) : $this->_itemsTotalList;
 }
 public function loadModel($id)
 {
     if (($model = RealtyItem::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('RealtyModule.realty', 'Page was not found!'));
     }
     return $model;
 }