| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- * @defgroup Tasks Tasks
- * @ingroup UnaModules
- *
- * @{
- */
- class BxGitHubGridApps extends BxBaseModGeneralGrid
- {
- protected $_iProfileId;
- public function __construct ($aOptions, $oTemplate = false)
- {
- $this->_sModule = 'bx_github';
- parent::__construct ($aOptions, $oTemplate);
- if(($sFfName = 'profile_id') && ($iValue = bx_get($sFfName)) !== false)
- $this->setProfileId($iValue);
- }
- public function getFormBlockTitleAPI($sAction, $iId = 0)
- {
- $sResult = '';
- switch($sAction) {
- case 'add':
- $sResult = _t('_bx_github_grid_popup_title_apps_add');
- break;
- case 'edit':
- $sResult = _t('_bx_github_grid_popup_title_apps_edit');
- break;
- }
- return $sResult;
- }
- public function getFormCallBackUrlAPI($sAction, $iId = 0)
- {
- return '/api.php?r=system/perfom_action_api/TemplServiceGrid/¶ms[]=&o=' . $this->_sObject . '&a=' . $sAction . '&id=' . $iId;
- }
- public function setProfileId($iProfileId)
- {
- $this->_iProfileId = (int)$iProfileId;
- $this->_aQueryAppend['profile_id'] = $this->_iProfileId;
- }
- public function performActionAdd()
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sAction = 'add';
- $oForm = $this->_getFormObject($sAction, $CNF['OBJECT_FORM_APPS_DISPLAY_ADD']);
- $oForm->initChecker();
- if($oForm->isSubmittedAndValid()) {
- if(($iId = (int)$oForm->insert(['profile_id' => $this->_iProfileId, 'added' => time()])) != 0)
- $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
- else
- $aRes = ['msg' => _t('_bx_github_err_cannot_perform_action')];
- return echoJson($aRes);
- }
- if($this->_bIsApi)
- return $this->getFormBlockAPI($oForm, $sAction);
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('apps_popup') . $sAction, _t('_bx_github_grid_popup_title_apps_' . $sAction), $this->_oModule->_oTemplate->parseHtmlByName('popup_apps.html', [
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
- }
- public function performActionEdit()
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $sAction = 'edit';
- $iId = $this->_getId();
- $aItem = $this->_oModule->_oDb->getApps(['sample' => 'id', 'id' => $iId]);
- if(!$aItem)
- return echoJson([]);
- $oForm = $this->_getFormObject($sAction, $CNF['OBJECT_FORM_APPS_DISPLAY_EDIT'], ['id' => $iId]);
- $oForm->initChecker($aItem);
- if($oForm->isSubmittedAndValid()) {
- if($oForm->update($aItem['id']) !== false)
- $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
- else
- $aRes = ['msg' => _t('_bx_github_err_cannot_perform_action')];
- return echoJson($aRes);
- }
- if($this->_bIsApi)
- return $this->getFormBlockAPI($oForm, $sAction, $iId);
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('apps_popup') . $sAction, _t('_bx_github_grid_popup_title_apps_' . $sAction), $this->_oModule->_oTemplate->parseHtmlByName('popup_apps.html', [
- 'form_id' => $oForm->aFormAttrs['id'],
- 'form' => $oForm->getCode(true),
- 'object' => $this->_sObject,
- 'action' => $sAction
- ]));
- echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
- }
- protected function _getCellCallbackUrl($mixedValue, $sKey, $aField, $aRow)
- {
- $mixedValue = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'authorize/' . $aRow['id'];
- return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
- }
- protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
- {
- $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(' AND `profile_id`=?', $this->_iProfileId);
- return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
- }
- protected function _getFormObject($sAction, $sDisplay, $aParams = [])
- {
- $CNF = &$this->_oModule->_oConfig->CNF;
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_APPS'], $sDisplay);
- $oForm->setId($sDisplay);
- $oForm->setName($sDisplay);
- $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', array_merge([
- 'o' => $this->_sObject,
- 'a' => $sAction,
- 'profile_id' => $this->_iProfileId
- ], $aParams)));
- return $oForm;
- }
- protected function _getId()
- {
- if(($aIds = bx_get('ids')) && is_array($aIds))
- return reset($aIds);
- if(($iId = bx_get('id')) !== false)
- return (int)$iId;
- return false;
- }
- }
- /** @} */
|