/** * Получить количество сущностей по фильтру * * @param array $aFilter Фильтр * @param string $sEntityFull Название класса сущности * @return int */ public function GetCountItemsByFilter($aFilter = array(), $sEntityFull = null) { $sEntityFull = $this->_NormalizeEntityRootName($sEntityFull); // Если параметр #cache указан и пуст, значит игнорируем кэширование для запроса if (array_key_exists('#cache', $aFilter) && !$aFilter['#cache']) { $iCount = $this->oMapperORM->GetCountItemsByFilter($aFilter, $sEntityFull); } else { $aFilterCache = $aFilter; unset($aFilterCache['#with']); $sCacheKey = $sEntityFull . '_count_items_by_filter_' . serialize($aFilterCache); $aCacheTags = array($sEntityFull . '_save', $sEntityFull . '_delete'); $iCacheTime = 60 * 60 * 24; // скорее лучше хранить в свойстве сущности, для возможности выборочного переопределения // переопределяем из параметров if (isset($aFilter['#cache'][0])) { $sCacheKey = $aFilter['#cache'][0]; } if (isset($aFilter['#cache'][1])) { $aCacheTags = $aFilter['#cache'][1]; } if (isset($aFilter['#cache'][2])) { $iCacheTime = $aFilter['#cache'][2]; } if (false === ($iCount = $this->Cache_Get($sCacheKey))) { $iCount = $this->oMapperORM->GetCountItemsByFilter($aFilter, $sEntityFull); $this->Cache_Set($iCount, $sCacheKey, $aCacheTags, $iCacheTime); } } return $iCount; }
/** * Получить количество сущностей по фильтру * * @param array $aFilter Фильтр * @param string $sEntityFull Название класса сущности * * @return int */ public function GetCountItemsByFilter($aFilter = array(), $sEntityFull = null) { if (is_null($sEntityFull)) { $sEntityFull = E::GetPluginPrefix($this) . 'Module' . E::GetModuleName($this) . '_Entity' . E::GetModuleName(get_class($this)); } elseif (!substr_count($sEntityFull, '_')) { $sEntityFull = E::GetPluginPrefix($this) . 'Module' . E::GetModuleName($this) . '_Entity' . $sEntityFull; } // Если параметр #cache указан и пуст, значит игнорируем кэширование для запроса if (array_key_exists('#cache', $aFilter) && !$aFilter['#cache']) { $iCount = $this->oMapper->GetCountItemsByFilter($aFilter, $sEntityFull); } else { $sEntityFullRoot = E::ModulePlugin()->GetRootDelegater('entity', $sEntityFull); $sCacheKey = $sEntityFullRoot . '_count_items_by_filter_' . serialize($aFilter); $aCacheTags = array($sEntityFullRoot . '_save', $sEntityFullRoot . '_delete'); $iCacheTime = 60 * 60 * 24; // скорее лучше хранить в свойстве сущности, для возможности выборочного переопределения // переопределяем из параметров if (isset($aFilter['#cache'][0])) { $sCacheKey = $aFilter['#cache'][0]; } if (isset($aFilter['#cache'][1])) { $aCacheTags = $aFilter['#cache'][1]; } if (isset($aFilter['#cache'][2])) { $iCacheTime = $aFilter['#cache'][2]; } if (false === ($iCount = E::ModuleCache()->Get($sCacheKey))) { $iCount = $this->oMapper->GetCountItemsByFilter($aFilter, $sEntityFull); E::ModuleCache()->Set($iCount, $sCacheKey, $aCacheTags, $iCacheTime); } } return $iCount; }