Skip to content

Commit

Permalink
Реализована фильтрация вывода каталога в зависимости от типа автомобиля.
Browse files Browse the repository at this point in the history
  • Loading branch information
antflk committed Mar 9, 2017
1 parent e42550a commit 2123427
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 18 deletions.
49 changes: 49 additions & 0 deletions Common/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace NS\TecDocSite\Common;

use NS\ABCPApi\Common\CarType;

/**
* Класс содержит вспомогательные функции.
*
* Class Helper
* @package NS\TecDocSite\Common
*/
class Helper
{
/**
* Содержит допустимые типы автомобилей.
*
* @var int[]
*/
public static $availableCarTypes = [
CarType::ALL,
CarType::CARS,
CarType::TRUCKS,
CarType::LIGHT_TRUCKS,
];

/**
* Возвращает тип автомобиля в зависимости от переданных GET параметров.
*
* @return int
*/
public static function getCarId()
{
return isset($_GET['carType']) && in_array($_GET['carType'],
self::$availableCarTypes) ? (int)$_GET['carType'] : 0;
}

/**
* Возвращает текст для использования в ссылка для типа автомобиля в зависимости от переданных GET параметров.
*
* @return string
*/
public static function getCarIdUrl()
{
return isset($_GET['carType']) && in_array($_GET['carType'],
self::$availableCarTypes) ? "&carType={$_GET['carType']}" : '';
}

}
11 changes: 7 additions & 4 deletions Pages/Group.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace NS\TecDocSite\Pages;

use NS\ABCPApi\RestApiClients\TecDoc;
use NS\ABCPApi\TecDocEntities\ModelVariant;
use NS\TecDocSite\Common\Helper;
use NS\TecDocSite\Common\Paginator;
use NS\TecDocSite\Common\PaginatorOptions;
use NS\TecDocSite\Common\TecDocApiConfig;
Expand Down Expand Up @@ -93,7 +95,7 @@ private static function getBreadcrumbs()
$modificationId = (int)$_GET['modelVariant'];
$selectedGroupId = (int)$_GET['group'];
$modification = $tecDocRestClient->getModificationById($modificationId);
$modelVariants = $tecDocRestClient->getModelVariant($modificationId);
$modelVariants = $tecDocRestClient->getModelVariant($modificationId, Helper::getCarId());
$modelVariant = new ModelVariant();
if (is_array($modelVariants)) {
foreach ($modelVariants as $oneModelVariant) {
Expand All @@ -103,18 +105,19 @@ private static function getBreadcrumbs()
}
}
}
$carTypeUrlText = Helper::getCarIdUrl();
$breadcrumbs = array(
array(
'name' => $modification->manufacturerName,
'url' => "?man={$modification->manufacturerId}"
'url' => "?man={$modification->manufacturerId}{$carTypeUrlText}"
),
array(
'name' => $modification->modelName,
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}"
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}{$carTypeUrlText}"
),
array(
'name' => $modification->name,
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}&modelVariant={$modification->id}"
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}&modelVariant={$modification->id}{$carTypeUrlText}"
),
array(
'name' => $modelVariant->name
Expand Down
9 changes: 6 additions & 3 deletions Pages/Index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace NS\TecDocSite\Pages;

use NS\ABCPApi\RestApiClients\TecDoc;
use NS\TecDocSite\Common\Helper;
use NS\TecDocSite\Common\TecDocApiConfig;
use NS\TecDocSite\Common\View;
use NS\TecDocSite\Interfaces\PageInterface;
Expand All @@ -26,22 +28,22 @@ public function getHtml()
->setUserKey(TecDocApiConfig::USER_KEY)
->setUserLogin(TecDocApiConfig::USER_LOGIN)
->setUserPsw(TecDocApiConfig::USER_PSW);
$carType = isset($_GET['carType']) ? $_GET['carType'] : 0;
$selectedLetter = !empty($_GET['letter']) ? $_GET['letter'] : '';
$manufacturers = $tecDocRestClient->getManufacturers($carType);
$manufacturers = $tecDocRestClient->getManufacturers(Helper::getCarId());
$manufacturersTemplateData = array();
foreach ($manufacturers as $oneManufacturer) {
$firstLetter = substr($oneManufacturer->name, 0, 1);
$manufacturersTemplateData[$firstLetter][] = $oneManufacturer;
}
$contentTemplateData = array(
'manufacturers' => $manufacturersTemplateData,
'carType' => $carType,
'carType' => Helper::getCarId(),
'breadcrumbs' => self::getBreadcrumbs(),
'selectedLetter' => $selectedLetter
);
$content = View::deploy('manufacturers.tpl', $contentTemplateData);
$templateData = array('content' => $content);

return View::deploy('index.tpl', $templateData);
}

