Skip to content

Commit

Permalink
Ticket #4770 - Usage of assistant in Studio Help.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Aug 15, 2024
1 parent 3768d97 commit 58023bc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
31 changes: 27 additions & 4 deletions inc/classes/BxDolCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
protected $_iId = 0; ///< obect id to be commented
protected $_iAuthorId = 0; ///< currently logged in user who browse, post, etc.

protected $_aT = array (); ///< an array of lang keys
protected $_aMarkers = array ();
protected $_aParams = [];
protected $_aT = []; ///< an array of lang keys
protected $_aMarkers = [];

protected $_sDisplayType = '';
protected $_sDpSessionKey = '';
Expand Down Expand Up @@ -279,15 +280,22 @@ protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false

$this->_sMetatagsObj = 'sys_cmts';

$this->_aT = array(
if(($aParams = bx_get('params')) !== false) {
if(is_string($aParams))
$aParams = json_decode($aParams, true);
if(!empty($aParams) && is_array($aParams))
$this->_aParams = array_merge($this->_aParams, $aParams);
}

$this->_aT = [
'block_comments_title' => '_cmt_block_comments_title',
'txt_sample_single' => '_cmt_txt_sample_comment_single',
'txt_sample_vote_single' => '_cmt_txt_sample_vote_single',
'txt_sample_reaction_single' => '_cmt_txt_sample_reaction_single',
'txt_sample_score_up_single' => '_cmt_txt_sample_score_up_single',
'txt_sample_score_down_single' => '_cmt_txt_sample_score_down_single',
'txt_min_form_placeholder' => '_cmt_txt_min_form_placeholder'
);
];

if ($iInit)
$this->init($iId);
Expand Down Expand Up @@ -409,6 +417,21 @@ public function init ($iId)
));
}

public function setParam($sName, $sValue)
{
$this->_aParams[$sName] = $sValue;
}

public function isParam($sName)
{
return isset($this->_aParams[$sName]);
}

public function getParam($sName)
{
return $this->_aParams[$sName];
}

public function getId ()
{
return $this->_iId;
Expand Down
7 changes: 6 additions & 1 deletion inc/js/classes/BxDolCmts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function BxDolCmts (options) {
this._sBrowseFilter = undefined == options.sBrowseFilter ? 'all' : options.sBrowseFilter;

this._sSP = options.sStylePrefix === undefined ? 'cmt' : options.sStylePrefix;
this._aParams = options.aParams === undefined ? false : options.aParams;
this._aHtmlIds = options.aHtmlIds;
this._sAnimationEffect = 'fade';
this._iAnimationSpeed = 'slow';
Expand Down Expand Up @@ -1097,11 +1098,15 @@ BxDolCmts.prototype._getCounter = function(oElement, bText)

BxDolCmts.prototype._getDefaultActions = function() {
var oDate = new Date();
return {
var oResult = {
sys: this._sSystem,
id: this._iObjId,
_t: oDate.getTime()
};
if(this._aParams)
oResult['params'] = this._aParams;

return oResult;
};

BxDolCmts.prototype._loading = function(e, bShow) {
Expand Down
25 changes: 16 additions & 9 deletions studio/classes/BxDolStudioAgentsAsstChatsCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class BxDolStudioAgentsAsstChatsCmts extends BxTemplCmts
{
protected static $_sParamAllowDelete = 'allow_delete';

protected $_oQueryAgents;

protected $_oAI;
Expand All @@ -17,8 +19,6 @@ class BxDolStudioAgentsAsstChatsCmts extends BxTemplCmts
protected $_iAssistantId;
protected $_sAssistantUrl;

protected $_bAllowDelete;

protected $_bAuto;

public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
Expand All @@ -45,7 +45,8 @@ public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
}
$this->_sAssistantUrl = BX_DOL_URL_STUDIO . bx_append_url_params('agents.php', ['page' => 'assistants', 'spage' => 'chats', 'aid' => $this->_iAssistantId]);

$this->_bAllowDelete = true;
if(!$this->isParam(self::$_sParamAllowDelete))
$this->setAllowDelete(true);

$this->_bAuto = false;
}
Expand Down Expand Up @@ -115,9 +116,14 @@ public function isAttachImageEnabled()
return false;
}

public function isAllowDelete()
{
return !$this->isParam(self::$_sParamAllowDelete) || (int)$this->getParam(self::$_sParamAllowDelete) != 0;
}

public function setAllowDelete($bAllow)
{
$this->_bAllowDelete = $bAllow;
$this->setParam(self::$_sParamAllowDelete, $bAllow ? 1 : 0);
}

public function addAuto($aValues, $bUnsetForm = false)
Expand Down Expand Up @@ -182,7 +188,7 @@ public function onPostAfter($iCmtId, $aDp = [])

protected function _getActionsBox(&$aCmt, $aBp = [], $aDp = [])
{
if(!$this->_bAllowDelete)
if(!$this->isAllowDelete())
return '';

return $this->_oTemplate->parseLink('javascript:void(0)', _t('_sys_menu_item_title_cmts_item_delete'), [
Expand Down Expand Up @@ -213,12 +219,13 @@ protected function _getTmplVarsText($aCmt)

protected function _getForm($sAction, $iId)
{
$aResult = parent::_getForm($sAction, $iId);
$oForm = parent::_getForm($sAction, $iId);

$aResult->aInputs['cmt_text']['db']['pass'] = 'xss';
return $aResult;
$oForm->aInputs['cmt_text']['db']['pass'] = 'xss';

return $oForm;
}

protected function _prepareTextForOutput($s, $iCmtId = 0)
{
return nl2br(parent::_prepareTextForOutput($s, $iCmtId));
Expand Down
10 changes: 10 additions & 0 deletions template/scripts/BxBaseCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public function getJsScript($aBp = [], $aDp = [])
'aHtmlIds' => $this->_aHtmlIds,
];

if($this->_aParams)
$aParams['aParams'] = $this->_aParams;

$this->addCssJs();
return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
}
Expand Down Expand Up @@ -1454,6 +1457,13 @@ protected function _getForm($sAction, $iId)
$oForm->aInputs['id']['value'] = $this->_iId;
$oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';

if($this->_aParams)
$oForm->aInputs = ['params' => [
'name' => 'params',
'type' => 'hidden',
'value' => json_encode($this->_aParams)
]] + $oForm->aInputs;

if(!$this->isAttachImageEnabled())
unset($oForm->aInputs['cmt_image']);

Expand Down

0 comments on commit 58023bc

Please sign in to comment.