RomanL 6 лет назад
Родитель
Сommit
9a52d599b8
4 измененных файлов с 166 добавлено и 0 удалено
  1. 32 0
      inc/js/functions.js
  2. 6 0
      template/badge.html
  3. 105 0
      template/scripts/BxBaseMenuSetBadges.php
  4. 23 0
      template/scripts/BxBaseServices.php

+ 32 - 0
inc/js/functions.js

@@ -671,6 +671,38 @@ function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
     }, 'json');
     }, 'json');
 }
 }
 
 
+/**
+ * Set ACL badge for specified content
+ * @param sModule - current module for content
+ * @param iContentId - content id to set badge for
+ * @param iBadgeId - badge id to assign to a given content
+ */
+function bx_set_badge (sModule, iContentId, iBadgeId, mixedLoadingElement) {
+    
+    var bLoading = typeof(mixedLoadingElement) != 'undefined';
+    if(bLoading)
+        bx_loading($(mixedLoadingElement), true);
+    $.post(sUrlRoot + 'menu.php', {o:'sys_set_badges', module: sModule, content_id: iContentId, badge_id: iBadgeId}, function(oData) {
+        if(bLoading)
+            bx_loading($(mixedLoadingElement), false);
+
+        if(oData.msg != undefined && oData.msg.length) {
+            bx_alert(oData.msg);
+            return;
+        }
+
+        if($(mixedLoadingElement).hasClass('bx-popup-applied'))
+            $(mixedLoadingElement).dolPopupHide().remove();
+
+        if(typeof(oData.card) == 'object')
+            for(var iField in oData.card) {
+                var oCard = $(oData.card[iField]);
+                $('#' + oCard.attr('id')).replaceWith(oCard);
+            }
+    }, 'json');
+}
+
+
 function validateLoginForm(eForm) {
 function validateLoginForm(eForm) {
     return true;
     return true;
 }
 }

+ 6 - 0
template/badge.html

@@ -0,0 +1,6 @@
+<div class="bx-badge bx-def-font-small __class__" __style__ title="__title__">
+	__icon__
+	<bx_if:content>
+		<span>__content__</span>
+	</bx_if:content>
+</div>

+ 105 - 0
template/scripts/BxBaseMenuSetBadges.php

@@ -0,0 +1,105 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+/**
+ * Menu to set badges for content
+ */
+class BxBaseMenuSetBadges extends BxTemplMenu
+{
+	protected $iContentId;
+    protected $_aSelectedIds = array();
+
+    public function __construct ($aObject, $oTemplate)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+
+    public function getCode ($iContentId = 0)
+    {
+    	$this->iContentId = $iContentId;
+        if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && ($iContentId = bx_get('content_id', 'post')) && ($iBadgeId = bx_get('badge_id', 'post')) && ($sModule = bx_get('module', 'post'))) {
+            $iContentId = urldecode($iContentId);
+            $iBadgeId = urldecode($iBadgeId);
+            echoJson($this->setBadge($iContentId, $iBadgeId, $sModule));
+            exit();
+        }
+
+        return parent::getCode ();
+    }
+
+    public function getMenuItems ()
+    {
+        $this->loadData();
+        return parent::getMenuItems();
+    }
+
+    protected function loadData()
+    {
+    	$iContentId = $this->iContentId;
+        $sModule = '';
+        
+    	if(bx_get('content_id') !== false)
+        	$iContentId = bx_process_input(bx_get('content_id'), BX_DATA_INT);
+       
+        if(bx_get('module') !== false)
+        	$sModule = bx_process_input(bx_get('module'));
+
+        $oBadges = BxDolBadges::getInstance();
+		$aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $iContentId, 'module' => $sModule));
+        
+        $aItems = array();
+        foreach ($aBadges as $aBadge) {
+            $aItems[] = array(
+                'id' => $aBadge['id'],
+                'name' => $aBadge['id'],
+                'class' => '',
+                'title' => BxDolService::call('system', 'get_badge', array($aBadge), 'TemplServices'),
+                'icon' => '',//$aBadge['icon'],
+                'selected' => true,
+                'link' => 'javascript:void(0);',
+                'onclick' => "bx_set_badge('" . $sModule . "', " . $iContentId . ", {$aBadge['id']}, " . bx_js_string("$(this).parents('.bx-popup-applied:first')") . ");"
+            );
+            if ($aBadge['badge_id'] != ''){
+                array_push($this->_aSelectedIds, $aBadge['id']);
+            }
+        }
+        
+        $this->_aObject['menu_items'] = $aItems;
+    }
+
+    protected function setBadge($iContentId, $iBadgeId , $sModule)
+    {
+		$iPerformerId = bx_get_logged_profile_id();
+        $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
+        if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
+            return array('code' => 1, 'msg' => $aCheck[CHECK_ACTION_MESSAGE]);
+        
+        $oBadges = BxDolBadges::getInstance();
+        $aBadges = $oBadges->getData(array('type' => 'by_module&object&badge', 'object_id' => $iContentId, 'module' => $sModule, 'badge_id' => $iBadgeId));
+        if(count($aBadges) > 0)
+            $oBadges->delete(array('type' => 'by_module&object&badge', 'module'=> $sModule, 'object_id' => $iContentId, 'badge_id' => $iBadgeId));
+        else
+            $oBadges->add($iBadgeId, $iContentId, $sModule);
+        
+        checkActionModule($iPerformerId, 'set badge', 'system', true); // perform action
+        
+        $aResult = array('code' => 0);
+        
+        return $aResult;
+    }
+    
+    protected function _isSelected ($a)
+    {
+        if (isset($a['name']) &&  in_array($a['name'], $this->_aSelectedIds))
+            return true;
+        return false;
+    }
+}
+
+/** @} */

+ 23 - 0
template/scripts/BxBaseServices.php

@@ -408,6 +408,29 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
 
 
         return $aResults;
         return $aResults;
     }
     }
+    
+    public function serviceGetBadge($aBadge, $isCompact = false)
+    {
+        $sClass = '';
+        if ($isCompact){
+            $aBadge['is_icon_only'] = 1;
+        }
+        if ($aBadge['is_icon_only'] == 1){
+            $sClass = 'bx-badge-compact';
+        }
+        
+        return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
+            'bx_if:content' => array(
+                'condition' => $aBadge['is_icon_only'] != '1',
+                'content' => array('content' => _t($aBadge['text'])),
+            ),
+            'title' => $aBadge['text'],
+            'icon' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon')),
+            'style' => $aBadge['color'] != '' ? 'style = "background-color: ' . $aBadge['color'] . '"' : '',
+            'class' => $sClass,
+            )
+    	);
+    }
 }
 }
 
 
 /** @} */
 /** @} */