Index: branches/5.2.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r14244 -r14628 --- branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnAddReview' || $event->Name == 'OnCreate') { $perm_helper =& $this->Application->recallObject('PermissionsHelper'); @@ -87,9 +89,13 @@ $res = $this->Application->CheckPermission($perm_prefix . '.ADD', 0, $perm_category) || $this->Application->CheckPermission($perm_prefix . '.MODIFY', 0, $perm_category); break; + + default: + $res = false; + break; } - if (!$res) { + if ( !$res ) { $event->status = kEvent::erPERM_FAIL; } @@ -167,54 +173,50 @@ * @access protected * @see OnListBuild */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); /* @var $object kDBList */ - if (!$this->Application->isAdminUser) { - $object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE); + if ( !$this->Application->isAdminUser ) { + $object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); } - switch ($event->Special) - { + switch ( $event->Special ) { case 'showall': $object->clearFilters(); break; 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')); + $parent_info = $object->getLinkedInfo(); + + $parent =& $this->Application->recallObject($parent_info['ParentPrefix']); + /* @var $parent kDBItem */ + + $object->addFilter('item_reviews', '%1$s.ItemId = ' . $parent->GetDBField('ResourceId')); break; - case 'products': // used in In-Portal (Sturcture & Data -> Reviews section) - $object->removeFilter('parent_filter'); // this is important + case 'products': // used in In-Portal (Structure & Data -> Reviews section) + $object->removeFilter('parent_filter'); // this is important $object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL'); break; - - /*case 'product': - $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // for LEFT JOIN - break;*/ } - if (preg_match('/(.*)-rev/', $event->Prefix, $regs)) { + if ( preg_match('/(.*)-rev/', $event->Prefix, $regs) ) { // "Structure & Data" -> "Reviews" (section in K4) $item_type = $this->Application->getUnitOption($regs[1], 'ItemType'); $object->addFilter('itemtype_filter', '%1$s.ItemType = ' . $item_type); - if ($this->Application->isAdmin) { + if ( $this->Application->isAdmin ) { // temporarily solution so we can see sub-items on separate grid in Admin $object->removeFilter('parent_filter'); - } + } } - if ($event->getEventParam('type') == 'current_user') { -// $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'].'"'); + if ( $event->getEventParam('type') == 'current_user' ) { + $object->addFilter('current_user', '%1$s.CreatedById = ' . $this->Application->RecallVar('user_id')); + $object->addFilter('current_ip', '%1$s.IPAddress = "' . $_SERVER['REMOTE_ADDR'] . '"'); } } @@ -256,9 +258,13 @@ * Prefills all fields on front-end * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); /* @var $object kDBItem */ @@ -269,7 +275,7 @@ $object->SetDBField('ItemType', $item_type); $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { // don't perform spam control on admin return ; } @@ -279,14 +285,14 @@ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0); - if ($spam_helper->InSpamControl()) { + if ( $spam_helper->InSpamControl() ) { $event->status = kEvent::erFAIL; $object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate'); - return ; + return; } $rating = $object->GetDBField('Rating'); - if ($rating < 1 || $rating > 5) { + if ( $rating < 1 || $rating > 5 ) { $object->SetDBField('Rating', null); } @@ -301,13 +307,19 @@ * Sets correct rating value * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ $rating = $object->GetDBField('Rating'); - if (!$rating) { + + if ( !$rating ) { $object->SetDBField('Rating', null); } } @@ -316,27 +328,33 @@ * Updates item review counter * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { + parent::OnAfterItemCreate($event); + $this->updateSubitemCounters($event); - if (!$this->Application->isAdminUser) { + if ( !$this->Application->isAdminUser ) { $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ $object =& $event->getObject(); + /* @var $object kDBItem */ + $parent_info = $object->getLinkedInfo(); $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - $review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval']; + $review_settings = $config_mapping['ReviewDelayValue'] . ':' . $config_mapping['ReviewDelayInterval']; $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings); $spam_helper->AddToSpamControl(); $review_status = $object->GetDBField('Status'); - if ($review_status == STATUS_ACTIVE || $review_status == STATUS_PENDING) { + if ( $review_status == STATUS_ACTIVE || $review_status == STATUS_PENDING ) { $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'ADD' : 'ADD.PENDING'); $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); $this->Application->EmailEventAdmin($email_event);