Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r4842 -r5119 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 4842) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5119) @@ -488,63 +488,54 @@ { $object =& $event->getObject( Array('skip_autoload' => true) ); - $property_mappings = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); + $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - $new_days_var = getArrayValue($property_mappings, 'NewDays'); - if($new_days_var) - { - $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, - IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. - $this->Application->ConfigValue($new_days_var). - '*3600*24), 1, 0), - %1$s.NewItem - )'); + // new items + $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, + IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. + $this->Application->ConfigValue($property_map['NewDays']). + '*3600*24), 1, 0), + %1$s.NewItem + )'); + + // hot items + $sql = 'SELECT Data + FROM '.TABLE_PREFIX.'Cache + WHERE VarName = "'.$property_map['HotLimit'].'"'; + $hot_limit = $this->Conn->GetOne($sql); + if ($hot_limit === false) { + $hot_limit = $this->CalculateHotLimit($event); } - - $hot_limit_var = getArrayValue($property_mappings, 'HotLimit'); - if($hot_limit_var) - { - $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$hot_limit_var.'"'; - $hot_limit = $this->Conn->GetOne($sql); - if($hot_limit === false) $hot_limit = $this->CalculateHotLimit($event); - $object->addCalculatedField('IsHot', ' IF(%1$s.HotItem = 2, - IF(%1$s.Hits >= '.$hot_limit.', 1, 0), - %1$s.HotItem - )'); - } - - $votes2pop_var = getArrayValue($property_mappings, 'VotesToPop'); - $rating2pop_var = getArrayValue($property_mappings, 'RatingToPop'); - - if($votes2pop_var && $rating2pop_var) - { - $object->addCalculatedField('IsPop', ' IF(%1$s.PopItem = 2, - IF(%1$s.CachedVotesQty >= '. - $this->Application->ConfigValue($votes2pop_var). - ' AND %1$s.CachedRating >= '. - $this->Application->ConfigValue($rating2pop_var). - ', 1, 0), - %1$s.PopItem)'); - } + $object->addCalculatedField('IsHot', ' IF(%1$s.HotItem = 2, + IF(%1$s.'.$property_map['ClickField'].' >= '.$hot_limit.', 1, 0), + %1$s.HotItem + )'); + + // popular items + $object->addCalculatedField('IsPop', ' IF(%1$s.PopItem = 2, + IF(%1$s.CachedVotesQty >= '. + $this->Application->ConfigValue($property_map['MinPopVotes']). + ' AND %1$s.CachedRating >= '. + $this->Application->ConfigValue($property_map['MinPopRating']). + ', 1, 0), + %1$s.PopItem)'); + } function CalculateHotLimit(&$event) { - $property_mappings = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - $hot_count_var = getArrayValue($property_mappings, 'HotCount'); - $hot_limit_var = getArrayValue($property_mappings, 'HotLimit'); - - if($hot_count_var && $hot_limit_var) - { - $last_hot = $this->Application->ConfigValue($hot_count_var) - 1; - $sql = 'SELECT Hits FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - ORDER BY Hits DESC - LIMIT '.$last_hot.', 1'; - $res = $this->Conn->GetCol($sql); - $hot_limit = (double)array_shift($res); - $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$hot_limit_var.'", "'.$hot_limit.'", '.adodb_mktime().')'); - return $hot_limit; - } + $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); + $click_field = $property_map['ClickField']; + + $last_hot = $this->Application->ConfigValue($property_map['MaxHotNumber']) - 1; + $sql = 'SELECT '.$click_field.' FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' + ORDER BY '.$click_field.' DESC + LIMIT '.$last_hot.', 1'; + $res = $this->Conn->GetCol($sql); + $hot_limit = (double)array_shift($res); + $this->Conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache VALUES ("'.$property_map['HotLimit'].'", "'.$hot_limit.'", '.adodb_mktime().')'); + return $hot_limit; + return 0; }