Procházet zdrojové kódy

#100 - Administration Tools

AntonLV před 12 roky
rodič
revize
c582f9771e

+ 1 - 0
grid.php

@@ -8,6 +8,7 @@
  */
 
 require_once('./inc/header.inc.php');
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 require_once(BX_DIRECTORY_PATH_INC . "utils.inc.php");
 
 bx_import('BxDolLanguages');

+ 19 - 0
modules/base/general/classes/BxBaseModGeneralConfig.php

@@ -15,10 +15,29 @@ class BxBaseModGeneralConfig extends BxDolModuleConfig
 {
     public $CNF;
 
+    protected $_aJsClass;
+    protected $_aJsObjects;
+    protected $_aGridObjects;
+
     function __construct($aModule)
     {
         parent::__construct($aModule);
     }
+
+	public function getJsClass($sType)
+    {
+        return isset($this->_aJsClass[$sType]) ? $this->_aJsClass[$sType] : '';
+    }
+
+    public function getJsObject($sType)
+    {
+		return isset($this->_aJsObjects[$sType]) ? $this->_aJsObjects[$sType] : '';
+    }
+
+    public function getGridObject($sType)
+    {
+		return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
+    }
 }
 
 /** @} */

+ 78 - 0
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -0,0 +1,78 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseGeneral Base classes for modules
+ * @ingroup     DolphinModules
+ * @{
+ */
+
+bx_import('BxDolModule');
+bx_import('BxTemplGrid');
+
+class BxBaseModGeneralGridAdministration extends BxTemplGrid
+{
+	protected $MODULE;
+	protected $_oModule;
+
+	protected $_sManageType;
+	protected $_sParamsDivider;
+
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+        
+        $this->_sManageType = 'administration';
+        $this->_sParamsDivider = '#-#';
+    }
+
+    public function _getFilterSelectOne($sFilterName, $aFilterValues)
+    {
+        if(empty($sFilterName) || empty($aFilterValues))
+            return '';
+
+		$sJsObject = $this->_oModule->_oConfig->getJsObject($this->_sManageType);
+
+		$sFilterField = '_s' . str_replace(' ', '', ucwords(str_replace('_', ' ', $sFilterName)));
+		foreach($aFilterValues as $sKey => $sValue)
+			$aFilterValues[$sKey] = _t($sValue);
+
+        $aInputModules = array(
+            'type' => 'select',
+            'name' => $sFilterName,
+            'attrs' => array(
+                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
+                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
+            ),
+            'value' => $this->$sFilterField,
+            'values' => array_merge(array('' => _t('_bx_persons_grid_filter_item_title_adm_select_one')), $aFilterValues)
+        );
+
+        bx_import('BxTemplFormView');
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInputModules);
+    }
+
+	protected function _getSearchInput()
+    {
+        $sJsObject = $this->_oModule->_oConfig->getJsObject($this->_sManageType);
+
+        $aInputSearch = array(
+            'type' => 'text',
+            'name' => 'search',
+            'attrs' => array(
+                'id' => 'bx-grid-search-' . $this->_sObject,
+                'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $sJsObject . '.onChangeFilter(this)'
+            )
+        );
+
+		bx_import('BxTemplFormView');
+        $oForm = new BxTemplFormView(array());
+        return $oForm->genRow($aInputSearch);
+    }
+}
+
+/** @} */

+ 13 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -53,6 +53,19 @@ class BxBaseModGeneralModule extends BxDolModule
 
     // ====== SERVICE METHODS
 
+	public function serviceManageEntities($sType)
+    {
+    	bx_import('BxDolGrid');
+        $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
+        if(!$oGrid)
+            return '';
+
+        $this->_oTemplate->addCss(array($sType . '.css'));
+        $this->_oTemplate->addJs(array($sType . '.js'));
+        $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
+        return $this->_oTemplate->getJsCode($sType) . $oGrid->getCode();
+    }
+
     /**
      * Add entry form
      * @return HTML string

+ 18 - 0
modules/base/general/classes/BxBaseModGeneralTemplate.php

@@ -23,6 +23,24 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
         parent::__construct($oConfig, $oDb);
         $this->addCss ('main.css');
     }
+
+	public function getJsCode($sType, $aRequestParams = array(), $bWrap = true)
+    {
+        $sBaseUri = $this->_oConfig->getBaseUri();
+        $sJsClass = $this->_oConfig->getJsClass($sType);
+        $sJsObject = $this->_oConfig->getJsObject($sType);
+
+        $aParams = array(
+            'sActionUri' => $sBaseUri,
+            'sActionUrl' => BX_DOL_URL_ROOT . $sBaseUri,
+            'sObjName' => $sJsObject,
+        	'sObjNameGrid' => $this->_oConfig->getGridObject($sType),
+            'oRequestParams' => !empty($aRequestParams) ? $aRequestParams : array()
+        );
+        $sContent = "var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode($aParams) . ");";
+
+        return !$bWrap ? $sContent : $this->_wrapInTagJsCode($sContent);
+    }
 }
 
 /** @} */

