Alex Trofimov 11 лет назад
Родитель
Сommit
f5ff550415

+ 97 - 0
inc/classes/BxDolCategory.php

@@ -0,0 +1,97 @@
+<?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    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @page objects
+ * @section category Category
+ * @ref BxDolCategory
+ */
+
+/**
+ * Categories object, make to look form lists as categories by making it clickable and display search results with all contents with the same category
+ */
+class BxDolCategory extends BxDol implements iBxDolFactoryObject
+{
+    protected $_sObject;
+    protected $_aObject;
+
+    /**
+     * Constructor
+     * @param $aObject array of editor options
+     */
+    public function __construct($aObject)
+    {
+        parent::__construct();
+
+        $this->_sObject = $aObject['object'];
+        $this->_aObject = $aObject;
+    }
+
+    /**
+     * Get category object instance by object name
+     * @param $sObject object name
+     * @return object instance or false on error
+     */
+    static public function getObjectInstance($sObject = false)
+    {
+        if (isset($GLOBALS['bxDolClasses']['BxDolCategory!'.$sObject]))
+            return $GLOBALS['bxDolClasses']['BxDolCategory!'.$sObject];
+
+        $aObject = BxDolCategoryQuery::getCategoryObject($sObject);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        $sClass = 'BxTemplCategory';
+        if (!empty($aObject['override_class_name']))
+            $sClass = $aObject['override_class_name'];
+        if (!empty($aObject['override_class_file']))
+            require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
+
+        $o = new $sClass($aObject);
+
+        return ($GLOBALS['bxDolClasses']['BxDolCategory!'.$sObject] = $o);
+    }
+
+    /**
+     * Get category object instance by form object and list name
+     * @param $sObjectForm form object name
+     * @patam $sListName list name
+     * @return object instance or false on error
+     */
+    static public function getObjectInstanceByFormAndList($sObjectForm, $sListName)
+    {
+        $aObject = BxDolCategoryQuery::getCategoryObjectByFormAndList($sObjectForm, $sListName);
+        return self::getObjectInstance($aObject['object']);
+    }
+
+    /**
+     * Get object name 
+     */
+    public function getObjectName()
+    {
+        return $this->_sObject;
+    }
+
+    /**
+     * Set condition for search results object for category object
+     * @param $oSearchResult search results object
+     * @param $mixedCategory category
+     */
+    public function setSearchCondition($oSearchResult, $mixedCategory)
+    {
+        $oSearchResult->aCurrent['restriction']['category_' . $this->_sObject] = array(
+            'value' => $mixedCategory,
+            'field' => $this->_aObject['field'],
+            'operator' => '=',
+            'table' => $this->_aObject['table'],
+        );
+    }
+}
+
+/** @} */

+ 47 - 0
inc/classes/BxDolCategoryQuery.php

@@ -0,0 +1,47 @@
+<?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    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * Database queries for category objects.
+ * @see BxDolCategory
+ */
+class BxDolCategoryQuery extends BxDolDb
+{
+    protected $_aObject;
+
+    public function __construct($aObject)
+    {
+        parent::__construct();
+        $this->_aObject = $aObject;
+    }
+
+    static public function getCategoryObject ($sObject)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_category` WHERE `object` = ?", $sObject);
+        $aObject = $oDb->getRow($sQuery);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        return $aObject;
+    }
+
+    static public function getCategoryObjectByFormAndList ($sObjectForm, $sListName)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_category` WHERE `form_object` = ? AND `list_name` = ?", $sObjectForm, $sListName);
+        $aObject = $oDb->getRow($sQuery);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        return $aObject;
+    }
+}
+
+/** @} */

+ 1 - 0
inc/classes/BxDolFormQuery.php

