/** * Get top page header * @return string */ public function getMenuHeaderView() { if (!defined('USER_ID') || !USER_ID) { return ''; } ob_start(); // Notifications from system $notification_repository = new UsersMessageEntityRepository(); $notification_repository->setWhereToUserId(USER_ID); $notification_repository->setWhereFromUserId(0); $notification_repository->addOrderByField('ts', true); $notification_repository->setWhereSeen(0); $total_notifications = $notification_repository->getCountOfObjectsInCollection(); $notification_repository->setLimit(10); $notifications = $notification_repository->getAsArrayOfObjects(); // Messages from users $messages_repository = new UsersMessageEntityRepository(); $messages_repository->setWhereToUserId(USER_ID); $messages_repository->addWhereFieldIsNot('from_user_id', 0); $messages_repository->addOrderByField('ts', true); $messages_repository->setWhereSeen(0); $total_messages = $messages_repository->getCountOfObjectsInCollection(); $messages_repository->setLimit(10); $messages = $messages_repository->getAsArrayOfObjects(); // Custom notifiers // TODO $custom_notifiers = []; $custom_notifiers[] = $this->getHelpTextsNotifier(); // Logo image and link $logo = ''; if (array_key_exists('logo', Configuration::getInstance()->get('cms'))) { $logo = Configuration::getInstance()->get('cms')['logo']; } $logo_link = DIR_CMS_URL; if (array_key_exists('logo_link', Configuration::getInstance()->get('cms'))) { $logo_link = Configuration::getInstance()->get('cms')['logo_link']; } $user_avatar = Users::getInstance()->getUserData('avatar'); if (!$user_avatar) { $user_avatar = '/vendor/devp-eu/tmcms-core/src/assets/cms/layout/img/avatar.png'; } $languages = AdminLanguages::getPairs(); $current_language = Users::getInstance()->getUserLng(); ?> <div class="page-header-inner"> <?php if ($logo) { ?> <div class="page-logo"> <a href="<?php echo $logo_link; ?> "> <img src="<?php echo $logo; ?> " alt="logo" class="logo-default"> </a> <div class="menu-toggler sidebar-toggler"></div> </div> <?php } ?> <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse"></a> <div class="top-menu"> <ul class="nav navbar-nav pull-right"> <li class="dropdown dropdown-extended dropdown-home" id="header_home_bar"> <a href="/" target="_blank" class="dropdown-toggle" data-hover="dropdown" data-close-others="true"> <i class="icon-home"></i> </a> </li> <?php if (count($languages) > 1) { ?> <li class="dropdown dropdown-language"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php echo LNG; ?> .png"> <span class="langname"><?php echo strtoupper(LNG); ?> </span> <i class="fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <?php foreach ($languages as $k => $v) { if ($k == LNG) { continue; } ?> <li> <a href="?p=users&do=_change_lng&lng=<?php echo $k; ?> "> <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php echo $k; ?> .png"> <?php echo $v; ?> </a> </li> <?php } ?> </ul> </li> <?php } ?> <?php if ($notifications) { ?> <li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <i class="icon-bell"></i> <span class="badge badge-default"><?php echo count($notifications); ?> </span> </a> <ul class="dropdown-menu"> <li> <p> You have <?php echo $total_notifications; ?> new notifications </p> </li> <li> <ul class="dropdown-menu-list scroller" style="height: 250px;"> <?php foreach ($notifications as $k => $message) { /** @var UsersMessageEntity $message */ ?> <li> <a href="#"> <span class="label label-sm label-icon label-warning"> <i class="fa fa-bell-o"></i> </span> <?php echo $message->getMessage(); ?> <span class="time"> <?php echo Converter::getTimeFromEventAgo($message->getTs()); ?> </span> </a> </li> <?php } ?> </ul> </li> <li class="external"> <a href="?p=home&do=notifications"> See all notifications <i class="m-icon-swapright"></i> </a> </li> </ul> </li> <?php } ?> <?php if ($messages) { ?> <li class="dropdown dropdown-extended dropdown-inbox" id="header_inbox_bar"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <i class="icon-envelope-open"></i> <span class="badge badge-default"><?php echo count($messages); ?> </span> </a> <ul class="dropdown-menu"> <li> <p> You have <?php echo $total_messages; ?> new messages </p> </li> <li> <ul class="dropdown-menu-list scroller" style="height: 250px;"> <?php foreach ($notifications as $k => $message) { /** @var UsersMessageEntity $message */ $user = new AdminUser($message->getFromUserId()); $avatar = $user->getAvatar(); ?> <li> <a href="?p=users&do=chat&user_id=2"> <?php if ($avatar) { ?> <span class="photo"> <img src="<?php echo $avatar; ?> " alt="" style="height=40px"> </span> <?php } ?> <span class="subject"> <span class="from"><?php echo $user->getName(); ?> </span> <span class="time"><?php echo Converter::getTimeFromEventAgo($message->getTs()); ?> </span> </span> <span class="message"><?php echo Converter::cutLongStrings($message->getMessage()); ?> </span> </a> </li> <?php } ?> </ul> </li> <li class="external"> <a href="?p=users&do=chat"> See all messages <i class="m-icon-swapright"></i> </a> </li> </ul> </li> <?php } ?> <?php if ($custom_notifiers) { ?> <?php echo implode('', $custom_notifiers); ?> <?php } ?> <li class="dropdown dropdown-user"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <img alt="" class="img-circle" src="<?php echo $user_avatar; ?> " style="height: 29px;"> <span class="username"><?php echo Users::getInstance()->getUserData('name'); ?> </span> <i class="fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <li> <a href="?p=users&do=users_edit&id=<?php echo USER_ID; ?> "> <i class="icon-user"></i> My Profile </a> </li> <li> <a href="?p=home&do=notifications"> <i class="icon-envelope-open"></i>My notifications <span class="badge badge-danger"> <?php echo count($notifications); ?> </span> </a> </li> <li class="divider"></li> <li> <a href="#" onclick="clipboard_forms.copy_page_forms(); return false;"> <i class="icon-cloud-download"></i>Copy form data </a> </li> <li> <a href="#" onclick="clipboard_forms.paste_page_forms(); return false;"> <i class="icon-cloud-upload"></i>Paste form data </a> </li> <li class="divider"></li> <li> <a href="?p=home&do=_exit" onclick="return confirm('<?php echo __('Are you sure?'); ?> ');"> <i class="icon-key"></i> Log Out </a> </li> </ul> </li> <?php // TODO right panel ?> <!-- <li class="dropdown dropdown-quick-sidebar-toggler">--> <!-- <a href="javascript:;" class="dropdown-toggle">--> <!-- <i class="icon-logout"></i>--> <!-- </a>--> <!-- </li>--> </ul> </div> </div> <?php return ob_get_clean(); }
<?php defined('INC') or exit; // Delete all message more than 1 week use TMCms\Admin\Users\Entity\UsersMessageEntityRepository; $messages_collection = new UsersMessageEntityRepository(); $messages_collection->setWhereToUserId(USER_ID); $messages_collection->setWhereFromUserId(0); // System only $messages_collection->setWhereOld(); $messages_collection->deleteObjectCollection(); // Get actual $messages_collection = new UsersMessageEntityRepository(); $messages_collection->setWhereSeen(0); $messages_collection->setWhereToUserId(USER_ID); $messages_collection->setLimit(3); $messages_collection->addOrderByField('ts', true); $data = []; foreach ($messages_collection->getAsArrayOfObjects() as $msg) { /** @var \TMCms\Admin\Users\Entity\UsersMessageEntity $msg */ $data[] = $msg->getAsArray(); $msg->setSeen(1); $msg->save(); } ob_start(); echo json_encode($data, JSON_FORCE_OBJECT); echo ob_get_clean(); $messages_collection->setSeen(1); $messages_collection->save(); die;