Index: trunk/kernel/include/item.php =================================================================== diff -u -N -r805 -r883 --- trunk/kernel/include/item.php (.../item.php) (revision 805) +++ trunk/kernel/include/item.php (.../item.php) (revision 883) @@ -739,6 +739,13 @@ return $count; } + /** + * Return comma separated CategoryId list, + * where this item is member (will be shown there) + * + * @param string $SourceTable + * @return string + */ function CategoryMemberList($SourceTable="") { $cats = array(); @@ -984,6 +991,49 @@ $this->SetPrimaryCategory($TargetCat); // 2 updates } } + + function refreshLastUpdate($cat_id = null) + { + $db =& GetADODBConnection(); + $prefix = GetTablePrefix(); + + // 1,2,3,4 - set lastupdate date to item's primary category as recent + // change date of all items in this category of same type as this item + + // 1. get item category or use passed one + if(!isset($cat_id)) $cat_id = $this->GetPrimaryCategory(); + if($cat_id == 0) return false; + + // 2. get all item ResourceIds in that category + $sql = 'SELECT ItemResourceId FROM '.$prefix.'CategoryItems WHERE CategoryId = '.$cat_id; + $item_rids = $db->GetCol($sql); + if($item_rids) + { + $item_rids = implode(',',$item_rids); + + // 2a. get LastUpdate date based on all item in $cat_id category + $sql = 'SELECT MAX(IF(Modified=0,CreatedOn,Modified)) FROM '.$this->tablename.' WHERE ResourceId IN ('.$item_rids.')'; + $item_last_update = $db->GetOne($sql); + } + else + { + $item_last_update = 0; + } + + // 3. get LastUpdate date based on all $cat_id subcategories + $sql = 'SELECT MAX(IF(Modified=0,CreatedOn,Modified)) FROM '.$prefix.'Category WHERE ParentId = '.$cat_id; + $cat_last_update = $db->GetOne($sql); + + $last_update = max($item_last_update,$cat_last_update); + + // 4. set $last_update date to $cat_id category + $sql = 'UPDATE '.$prefix.'Category SET Modified = '.$last_update.' WHERE CategoryId = '.$cat_id; + $db->Execute($sql); + + // 5. get $cat_id parent CategoryId + $sql = 'SELECT ParentId FROM '.$prefix.'Category WHERE CategoryId = '.$cat_id; + if($cat_id > 0) $this->refreshLastUpdate( $db->GetOne($sql) ); + } } ?> \ No newline at end of file Index: trunk/kernel/include/itemdb.php =================================================================== diff -u -N -r881 -r883 --- trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 881) +++ trunk/kernel/include/itemdb.php (.../itemdb.php) (revision 883) @@ -109,14 +109,14 @@ $this->Set($var, $value); } - function SetModified($UserId=NULL) + function SetModified($UserId=NULL,$modificationDate=null) { global $objSession; $keys = array_keys($this->Data); if(in_array("Modified",$keys)) { - $this->Set("Modified",adodb_date("U")); + $this->Set("Modified", isset($modificationDate) ? $modificationDate : adodb_date("U") ); } if(in_array("ModifiedById",$keys)) { @@ -266,14 +266,14 @@ return true; } - function Update($UpdatedBy=NULL) + function Update($UpdatedBy=NULL,$modificationDate = null) { global $Errors, $objSession; if(count($this->m_dirtyFieldsMap) == 0) return true; - $this->SetModified($UpdatedBy); + $this->SetModified($UpdatedBy,$modificationDate); $sql = "UPDATE ".$this->tablename ." SET "; $first = 1;