@@ -116,6 +116,7 @@ class BxDolFormQuery extends BxDolDb
 
             if (!empty($a['values'])) {
                 if (0 == strncmp(BX_DATA_LISTS_KEY_PREFIX, $a['values'], 2)) {
+                    $aInput['values_list_name'] = trim($a['values'], BX_DATA_LISTS_KEY_PREFIX . ' ');
                     $aInput['values'] = self::getDataItems(trim($a['values'], BX_DATA_LISTS_KEY_PREFIX . ' '), isset(self::$TYPES_SET[$aInput['type']]));
                 } else {
                     $aInput['values'] = unserialize($a['values']);

+ 18 - 0
inc/classes/BxDolSearch.php

@@ -48,6 +48,7 @@ class BxDolSearch extends BxDol
 
     protected $_bLiveSearch = false;
     protected $_sMetaType = '';
+    protected $_sCategoryObject = '';
 
     /**
      * Constructor
@@ -99,6 +100,7 @@ class BxDolSearch extends BxDol
             $oEx->setId($aValue['id']);
             $oEx->setLiveSearch($this->_bLiveSearch);
             $oEx->setMetaType($this->_sMetaType);
+            $oEx->setCategoryObject($this->_sCategoryObject);
             $oEx->setCenterContentUnitSelector(false);
             $sCode .= $oEx->processing();
         }
@@ -133,6 +135,10 @@ class BxDolSearch extends BxDol
             $this->_sMetaType = $s;
     }
 
+    public function setCategoryObject($s)
+    {
+        $this->_sCategoryObject = $s;
+    }
 }
 
 /*
@@ -255,6 +261,7 @@ class BxDolSearchResult implements iBxDolReplaceable
 
     protected $_bLiveSearch = false;
     protected $_sMetaType = '';
+    protected $_sCategoryObject = '';
 
     protected $_aMarkers = array (); ///< markers to replace somewhere, usually title and browse url (defined in custom class)
 
@@ -293,6 +300,11 @@ class BxDolSearchResult implements iBxDolReplaceable
         $this->_sMetaType = $s;
     }
 
+    public function setCategoryObject($s)
+    {
+        $this->_sCategoryObject = $s;
+    }
+
     /**
      * Display empty message if there is no content, custom empty message can be used.
      * @param $b - boolan value to enable or disable 'empty' message
@@ -613,6 +625,12 @@ class BxDolSearchResult implements iBxDolReplaceable
             }
         }
 
+        // category
+        if ($this->_sCategoryObject && $o = BxDolCategory::getObjectInstance($this->_sCategoryObject)) {
+            unset($this->aCurrent['restriction']['keyword']);
+            $o->setSearchCondition($this, $sKeyword);
+        }
+
         $this->setPaginate();
         $iNum = $this->getNum();
         if ($iNum > 0) {

+ 17 - 0
modules/boonex/lagoon/data/template/system/scripts/BxTemplCategory.php

@@ -0,0 +1,17 @@
+<?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    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolCategory
+ */
+class BxTemplCategory extends BxBaseCategory
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplCategory.php

@@ -0,0 +1,17 @@
+<?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    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolCategory
+ */
+class BxTemplCategory extends BxBaseCategory
+{
+}
+
+/** @} */

+ 1 - 0
searchKeyword.php

@@ -13,6 +13,7 @@ require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 $oSearch = new BxTemplSearch(bx_get('section'));
 $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
 $oSearch->setMetaType(bx_process_input(bx_get('type')));
+$oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
 
 $sCode = '';
 if (bx_get('keyword')) {

+ 1 - 0
searchKeywordContent.php

@@ -15,6 +15,7 @@ bx_import('BxDolLanguages');
 $o = new BxDolSearch(bx_get('section'));
 $o->setLiveSearch(bx_get('live_search') ? 1 : 0);
 $o->setMetaType(bx_process_input(bx_get('type')));
+$o->setCategoryObject(bx_process_input(bx_get('cat')));
 
 $s = $o->response();
 if (!$s)

+ 54 - 0
template/scripts/BxBaseCategory.php

@@ -0,0 +1,54 @@
+<?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    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * Category objects representation.
+ * @see BxDolCategory
+ */
+class BxBaseCategory extends BxDolCategory
+{
+    protected $_oTemplate;
+
+    public function __construct ($aObject, $oTemplate = null)
+    {
+        parent::__construct ($aObject);
+
+        if ($oTemplate)
+            $this->_oTemplate = $oTemplate;
+        else
+            $this->_oTemplate = BxDolTemplate::getInstance();
+    }
+
+    public function getCategoryUrl($sName, $sValue, $sCategoryObject)
+    {
+        $sUrl = BX_DOL_URL_ROOT . 'searchKeyword.php?cat=' . rawurlencode($sCategoryObject) . '&keyword=' . rawurlencode($sValue);
+        if ($this->_aObject['search_object'])
+            $sUrl .= '&section[]=' . rawurlencode($this->_aObject['search_object']);
+        return $sUrl;
+    }
+
+    /**
+     * Get link to list all items with the same category
+     */
+    public function getCategoryLink($sName, $sValue, $sCategoryObject)
+    {
+        $sUrl = $this->getCategoryUrl($sName, $sValue, $sCategoryObject);
+        return '<a href="' . $sUrl . '">' . $sName . '</a>';
+    }
+
+    /**
+     * Get all categories list
+     */
+    public function getCategoriesList()
+    {
+        // TODO:
+    }
+}
+
+/** @} */

+ 9 - 1
template/scripts/BxBaseFormView.php

@@ -306,7 +306,7 @@ EOS;
 
             case 'select':
             case 'radio_set':
-                $sValue = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
+                $sValue = $this->genViewRowValueForSelect($aInput);
             break;
 
             case 'datepicker':
@@ -349,6 +349,14 @@ EOS;
         return $sValue;
     }
 
+    function genViewRowValueForSelect(&$aInput)
+    {
+        $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
+        if (isset($aInput['values_list_name'])  && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])))
+            return $oCategory->getCategoryLink($s, $aInput['value'], $oCategory->getObjectName());
+        return $s;
+    }
+
     /**
      * Generate standard row
      *

+ 1 - 1
template/scripts/BxBaseSearch.php

@@ -25,7 +25,7 @@ class BxBaseSearch extends BxDolSearch
 
     public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false)
     {
-        if ($this->_sMetaType)
+        if ($this->_sMetaType || $this->_sCategoryObject)
             return '';
 
         if (false === $sTitle)