Index: trunk/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r8441 -r8444 --- trunk/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8441) +++ trunk/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 8444) @@ -3,6 +3,22 @@ class ReviewsEventHandler extends kDBEventHandler { /** + * Get's special of main item for linking with subitem + * + * @param kEvent $event + * @return string + */ + function getMainSpecial(&$event) + { + if ($event->Special == 'product' && !$this->Application->IsAdmin()) { + // rev.product should auto-link + return ''; + } + + return parent::getMainSpecial($event); + } + + /** * Checks REVIEW/REVIEW.PENDING permission by main object primary category (not current category) * * @param kEvent $event @@ -54,6 +70,7 @@ function SetCustomQuery(&$event) { $object =& $event->getObject(); + /* @var $object kDBList */ if (!$this->Application->IsAdmin()) { $object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE); @@ -65,36 +82,28 @@ $object->clearFilters(); break; - case 'item': + case 'item': // used ? $object->clearFilters(); $info = $object->getLinkedInfo(); $this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true); $parent =& $this->Application->recallObject($info['ParentPrefix']); $object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId')); break; - case 'products': + case 'products': // used ? $object->removeFilter('parent_filter'); // this is important $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); break; case 'product': - $object->clearFilters(); - $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); - $this->Application->setUnitOption('p', 'AutoLoad', true); - $product =& $this->Application->recallObject('p'); - $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId')); + $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // for LEFT JOIN break; } if ($event->getEventParam('type') == 'current_user') { - $user_id = $this->getUserID(); - $ip = $_SERVER['REMOTE_ADDR']; - $object =& $event->getObject( Array('skip_autoload' => true) ); - $product_info = $object->getLinkedInfo(); - $object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']); - $object->addFilter('current_user', '%1$s.CreatedById = '.$user_id); - $object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"'); + $object->removeFilter('active'); + $object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id')); + $object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"'); } } @@ -105,86 +114,7 @@ */ function OnAddReview(&$event) { - $user_id = $this->getUserID(); - $event->redirect_params = Array('pass' => 'all,p'); - - $object =& $event->getObject( Array('skip_autoload' => true) ); - $parent_info = $object->getLinkedInfo(); - $review_fields = $this->Application->GetVar($event->getPrefixSpecial(true)); - - $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl - WHERE ItemResourceId='.$parent_info['ParentId'].' - AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'" - AND PortalUserId='.$user_id.' - AND DataType="Review"'; - $res = $this->Conn->GetRow($sql); - - if( $res && $res['Expire'] < adodb_mktime() ) - { - $sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl - WHERE ItemResourceId='.$parent_info['ParentId'].' - AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'" - AND PortalUserId='.$user_id.' - AND DataType="Review"'; - $this->Conn->Query($sql); - unset($res); - } - - if(!$res) - { - $object->SetFieldsFromHash( array_shift($review_fields) ); - $object->SetDBField('CreatedById', $user_id); - $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); - $object->SetDBField('CreatedOn', adodb_mktime()); - - $module_info = $this->Application->findModule('Var',$parent_info['ParentPrefix']); - $object->SetDBField('Module', $module_info['Name']); - if( $this->Application->CheckPermission( $this->getPermPrefix($event).'.REVIEW.PENDING', 0) ) - { - $object->SetDBField('Status', 2); - $template_var = 'success_pending_template'; - } - if( $this->Application->CheckPermission($this->getPermPrefix($event).'.REVIEW', 0) ) - { - $object->SetDBField('Status', 1); - $template_var = 'success_template'; - } - - $object->SetDBField('ItemId', $parent_info['ParentId']); - - $event->CallSubEvent('OnCreate'); - - if($event->status == erSUCCESS) - { - $parent =& $this->Application->recallObject($parent_info['ParentPrefix']); - $sql = ' SELECT COUNT(ReviewId) - FROM '.$object->TableName.' - WHERE ItemId='.$parent_info['ParentId']; - $review_qty = $this->Conn->GetOne($sql); - $parent->SetDBField('CachedReviewsQty', $review_qty); - $parent->Update(); - $expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval'); - $sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl - (ItemResourceId, IPaddress, PortalUserId, DataType, Expire) - VALUES ('.$parent_info['ParentId'].', - "'.$_SERVER['REMOTE_ADDR'].'", - '.$user_id.', - "Review", - '.$expire.')'; - $this->Conn->Query($sql); - - $event->redirect_params = Array('pass' => 'all,'.$parent_info['ParentPrefix']); - $event->redirect = $this->Application->GetVar($template_var); - } - } - else - { -// $this->Application->removeObject($event->getPrefixSpecial()); - $event->status == erFAIL; - $event->redirect=false; - $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent'; - $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate'); - } + $event->CallSubEvent('OnCreate'); } /** @@ -263,7 +193,7 @@ /* @var $spam_helper SpamHelper */ $object =& $event->getObject(); - $parent_info = $object->getLinkedInfo($event->Special); + $parent_info = $object->getLinkedInfo(); $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); $review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval']; @@ -327,22 +257,9 @@ $next_template = $object->GetDBField('Status') == STATUS_ACTIVE ? 'success_template' : 'success_pending_template'; $event->redirect = $this->Application->GetVar($next_template); $event->SetRedirectParam('opener', 's'); - } - /** - * Returns current user id for reviews, for logic ask Kostja T. - * - * @return int - */ - function getUserID() - { - $user_id = $this->Application->RecallVar('user_id'); - - if ($user_id == 0) { - $user_id = -2; - } - - return $user_id; + $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $event->SetRedirectParam('pass', 'm,'.$parent_prefix); } }