Expand All @@ -55,6 +57,7 @@ private static function getBreadcrumbs()
$templateData = array(
'breadcrumbs' => array()
);

return View::deploy('common/breadcumbs.tpl', $templateData);
}
}
15 changes: 11 additions & 4 deletions Pages/ModelVariant.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace NS\TecDocSite\Pages;

use NS\ABCPApi\RestApiClients\TecDoc;
use NS\TecDocSite\Common\Helper;
use NS\TecDocSite\Common\TecDocApiConfig;
use NS\TecDocSite\Common\View;
use NS\TecDocSite\Interfaces\PageInterface;
Expand All @@ -27,14 +29,17 @@ public function getHtml()
->setUserLogin(TecDocApiConfig::USER_LOGIN)
->setUserPsw(TecDocApiConfig::USER_PSW);
$modificationId = $_GET['modelVariant'];
$tree = $tecDocRestClient->getModelVariant($modificationId);
$tree = $tecDocRestClient->getModelVariant($modificationId, Helper::getCarId());
$carTypeUrlText = Helper::getCarIdUrl();
$contentTemplateData = array(
'tree' => $tree,
'carType' => Helper::getCarId(),
'breadcrumbs' => self::getBreadcrumbs(),
'url' => "/?man={$_REQUEST['man']}&model={$_REQUEST['model']}&modelVariant={$_REQUEST['modelVariant']}&group="
'url' => "/?man={$_REQUEST['man']}&model={$_REQUEST['model']}&modelVariant={$_REQUEST['modelVariant']}{$carTypeUrlText}&group="
);
$content = View::deploy('tree.tpl', $contentTemplateData);
$templateData = array('content' => $content);

return View::deploy('index.tpl', $templateData);
}

Expand All @@ -52,14 +57,15 @@ private static function getBreadcrumbs()
->setUserPsw(TecDocApiConfig::USER_PSW);
$modificationId = (int)$_GET['modelVariant'];
$modification = $tecDocRestClient->getModificationById($modificationId);
$carTypeUrlText = Helper::getCarIdUrl();
$breadcrumbs = array(
array(
'name' => $modification->manufacturerName,
'url' => "?man={$modification->manufacturerId}"
'url' => "?man={$modification->manufacturerId}{$carTypeUrlText}"
),
array(
'name' => $modification->modelName,
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}"
'url' => "?man={$modification->manufacturerId}&model={$modification->modelId}{$carTypeUrlText}"
),
array(
'name' => $modification->name
Expand All @@ -68,6 +74,7 @@ private static function getBreadcrumbs()
$templateData = array(
'breadcrumbs' => $breadcrumbs
);

return View::deploy('common/breadcumbs.tpl', $templateData);
}
}
6 changes: 4 additions & 2 deletions Pages/Models.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace NS\TecDocSite\Pages;

use NS\ABCPApi\RestApiClients\TecDoc;
use NS\TecDocSite\Common\Helper;
use NS\TecDocSite\Common\TecDocApiConfig;
use NS\TecDocSite\Common\View;
use NS\TecDocSite\Interfaces\PageInterface;
Expand All @@ -27,8 +29,7 @@ public function getHtml()
->setUserLogin(TecDocApiConfig::USER_LOGIN)
->setUserPsw(TecDocApiConfig::USER_PSW);
$manufacturerId = $_GET['man'];
$dataModels = $tecDocRestClient->getModels($manufacturerId);

