Index: trunk/kernel/include/parseditem.php =================================================================== diff -u -r988 -r1009 --- trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 988) +++ trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 1009) @@ -1206,6 +1206,7 @@ $c->SetFromArray($data); $c->idfield = $idfield; $c->Dirty(); + if($c->Get($idfield) < 1) { $old_id = $c->Get($idfield); @@ -1227,6 +1228,7 @@ } $c->Create(); } + $item_ids[]=$c->UniqueId(); // save item id for future use if(is_numeric($c->Get("ResourceId"))) { if( isset($c->Related) && is_object($c->Related) ) @@ -1290,6 +1292,8 @@ if($edit_table) @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table"); @$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$objSession->GetEditTable("CategoryItems")); unset($GLOBALS['_CopyFromEditTable']); + + return $item_ids; } function GetNextTempID() @@ -2126,38 +2130,24 @@ return $ExtraId; } + + /** + * Return all listype (from tags) to id mappings + * + * @return Array + * @access private + */ + function GetListTypes() + { + return Array( '_'=>0,'category'=>1,'myitems'=>2,'hot'=>3,'pop'=>4, + 'pick'=>5,'favorites'=>6,'new'=>8); + } + function CacheListType($ListType) { - if(!strlen($ListType)) - $ListType="_"; - switch($ListType) - { - case "_": - $ListTypeId = 0; - break; - case "category": - $ListTypeId = 1; - break; - case "myitems": - $ListTypeId = 2; - break; - case "hot": - $ListTypeId = 3; - break; - case "pop": - $ListTypeId = 4; - break; - case "pick": - $ListTypeId = 5; - break; - case "favorites": - $ListTypeId = 6; - break; - case "new": - $ListTypeId = 8; - break; - } - return $ListTypeId; + if($ListType) $ListType='_'; + $mapping=$this->GetListTypes(); + return $mapping[$ListType]; } function PerformItemCount($attribs=array()) @@ -2838,7 +2828,25 @@ } } - + + /** + * Updates count cache for selected ids in list + * + * @param Array $item_ids + * @access protected + */ + function FlushCache($item_ids) + { + $db =& GetADODBConnection(); + if(is_array($item_ids)) $item_ids=implode(',',$item_ids); + + $sql = 'SELECT ResourceId FROM '.$this->SourceTable.' WHERE '.$this->GetIDField().' IN ('.$item_ids.')'; + $resource_ids=$db->GetCol($sql); + $sql='SELECT CategoryId FROM '.GetTablePrefix().'CategoryItems WHERE ItemResourceId IN ('.implode(',',$resource_ids).')'; + $cat_ids=$db->GetCol($sql); + UpdateCategoryCount($this->ItemType, $cat_ids, $this->GetListTypes()); + } + function PasteFromClipboard($TargetCat,$NameField="") { global $objSession,$objCatList; @@ -2863,7 +2871,7 @@ { $item->CopyToNewResource($TargetCat,$NameField); // create item copy, but with new ResourceId $item->AddToCategory($TargetCat); - UpdateCategoryCount($item->type,$TargetCat); + UpdateCategoryCount($item->type,$TargetCat, $this->GetListTypes() ); } }