Index: branches/5.1.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 12127) +++ branches/5.1.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 12657) @@ -1,6 +1,6 @@ Application->GetTopmostPrefix($event->Prefix, true); // this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p - $item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix'); - return $item_prefix; + return $this->Application->getUnitOption($main_prefix, 'PermItemPrefix'); } /** @@ -326,21 +327,67 @@ $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) { + $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); + } } } - /** * Updates item review counter * * @param kEvent $event */ function OnAfterItemUpdate(&$event) { + parent::OnAfterItemUpdate($event); + $this->updateSubitemCounters($event); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if ($this->Application->IsAdmin() && !$object->IsTempTable()) { + // send email on review status change from reviews grid in admin + $review_status = $object->GetDBField('Status'); + $process_status = Array (STATUS_ACTIVE, STATUS_DISABLED); + + if (($review_status != $object->GetOriginalField('Status')) && in_array($review_status, $process_status)) { + $this->_loadMainObject($event); + + $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'APPROVE' : 'DENY'); + $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); + } + } } /** + * Loads main object of review (link, article, etc.) + * + * @param kEvent $event + * @return kCatDBItem + */ + function _loadMainObject(&$event) + { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $parent_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $parent_table_key = $this->Application->getUnitOption($event->Prefix, 'ParentTableKey'); + $foreign_key = $this->Application->getUnitOption($event->Prefix, 'ForeignKey'); + + $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); + } + + /** * Updates total review counter, cached rating, votes count * * @param kEvent $event @@ -496,6 +543,4 @@ } return $title_field; } - } - -?> \ No newline at end of file + } \ No newline at end of file