Index: trunk/kernel/include/item.php =================================================================== diff -u -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