$aParticipants[$iProfileId]); unset($aParticipants[$iProfileId]); $aParticipants = $a + $aParticipants; } return $aParticipants; } /** * Action methods */ public function actionUpdateStatus($sAction = '', $iContentId = 0) { if(empty($sAction) && bx_get('action') !== false) $sAction = bx_process_input(bx_get('action')); if(empty($iContentId) && bx_get('id') !== false) $iContentId = (int)bx_get('id'); $aContentInfo = $this->_oDb->getContentInfoById($iContentId); if(empty($aContentInfo) || !is_array($aContentInfo)) return echoJson(array('code' => 1, 'message' => _t('_bx_forum_err_not_found'))); $sMethodCheck = 'checkAllowed' . bx_gen_method_name($sAction) . 'AnyEntry'; $sResult = $this->$sMethodCheck($aContentInfo); if($sResult !== CHECK_ACTION_RESULT_ALLOWED) return echoJson(array('code' => 2, 'message' => $sResult)); if(!$this->_oDb->updateStatus($sAction, $aContentInfo)) return echoJson(array('code' => 3, 'message' => _t('_error occured'))); echoJson(array('code' => 0, 'id' => $iContentId, 'reload' => 1)); } /** * Service methods */ public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true) { $sType = 'new'; if($sUnitView != 'table') return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate); return $this->_serviceBrowseTable($sType); } public function serviceBrowseLatest($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true) { $sType = 'latest'; if($sUnitView != 'table') return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate); return $this->_serviceBrowseTable($sType); } public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true) { $sType = 'top'; if($sUnitView != 'table') return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate); return $this->_serviceBrowseTable($sType); } /** * Get number of unread messages for spme profile * @param $iProfileId - profile to get unread messages for, if omitted then currently logged is profile is used * @return integer */ public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0) { if (!$iProfileId) $iProfileId = bx_get_logged_profile_id(); return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId); } /** * Update last comment time and author */ public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '') { $CNT = $this->_oConfig->CNF; $iContentId = (int)$iContentId; if(!$iContentId) return false; $aContentInfo = $this->_oDb->getContentInfoById($iContentId); if(!$aContentInfo) return false; if(!$iTimestamp) $iTimestamp = time(); if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp)) return false; // send notification to author if($iProfileId != $aContentInfo[$CNT['FIELD_AUTHOR']]) { $oProfile = BxDolProfile::getInstance($iProfileId); if($oProfile) sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNT['FIELD_AUTHOR']], array( 'SenderDisplayName' => $oProfile->getDisplayName(), 'SenderUrl' => $oProfile->getUrl(), 'Message' => $sCommentText, ), BX_EMAIL_NOTIFY); } return true; } /** * Entry collaborators block */ public function serviceEntityParticipants ($iContentId = 0) { if (!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT); if (!$iContentId) return false; $aContentInfo = $this->_oDb->getContentInfoById($iContentId); if (!$aContentInfo) return false; return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right'); } /** * No social sharing for private discussions */ public function serviceEntitySocialSharing($iContentId = 0) { return ''; } /** * No thumbs for discussions */ public function checkAllowedSetThumb() { return _t('_sys_txt_access_denied'); } public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0) return false; return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction); } public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1) return false; return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction); } public function checkAllowedLockAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 0) return false; return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction); } public function checkAllowedUnlockAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 1) return false; return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction); } public function checkAllowedHideAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] == 'hidden') return false; return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction); } public function checkAllowedUnhideAnyEntry($aDataEntry, $isPerformAction = false) { $CNF = $this->_oConfig->CNF; if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != 'hidden') return false; return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction); } /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking. */ protected function _checkAllowedAction($sAction, $aDataEntry, $isPerformAction = false) { if($this->_isModerator($isPerformAction)) return CHECK_ACTION_RESULT_ALLOWED; $aCheck = checkActionModule($this->_iProfileId, $sAction, $this->getName(), $isPerformAction); if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) return CHECK_ACTION_RESULT_ALLOWED; return _t('_sys_txt_access_denied'); } protected function _serviceBrowseTable($sType) { $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']); if(!$oGrid) return false; $oGrid->setBrowseType($sType); $oGrid->addMarkers(array( 'profile_id' => bx_get_logged_profile_id(), )); return $oGrid->getCode(); } } /** @} */