Przeglądaj źródła

#2431 studio & install changes

RomanL 6 lat temu
rodzic
commit
c6dd519571

+ 5 - 0
inc/classes/BxDolBadges.php

@@ -41,6 +41,11 @@ class BxDolBadges extends BxDolFactory implements iBxDolSingleton
     {
         return $this->_oDb->delete($iID);
     }
+    
+    public function add($iBadgeId, $iObjectId, $sModule)
+    {
+        return $this->_oDb->add($iBadgeId, $iObjectId, $sModule);
+    }
 }
 
 /** @} */

+ 69 - 3
inc/classes/BxDolBadgesQuery.php

@@ -28,7 +28,7 @@ class BxDolBadgesQuery extends BxDolDb
         $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
 
         $sSelectClause = "`sc`.*";
-        $sJoinClause = $sWhereClause = $sGroupClause = "";
+        $sJoinClause = $sWhereClause = $sGroupClause = $sLimitClause = "";
         $sOrderClause = "`sc`.`added` ASC";
 
         if(isset($aParams['count_only']) && $aParams['count_only'] === true) {
@@ -45,6 +45,52 @@ class BxDolBadgesQuery extends BxDolDb
                 $sJoinClause = "LEFT JOIN `sys_badges2objects` `soc` ON `sc`.`id` =  `soc`.`badge_id`";
                 $sGroupClause = "`sc`.`module`";
                 break;
+              
+            case 'by_module&object':
+                $aMethod['name'] = 'getAll';
+                $sSelectClause = "`sc`.`id`, `sc`.`id`, `sc`.`text`, `sc`.`color`, `sc`.`is_icon_only`, `sc`.`icon`, `soc`.`id` AS `badge_id`";
+                $sJoinClause = "LEFT JOIN `sys_badges2objects` `soc` ON `sc`.`id` =  `soc`.`badge_id` AND `soc`.`object_id` = :object_id";
+                $sWhereClause = " AND `sc`.`module` = :module";
+                $aMethod['params'][1] = array(
+                    'object_id' => $aParams['object_id'],
+                    'module' => $aParams['module']
+                );
+                break;
+                
+            case 'by_module&object2':
+                $aMethod['name'] = 'getAll';
+                $sSelectClause = "`sc`.`id`, `sc`.`id`, `sc`.`text`, `sc`.`color`, `sc`.`is_icon_only`, `sc`.`icon`, `soc`.`id` AS `badge_id`";
+                $sJoinClause = "INNER JOIN `sys_badges2objects` `soc` ON `sc`.`id` =  `soc`.`badge_id` AND `soc`.`object_id` = :object_id";
+                $sWhereClause = " AND `sc`.`module` = :module";
+                $aMethod['params'][1] = array(
+                    'object_id' => $aParams['object_id'],
+                    'module' => $aParams['module']
+                );
+                break;
+                
+            case 'by_module&object2_single':
+                $aMethod['name'] = 'getAll';
+                $sSelectClause = "`sc`.`id`, `sc`.`id`, `sc`.`text`, `sc`.`color`, `sc`.`is_icon_only`, `sc`.`icon`, `soc`.`id` AS `badge_id`";
+                $sJoinClause = "INNER JOIN `sys_badges2objects` `soc` ON `sc`.`id` =  `soc`.`badge_id` AND `soc`.`object_id` = :object_id";
+                $sWhereClause = " AND `sc`.`module` = :module";
+                $sLimitClause = "LIMIT 0, 1";
+                $aMethod['params'][1] = array(
+                    'object_id' => $aParams['object_id'],
+                    'module' => $aParams['module']
+                );
+                break;
+                
+            case 'by_module&object&badge':
+                $aMethod['name'] = 'getAll';
+                $sSelectClause = "`sc`.`id`, `sc`.`id`, `sc`.`text`, `sc`.`icon`, `soc`.`id` AS `badge_id`";
+                $sJoinClause = "INNER JOIN `sys_badges2objects` `soc` ON `sc`.`id` =  `soc`.`badge_id` AND `soc`.`object_id` = :object_id";
+                $sWhereClause = " AND `sc`.`module` = :module  AND `sc`.`id` = :badge_id";
+                $aMethod['params'][1] = array(
+                    'object_id' => $aParams['object_id'],
+                    'badge_id' => $aParams['badge_id'],
+                    'module' => $aParams['module']
+                );
+                break;
                 
             case 'id':
             	$aMethod['name'] = 'getRow';
@@ -64,7 +110,7 @@ class BxDolBadgesQuery extends BxDolDb
 
         $aMethod['params'][0] = "SELECT " . $sSelectClause . " 
             FROM `" . $this->_sTableBadges . "` AS `sc`" . $sJoinClause . " 
-            WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
+            WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause. " " . $sLimitClause;
         $oRv = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
         if ($aItems === false)
             return $oRv;
@@ -78,6 +124,18 @@ class BxDolBadgesQuery extends BxDolDb
         return $this->query($sSql);
     }
     