$dataModels = $tecDocRestClient->getModels($manufacturerId, Helper::getCarId());
$begin = 1990;
$end = (int)date('Y');
$step = 10;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function getHtml()
'breadcrumbs' => self::getBreadcrumbs(),
'selectedYear' => $selectedYear,
'yearsFilter' => $yearsFilter,
'carType' => Helper::getCarId(),
'man' => $manufacturerId
);
$templateData = array(
Expand Down
10 changes: 8 additions & 2 deletions Pages/Modifications.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

namespace NS\TecDocSite\Pages;

use NS\ABCPApi\RestApiClients\TecDoc;
use NS\TecDocSite\Common\Helper;
use NS\TecDocSite\Common\TecDocApiConfig;
use NS\TecDocSite\Common\View;
use NS\TecDocSite\Interfaces\PageInterface;
Expand All @@ -28,14 +30,16 @@ public function getHtml()
->setUserPsw(TecDocApiConfig::USER_PSW);
$manufacturerId = $_GET['man'];
$modelId = $_GET['model'];
$modifications = $tecDocRestClient->getModifications($manufacturerId, $modelId);
$modifications = $tecDocRestClient->getModifications($manufacturerId, $modelId, Helper::getCarId());
$contentTemplateData = array(
'modifications' => $modifications,
'breadcrumbs' => self::getBreadcrumbs(),
'carType' => Helper::getCarId(),
'man' => $manufacturerId
);
$content = View::deploy('modifications.tpl', $contentTemplateData);
$templateData = array('content' => $content);

return View::deploy('index.tpl', $templateData);
}

Expand All @@ -55,11 +59,12 @@ private static function getBreadcrumbs()
$manufacturerId = (int)$_GET['man'];
$manufacturers = $tecDocRestClient->getManufacturers();
if (is_array($manufacturers)) {
$carTypeUrlText = Helper::getCarIdUrl();
foreach ($manufacturers as $oneManufacturer) {
if ($oneManufacturer->id === $manufacturerId) {
$breadcrumbs[] = array(
'name' => $oneManufacturer->name,
'url' => "?man={$manufacturerId}"
'url' => "?man={$manufacturerId}{$carTypeUrlText}"
);
}
}
Expand All @@ -78,6 +83,7 @@ private static function getBreadcrumbs()
$templateData = array(
'breadcrumbs' => $breadcrumbs
);

return View::deploy('common/breadcumbs.tpl', $templateData);
}
}
2 changes: 1 addition & 1 deletion View/manufacturers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ul>
{foreach from=$manufacturer item=man}
<li class="liSearch">
<a href="/?man={$man->id}" class="forSearch">{$man->name}</a>
<a href="/?man={$man->id}{if $data.carType}&carType={$data.carType}{/if}" class="forSearch">{$man->name}</a>
</li>
{/foreach}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion View/models.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{foreach from=$data.models item=oneModel}
<li class="couple forSearch">
<div class="TecDocModel">
<a href="/?man={$data.man}&model={$oneModel->id}">{$oneModel->name}</a>
<a href="/?man={$data.man}&model={$oneModel->id}{if $data.carType}&carType={$data.carType}{/if}">{$oneModel->name}</a>
</div>
<div class="TecDocYear">
{if $oneModel->yearFrom}{$oneModel->yearFrom->format('m/Y')}{/if}
Expand Down
2 changes: 1 addition & 1 deletion View/modifications.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</td>
{*Модель*}
<td>
<a href="/?man={$smarty.get.man}&model={$smarty.get.model}&modelVariant={$modification->id}">{$modification->name}</a>
<a href="/?man={$smarty.get.man}&model={$smarty.get.model}&modelVariant={$modification->id}{if $data.carType}&carType={$data.carType}{/if}">{$modification->name}</a>
</td>
{*Год выпуска*}
<td>{if $modification->yearFrom}{$modification->yearFrom->format('m/Y')}{/if}
Expand Down

0 comments on commit 2123427

Please sign in to comment.