Просмотр исходного кода

#24 - Timeline: Issue with Hidden and Autoreadded events.

AntonLV 11 лет назад
Родитель
Сommit
a9bbf5cd95

+ 4 - 1
modules/base/notifications/classes/BxBaseModNotificationsDb.php

@@ -150,7 +150,10 @@ class BxBaseModNotificationsDb extends BxDolModuleDb
         foreach($aParamsSet as $sKey => $sValue)
            $aSet[] = $this->prepare("`" . $sKey . "`=?", $sValue);
 
-        if((int)$this->query("INSERT INTO `{$this->_sTable}` SET " . implode(", ", $aSet) . ", `date`=UNIX_TIMESTAMP()") <= 0)
+		if(empty($aParamsSet['date']))
+			$aSet[] = "`date`=UNIX_TIMESTAMP()";
+
+        if((int)$this->query("INSERT INTO `{$this->_sTable}` SET " . implode(", ", $aSet)) <= 0)
             return 0;
 
         return (int)$this->lastId();

+ 1 - 0
modules/base/text/classes/BxBaseModTextModule.php

@@ -343,6 +343,7 @@ class BxBaseModTextModule extends BxBaseModGeneralModule
                 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
                 'images' => $aImages,
             ), //a string to display or array to parse default template before displaying.
+            'date' => $aContentInfo[$CNF['FIELD_ADDED']],
             'votes' => $aVotes,
             'comments' => $aComments,
             'title' => '', //may be empty.

+ 22 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -240,6 +240,28 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         $sPrefix = $this->getPrefix('common_post');
         return strpos($sType, $sPrefix) === false && !empty($sAction);
     }
+    public function getSystemData(&$aEvent)
+    {
+		$sHandler = $aEvent['type'] . '_' . $aEvent['action'];
+        if(!$this->isHandler($sHandler))
+            return false;
+
+        $aHandler = $this->getHandlers($sHandler);
+        if(empty($aHandler['module_name']) || empty($aHandler['module_class']) || empty($aHandler['module_method']))
+        	return false; 
+
+		$aEvent['js_mode'] = $this->getJsMode();
+		return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent), $aHandler['module_class']);
+    }
+    public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
+    {
+    	$aDescriptor = array(
+    		'type' => $sType, 
+    		'action' => $sAction,
+    		'object_id' => $iObjectId
+    	);
+    	return $this->getSystemData($aDescriptor);
+    }
 }
 
 /** @} */

+ 17 - 3
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -115,8 +115,20 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
 		$aShared = $this->getEvents($aParams);
 		if($bSystem && (empty($aShared) || !is_array($aShared))) {
+			$iOwnerId = 0;
+			$iDate = 0;
+			$iHidden = 1;
+
+			$mixedResult = $this->_oConfig->getSystemDataByDescriptor($sType, $sAction, $iObjectId);
+			if(is_array($mixedResult)) {
+				$iOwnerId = !empty($mixedResult['owner_id']) ? (int)$mixedResult['owner_id'] : 0;
+				$iDate = !empty($mixedResult['date']) ? (int)$mixedResult['date'] : 0;
+				if(!empty($iOwnerId) && !empty($iDate))
+					$iHidden = 0;
+			}
+
 			$iId = $this->insertEvent(array(
-				'owner_id' => 0,
+				'owner_id' => $iOwnerId,
 				'type' => $sType,
 				'action' => $sAction,
 				'object_id' => $iObjectId,
@@ -124,7 +136,8 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 				'content' => '',
 				'title' => '',
 				'description' => '',
-				'hidden' => 1
+				'date' => $iDate,
+				'hidden' => $iHidden
 			));
 
 			$aShared = $this->getEvents(array('browse' => 'id', 'value' => $iId));
@@ -315,7 +328,8 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 
     protected function _getSqlPartsEventsList($aParams)
     {
-    	$sJoinClause = $sWhereClause = "";
+    	$sJoinClause = "";
+    	$sWhereClause = "AND `{$this->_sTable}`.`hidden`='0' ";
 
 		if(isset($aParams['active']))
         	$sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`active`=? ", (int)$aParams['active']);

+ 4 - 10
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -818,17 +818,11 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
     protected function _getSystemData(&$aEvent)
     {
-        $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
-        if(!$this->_oConfig->isHandler($sHandler))
-            return '';
-
-        $aHandler = $this->_oConfig->getHandlers($sHandler);
-        if(!empty($aHandler['module_name']) && !empty($aHandler['module_class']) && !empty($aHandler['module_method'])) {
-        	$aEvent['js_mode'] = $this->_oConfig->getJsMode();
-            return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent), $aHandler['module_class']);
-        }
+        $mixedResult = $this->_oConfig->getSystemData($aEvent);
+		if($mixedResult !== false)
+			return $mixedResult;
 
-		$sMethod = 'display' . bx_gen_method_name($aHandler['alert_unit'] . '_' . $aHandler['alert_action']);
+		$sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
 		if(!method_exists($this, $sMethod))
         	return '';