Skip to content

Commit

Permalink
added switching location
Browse files Browse the repository at this point in the history
  • Loading branch information
anikeevda committed Nov 14, 2017
1 parent 1ad1498 commit eaad73c
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 600 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ domstor_template:
builder:
org_id: 13 #Идентификатор вашей организации в системе Домстор
location_id: 2004 #Идентификатор города в системе Домстор. 2004 - Кемерово, 2006 - Новокузнецк, 2236 - Новосибирск
cache_dir: '%kernel.cache_dir%' #Директория, где хранится кэш объектов
cache_type: 'file' #Тип кэширования. Поддерживаются: file, apc, array, xcache, memcache
cache_time: 86400 #Время жизни кэша
filter_template_dir: '%kernel.root_dir%/../src/AppBundle/Resources/views/Filters'
cache:
type: 'file' #Тип кэширования. Поддерживаются: file, apc, array, xcache, memcache
time: 86400 #Время жизни кэша
uniq_key: '13' #Уникальный ключ хэша
options:
directory: '%kernel.cache_dir%' #Директория, где хранится кэш объектов
filter:
template_dir: '%kernel.root_dir%/../src/AppBundle/Resources/views/Filters'
links: #Список населенных пунктов для поиска недвижимости
2004: 'Недвижимость в Кемерово'
43: 'Недвижимость в Кемеровской области'
mailer:
request:
service: 'default' #mailer-сервис, через который будут отправляться сообщения о поступлении новых заявок
Expand Down
15 changes: 11 additions & 4 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ domstor_template:
builder:
org_id: 13
location_id: 2004
cache_dir: '%kernel.cache_dir%'
cache_type: 'file'
cache_time: 86400
filter_template_dir: '%kernel.root_dir%/../src/AppBundle/Resources/views/Filters'
cache:
type: 'file'
time: 86400
uniq_key: '13'
options:
directory: '%kernel.cache_dir%'
filter:
template_dir: '%kernel.root_dir%/../src/AppBundle/Resources/views/Filters'
links:
2004: 'Недвижимость в Кемерово'
43: 'Недвижимость в Кемеровской области'
mailer:
request:
service: 'default'
Expand Down
1 change: 1 addition & 0 deletions app/config/sonata/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ sonata_block:
domstor.template.block.home.vacancy.service: ~
domstor.template.block.realtyicons.service: ~
domstor.template.block.domstor_filter.service: ~
domstor.template.block.switch_location.service: ~

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": ">=7.1",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"domstor-project/template-bundle": "^1.6",
"domstor-project/template-bundle": "1.7.*",
"incenteev/composer-parameter-handler": "^2.0",
"leafo/scssphp": "^0.6",
"patchwork/jsqueeze": "^2.0",
Expand Down
52 changes: 34 additions & 18 deletions src/AppBundle/Controller/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,41 @@
use Domstor\TemplateBundle\Model\TitleProviderInterface;
use Domstor_Builder;
use Domstor_Domstor;
use Symfony\Component\Config\FileLocatorInterface;

/**
* @Route("/objects")
*/
class ObjectsController extends Controller
{
/**
* @Route("/{object}/{action}/{id}")
* @param int $location
* @param string $object
* @param string $action
* @param string $id
* @param Request $request
* @Route("/{location}/{object}/{action}/{id}")
* @Template()
* @return array
*/
public function detailAction($object, $action, $id) {
/* @var $locator \Symfony\Component\Config\FileLocatorInterface */
public function detailAction($location, $object, $action, $id, Request $request) {
/* @var $locator FileLocatorInterface */
$locator = $this->container->get('file_locator');
/* @var $builder Domstor_Builder */
$builder = $this->get('domstor.template.domstorlib.domstor_builder');
$baseParams = $this->getParameter('domstor.template.domstorlib.domstor_parameters');
$domstor = $builder->build(array(
'org_id' => $baseParams['org_id'],
'location_id' => $baseParams['location_id'],
'location_id' => $location,
'cache' => array(
'type' => $baseParams['cache_type'],
'time' => $baseParams['cache_time'],
'uniq_key' => (string)$baseParams['org_id'],
'options' => array('directory' => $locator->locate($baseParams['cache_dir'])),
'type' => $baseParams['cache']['type'],
'time' => $baseParams['cache']['time'],
'uniq_key' => $baseParams['cache']['uniq_key'],
'options' => array('directory' => $locator->locate($baseParams['cache']['options']['directory'])),
),
'href_templates' => array(
'object' => $this->generateUrl('app_objects_detail', array(
'location'=> $location,
'object' => $object,
'action' => $action,
'id' => '-id',
Expand All @@ -44,7 +52,7 @@ public function detailAction($object, $action, $id) {
'object' => $object,
'action' => $action,
)).'?page=%page%sort%filter',

),
'href_placeholders' => array(
'id' => '-id',
Expand All @@ -60,39 +68,46 @@ public function detailAction($object, $action, $id) {
}
/* @var $titleProvider TitleProviderInterface */
$titleProvider = $this->get('domstor.template.provider.title');
return array(
return [
'detail' => $detail,
'object' => $object,
'action' => $action,
'list_url' => $domstor->getListLink($object, $action),
'list_title' => $titleProvider->getListTitle($object, $action, $domstor->getLocationName('pr')),
);
'list_title' => $titleProvider->getListTitle($object, $action, $domstor->getLocationName('pr'))
];
}

/**
* @param string $object
* @param string $action
* @param Request $request
* @Route("/{object}/{action}")
* @Template()
* @return array
*/
public function listAction($object, $action, Request $request) {
$locationFromCookie = $request->cookies->get('location_id',null);
/* @var $locator \Symfony\Component\Config\FileLocatorInterface */
$locator = $this->container->get('file_locator');
/* @var $builder Domstor_Builder */
$builder = $this->get('domstor.template.domstorlib.domstor_builder');
$baseParams = $this->getParameter('domstor.template.domstorlib.domstor_parameters');
$locationId = is_numeric($locationFromCookie) ? (int)$locationFromCookie : $baseParams['location_id'];
$domstor = $builder->build(array(
'org_id' => $baseParams['org_id'],
'location_id' => $baseParams['location_id'],
'location_id' => $locationId,
'cache' => array(
'type' => $baseParams['cache_type'],
'time' => $baseParams['cache_time'],
'uniq_key' => (string)$baseParams['org_id'],
'options' => array('directory' => $locator->locate($baseParams['cache_dir'])),
'type' => $baseParams['cache']['type'],
'time' => $baseParams['cache']['time'],
'uniq_key' => $baseParams['cache']['uniq_key'],
'options' => array('directory' => $locator->locate($baseParams['cache']['options']['directory'])),
),
'filter' => array(
'template_dir' => $locator->locate($baseParams['filter_template_dir']),
'template_dir' => $locator->locate($baseParams['filter']['template_dir']),
),
'href_templates' => array(
'object' => $this->generateUrl('app_objects_detail', array(
'location' => $locationId,
'object' => $object,
'action' => $action,
'id' => '-id',
Expand Down Expand Up @@ -126,6 +141,7 @@ public function listAction($object, $action, Request $request) {
'list' => $list,
'locationsList' => $locationList,
'title' => $titleProvider->getListTitle($object, $action, $domstor->getLocationName('pr')),
'currentLocation'=>$locationId
];
}

Expand Down
Loading

0 comments on commit eaad73c

Please sign in to comment.