getObject(); switch ($event->Special) { case 'showall': $object->clearFilters(); break; case 'products': $object->removeFilter('parent_filter'); // this is important $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // $object->addFilter('active', '%1$s.Status = 1'); /*$this->Application->setUnitOption('p', 'AutoLoad', true); $product =& $this->Application->recallObject('p'); $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));*/ break; case 'product': $object->clearFilters(); $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); $object->addFilter('active', '%1$s.Status = 1'); $this->Application->setUnitOption('p', 'AutoLoad', true); $product =& $this->Application->recallObject('p'); $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId')); break; } if($event->getEventParam('type') == 'current_user') { $user_id = $this->Application->GetVar('u_id') ? $this->Application->GetVar('u_id') : -2; $ip = $_SERVER['REMOTE_ADDR']; $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); $object =& $event->getObject(); $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.'"'); } } /** * Adds review from front in case if user is logged in * * @param kEvent $event */ function OnAddReview(&$event) { $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id'); $event->redirect_params = Array('pass' => 'all,p'); $this->Application->setUnitOption($event->Prefix,'AutoLoad',false); $object =& $event->getObject(); $item_info = $this->Application->GetVar('rev_product'); $product_info = $object->getLinkedInfo(); $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl WHERE ItemResourceId='.$product_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='.$product_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($item_info) ); $object->SetDBField('CreatedById', $user_id); $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); $object->SetDBField('CreatedOn', adodb_mktime()); if( $this->Application->CheckPermission('PRODUCT.REVIEW.PENDING', 0) ) { $object->SetDBField('Status', 2); } elseif( $this->Application->CheckPermission('PRODUCT.REVIEW', 0) ) { $object->SetDBField('Status', 1); } $object->SetDBField('ItemId', $product_info['ParentId']); $event->CallSubEvent('OnCreate'); if($event->status == erSUCCESS) { $product_object =& $this->Application->recallObject('p'); $sql = ' SELECT COUNT(ReviewId) FROM '.$object->TableName.' WHERE ItemId='.$product_info['ParentId']; $review_qty = $this->Conn->GetOne($sql); $product_object->SetDBField('CachedReviewsQty', $review_qty); $product_object->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 ('.$product_info['ParentId'].', "'.$_SERVER['REMOTE_ADDR'].'", '.$user_id.', "Review", '.$expire.')'; $this->Conn->Query($sql); $event->redirect_params = Array('pass' => 'all,p'); $event->redirect = $this->Application->GetVar('success_template'); } } else { $event->status == erFAIL; $event->redirect=false; $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent'; $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate'); } } } ?>