Przeglądaj źródła

Ticket #657 - Search in Grids and related changes.

AntonLV 9 lat temu
rodzic
commit
3874a51e35

+ 1 - 1
inc/classes/BxDolCmts.php

@@ -936,7 +936,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
         $this->setId($aComment['cmt_object_id']);
 
-        return $aComment;
+        return BxDolContentInfo::formatFields($aComment);
     }
 
     public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')

+ 71 - 6
inc/classes/BxDolContentInfo.php

@@ -41,20 +41,22 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
 
     protected $_sSystem;
     protected $_aSystem;
+    protected $_aGrid;
 
     protected function __construct($sSystem)
     {
         parent::__construct();
 
+        if(empty($sSystem))
+            return;
+
         $aSystems = $this->getSystems();
         if(!isset($aSystems[$sSystem]))
             return;
 
         $this->_sSystem = $sSystem;
         $this->_aSystem = $aSystems[$sSystem];
-
-        if(empty($this->_sSystem))
-            return;
+        $this->_aGrid = array();
     }
 
    /**
@@ -130,10 +132,32 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
         return self::getObjectInstanceByAlertCommon('delete', $sUnit, $sAction);
     }
 
+	/**
+     * get content info object instance (for internal usage). 
+     * @see self::getObjectInstanceByAlertAdd, self::getObjectInstanceByAlertUpdate and self::getObjectInstanceByAlertDelete
+     * @param $sAlertType alert type (add, update, delete)
+     * @param $sUnit alert unit
+     * @param $sAction alert action
+     * @return null on error, or ready to use class instance
+     */
+    public static function getObjectInstanceByGrid($sGrid)
+    {
+        $aGrids = self::getGrids();
+        if(!isset($aGrids[$sGrid]))
+            return null;
+
+        $oObject = self::getObjectInstance($aGrids[$sGrid]['object']);
+        $oObject->setGrid($aGrids[$sGrid]);
+
+        return $oObject;
+    }
+
     public static function &getSystems()
     {
-        if(!isset($GLOBALS['bx_dol_content_info_systems']))
-            $GLOBALS['bx_dol_content_info_systems'] = BxDolDb::getInstance()->fromCache('sys_objects_content_info', 'getAllWithKey', '
+        $sKey = 'bx_dol_content_info_systems';
+
+        if(!isset($GLOBALS[$sKey]))
+            $GLOBALS[$sKey] = BxDolDb::getInstance()->fromCache('sys_objects_content_info', 'getAllWithKey', '
                 SELECT
                     `id` as `id`,
                     `name` AS `name`,
@@ -146,7 +170,25 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
                     `class_file` AS `class_file`
                 FROM `sys_objects_content_info`', 'name');
 
-        return $GLOBALS['bx_dol_content_info_systems'];
+        return $GLOBALS[$sKey];
+    }
+
+    public static function &getGrids()
+    {
+        $sKey = 'bx_dol_content_info_grids';
+
+        if(!isset($GLOBALS[$sKey]))
+            $GLOBALS[$sKey] = BxDolDb::getInstance()->fromCache('sys_objects_content_info_grids', 'getAllWithKey', '
+                SELECT
+                    `id` as `id`,
+                    `object` AS `object`,
+                    `grid_object` AS `grid_object`,
+                    `grid_field_id` AS `grid_field_id`,
+                    `condition` AS `condition`,
+                    `selection` AS `selection`
+                FROM `sys_content_info_grids`', 'grid_object');
+
+        return $GLOBALS[$sKey];
     }
 
     public static function &getSystemsByAlertType($sAlertType)
@@ -162,6 +204,24 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
         return $GLOBALS[$sKey];
     }
 
+    public static function formatFields($aContentInfo)
+    {
+        foreach ($aContentInfo as $sKey => $mixedValue)
+            if(is_numeric($mixedValue)) {
+                if(strpos($mixedValue, '.') !== false)
+                    $aContentInfo[$sKey] = (float)$mixedValue;
+                else 
+                    $aContentInfo[$sKey] = (int)$mixedValue;
+            }
+
+        return $aContentInfo;
+    }
+
+    public function setGrid($aGrid)
+    {
+        $this->_aGrid = $aGrid;
+    }
+
     public function getName()
     {
         return $this->_sSystem;
@@ -172,6 +232,11 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
         return $this->_aSystem['title'];
     }
 
+    public function getGrid()
+    {
+        return $this->_aGrid;
+    }
+
     public function getContentAuthor ($iContentId)
     {
         return $this->_call('get_author', $iContentId);

+ 10 - 1
inc/classes/BxDolGrid.php

@@ -392,6 +392,13 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         if (false === stripos($sQuery, ' WHERE '))
             $sQuery .= " WHERE 1 ";
 
+        $aResults = false;
+        $oZ = new BxDolAlerts('grid', 'get_data', 0, false, array('object' => $this->_sObject, 'options' => $this->_aOptions, 'markers' => $this->_aMarkers, 'filter' => $sFilter, 'results' => &$aResults));
+    	$oZ->alert();
+
+    	if($aResults !== false)
+    	    return $aResults;
+
         // add filter condition
         $sOrderByFilter = '';
         if ($sFilter && (!empty($this->_aOptions['filter_fields']) || !empty($this->_aOptions['filter_fields_translatable']))) {
@@ -456,6 +463,9 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
                 $sCond = rtrim($sCond, ' OR ');
             }
 
+            $oZ = new BxDolAlerts('grid', 'get_data_by_filter', 0, false, array('object' => $this->_sObject, 'options' => $this->_aOptions, 'markers' => $this->_aMarkers, 'filter' => $sFilter, 'conditions' => &$sCond));
+        	$oZ->alert();
+
             if ($sCond)
                 $sQuery .= ' AND (' . $sCond . ')';
         }
@@ -463,7 +473,6 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         // add order
         $sQuery .= $this->_getDataSqlOrderClause ($sOrderByFilter, $sOrderField, $sOrderDir);
 
-
         $sQuery = $sQuery . $oDb->prepareAsString(' LIMIT ?, ?', $iStart, $iPerPage);
         return $oDb->getAll($sQuery);
     }

Plik diff jest za duży
+ 0 - 0
install/sql/system.sql


+ 10 - 1
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -80,7 +80,7 @@ class BxBaseModGeneralModule extends BxDolModule
     {
         $CNF = &$this->_oConfig->CNF;
 
-        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        $aContentInfo = $this->_getFields($iContentId);
         if(empty($aContentInfo))
             return array();
 
@@ -1028,6 +1028,15 @@ class BxBaseModGeneralModule extends BxDolModule
         //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
     }
 
+    protected function _getFields($iContentId)
+    {
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo))
+            return array();
+
+        return BxDolContentInfo::formatFields($aContentInfo);
+    }
+
     protected function _getFieldValue($sField, $iContentId)
     {
         $CNF = &$this->_oConfig->CNF;

+ 9 - 0
modules/boonex/forum/classes/BxForumModule.php

@@ -74,6 +74,15 @@ class BxForumModule extends BxBaseModTextModule
     /**
      * Service methods
      */
+    public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
+    {
+        $aContentInfo = $this->_getFields($iContentId);
+        if(empty($aContentInfo))
+            return array();
+
+        return $aContentInfo;
+    }
+
 	public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
     {
     	$sType = 'new';

+ 2 - 0
modules/boonex/forum/install/sql/disable.sql

@@ -74,6 +74,8 @@ DELETE FROM `sys_objects_feature` WHERE `name` = @sName;
 -- CONTENT INFO
 DELETE FROM `sys_objects_content_info` WHERE `name` IN (@sName, 'bx_forum_cmts');
 
+DELETE FROM `sys_content_info_grids` WHERE `object` IN (@sName);
+
 
 -- ALERTS
 SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);

+ 3 - 0
modules/boonex/forum/install/sql/enable.sql

@@ -463,6 +463,9 @@ INSERT INTO `sys_objects_content_info` (`name`, `title`, `alert_unit`, `alert_ac
 (@sName, '_bx_forum', @sName, 'added', 'edited', 'deleted', '', ''),
 ('bx_forum_cmts', '_bx_forum_cmts', @sName, 'commentPost', 'commentUpdated', 'commentRemoved', 'BxDolContentInfoCmts', '');
 
+INSERT INTO `sys_content_info_grids` (`object`, `grid_object`, `grid_field_id`, `condition`, `selection`) VALUES
+(@sName, @sName, 'id', '', 'a:1:{s:4:"sort";a:2:{s:5:"stick";s:4:"desc";s:12:"lr_timestamp";s:4:"desc";}}');
+
 
 -- ALERTS
 INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 

+ 6 - 1
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -363,7 +363,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
     public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
     {
-        return $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
+        $aContentInfo = $this->_oDb->getEvents(array(
+        	'browse' => 'id', 
+        	'value' => $iContentId)
+        );
+
+        return BxDolContentInfo::formatFields($aContentInfo);
     }
 
     public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików