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))); }
public static function getActiveCity() { if (self::$_activeCity === null) { $ownerActiveCond = ''; if (param('useUserads')) { $ownerActiveCond = ' AND ap.owner_active = ' . Apartment::STATUS_ACTIVE . ' '; } $sql = 'SELECT ac.name_' . Yii::app()->language . ' AS name, ac.id AS id FROM {{apartment}} ap, {{apartment_city}} ac WHERE ac.id = ap.city_id AND ap.price_type IN (' . implode(',', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))) . ') AND ap.active = ' . Apartment::STATUS_ACTIVE . ' ' . $ownerActiveCond . ' ORDER BY ac.sorter'; $results = Yii::app()->db->createCommand($sql)->queryAll(); self::$_activeCity = CHtml::listData($results, 'id', 'name'); } return self::$_activeCity; }
public static function getApartments($limit = 10, $usePagination = 1, $all = 1, $criteria = null) { $pages = array(); Yii::app()->getModule('apartments'); if ($criteria === null) { $criteria = new CDbCriteria(); } if (!$all) { $criteria->addCondition('t.deleted = 0'); $criteria->addCondition('t.active = ' . Apartment::STATUS_ACTIVE); if (param('useUserads')) { $criteria->addCondition('owner_active = ' . Apartment::STATUS_ACTIVE); } } $sort = new CSort('Apartment'); $sort->attributes = array('price' => 'price', 'date_created' => 'date_created'); if (!$criteria->order) { $sort->defaultOrder = 't.date_up_search DESC, t.sorter DESC'; } $sort->applyOrder($criteria); $sorterLinks = self::getSorterLinks($sort); $criteria->addCondition('t.owner_id = 1 OR t.owner_active = 1'); $criteria->addInCondition('t.type', Apartment::availableApTypesIds()); $criteria->addInCondition('t.price_type', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))); // find count $apCount = Apartment::model()->count($criteria); if ($usePagination) { $pages = new CPagination($apCount); $pages->pageSize = $limit; $pages->applyLimit($criteria); } else { $criteria->limit = $limit; } if (issetModule('seo')) { $criteria->with = array('seo'); } // $apartments = Apartment::model() // ->cache(param('cachingTime', 1209600), Apartment::getImagesDependency()) // ->with(array('images')) // ->findAll($criteria); return array('pages' => $pages, 'sorterLinks' => $sorterLinks, 'apCount' => $apCount, 'criteria' => $criteria); }
} if (issetModule('currency')) { // Даем вводить ценую только в дефолтной валюте echo ' ' . Currency::getDefaultCurrencyName(); $model->in_currency = Currency::getDefaultCurrencyModel()->char_code; echo $form->hiddenField($model, 'in_currency'); // $form->dropDownList($model, 'in_currency', Currency::getActiveCurrencyArray(2), array('class' => 'width120')) } else { echo ' ' . param('siteCurrency', '$'); } if ($model->type == Apartment::TYPE_RENT) { $priceArray = Apartment::getPriceArray($model->type); if (!in_array($model->price_type, array_keys($priceArray))) { $model->price_type = Apartment::PRICE_PER_MONTH; } echo ' ' . $form->dropDownList($model, 'price_type', Apartment::getPriceArray($model->type), array('class' => 'width150')); } ?> </div> <?php echo $form->error($model, 'price'); ?> </div> <div class="clear"></div> <?php $this->widget('application.modules.lang.components.langFieldWidget', array('model' => $model, 'field' => 'title', 'type' => 'string')); echo '<br/>'; if ($model->type == Apartment::TYPE_CHANGE) { echo '<div class="clear"> </div>'; $this->widget('application.modules.lang.components.langFieldWidget', array('model' => $model, 'field' => 'exchange_to', 'type' => 'text'));
public function getCountAd() { if ($this->type != User::TYPE_AGENCY) { return (int) $this->countAdRel; } $sql = "SELECT id FROM {{users}} WHERE agency_user_id = :user_id AND agent_status=:status"; $agentsId = Yii::app()->db->createCommand($sql)->queryColumn(array(':user_id' => $this->id, ':status' => User::AGENT_STATUS_CONFIRMED)); if (!$agentsId) { return (int) $this->countAdRel; } $sql = "SELECT count(id) FROM {{apartment}} WHERE active = 1 AND owner_active = 1 AND price_type IN(" . implode(',', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))) . ") AND (owner_id = :user_id OR owner_id IN (" . implode(',', $agentsId) . "))"; return (int) Yii::app()->db->createCommand($sql)->queryScalar(array(':user_id' => $this->id)); }
public function actionMainsearch($rss = null) { $countAjax = Yii::app()->request->getParam('countAjax'); $href = Yii::app()->getBaseUrl(true) . '/' . Yii::app()->request->getPathInfo(); Yii::app()->clientScript->registerLinkTag('canonical', null, $href); unset($href); if (Yii::app()->request->getParam('currency')) { setCurrency(); $this->redirect(array('mainsearch')); } $criteria = new CDbCriteria(); $criteria->addCondition('t.active = ' . Apartment::STATUS_ACTIVE); $criteria->addCondition('t.deleted = 0'); if (param('useUserads')) { $criteria->addCondition('t.owner_active = ' . Apartment::STATUS_ACTIVE); } $criteria->addInCondition('t.type', Apartment::availableApTypesIds()); $criteria->addInCondition('t.price_type', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))); $this->sApId = (int) Yii::app()->request->getParam('sApId'); if ($this->sApId) { $criteria->addCondition('id = :sApId'); $criteria->params[':sApId'] = $this->sApId; $apCount = Apartment::model()->count($criteria); if ($countAjax && Yii::app()->request->isAjaxRequest) { $this->echoAjaxCount($apCount); } if ($apCount) { $apartmentModel = Apartment::model()->findByPk($this->sApId); Yii::app()->controller->redirect($apartmentModel->getUrl()); Yii::app()->end(); } } // rooms if (issetModule('selecttoslider') && param('useRoomSlider') == 1) { $roomsMin = Yii::app()->request->getParam('room_min'); $roomsMax = Yii::app()->request->getParam('room_max'); if ($roomsMin || $roomsMax) { $criteria->addCondition('num_of_rooms >= :roomsMin AND num_of_rooms <= :roomsMax'); $criteria->params[':roomsMin'] = $roomsMin; $criteria->params[':roomsMax'] = $roomsMax; $this->roomsCountMin = $roomsMin; $this->roomsCountMax = $roomsMax; } } else { $rooms = Yii::app()->request->getParam('rooms'); if ($rooms) { if ($rooms == 4) { $criteria->addCondition('num_of_rooms >= :rooms'); } else { $criteria->addCondition('num_of_rooms = :rooms'); } $criteria->params[':rooms'] = $rooms; $this->roomsCount = $rooms; } } $this->bStart = Yii::app()->request->getParam('b_start'); $this->bEnd = Yii::app()->request->getParam('b_end'); if ($this->bStart) { $dateStart = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($this->bStart, Booking::getYiiDateFormat())); if ($this->bEnd) { $dateEnd = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($this->bEnd, Booking::getYiiDateFormat())); } else { $dateEnd = $dateStart; } if ($dateStart && $dateEnd) { $criteria->addCondition('t.id NOT IN ( SELECT DISTINCT b.apartment_id FROM {{booking_calendar}} AS b WHERE b.date_start BETWEEN :b_start AND :b_end OR :b_start BETWEEN b.date_start AND b.date_end )'); $criteria->params['b_start'] = $dateStart; $criteria->params['b_end'] = $dateEnd; } } // floor if (issetModule('selecttoslider') && param('useFloorSlider') == 1) { $floorMin = Yii::app()->request->getParam('floor_min'); $floorMax = Yii::app()->request->getParam('floor_max'); if ($floorMin || $floorMax) { $criteria->addCondition('floor >= :floorMin AND floor <= :floorMax'); $criteria->params[':floorMin'] = $floorMin; $criteria->params[':floorMax'] = $floorMax; $this->floorCountMin = $floorMin; $this->floorCountMax = $floorMax; } } else { $floor = Yii::app()->request->getParam('floor'); if ($floor) { $criteria->addCondition('floor = :floor'); $criteria->params[':floor'] = $floor; $this->floorCount = $floor; } } // square if (issetModule('selecttoslider') && param('useSquareSlider') == 1) { $squareMin = Yii::app()->request->getParam('square_min'); $squareMax = Yii::app()->request->getParam('square_max'); if ($squareMin || $squareMax) { $criteria->addCondition('square >= :squareMin AND square <= :squareMax'); $criteria->params[':squareMin'] = $squareMin; $criteria->params[':squareMax'] = $squareMax; $this->squareCountMin = $squareMin; $this->squareCountMax = $squareMax; } } else { $square = Yii::app()->request->getParam('square'); if ($square) { $criteria->addCondition('square <= :square'); $criteria->params[':square'] = $square; $this->squareCount = $square; } } $landSquare = Yii::app()->request->getParam('land_square'); if ($landSquare) { $criteria->addCondition('land_square <= :land_square'); $criteria->params[':land_square'] = $landSquare; $this->landSquare = $landSquare; } $ci_Square = Yii::app()->request->getParam('ci_square'); if ($ci_Square) { $criteria->addCondition('ci_square <= :ci_square'); $criteria->params[':ci_square'] = $ci_Square; $this->ci_Square = $ci_Square; } $this->selectedCity = Yii::app()->request->getParam('city', array()); if (isset($this->selectedCity[0]) && $this->selectedCity[0] == 0) { $this->selectedCity = array(); } $this->wp = Yii::app()->request->getParam('wp'); if ($this->wp) { $criteria->addCondition('count_img > 0'); } $this->ot = Yii::app()->request->getParam('ot'); if ($this->ot) { $criteria->join = 'INNER JOIN {{users}} AS u ON u.id = t.owner_id'; if ($this->ot == User::TYPE_PRIVATE_PERSON) { $ownerTypes = array(User::TYPE_PRIVATE_PERSON, User::TYPE_ADMIN); } if ($this->ot == User::TYPE_AGENCY) { $ownerTypes = array(User::TYPE_AGENT, User::TYPE_AGENCY); } if (isset($ownerTypes) && $ownerTypes) { $criteria->compare('u.type', $ownerTypes); } } if (issetModule('location')) { $country = Yii::app()->request->getParam('country'); if ($country) { $this->selectedCountry = $country; $criteria->compare('loc_country', $country); } $region = Yii::app()->request->getParam('region'); if ($region) { $this->selectedRegion = $region; $criteria->compare('loc_region', $region); } if ($this->selectedCity) { $criteria->compare('t.loc_city', $this->selectedCity); } } else { if ($this->selectedCity) { $criteria->compare('t.city_id', $this->selectedCity); } } $this->objType = Yii::app()->request->getParam('objectType'); if ($this->objType) { $criteria->compare('obj_type_id', $this->objType); } // type $this->apType = Yii::app()->request->getParam('apType'); if ($this->apType) { $criteria->addCondition('price_type = :apType'); $criteria->params[':apType'] = $this->apType; } $type = Yii::app()->request->getParam('type'); if ($type) { $criteria->addCondition('type = :type'); $criteria->params[':type'] = $type; } // price if (issetModule('selecttoslider') && param('usePriceSlider') == 1) { $priceMin = Yii::app()->request->getParam("price_min"); $priceMax = Yii::app()->request->getParam("price_max"); if ($priceMin || $priceMax) { $criteria->addCondition('(price >= :priceMin AND price <= :priceMax) OR (is_price_poa = 1)'); if (issetModule('currency')) { $criteria->params[':priceMin'] = floor(Currency::convertToDefault($priceMin)); $criteria->params[':priceMax'] = ceil(Currency::convertToDefault($priceMax)); } else { $criteria->params[':priceMin'] = $priceMin; $criteria->params[':priceMax'] = $priceMax; } $this->priceSlider["min"] = $priceMin; $this->priceSlider["max"] = $priceMax; } } else { $price = Yii::app()->request->getParam('price'); if (issetModule('currency')) { $priceDefault = ceil(Currency::convertToDefault($price)); } else { $priceDefault = $price; } if ($priceDefault) { $criteria->addCondition('(price <= :price) OR (is_price_poa = 1)'); $criteria->params[':price'] = $priceDefault; $this->price = $price; } } // ключевые слова $term = Yii::app()->request->getParam('term'); $doTermSearch = Yii::app()->request->getParam('do-term-search'); if ($term && $doTermSearch == 1) { $term = utf8_substr($term, 0, 50); $term = cleanPostData($term); if ($term && utf8_strlen($term) >= $this->minLengthSearch) { $this->term = $term; $words = explode(' ', $term); foreach ($words as $key => $value) { if (mb_strlen($value, "UTF-8") < $this->minLengthSearch) { unset($words[$key]); } } if (count($words) > 1) { $cleanWords = array(); foreach ($words as $word) { if (utf8_strlen($word) >= $this->minLengthSearch) { $cleanWords[] = $word; } } $searchString = '+' . implode('* +', $cleanWords) . '* '; # https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html $sql = 'SELECT id FROM {{apartment}} WHERE MATCH (title_' . Yii::app()->language . ', description_' . Yii::app()->language . ', description_near_' . Yii::app()->language . ', address_' . Yii::app()->language . ') AGAINST ("' . $searchString . '" IN BOOLEAN MODE)'; } else { $sql = 'SELECT id FROM {{apartment}} WHERE MATCH (title_' . Yii::app()->language . ', description_' . Yii::app()->language . ', description_near_' . Yii::app()->language . ', address_' . Yii::app()->language . ') AGAINST ("*' . $term . '*" IN BOOLEAN MODE)'; } $resTerm = Yii::app()->db->createCommand($sql)->queryAll(); if (is_array($resTerm) && count($resTerm) > 0) { $resTerm = CHtml::listData($resTerm, 'id', 'relevance'); $criteria->addInCondition('t.id', array_keys($resTerm)); } else { $criteria->addInCondition('t.id', array(0)); # ничего не найдено } } } // поиск объявлений владельца $this->userListingId = Yii::app()->request->getParam('userListingId'); if ($this->userListingId) { $criteria->addCondition('owner_id = :userListingId'); $criteria->params[':userListingId'] = $this->userListingId; } $filterName = null; // Поиск по справочникам - клик в просмотре профиля анкеты if (param('useReferenceLinkInView')) { if (Yii::app()->request->getQuery('serviceId', false)) { $serviceId = Yii::app()->request->getQuery('serviceId', false); if ($serviceId) { $serviceIdArray = explode('-', $serviceId); if (is_array($serviceIdArray) && count($serviceIdArray) > 0) { $value = (int) $serviceIdArray[0]; $sql = 'SELECT DISTINCT apartment_id FROM {{apartment_reference}} WHERE reference_value_id = ' . $value; $apartmentIds = Yii::app()->db->cache(param('cachingTime', 1209600), Apartment::getDependency())->createCommand($sql)->queryColumn(); //$apartmentIds = Yii::app()->db->createCommand($sql)->queryColumn(); $criteria->addInCondition('t.id', $apartmentIds); Yii::app()->getModule('referencevalues'); $sql = 'SELECT title_' . Yii::app()->language . ' FROM {{apartment_reference_values}} WHERE id = ' . $value; $filterName = Yii::app()->db->cache(param('cachingTime', 1209600), ReferenceValues::getDependency())->createCommand($sql)->queryScalar(); if ($filterName) { $filterName = CHtml::encode($filterName); } } } } } if (issetModule('formeditor')) { $newFieldsAll = FormDesigner::getNewFields(); foreach ($newFieldsAll as $field) { $value = CHtml::encode(Yii::app()->request->getParam($field->field)); if (!$value) { continue; } $fieldString = $field->field; $this->newFields[$fieldString] = $value; switch ($field->compare_type) { case FormDesigner::COMPARE_EQUAL: $criteria->compare($fieldString, $value); break; case FormDesigner::COMPARE_LIKE: $criteria->compare($fieldString, $value, true); break; case FormDesigner::COMPARE_FROM: $value = intval($value); $criteria->compare($fieldString, ">={$value}"); break; case FormDesigner::COMPARE_TO: $value = intval($value); $criteria->compare($fieldString, "<={$value}"); break; } } } if ($rss && issetModule('rss')) { $this->widget('application.modules.rss.components.RssWidget', array('criteria' => $criteria)); } // find count $apCount = Apartment::model()->count($criteria); if ($countAjax && Yii::app()->request->isAjaxRequest) { $this->echoAjaxCount($apCount); } $searchParams = $_GET; if (isset($searchParams['is_ajax'])) { unset($searchParams['is_ajax']); } Yii::app()->user->setState('searchUrl', Yii::app()->createUrl('/search', $searchParams)); unset($searchParams); if (Yii::app()->request->isAjaxRequest) { // $modeListShow = User::getModeListShow(); // if ($modeListShow == 'table') { // # нужны скрипты и стили, поэтому processOutput установлен в true только для table // $this->renderPartial('index', array( // 'criteria' => $criteria, // 'apCount' => $apCount, // 'filterName' => $filterName, // ), false, true); // } // else { $this->renderPartial('index', array('criteria' => $criteria, 'apCount' => $apCount, 'filterName' => $filterName)); // } } else { $this->render('index', array('criteria' => $criteria, 'apCount' => $apCount, 'filterName' => $filterName)); } }
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)); } }
public static function getCountUserObjects($userId) { if (!$userId) { $userId = Yii::app()->user->id; } $sql = 'SELECT COUNT(id) FROM {{apartment}} WHERE owner_id = ' . $userId . ' AND active <> ' . Apartment::STATUS_DRAFT . ' AND owner_active = ' . Apartment::STATUS_ACTIVE . ' AND price_type IN(' . implode(",", array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))) . ')'; $result = Yii::app()->db->createCommand($sql)->queryScalar(); return $result; }
public static function getDataForListings($userId) { $criteria = new CDbCriteria(); $criteria->addCondition('active = ' . Apartment::STATUS_ACTIVE); if (param('useUserads')) { $criteria->addCondition('owner_active = ' . Apartment::STATUS_ACTIVE); } $criteria->addInCondition('type', Apartment::availableApTypesIds()); $criteria->addInCondition('price_type', array_keys(Apartment::getPriceArray(Apartment::PRICE_SALE, true))); $userModel = User::model()->findByPk($userId); $userName = $userModel->getNameForType(); if ($userModel->type == User::TYPE_AGENCY) { $userName = $userModel->getTypeName() . ' "' . $userName . '"'; $sql = "SELECT id FROM {{users}} WHERE agency_user_id = :user_id AND agent_status=:status"; $agentsId = Yii::app()->db->createCommand($sql)->queryColumn(array(':user_id' => $userId, ':status' => User::AGENT_STATUS_CONFIRMED)); $agentsId[] = $userId; $criteria->compare('owner_id', $agentsId, false); } else { $criteria->compare('owner_id', $userId); } return array('criteria' => $criteria, 'userName' => $userName); }