public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $service = PostService::getInstance(); $count = $params->customParamList['count']; $previewLength = $params->customParamList['previewLength']; $list = $service->findList(0, $count); if ((empty($list) || false && !OW::getUser()->isAuthorized('blogs', 'add') && !OW::getUser()->isAuthorized('blogs', 'view')) && !$params->customizeMode) { $this->setVisible(false); return; } $posts = array(); $userService = BOL_UserService::getInstance(); $postIdList = array(); foreach ($list as $dto) { /* @var $dto Post */ if (mb_strlen($dto->getTitle()) > 50) { $dto->setTitle(UTIL_String::splitWord(UTIL_String::truncate($dto->getTitle(), 50, '...'))); } $text = $service->processPostText($dto->getPost()); $posts[] = array('dto' => $dto, 'text' => UTIL_String::splitWord(UTIL_String::truncate($text, $previewLength)), 'truncated' => mb_strlen($text) > $previewLength, 'url' => OW::getRouter()->urlForRoute('user-post', array('id' => $dto->getId()))); $idList[] = $dto->getAuthorId(); $postIdList[] = $dto->id; } $commentInfo = array(); if (!empty($idList)) { $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($idList, true, false); $this->assign('avatars', $avatars); $urls = BOL_UserService::getInstance()->getUserUrlsForList($idList); $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('blog-post', $postIdList); $toolbars = array(); foreach ($list as $dto) { $toolbars[$dto->getId()] = array(array('class' => 'ow_icon_control ow_ic_user', 'href' => isset($urls[$dto->getAuthorId()]) ? $urls[$dto->getAuthorId()] : '#', 'label' => isset($avatars[$dto->getAuthorId()]['title']) ? $avatars[$dto->getAuthorId()]['title'] : ''), array('class' => 'ow_remark ow_ipc_date', 'label' => UTIL_DateTime::formatDate($dto->getTimestamp()))); } $this->assign('tbars', $toolbars); } $this->assign('commentInfo', $commentInfo); $this->assign('list', $posts); if ($service->countPosts() > 0) { $toolbar = array(); if (OW::getUser()->isAuthorized('blogs', 'add')) { $toolbar[] = array('label' => OW::getLanguage()->text('blogs', 'add_new'), 'href' => OW::getRouter()->urlForRoute('post-save-new')); } if (OW::getUser()->isAuthorized('blogs', 'view')) { $toolbar[] = array('label' => OW::getLanguage()->text('blogs', 'go_to_blog'), 'href' => Ow::getRouter()->urlForRoute('blogs')); } if (!empty($toolbar)) { $this->setSettingValue(self::SETTING_TOOLBAR, $toolbar); } } }
public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $service = LinkService::getInstance(); $count = $params->customParamList['count']; $list = $service->findList(0, $count); if ((empty($list) || false && !OW::getUser()->isAuthorized('links', 'add') && !OW::getUser()->isAuthorized('links', 'view')) && !$params->customizeMode) { $this->setVisible(false); return; } $links = array(); $toolbars = array(); $userService = BOL_UserService::getInstance(); $authorIdList = array(); foreach ($list as $dto) { $dto->setUrl(strip_tags($dto->getUrl())); $dto->setTitle(strip_tags($dto->getTitle())); $dto->setDescription(strip_tags($dto->getDescription())); $links[] = array('dto' => $dto); $idList[] = $dto->id; $authorIdList[] = $dto->getUserId(); } $commentInfo = array(); $this->assign('avatars', null); if (!empty($idList)) { $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('link', $idList); $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($authorIdList, true, false); $this->assign('avatars', $avatars); $urls = BOL_UserService::getInstance()->getUserUrlsForList($authorIdList); } $tbars = array(); foreach ($list as $dto) { $tbars[$dto->getId()] = array(array('class' => 'ow_icon_control ow_ic_user', 'href' => !empty($urls[$dto->getUserId()]) ? $urls[$dto->getUserId()] : '#', 'label' => !empty($avatars[$dto->getUserId()]['title']) ? $avatars[$dto->getUserId()]['title'] : ''), array('class' => 'ow_remark ow_ipc_date', 'label' => UTIL_DateTime::formatDate($dto->getTimestamp()))); } $this->assign('tbars', $tbars); $this->assign('commentInfo', $commentInfo); $this->assign('list', $links); if ($service->countAll()) { $toolbar = array(); if (OW::getUser()->isAuthorized('links', 'add')) { $toolbar[] = array('label' => OW::getLanguage()->text('links', 'add_new'), 'href' => OW::getRouter()->urlForRoute('link-save-new')); } if (OW::getUser()->isAuthorized('links', 'view')) { $toolbar[] = array('label' => OW::getLanguage()->text('links', 'go_to_links'), 'href' => Ow::getRouter()->urlForRoute('links')); } if (!empty($toolbar)) { $this->setSettingValue(self::SETTING_TOOLBAR, $toolbar); } } }