Index: install/install_schema.sql =================================================================== --- install/install_schema.sql (revision 14635) +++ install/install_schema.sql (working copy) @@ -800,6 +800,8 @@ `Status` tinyint(4) NOT NULL DEFAULT '2', TextFormat int(11) NOT NULL DEFAULT '0', Module varchar(255) NOT NULL DEFAULT '', + HelpfulCount int(11) NOT NULL, + NotHelpfulCount int(11) NOT NULL, PRIMARY KEY (ReviewId), KEY CreatedOn (CreatedOn), KEY ItemId (ItemId), Index: install/upgrades.sql =================================================================== --- install/upgrades.sql (revision 14636) +++ install/upgrades.sql (working copy) @@ -2142,3 +2142,7 @@ ALTER TABLE Skins ADD DisplaySiteNameInHeader TINYINT(1) NOT NULL DEFAULT '1'; DELETE FROM PersistantSessionData WHERE VariableName LIKE 'formsubs_Sort%' AND VariableValue = 'FormFieldId'; + +ALTER TABLE ItemReview + ADD HelpfulCount INT NOT NULL , + ADD NotHelpfulCount INT NOT NULL; Index: kernel/db/cat_event_handler.php =================================================================== --- kernel/db/cat_event_handler.php (revision 14644) +++ kernel/db/cat_event_handler.php (working copy) @@ -33,6 +33,7 @@ 'OnCancelAction' => Array ('self' => true), 'OnItemBuild' => Array ('self' => true), 'OnMakeVote' => Array ('self' => true), + 'OnReviewHelpful' => Array ('self' => true), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -2793,6 +2794,43 @@ } /** + * Marks review as useful + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnReviewHelpful(&$event) + { + $review_id = (int)$this->Application->GetVar('review_id'); + + if ( !$review_id ) { + return; + } + + $spam_helper =& $this->Application->recallObject('SpamHelper'); + /* @var $spam_helper SpamHelper */ + + $spam_helper->InitHelper($review_id, 'ReviewHelpful', strtotime('+1 month') - strtotime('now')); + + if ( $spam_helper->InSpamControl() ) { + return; + } + + $field = (int)$this->Application->GetVar('helpful') ? 'HelpfulCount' : 'NotHelpfulCount'; + + $sql = 'UPDATE ' . $this->Application->getUnitOption('rev', 'TableName') . ' + SET ' . $field . ' = ' . $field . ' + 1 + WHERE ' . $this->Application->getUnitOption('rev', 'IDField') . ' = ' . $review_id; + $this->Conn->Query($sql); + + if ( $this->Conn->getAffectedRows() ) { + // db was changed -> review with such ID exists + $spam_helper->AddToSpamControl(); + } + } + + /** * [HOOK] Allows to add cloned subitem to given prefix * * @param kEvent $event Index: units/reviews/reviews_config.php =================================================================== --- units/reviews/reviews_config.php (revision 14590) +++ units/reviews/reviews_config.php (working copy) @@ -162,6 +162,8 @@ 'not_null' => 1, 'default' => 0, ), 'Module' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''), + 'HelpfulCount' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'NotHelpfulCount' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0) ), 'VirtualFields' => Array ( @@ -189,6 +191,8 @@ 'CreatedOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ), 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 80, ), 'Rating' => Array ('filter_block' => 'grid_options_filter', 'width' => 80, ), + 'HelpfulCount' => Array ('title' => 'la_col_HelpfulCount', 'filter_block' => 'grid_range_filter'), + 'NotHelpfulCount' => Array ('title' => 'la_col_NotHelpfulCount', 'filter_block' => 'grid_range_filter'), ), ), @@ -206,6 +210,8 @@ 'CreatedOn' => Array ('filter_block' => 'grid_date_range_filter', 'width' => 145, ), 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 80, ), 'Rating' => Array ('filter_block' => 'grid_options_filter', 'width' => 80, ), + 'HelpfulCount' => Array ('title' => 'la_col_HelpfulCount', 'filter_block' => 'grid_range_filter'), + 'NotHelpfulCount' => Array ('title' => 'la_col_NotHelpfulCount', 'filter_block' => 'grid_range_filter'), ), ), ), Index: units/reviews/reviews_tag_processor.php =================================================================== --- units/reviews/reviews_tag_processor.php (revision 14628) +++ units/reviews/reviews_tag_processor.php (working copy) @@ -43,6 +43,18 @@ return $this->Application->HREF($edit_template,'', $url_params); } + function HelpfulLink($params) + { + $object =& $this->getObject($params); + /* @var $object kDBItem */ + + $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); + $params['events[' . $parent_prefix . ']'] = 'OnReviewHelpful'; + $params['review_id'] = $object->GetID(); + + return $this->Application->ProcessParsedTag($parent_prefix, 'ItemLink', $params); + } + /** * Get's reuested field value *