Esempio n. 1
0
 public function actionView($id = 0)
 {
     //$this->layout='//layouts/inner';
     Yii::app()->bootstrap->plugins['tooltip'] = array('selector' => ' ', 'options' => array('placement' => 'top'));
     $model = $this->loadModelWith(array('windowTo', 'objType', 'city'));
     if (!in_array($model->type, Apartment::availableApTypesIds()) || !in_array($model->price_type, array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true)))) {
         throw404();
     }
     $this->render('view', array('model' => $model, 'statistics' => Apartment::getApartmentVisitCount($model)));
 }
Esempio n. 2
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)));
     }
 }
Esempio n. 3
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));
     }
 }