Пример #1
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     if (!$model->active) {
         throw404();
     }
     if ($model->id == 4) {
         //User Agreement
         $field = 'body_' . Yii::app()->language;
         $model->{$field} = str_replace('{site_domain}', IdnaConvert::checkDecode(Yii::app()->getBaseUrl(true)), $model->{$field});
         $model->{$field} = str_replace('{site_title}', CHtml::encode(Yii::app()->name), $model->{$field});
     }
     $this->showSearchForm = $model->widget && $model->widget == 'apartments' ? true : false;
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('view', array('model' => $model));
     } else {
         $this->render('view', array('model' => $model));
     }
 }
Пример #2
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     $this->render('view', array('model' => $model));
 }
Пример #3
0
 public function actionView($id = 0, $url = '')
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'sorter';
     $criteria->condition = 'active=1';
     $articles = Article::model()->cache(param('cachingTime', 1209600), Article::getCacheDependency())->findAll($criteria);
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $this->render('view', array('model' => $this->loadModel($id), 'articles' => $articles));
 }
Пример #4
0
 public function actionView($id = 0, $url = '')
 {
     //		if(Yii::app()->user->getState('isAdmin')){
     //			$this->redirect(array('backend/main/view', 'id' => $id));
     //		}
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     $this->render('view', array('model' => $model));
 }
Пример #5
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     if (!$model->active) {
         throw404();
     }
     if (isset($_GET['is_ajax'])) {
         $this->renderPartial('view', array('model' => $model));
     } else {
         $this->render('view', array('model' => $model));
     }
 }
Пример #6
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id);
     if ($model) {
         if (Yii::app()->request->getParam('is_ajax')) {
             $this->renderPartial('view', array('model' => $model), false, true);
         } else {
             $this->render('view', array('model' => $model));
         }
     } else {
         Yii::app()->user->setFlash('error', tc('Page not found.'));
         $this->redirect(array('/site/index'));
     }
 }
Пример #7
0
 public function actionView($id = 0, $url = '', $printable = 0)
 {
     // если админ - делаем редирект на просмотр в админку
     //		if(Yii::app()->user->getState('isAdmin')){
     //			$this->redirect(array('backend/main/view', 'id' => $id));
     //		}
     $apartment = NULL;
     if (($id || $url) && issetModule('seo')) {
         $url = $url ? $url : $id;
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if ($seo) {
             $this->setSeo($seo);
             $id = $seo->model_id;
         }
     }
     if ($id) {
         $apartment = Apartment::model()->with(array('windowTo', 'objType', 'city'))->findByPk($id);
     }
     if (!$apartment) {
         throw404();
     }
     if (!in_array($apartment->type, Apartment::availableApTypesIds())) {
         throw404();
     }
     // "Толстый" запрос из-за JOIN'ов. Кешируем его.
     // Зависимость кеша - выбираем дату последней модификации из 4 таблиц
     //		$apartment = Apartment::model()
     //			->cache(param('cachingTime', 1209600), Apartment::getFullDependency($id))
     //			->with('windowTo', 'comments', 'images', 'objType', 'city')
     //			->findByPk($id);
     //
     //        if (!$apartment)
     //            throw404();
     if ($apartment->owner_id != 1 && $apartment->owner_active == Apartment::STATUS_INACTIVE) {
         if (!(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id) && !Yii::app()->user->getState('isAdmin')) {
             Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
             throw404();
         }
     }
     if (($apartment->active == Apartment::STATUS_INACTIVE || $apartment->active == Apartment::STATUS_MODERATION) && !Yii::app()->user->getState('isAdmin') && !(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id)) {
         Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
         //$this->redirect(Yii::app()->homeUrl);
         throw404();
     }
     if ($apartment->active == Apartment::STATUS_MODERATION && $apartment->owner_active == Apartment::STATUS_ACTIVE && $apartment->owner_id == Yii::app()->user->id) {
         Yii::app()->user->setFlash('error', tc('Awaiting moderation'));
     }
     $dateFree = CDateTimeParser::parse($apartment->is_free_to, 'yyyy-MM-dd');
     if ($dateFree && $dateFree < time() - 60 * 60 * 24) {
         $apartment->is_special_offer = 0;
         $apartment->update(array('is_special_offer'));
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $ipAddress = Yii::app()->request->userHostAddress;
         $userAgent = Yii::app()->request->userAgent;
         Apartment::setApartmentVisitCount($apartment, $ipAddress, $userAgent);
     }
     if ($printable) {
         $this->layout = '//layouts/print';
         $this->render('view_print', array('model' => $apartment));
     } else {
         Apartment::model()->setLastVisitedObjectsCookies($apartment->id);
         $this->render('view', array('model' => $apartment, 'statistics' => Apartment::getApartmentVisitCount($apartment)));
     }
 }
