cache dataccessfunctions
This commit is contained in:
@@ -56,6 +56,8 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
protected $request;
|
||||
protected $dispatcher;
|
||||
|
||||
private static $dataAccessCache = array();
|
||||
|
||||
public function __construct(Request $request, SecurityContext $securityContext, ParserContext $parserContext, ContainerAwareEventDispatcher $dispatcher)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
@@ -160,7 +162,12 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
|
||||
public function countryDataAccess($params, $smarty)
|
||||
{
|
||||
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
|
||||
if(array_key_exists('defaultCountry', self::$dataAccessCache)) {
|
||||
$defaultCountry = self::$dataAccessCache['defaultCountry'];
|
||||
} else {
|
||||
$defaultCountry = CountryQuery::create()->findOneByByDefault(1);
|
||||
self::$dataAccessCache['defaultCountry'] = $defaultCountry;
|
||||
}
|
||||
|
||||
switch($params["attr"]) {
|
||||
case "default":
|
||||
@@ -170,6 +177,13 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
|
||||
public function cartDataAccess($params, $smarty)
|
||||
{
|
||||
if(array_key_exists('currentCountry', self::$dataAccessCache)) {
|
||||
$currentCountry = self::$dataAccessCache['currentCountry'];
|
||||
} else {
|
||||
$currentCountry = CountryQuery::create()->findOneById(64); // @TODO : make it magic
|
||||
self::$dataAccessCache['currentCountry'] = $currentCountry;
|
||||
}
|
||||
|
||||
$cart = $this->getCart($this->request);
|
||||
$result = "";
|
||||
switch($params["attr"]) {
|
||||
@@ -180,9 +194,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
$result = $cart->getTotalAmount();
|
||||
break;
|
||||
case "total_taxed_price":
|
||||
$result = $cart->getTaxedAmount(
|
||||
CountryQuery::create()->findOneById(64) // @TODO : make it magic
|
||||
);
|
||||
$result = $cart->getTaxedAmount($currentCountry);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -234,24 +246,30 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
*/
|
||||
protected function dataAccessWithI18n($objectLabel, $params, ModelCriteria $search, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID')
|
||||
{
|
||||
$lang = $this->getNormalizedParam($params, array('lang'));
|
||||
if ($lang === null) {
|
||||
$lang = $this->request->getSession()->getLang()->getId();
|
||||
if(array_key_exists('data_' . $objectLabel, self::$dataAccessCache)) {
|
||||
$data = self::$dataAccessCache['data_' . $objectLabel];
|
||||
} else {
|
||||
$lang = $this->getNormalizedParam($params, array('lang'));
|
||||
if ($lang === null) {
|
||||
$lang = $this->request->getSession()->getLang()->getId();
|
||||
}
|
||||
|
||||
ModelCriteriaTools::getI18n(
|
||||
false,
|
||||
$lang,
|
||||
$search,
|
||||
$this->request->getSession()->getLang()->getLocale(),
|
||||
$columns,
|
||||
$foreignTable,
|
||||
$foreignKey,
|
||||
true
|
||||
);
|
||||
|
||||
$data = $search->findOne();
|
||||
|
||||
self::$dataAccessCache['data_' . $objectLabel] = $data;
|
||||
}
|
||||
|
||||
ModelCriteriaTools::getI18n(
|
||||
false,
|
||||
$lang,
|
||||
$search,
|
||||
$this->request->getSession()->getLang()->getLocale(),
|
||||
$columns,
|
||||
$foreignTable,
|
||||
$foreignKey,
|
||||
true
|
||||
);
|
||||
|
||||
$data = $search->findOne();
|
||||
|
||||
$noGetterData = array();
|
||||
foreach ($columns as $column) {
|
||||
$noGetterData[$column] = $data->getVirtualColumn('i18n_' . $column);
|
||||
|
||||
Reference in New Issue
Block a user