|
|
@@ -19,10 +19,8 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
{
|
|
|
parent::__construct ($aOptions, $oTemplate);
|
|
|
|
|
|
- $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
-
|
|
|
- $this->_iRoleId = 0;
|
|
|
- if(($iRoleId = (int)bx_get('role_id')) !== false)
|
|
|
+ $this->_iRoleId = false;
|
|
|
+ if(($iRoleId = bx_get('role_id')) !== false)
|
|
|
$this->setRoleId($iRoleId);
|
|
|
}
|
|
|
|
|
|
@@ -50,9 +48,17 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
return '/api.php?r=system/perfom_action_api/TemplServiceGrid/¶ms[]=&o=' . $this->_sObject . '&a=' . $sAction . '&profile_id=' . $this->_iGroupProfileId . '&role_id=' . $this->_iRoleId . '&id=' . $iId;
|
|
|
}
|
|
|
|
|
|
- public function setRoleId($iRoleId)
|
|
|
+ public function setRoleId($mixedRoleId)
|
|
|
{
|
|
|
- $this->_iRoleId = (int)$iRoleId;
|
|
|
+ if(is_string($mixedRoleId)) {
|
|
|
+ if($mixedRoleId === '')
|
|
|
+ return;
|
|
|
+
|
|
|
+ if(!is_numeric($mixedRoleId))
|
|
|
+ $mixedRoleId = $this->_roleIdS2I($mixedRoleId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->_iRoleId = (int)$mixedRoleId;
|
|
|
$this->_aQueryAppend['role_id'] = $this->_iRoleId;
|
|
|
}
|
|
|
|
|
|
@@ -88,21 +94,27 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
return $this->_bIsApi ? [bx_api_get_msg($mixedResult)] : echoJson(['msg' => $mixedResult]);
|
|
|
|
|
|
$sFilter = bx_get('filter');
|
|
|
- if(strpos($sFilter, $this->_sParamsDivider) !== false)
|
|
|
- list($this->_iRoleId, $sFilter) = explode($this->_sParamsDivider, $sFilter);
|
|
|
+ if(strpos($sFilter, $this->_sParamsDivider) !== false) {
|
|
|
+ list($sRoleId, $sFilter) = explode($this->_sParamsDivider, $sFilter);
|
|
|
+ if($sRoleId)
|
|
|
+ $this->setRoleId($sRoleId);
|
|
|
+ }
|
|
|
|
|
|
- if(!is_numeric($this->_iRoleId) && ($iRoleId = bx_get('role_id')) !== false)
|
|
|
- $this->_iRoleId = (int)$iRoleId;
|
|
|
+ if($this->_iRoleId === false && ($sRoleId = bx_get('role_id')) !== false)
|
|
|
+ $this->setRoleId($sRoleId);
|
|
|
|
|
|
$sForm = $CNF['OBJECT_FORM_PRICE_DISPLAY_ADD'];
|
|
|
$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_PRICE'], $CNF['OBJECT_FORM_PRICE_DISPLAY_ADD']);
|
|
|
$oForm->setId($sForm);
|
|
|
$oForm->setName($sForm);
|
|
|
- $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', array('o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId)));
|
|
|
+ $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId]));
|
|
|
$oForm->setRoleId($this->_iRoleId);
|
|
|
|
|
|
$oForm->initChecker();
|
|
|
if($oForm->isSubmittedAndValid()) {
|
|
|
+ $sRoleId = $oForm->getCleanValue('role_id');
|
|
|
+ BxDolForm::setSubmittedValue('role_id', $this->_roleIdS2I($sRoleId), $oForm->aFormAttrs['method']);
|
|
|
+
|
|
|
$iPeriod = $oForm->getCleanValue('period');
|
|
|
$sPeriodUnit = $oForm->getCleanValue('period_unit');
|
|
|
|
|
|
@@ -113,6 +125,9 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
if(!empty($aPrice) && is_array($aPrice))
|
|
|
return ($sMsg = _t($CNF['T']['err_price_duplicate'])) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : echoJson(['msg' => $sMsg]);
|
|
|
|
|
|
+ if($oForm->getCleanValue('default') != 0)
|
|
|
+ $this->_oModule->_oDb->updatePrices(['default' => 0], ['profile_id' => $this->_iGroupProfileId]);
|
|
|
+
|
|
|
$iId = (int)$oForm->insert(['profile_id' => $this->_iGroupProfileId, 'added' => time(), 'order' => $this->_oModule->_oDb->getPriceOrderMax($this->_iRoleId) + 1]);
|
|
|
if($iId != 0)
|
|
|
$aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
|
|
|
@@ -153,14 +168,19 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
if(!is_array($aItem) || empty($aItem))
|
|
|
return $this->_bIsApi ? [] : echoJson([]);
|
|
|
|
|
|
+ $aItem['role_id'] = $this->_roleIdI2S($aItem['role_id']);
|
|
|
+
|
|
|
$sForm = $CNF['OBJECT_FORM_PRICE_DISPLAY_EDIT'];
|
|
|
$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_PRICE'], $CNF['OBJECT_FORM_PRICE_DISPLAY_EDIT']);
|
|
|
$oForm->setId($sForm);
|
|
|
$oForm->setName($sForm);
|
|
|
- $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId]));
|
|
|
+ $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId]));
|
|
|
|
|
|
$oForm->initChecker($aItem);
|
|
|
if($oForm->isSubmittedAndValid()) {
|
|
|
+ if($oForm->getCleanValue('default') != 0)
|
|
|
+ $this->_oModule->_oDb->updatePrices(['default' => 0], ['profile_id' => $this->_iGroupProfileId]);
|
|
|
+
|
|
|
if($oForm->update($aItem['id']) !== false)
|
|
|
$aRes = ['grid' => $this->getCode(false), 'blink' => $aItem['id']];
|
|
|
else
|
|
|
@@ -189,17 +209,17 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
|
|
|
$aIds = bx_get('ids');
|
|
|
if(!$aIds || !is_array($aIds))
|
|
|
- return echoJson(array());
|
|
|
+ return echoJson([]);
|
|
|
|
|
|
$iAffected = 0;
|
|
|
- $aIdsAffected = array();
|
|
|
+ $aIdsAffected = [];
|
|
|
foreach($aIds as $iId)
|
|
|
- if($this->_oModule->_oDb->deletePrices(array('id' => $iId))) {
|
|
|
+ if($this->_oModule->_oDb->deletePrices(['id' => $iId])) {
|
|
|
$aIdsAffected[] = $iId;
|
|
|
$iAffected++;
|
|
|
}
|
|
|
|
|
|
- return echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['err_cannot_perform'])));
|
|
|
+ return echoJson($iAffected ? ['grid' => $this->getCode(false), 'blink' => $aIdsAffected] : ['msg' => _t($CNF['T']['err_cannot_perform'])]);
|
|
|
}
|
|
|
|
|
|
protected function _addJsCss()
|
|
|
@@ -217,32 +237,39 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ protected function _getCellDefaultPrice($mixedValue, $sKey, $aField, $aRow)
|
|
|
+ {
|
|
|
+ return parent::_getCellDefault((int)$mixedValue != 0 ? _t('_Yes') : '', $sKey, $aField, $aRow);
|
|
|
+ }
|
|
|
+
|
|
|
protected function _getFilterControls()
|
|
|
{
|
|
|
parent::_getFilterControls();
|
|
|
|
|
|
$sContent = '';
|
|
|
- $oForm = new BxTemplFormView(array());
|
|
|
+ $oForm = new BxTemplFormView([]);
|
|
|
|
|
|
- $aInputRoles = array(
|
|
|
+ $aInputRoles = [
|
|
|
'type' => 'select',
|
|
|
'name' => 'role',
|
|
|
- 'attrs' => array(
|
|
|
+ 'attrs' => [
|
|
|
'id' => 'bx-grid-level-' . $this->_sObject,
|
|
|
'onChange' => 'javascript:' . $this->_oModule->_oConfig->getJsObject('prices') . '.onChangeRole()'
|
|
|
- ),
|
|
|
+ ],
|
|
|
'value' => $this->_iRoleId,
|
|
|
- 'values' => $this->_aRoles
|
|
|
- );
|
|
|
+ 'values' => ['' => _t('_Select_all')]
|
|
|
+ ];
|
|
|
+ foreach($this->_aRoles as $iId => $sTitle)
|
|
|
+ $aInputRoles['values'][$this->_roleIdI2S($iId)] = $sTitle;
|
|
|
$sContent .= $oForm->genRow($aInputRoles);
|
|
|
|
|
|
- $aInputSearch = array(
|
|
|
+ $aInputSearch = [
|
|
|
'type' => 'text',
|
|
|
'name' => 'keyword',
|
|
|
- 'attrs' => array(
|
|
|
+ 'attrs' => [
|
|
|
'id' => 'bx-grid-search-' . $this->_sObject,
|
|
|
- ),
|
|
|
- );
|
|
|
+ ]
|
|
|
+ ];
|
|
|
$sContent .= $oForm->genRow($aInputSearch);
|
|
|
|
|
|
return $sContent;
|
|
|
@@ -250,17 +277,18 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
|
|
|
protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
|
|
|
{
|
|
|
- if(strpos($sFilter, $this->_sParamsDivider) !== false) {
|
|
|
- list($iRoleId, $sFilter) = explode($this->_sParamsDivider, $sFilter);
|
|
|
- if(!is_numeric($iRoleId))
|
|
|
- $iRoleId = 0;
|
|
|
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString("AND `profile_id`=?", $this->_iGroupProfileId);
|
|
|
|
|
|
- $this->setRoleId($iRoleId);
|
|
|
+ if(strpos($sFilter, $this->_sParamsDivider) !== false) {
|
|
|
+ list($sRoleId, $sFilter) = explode($this->_sParamsDivider, $sFilter);
|
|
|
+ if(!empty($sRoleId))
|
|
|
+ $this->setRoleId($this->_roleIdS2I($sRoleId));
|
|
|
}
|
|
|
|
|
|
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString("AND `profile_id`=? AND `role_id`=? ", $this->_iGroupProfileId, $this->_iRoleId);
|
|
|
+ if($this->_iRoleId !== false)
|
|
|
+ $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `role_id`=? ", $this->_iRoleId);
|
|
|
|
|
|
- return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);;
|
|
|
+ return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
|
|
|
}
|
|
|
|
|
|
protected function _isVisibleGrid ($a)
|