+ 15 - 0
modules/base/general/template/css/administration.css

@@ -0,0 +1,15 @@
+/*--- General ---*/
+div.bx-grid-header div.bx-form-element-wrapper {
+    position: relative;
+    float: left;
+    width: 165px;
+}
+
+/*--- Administration tools ---*/
+div.bx-grid-header div#bx-form-element-filter1 {
+    margin-right: 20px;
+}
+div.bx-grid-header div#bx-form-element-filter1,
+div.bx-grid-header div#bx-form-element-search {
+    margin-top: 0px;
+}

+ 1 - 0
modules/base/general/template/css/moderation.css

@@ -0,0 +1 @@
+@import url(administration.css);

+ 104 - 0
modules/base/profile/classes/BxBaseModProfileGridAdministration.php

@@ -0,0 +1,104 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseGeneral Base classes for modules
+ * @ingroup     DolphinModules
+ * 
+ * @{
+ */
+
+bx_import('BxBaseModGeneralGridAdministration');
+
+class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministration
+{
+	protected $_sFilter1;
+
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+    	$sFilter1 = bx_get('filter1');
+        if(!empty($sFilter1)) {
+            $this->_sFilter1 = bx_process_input($sFilter1);
+            $this->_aQueryAppend['filter1'] = $this->_sFilter1;
+        }
+    }
+
+	public function performActionDelete()
+    {
+        $iAffected = 0;
+        $aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) {
+            $this->_echoResultJson(array());
+            exit;
+        }
+
+        $aIdsAffected = array ();
+        foreach($aIds as $iId) {
+        	$oProfile = BxDolProfile::getInstanceByContentAndType((int)$iId, $this->_oModule->_oConfig->getName());
+
+        	if((int)$this->_delete($iId) == 0)
+                continue;
+
+        	if(!$oProfile->delete())
+        		continue;
+
+            $aIdsAffected[] = $iId;
+            $iAffected++;
+        }
+
+        $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_adm_nav_err_menus_delete')));
+    }
+
+	protected function _switcherChecked2State($isChecked)
+    {
+        return $isChecked ? 'active' : 'suspended';
+    }
+
+    protected function _switcherState2Checked($mixedState)
+    {
+        return 'active' == $mixedState ? true : false;
+    }
+
+    protected function _enable ($mixedId, $isChecked)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("UPDATE `sys_profiles` SET `status` = ? WHERE `content_id` = ? AND `type` = ?", $this->_switcherChecked2State($isChecked), $mixedId, $this->_oModule->_oConfig->getName());
+        return $oDb->query($sQuery);
+    }
+
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    {
+        if(strpos($sFilter, $this->_sParamsDivider) !== false)
+            list($this->_sFilter1, $sFilter) = explode($this->_sParamsDivider, $sFilter);
+
+    	if(!empty($this->_sFilter1))
+        	$this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `tp`.`status`=?", $this->_sFilter1);
+
+        return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
+    }
+
+    //--- Layout methods ---//
+	protected function _getFilterControls()
+    {
+        parent::_getFilterControls();
+
+        $sFilterName = 'filter1';
+        $aFilterValues = array(
+			'active' => '_bx_persons_grid_filter_item_title_adm_active',
+            'pending' => '_bx_persons_grid_filter_item_title_adm_pending',
+            'suspended' => '_bx_persons_grid_filter_item_title_adm_suspended',
+		);
+
+        return  $this->_getFilterSelectOne($sFilterName, $aFilterValues) . $this->_getSearchInput();
+    }
+
+    protected function _getCellLastOnline($mixedValue, $sKey, $aField, $aRow)
+    {
+        return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
+    }
+}
+
+/** @} */

+ 29 - 0
modules/base/profile/classes/BxBaseModProfileGridModeration.php

@@ -0,0 +1,29 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseGeneral Base classes for modules
+ * @ingroup     DolphinModules
+ * 
+ * @{
+ */
+
+bx_import('BxBaseModProfileGridAdministration');
+
+class BxBaseModProfileGridModeration extends BxBaseModProfileGridAdministration
+{
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+        $this->_sManageType = 'moderation';
+    }
+
+	public function performActionDelete()
+    {
+        $this->_echoResultJson(array());
+    }
+}
+
+/** @} */