+    function add($iBadgeId, $iObjectId, $sModule)
+    {
+        $sSql = "INSERT `sys_badges2objects` (`badge_id`, `object_id`, `added`, `module`) VALUES (:badge_id, :object_id, :added, :module)";
+        $aBindings = array(
+            'badge_id' => $iBadgeId,
+            'object_id' => $iObjectId,
+            'added' => time(),
+            'module' => $sModule,
+        );
+        return $this->query($sSql, $aBindings);
+    }
+    
     public function delete($aParams = array())
     {
         switch($aParams['type']) {
@@ -88,13 +146,21 @@ class BxDolBadgesQuery extends BxDolDb
                 );
                 break;
                 
-            case 'by_module_and_object':
+            case 'by_module&object':
                 $sQuery = " WHERE `module` = :module AND object_id = :object_id";
                 $aBindings = array(
                     'module' => $aParams['module'],
                     'object_id' => $aParams['object_id'],
                 );
                 break;
+            case 'by_module&object&badge':   
+                $sQuery = " WHERE `module` = :module AND object_id = :object_id AND badge_id = :badge_id";
+                $aBindings = array(
+                    'module' => $aParams['module'],
+                    'object_id' => $aParams['object_id'],
+                    'badge_id' => $aParams['badge_id'],
+                );
+                break;
         }
         
         $sQuery = "DELETE FROM `sys_badges2objects`" . $sQuery;

+ 8 - 5
install/sql/system.sql

@@ -1607,7 +1607,9 @@ CREATE TABLE `sys_badges` (
   `added` int(11) NOT NULL, 
   `module` varchar(32) NOT NULL default '',
   `text` varchar(255) NOT NULL default '',
-  `icon` varchar(255) NOT NULL,
+  `icon` varchar(255) NOT NULL default '',
+  `color` varchar(32) NOT NULL default '',
+  `is_icon_only` tinyint(4) NOT NULL default '1',
   PRIMARY KEY (`id`)
 );
 
@@ -4109,10 +4111,11 @@ INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable
 ('sys_audit_administration', 'action', '_adm_pgt_txt_audit_action', '15%', 1, 25, '', 6),
 
 ('sys_badges_administration', 'checkbox', '_sys_select', '2%', 0, 0, '', 1),
-('sys_badges_administration', 'module', '_adm_form_txt_badges_module', '20%', 1, 25, '', 2),
-('sys_badges_administration', 'text', '_adm_pgt_txt_badges_text', '38%', 1, 25, '', 3),
-('sys_badges_administration', 'icon', '_adm_pgt_txt_badges_icon', '20%', 1, 25, '', 4),
-('sys_badges_administration', 'actions', '', '20%', 0, 0, '', 5);
+('sys_badges_administration', 'view', '_adm_form_txt_badges_view', '15%', 1, 0, '', 2),
+('sys_badges_administration', 'module', '_adm_form_txt_badges_module', '15%', 1, 25, '', 3),
+('sys_badges_administration', 'text', '_adm_pgt_txt_badges_text', '28%', 1, 35, '', 4),
+('sys_badges_administration', 'icon', '_adm_pgt_txt_badges_icon', '20%', 1, 0, '', 5),
+('sys_badges_administration', 'actions', '', '20%', 0, 0, '', 6);
 
 
 CREATE TABLE IF NOT EXISTS `sys_grid_actions` (

+ 44 - 4
studio/template/css/badges.css

@@ -48,14 +48,54 @@ div#bx-form-element-type .bx-menu-ver .bx-def-hr {
 div#bx-form-element-info textarea.bx-form-input-textarea {
 	height: 53px;
 }
-img.bx-nav-badge-icon {
-    width: 32px;
-    height: 32px;
-}
 div.bx-badge-item-icon-preview img {
     max-width: 128px;
     max-height: 128px;
 }