Пример #8
0
 public function actionView($id = 0, $url = '', $printable = 0)
 {
     //$this->showSearchForm = false;
     $this->htmlPageId = 'viewlisting';
     $apartment = NULL;
     $seo = NULL;
     if (($id || $url) && issetModule('seo')) {
         $url = $url ? $url : $id;
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if ($seo) {
             $this->setSeo($seo);
             $id = $seo->model_id;
         }
     }
     if ($id) {
         $apartment = Apartment::model()->with(array('windowTo', 'objType', 'city'))->findByPk($id);
         // избавляемся от дублей
         $apartmentUrl = $apartment->getUrl(false);
         if (!$printable && issetModule('seo') && $apartment->seo && Yii::app()->request->url != $apartmentUrl) {
             $this->redirect($apartmentUrl, true, 301);
         }
     }
     if (!$apartment) {
         throw404();
     }
     if (!in_array($apartment->type, Apartment::availableApTypesIds()) || !in_array($apartment->price_type, array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true)))) {
         throw404();
     }
     if ($apartment->owner_id != 1 && $apartment->owner_active == Apartment::STATUS_INACTIVE) {
         if (!(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id) && !Yii::app()->user->checkAccess('backend_access')) {
             Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
             throw404();
         }
     }
     if (($apartment->active == Apartment::STATUS_INACTIVE || $apartment->active == Apartment::STATUS_MODERATION) && !Yii::app()->user->checkAccess('backend_access') && !(isset(Yii::app()->user->id) && Yii::app()->user->id == $apartment->owner_id)) {
         Yii::app()->user->setFlash('notice', tt('apartments_main_index_propertyNotAvailable', 'apartments'));
         //$this->redirect(Yii::app()->homeUrl);
         throw404();
     }
     if ($apartment->active == Apartment::STATUS_MODERATION && $apartment->owner_active == Apartment::STATUS_ACTIVE && $apartment->owner_id == Yii::app()->user->id) {
         Yii::app()->user->setFlash('error', tc('Awaiting moderation'));
     }
     if ($apartment->deleted) {
         Yii::app()->user->setFlash('error', tt('Listing is deleted', 'apartments'));
     }
     $dateFree = CDateTimeParser::parse($apartment->is_free_to, 'yyyy-MM-dd');
     if ($dateFree && $dateFree < time() - 60 * 60 * 24) {
         $apartment->is_special_offer = 0;
         $apartment->update(array('is_special_offer'));
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $ipAddress = Yii::app()->request->userHostAddress;
         $userAgent = Yii::app()->request->userAgent;
         Apartment::setApartmentVisitCount($apartment, $ipAddress, $userAgent);
     }
     $lastNews = News::getLastNews();
     $lastArticles = Article::getLastArticles();
     #######################################################################
     # для соц. кнопок
     if ($apartment->getStrByLang("title")) {
         Yii::app()->clientScript->registerMetaTag($apartment->getStrByLang("title"), null, null, array('property' => 'og:title'));
     }
     if ($apartment->getStrByLang("description")) {
         Yii::app()->clientScript->registerMetaTag($apartment->getStrByLang("description"), null, null, array('property' => 'og:description'));
     }
     Yii::app()->clientScript->registerMetaTag($apartment->getUrl(), null, null, array('property' => 'og:url'));
     if (Yii::app()->theme->name == 'atlas') {
         $res = Images::getMainThumb(640, 400, $apartment->images);
     } else {
         $res = Images::getMainThumb(300, 200, $apartment->images);
     }
     if (isset($res['thumbUrl']) && $res['thumbUrl']) {
         Yii::app()->clientScript->registerMetaTag($res['thumbUrl'], null, null, array('property' => 'og:image'));
         Yii::app()->clientScript->registerLinkTag('image_src', null, $res['thumbUrl']);
     }
     #######################################################################
     if ($printable) {
         $this->layout = '//layouts/print';
         $this->render('view_print', array('model' => $apartment));
     } else {
         $this->render('view', array('model' => $apartment, 'statistics' => Apartment::getApartmentVisitCount($apartment), 'lastNews' => $lastNews, 'lastArticles' => $lastArticles));
     }
 }