/** * Получить число сущностей по связанной таблице * * @param array $aJoinData Фильтр * @param string $sEntityFull Название класса сущности * * @return int */ public function GetCountItemsByJoinTable($aJoinData = 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', $aJoinData) && !$aJoinData['#cache']) { $iCount = $this->oMapper->GetCountItemsByJoinTable($aJoinData, $sEntityFull); } else { $sEntityFullRoot = E::ModulePlugin()->GetRootDelegater('entity', $sEntityFull); $sCacheKey = $sEntityFullRoot . '_count_items_by_join_table_' . serialize($aJoinData); $aCacheTags = array(); $iCacheTime = 60 * 60 * 24; // скорее лучше хранить в свойстве сущности, для возможности выборочного переопределения // переопределяем из параметров if (isset($aJoinData['#cache'][0])) { $sCacheKey = $aJoinData['#cache'][0]; } if (isset($aJoinData['#cache'][1])) { $aCacheTags = $aJoinData['#cache'][1]; } if (isset($aJoinData['#cache'][2])) { $iCacheTime = $aJoinData['#cache'][2]; } $aCacheTags[] = 'm2m_' . $aJoinData['#relation_key'] . $aJoinData['#by_key'] . $aJoinData['#by_value']; if (false === ($iCount = E::ModuleCache()->Get($sCacheKey))) { $iCount = $this->oMapper->GetCountItemsByJoinTable($aJoinData, $sEntityFull); E::ModuleCache()->Set($iCount, $sCacheKey, $aCacheTags, $iCacheTime); } } return $iCount; }