+div.bx-badge {
+	display: flex;
+    align-items:center;
+	text-align: center;
+    background:#ff0000;
+    color:#fff;	
+	width: 150px;
+	vertical-align: middle;
+	height: 1.25rem;
+	line-height: 1.25rem;
+	padding: 0.25rem 0.5rem ;
+	border-radius: 1em;
+	white-space: nowrap; 
+	text-overflow: ellipsis; 
+    overflow: hidden;
+}
+img.bx-badge-icon {
+    width: 20px;
+    height: 20px;
+}
+div.bx-badge img{
+
+	margin-right: 0.25rem;
+}
+div.bx-badge span{
+	text-overflow: ellipsis; 
+    overflow: hidden;
+}
+div.bx-badge .sys-icon{
+	color:#fff;
+	font-size: 1.25rem;
+	margin-right: 0.25rem;
+}
+div.bx-badge.bx-badge-compact{
+	width: 1.25rem;
+	text-align: center;
+}
+div.bx-badge.bx-badge-compact .sys-icon{
+	width: 1.25rem;
+}
+div.bx-badge.bx-badge-compact .sys-icon,
+div.bx-badge.bx-badge-compact img{
+	margin-right: 0;
+}
 
 /*--- Pre Lists page -> Add/Edit Form block ---*/
 div.bx-form-add-list {}

+ 45 - 6
studio/template/scripts/BxBaseStudioBadgesGrid.php

@@ -89,7 +89,6 @@ class BxBaseStudioBadgesGrid extends BxDolStudioBadgesGrid
         $oForm = $this->_getForm($sAction, $aBadge);
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
-            
             $bIconImageCur = is_numeric($aBadge['icon']) && (int)$aBadge['icon'] != 0;
             $bIconImageNew = !empty($_FILES['icon_image']['tmp_name']);
 
@@ -115,11 +114,10 @@ class BxBaseStudioBadgesGrid extends BxDolStudioBadgesGrid
 
                 $oStorage->afterUploadCleanup($sIcon, 0);
             } else if($bIconImageCur && !$bIconFont)
-                $sIcon = $aItem['icon'];
-
+                $sIcon = $aBadge['icon'];
+           
             BxDolForm::setSubmittedValue('icon', $sIcon, $oForm->aFormAttrs['method']);
             
-            
             $mixedResult = $oForm->update($iId);
             if(is_numeric($mixedResult))
                 $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
@@ -194,6 +192,18 @@ class BxBaseStudioBadgesGrid extends BxDolStudioBadgesGrid
         ));
     }
     
+    protected function _getCellModule ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $oModule = bxDolModule::getInstance($aRow['module']);
+        if($oModule && $oModule instanceof iBxDolContentInfoService){
+            $mixedValue = $oModule->_aModule['title'];
+        }
+        else{
+            $mixedValue = $aRow['module'];
+        }
+        return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
+    }
+    
     protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
     {
         return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
@@ -206,7 +216,13 @@ class BxBaseStudioBadgesGrid extends BxDolStudioBadgesGrid
     
     protected function _getCellIcon ($mixedValue, $sKey, $aField, $aRow)
     {
-        $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-nav-badge-icon bx-def-border'));
+        $mixedValue = $this->_oTemplate->getIcon($mixedValue, array('class' => 'bx-badge-icon bx-def-border'));
+        return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
+    }
+    
+    protected function _getCellView ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $mixedValue = BxDolService::call('system', 'get_badge', array($aRow), 'TemplServices');
         return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
     }
          
@@ -311,13 +327,36 @@ class BxBaseStudioBadgesGrid extends BxDolStudioBadgesGrid
                     'type' => 'text',
                     'name' => 'text',
                     'caption' => _t('_adm_form_txt_badges_text'),
-                    'info' => _t('_adm_form_dsc_badges_icon'),
+                    'info' => '',
                     'value' => isset($aBadge['text']) ? $aBadge['text'] : '',
                     'required' => '1',
                     'db' => array (
                         'pass' => 'Xss',
                     )
                 ),
+                'color' => array(
+                    'type' => 'rgb',
+                    'name' => 'color',
+                    'caption' => _t('_adm_form_txt_badges_color'),
+                    'info' => '',
+                    'value' => isset($aBadge['color']) ? $aBadge['color'] : '',
+                    'required' => '1',
+                    'db' => array (
+                        'pass' => 'Xss',
+                    )
+                ),
+                'is_icon_only' => array(
+                    'type' => 'switcher',
+                    'name' => 'is_icon_only',
+                    'caption' => _t('_adm_form_txt_badges_is_icon_only'),
+                    'info' => '',
+                    'value' => '1',
+                    'checked' => isset($aBadge['is_icon_only']) && $aBadge['is_icon_only'] == '1',
+                    'required' => '0',
+                    'db' => array (
+                        'pass' => 'Xss',
+                    )
+                ),
                 'icon' => array(
                     'type' => 'text',
                     'name' => 'icon',