public function initForm() { $jsParams = array('entityType' => $this->params->getEntityType(), 'entityId' => $this->params->getEntityId(), 'pluginKey' => $this->params->getPluginKey(), 'contextId' => $this->cmpContextId, 'userAuthorized' => $this->isAuthorized, 'customId' => $this->params->getCustomId()); if ($this->isAuthorized) { OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'jquery.autosize.js'); $taId = 'cta' . $this->id; $attchId = 'attch' . $this->id; $attchUid = BOL_CommentService::getInstance()->generateAttachmentUid($this->params->getEntityType(), $this->params->getEntityId()); $jsParams['ownerId'] = $this->params->getOwnerId(); $jsParams['cCount'] = isset($this->batchData['countOnPage']) ? $this->batchData['countOnPage'] : $this->params->getCommentCountOnPage(); $jsParams['initialCount'] = $this->params->getInitialCommentsCount(); $jsParams['loadMoreCount'] = $this->params->getLoadMoreCount(); $jsParams['countOnPage'] = $this->params->getCommentCountOnPage(); $jsParams['uid'] = $this->id; $jsParams['addUrl'] = OW::getRouter()->urlFor('BASE_CTRL_Comments', 'addComment'); $jsParams['displayType'] = $this->params->getDisplayType(); $jsParams['textAreaId'] = $taId; $jsParams['attchId'] = $attchId; $jsParams['attchUid'] = $attchUid; $jsParams['enableSubmit'] = true; $jsParams['mediaAllowed'] = BOL_TextFormatService::getInstance()->isCommentsRichMediaAllowed(); $jsParams['labels'] = array('emptyCommentMsg' => OW::getLanguage()->text('base', 'empty_comment_error_msg'), 'disabledSubmit' => OW::getLanguage()->text('base', 'submit_disabled_error_msg'), 'attachmentLoading' => OW::getLanguage()->text('base', 'submit_attachment_not_loaded')); if (!empty($this->staticData['currentUserInfo'])) { $userInfoToAssign = $this->staticData['currentUserInfo']; } else { $currentUserInfo = BOL_AvatarService::getInstance()->getDataForUserAvatars(array(OW::getUser()->getId())); $userInfoToAssign = $currentUserInfo[OW::getUser()->getId()]; } $buttonContId = 'bCcont' . $this->id; if (BOL_TextFormatService::getInstance()->isCommentsRichMediaAllowed()) { $this->addComponent('attch', new BASE_CLASS_Attachment($this->params->getPluginKey(), $attchUid, $buttonContId)); } $this->assign('buttonContId', $buttonContId); $this->assign('currentUserInfo', $userInfoToAssign); $this->assign('formCmp', true); $this->assign('taId', $taId); $this->assign('attchId', $attchId); } OW::getDocument()->addOnloadScript("new OwComments(" . json_encode($jsParams) . ");"); $this->assign('displayType', $this->params->getDisplayType()); // add comment list cmp $this->addComponent('commentList', new BASE_CMP_CommentsList($this->params, $this->id)); }
protected function init() { if ($this->commentCount === 0 && $this->params->getShowEmptyList()) { $this->assign('noComments', true); } $countToLoad = 0; if ($this->commentCount === 0) { $commentList = array(); } else { if (in_array($this->params->getDisplayType(), array(BASE_CommentsParams::DISPLAY_TYPE_WITH_LOAD_LIST, BASE_CommentsParams::DISPLAY_TYPE_WITH_LOAD_LIST_MINI))) { $commentList = empty($this->batchData['commentsList']) ? $this->commentService->findCommentList($this->params->getEntityType(), $this->params->getEntityId(), 1, $this->params->getInitialCommentsCount()) : $this->batchData['commentsList']; $commentList = array_reverse($commentList); $countToLoad = $this->commentCount - $this->params->getInitialCommentsCount(); $this->assign('countToLoad', $countToLoad); } else { $commentList = $this->commentService->findCommentList($this->params->getEntityType(), $this->params->getEntityId(), $this->page, $this->params->getCommentCountOnPage()); } } OW::getEventManager()->trigger(new OW_Event('base.comment_list_prepare_data', array('list' => $commentList, 'entityType' => $this->params->getEntityType(), 'entityId' => $this->params->getEntityId()))); OW::getEventManager()->bind('base.comment_item_process', array($this, 'itemHandler')); $this->assign('comments', $this->processList($commentList)); $pages = false; if ($this->params->getDisplayType() === BASE_CommentsParams::DISPLAY_TYPE_WITH_PAGING) { $pagesCount = $this->commentService->findCommentPageCount($this->params->getEntityType(), $this->params->getEntityId(), $this->params->getCommentCountOnPage()); if ($pagesCount > 1) { $pages = $this->getPages($this->page, $pagesCount, 8); $this->assign('pages', $pages); } } else { $pagesCount = 0; } $this->assign('loadMoreLabel', OW::getLanguage()->text('base', 'comment_load_more_label')); static $dataInit = false; if (!$dataInit) { $staticDataArray = array('respondUrl' => OW::getRouter()->urlFor('BASE_CTRL_Comments', 'getCommentList'), 'delUrl' => OW::getRouter()->urlFor('BASE_CTRL_Comments', 'deleteComment'), 'delAtchUrl' => OW::getRouter()->urlFor('BASE_CTRL_Comments', 'deleteCommentAtatchment'), 'delConfirmMsg' => OW::getLanguage()->text('base', 'comment_delete_confirm_message'), 'preloaderImgUrl' => OW::getThemeManager()->getCurrentTheme()->getStaticImagesUrl() . 'ajax_preloader_button.gif'); OW::getDocument()->addOnloadScript("window.owCommentListCmps.staticData=" . json_encode($staticDataArray) . ";"); $dataInit = true; } $jsParams = json_encode(array('totalCount' => $this->commentCount, 'contextId' => $this->cmpContextId, 'displayType' => $this->params->getDisplayType(), 'entityType' => $this->params->getEntityType(), 'entityId' => $this->params->getEntityId(), 'pagesCount' => $pagesCount, 'initialCount' => $this->params->getInitialCommentsCount(), 'loadMoreCount' => $this->params->getLoadMoreCount(), 'commentIds' => $this->commentIdList, 'pages' => $pages, 'pluginKey' => $this->params->getPluginKey(), 'ownerId' => $this->params->getOwnerId(), 'commentCountOnPage' => $this->params->getCommentCountOnPage(), 'cid' => $this->id, 'actionArray' => $this->actionArr, 'countToLoad' => $countToLoad)); OW::getDocument()->addOnloadScript("window.owCommentListCmps.items['{$this->id}'] = new OwCommentsList({$jsParams});\n window.owCommentListCmps.items['{$this->id}'].init();"); }