logger = $logger;
$this->db = $db;
}
public function __invoke(string $scope)
{
list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
// Get archives with notifications enabled
$Archives = NewsArchiveModel::findBy('nc_enable','1');
if ($Archives !== null)
{
list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
while ($Archives->next())
{
$Archive = $Archives->current();
$arrGroupIds = StringUtil::deserialize($Archive->nc_notification_groups,true);
$time = Date::floorToMinute();
// Do we have new news items
$News = $this->db->executeQuery("SELECT id, alias, headline, `date`, teaser FROM tl_news WHERE pid = ? AND nc_sent != '1' AND date <='$time' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY `date` DESC, `time` DESC",[$Archive->id]);
$arrNewsIds = array();
// Load groups and notification models if we have news to share
if ($News->rowCount() && ($Notification = Notification::findByPk($Archive->nc_notification)) !== null && ($Groups = MemberGroupModel::findMultipleByIds($arrGroupIds)) !== null)
{
foreach ($News->iterateAssociative() as $item)
{
$arrNewsIds[] = $item['id'];
$arrNews = array();
$arrNewsPlain = array();
$strText = '';
$objContentElement = ContentModel::findPublishedByPidAndTable($item['id'], 'tl_news');
if ($objContentElement !== null)
{
while ($objContentElement->next())
{
$strText .= Controller::getContentElement($objContentElement->current());
}
}
$arrRow = array(
'date' => date('d.m.Y',$item['date']),
'headline' => $item['headline'],
'teaser' => $item['teaser'] ? StringUtil::substr(strip_tags(str_ireplace(array('
','
','
','
'),' ',$item['teaser'])),128) : '',
'text_plain' => $strText ? strip_tags(str_ireplace(array('
','
','
','
'),' ',$strText)) : ($item['teaser'] ? strip_tags(str_ireplace(array('
','
','
','
'),' ',$item['teaser'])) : ''), 'text_html' => $strText ?: $item['teaser'] ); if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null) { // $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias'])).'?ltoken=%%_TOKEN_%%'; $arrRow['url'] = $objJumpTo->getAbsoluteUrl(sprintf((Config::get('useAutoItem') ? '/%s' : '/items/%s'),$item['alias'])); } $arrNews[] = $arrRow; $arrNewsPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline']; $arrNewsHtml[] = '
'.$arrRow['teaser'].'
'. ($arrRow['url'] ? '' : '') .'