Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/reviews/reviews_event_handler.php
Show All 37 Lines | |||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return bool | * @return bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function CheckPermission(kEvent $event) | public function CheckPermission(kEvent $event) | ||||
{ | { | ||||
if ( $event->Name == 'OnAddReview' || $event->Name == 'OnCreate' ) { | if ( $event->Name == 'OnAddReview' || $event->Name == 'OnCreate' ) { | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
/** @var kCatDBItem $main_object */ | |||||
$main_object = $this->Application->recallObject($parent_prefix); | $main_object = $this->Application->recallObject($parent_prefix); | ||||
/* @var $main_object kCatDBItem */ | |||||
$perm_name = $this->getPermPrefix($event).'.REVIEW'; | $perm_name = $this->getPermPrefix($event).'.REVIEW'; | ||||
$res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) || | $res = $this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId')) || | ||||
$this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId')); | $this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId')); | ||||
if ( !$res ) { | if ( !$res ) { | ||||
$event->status = kEvent::erPERM_FAIL; | $event->status = kEvent::erPERM_FAIL; | ||||
} | } | ||||
return $res; | return $res; | ||||
} | } | ||||
$check_events = Array ( | $check_events = Array ( | ||||
'OnItemBuild', 'OnUpdate', /*'OnMassApprove', 'OnMassDecline'*/ | 'OnItemBuild', 'OnUpdate', /*'OnMassApprove', 'OnMassDecline'*/ | ||||
); | ); | ||||
$perm_category = $this->_getReviewCategory($event); | $perm_category = $this->_getReviewCategory($event); | ||||
if ( in_array($event->Name, $check_events) ) { | if ( in_array($event->Name, $check_events) ) { | ||||
// check for PRODUCT.VIEW permission | // check for PRODUCT.VIEW permission | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$perm_prefix = $this->getPermPrefix($event); | $perm_prefix = $this->getPermPrefix($event); | ||||
if ( $perm_category === false ) { | if ( $perm_category === false ) { | ||||
// no item id present -> allow | // no item id present -> allow | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
$review_id = false; | $review_id = false; | ||||
} | } | ||||
if (!$review_id) { | if (!$review_id) { | ||||
return false; | return false; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// 1. get main item resource id (use object, because of temp tables in admin) | // 1. get main item resource id (use object, because of temp tables in admin) | ||||
$sql = 'SELECT ItemId | $sql = 'SELECT ItemId | ||||
FROM ' . $object->TableName . ' | FROM ' . $object->TableName . ' | ||||
WHERE ' . $object->IDField . ' = ' . $review_id; | WHERE ' . $object->IDField . ' = ' . $review_id; | ||||
$resource_id = $this->Conn->GetOne($sql); | $resource_id = $this->Conn->GetOne($sql); | ||||
// 2. set main item id (for permission checks) | // 2. set main item id (for permission checks) | ||||
Show All 29 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @access protected | * @access protected | ||||
* @see OnListBuild | * @see OnListBuild | ||||
*/ | */ | ||||
protected function SetCustomQuery(kEvent $event) | protected function SetCustomQuery(kEvent $event) | ||||
{ | { | ||||
parent::SetCustomQuery($event); | parent::SetCustomQuery($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
if ( !$this->Application->isAdminUser ) { | if ( !$this->Application->isAdminUser ) { | ||||
$object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); | $object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); | ||||
} | } | ||||
switch ($event->Special) { | switch ($event->Special) { | ||||
case 'showall': | case 'showall': | ||||
$object->clearFilters(); | $object->clearFilters(); | ||||
break; | break; | ||||
case 'item': // used ? | case 'item': // used ? | ||||
$object->clearFilters(); | $object->clearFilters(); | ||||
$parent_info = $object->getLinkedInfo(); | $parent_info = $object->getLinkedInfo(); | ||||
/** @var kDBItem $parent */ | |||||
$parent = $this->Application->recallObject($parent_info['ParentPrefix']); | $parent = $this->Application->recallObject($parent_info['ParentPrefix']); | ||||
/* @var $parent kDBItem */ | |||||
$object->addFilter('item_reviews', '%1$s.ItemId = ' . $parent->GetDBField('ResourceId')); | $object->addFilter('item_reviews', '%1$s.ItemId = ' . $parent->GetDBField('ResourceId')); | ||||
break; | break; | ||||
case 'products': // used in In-Portal (Structure & Data -> Reviews section) | case 'products': // used in In-Portal (Structure & Data -> Reviews section) | ||||
$object->removeFilter('parent_filter'); // this is important | $object->removeFilter('parent_filter'); // this is important | ||||
$object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL'); | $object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL'); | ||||
break; | break; | ||||
Show All 30 Lines | |||||
* Get new review status on user review permission | * Get new review status on user review permission | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return int | * @return int | ||||
*/ | */ | ||||
function getReviewStatus($event) | function getReviewStatus($event) | ||||
{ | { | ||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
/** @var kCatDBItem $main_object */ | |||||
$main_object = $this->Application->recallObject($parent_prefix); | $main_object = $this->Application->recallObject($parent_prefix); | ||||
/* @var $main_object kCatDBItem */ | |||||
$ret = STATUS_DISABLED; | $ret = STATUS_DISABLED; | ||||
$perm_name = $this->getPermPrefix($event).'.REVIEW'; | $perm_name = $this->getPermPrefix($event).'.REVIEW'; | ||||
if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) { | if ($this->Application->CheckPermission($perm_name, 0, $main_object->GetDBField('CategoryId'))) { | ||||
$ret = STATUS_ACTIVE; | $ret = STATUS_ACTIVE; | ||||
} | } | ||||
else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) { | else if ($this->Application->CheckPermission($perm_name.'.PENDING', 0, $main_object->GetDBField('CategoryId'))) { | ||||
$ret = STATUS_PENDING; | $ret = STATUS_PENDING; | ||||
} | } | ||||
return $ret; | return $ret; | ||||
} | } | ||||
/** | /** | ||||
* Prefills all fields on front-end | * Prefills all fields on front-end | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemCreate(kEvent $event) | protected function OnBeforeItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemCreate($event); | parent::OnBeforeItemCreate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$parent_info = $object->getLinkedInfo(); | $parent_info = $object->getLinkedInfo(); | ||||
$item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); | $item_type = $this->Application->getUnitOption($parent_info['ParentPrefix'], 'ItemType'); | ||||
$object->SetDBField('IPAddress', $this->Application->getClientIp()); | $object->SetDBField('IPAddress', $this->Application->getClientIp()); | ||||
$object->SetDBField('ItemType', $item_type); | $object->SetDBField('ItemType', $item_type); | ||||
$object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); | $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 | // don't perform spam control on admin | ||||
return ; | return ; | ||||
} | } | ||||
/** @var SpamHelper $spam_helper */ | |||||
$spam_helper = $this->Application->recallObject('SpamHelper'); | $spam_helper = $this->Application->recallObject('SpamHelper'); | ||||
/* @var $spam_helper SpamHelper */ | |||||
$spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0); | $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0); | ||||
if ( $spam_helper->InSpamControl() ) { | if ( $spam_helper->InSpamControl() ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
$object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate'); | $object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate'); | ||||
return; | return; | ||||
} | } | ||||
Show All 16 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemUpdate(kEvent $event) | protected function OnBeforeItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemUpdate($event); | parent::OnBeforeItemUpdate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$rating = $object->GetDBField('Rating'); | $rating = $object->GetDBField('Rating'); | ||||
if ( !$rating ) { | if ( !$rating ) { | ||||
$object->SetDBField('Rating', null); | $object->SetDBField('Rating', null); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Updates item review counter | * Updates item review counter | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemCreate(kEvent $event) | protected function OnAfterItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemCreate($event); | parent::OnAfterItemCreate($event); | ||||
$this->updateSubitemCounters($event); | $this->updateSubitemCounters($event); | ||||
if ( !$this->Application->isAdminUser ) { | if ( !$this->Application->isAdminUser ) { | ||||
/** @var SpamHelper $spam_helper */ | |||||
$spam_helper = $this->Application->recallObject('SpamHelper'); | $spam_helper = $this->Application->recallObject('SpamHelper'); | ||||
/* @var $spam_helper SpamHelper */ | |||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$parent_info = $object->getLinkedInfo(); | $parent_info = $object->getLinkedInfo(); | ||||
$config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); | $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->InitHelper($parent_info['ParentId'], 'Review', $review_settings); | ||||
$spam_helper->AddToSpamControl(); | $spam_helper->AddToSpamControl(); | ||||
Show All 16 Lines | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemUpdate(kEvent $event) | protected function OnAfterItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemUpdate($event); | parent::OnAfterItemUpdate($event); | ||||
$this->updateSubitemCounters($event); | $this->updateSubitemCounters($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $this->Application->isAdminUser && !$object->IsTempTable() ) { | if ( $this->Application->isAdminUser && !$object->IsTempTable() ) { | ||||
// send email on review status change from reviews grid in admin | // send email on review status change from reviews grid in admin | ||||
$review_status = $object->GetDBField('Status'); | $review_status = $object->GetDBField('Status'); | ||||
$process_status = Array (STATUS_ACTIVE, STATUS_DISABLED); | $process_status = Array (STATUS_ACTIVE, STATUS_DISABLED); | ||||
if ( ($review_status != $object->GetOriginalField('Status')) && in_array($review_status, $process_status) ) { | if ( ($review_status != $object->GetOriginalField('Status')) && in_array($review_status, $process_status) ) { | ||||
$this->_loadMainObject($event); | $this->_loadMainObject($event); | ||||
$email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'APPROVE' : 'DENY'); | $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'APPROVE' : 'DENY'); | ||||
$this->Application->emailUser($email_event, $object->GetDBField('CreatedById')); | $this->Application->emailUser($email_event, $object->GetDBField('CreatedById')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Loads main object of review (link, article, etc.) | * Loads main object of review (link, article, etc.) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return kCatDBItem | * @return kCatDBItem | ||||
*/ | */ | ||||
function _loadMainObject($event) | function _loadMainObject($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
$parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey'); | $parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey'); | ||||
$foreign_key = $this->Application->getUnitOption($event->Prefix, 'ForeignKey'); | $foreign_key = $this->Application->getUnitOption($event->Prefix, 'ForeignKey'); | ||||
/** @var kDBItem $main_object */ | |||||
$main_object = $this->Application->recallObject($parent_prefix, null, Array ('skip_autoload' => true)); | $main_object = $this->Application->recallObject($parent_prefix, null, Array ('skip_autoload' => true)); | ||||
/* @var $main_object kDBItem */ | |||||
$main_object->Load($object->GetDBField($foreign_key), $parent_table_key); | $main_object->Load($object->GetDBField($foreign_key), $parent_table_key); | ||||
} | } | ||||
/** | /** | ||||
* Updates total review counter, cached rating, votes count | * Updates total review counter, cached rating, votes count | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function updateSubitemCounters($event) | function updateSubitemCounters($event) | ||||
{ | { | ||||
if ( $event->Special == '-item' ) { | if ( $event->Special == '-item' ) { | ||||
// ignore Main Item Copy/Pasting and Deleting | // ignore Main Item Copy/Pasting and Deleting | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
$parent_table = $this->Application->getUnitOption($parent_prefix, 'TableName'); | $parent_table = $this->Application->getUnitOption($parent_prefix, 'TableName'); | ||||
if ( $object->IsTempTable() ) { | if ( $object->IsTempTable() ) { | ||||
$parent_table = $this->Application->GetTempName($parent_table, 'prefix:' . $object->Prefix); | $parent_table = $this->Application->GetTempName($parent_table, 'prefix:' . $object->Prefix); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
protected function OnCreate(kEvent $event) | protected function OnCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnCreate($event); | parent::OnCreate($event); | ||||
if ( $event->status != kEvent::erSUCCESS || $this->Application->isAdmin ) { | if ( $event->status != kEvent::erSUCCESS || $this->Application->isAdmin ) { | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $this->Application->GetVar('ajax') == 'yes' ) { | if ( $this->Application->GetVar('ajax') == 'yes' ) { | ||||
/** @var AjaxFormHelper $ajax_form_helper */ | |||||
$ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | $ajax_form_helper = $this->Application->recallObject('AjaxFormHelper'); | ||||
/* @var $ajax_form_helper AjaxFormHelper */ | |||||
$params = Array ('status' => 'OK'); | $params = Array ('status' => 'OK'); | ||||
if ( $event->status != kEvent::erSUCCESS ) { | if ( $event->status != kEvent::erSUCCESS ) { | ||||
$ajax_form_helper->prepareJSONErrors($event, $params); | $ajax_form_helper->prepareJSONErrors($event, $params); | ||||
} | } | ||||
// let FormManager decide what template to show | // let FormManager decide what template to show | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | |||||
protected function OnSetPerPage(kEvent $event) | protected function OnSetPerPage(kEvent $event) | ||||
{ | { | ||||
parent::OnSetPerPage($event); | parent::OnSetPerPage($event); | ||||
$parent_prefix = $event->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | $parent_prefix = $event->Application->getUnitOption($event->Prefix, 'ParentPrefix'); | ||||
$event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial() . ',' . $parent_prefix); | $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial() . ',' . $parent_prefix); | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |