/** * The delete handler will drop all entries associated with any deleted object * so that our DB is clean. * * Uses SUDO to ensure privileges. */ function _on_watched_dba_delete($object) { $sudo = midcom::get('auth')->request_sudo(); $result = net_nehmer_comments_comment::list_by_objectguid($object->guid); foreach ($result as $comment) { $comment->delete(); } if ($sudo) { midcom::get('auth')->drop_sudo(); } }
/** * Loads the comments, does any processing according to the state of the GET list. * On successful processing we relocate once to ourself. * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ function _handler_comments($handler_id, array $args, array &$data) { if (!mgd_is_guid($args[0])) { throw new midcom_error("The GUID '{$args[0]}' is invalid. Cannot continue."); } $this->_objectguid = $args[0]; midcom::get('cache')->content->register($this->_objectguid); if ($handler_id == 'view-comments-nonempty') { $this->_comments = net_nehmer_comments_comment::list_by_objectguid_filter_anonymous($this->_objectguid, $this->_config->get('items_to_show'), $this->_config->get('item_ordering'), $this->_config->get('paging')); } else { $this->_comments = net_nehmer_comments_comment::list_by_objectguid($this->_objectguid, $this->_config->get('items_to_show'), $this->_config->get('item_ordering'), $this->_config->get('paging')); } if ($this->_config->get('paging') !== false) { $data['qb_pager'] = $this->_comments; $this->_comments = $this->_comments->execute(); } if (midcom::get('auth')->user || $this->_config->get('allow_anonymous')) { $this->_init_post_controller(); $this->_process_post(); // This might exit. } if ($this->_comments) { $this->_init_display_datamanager(); } $this->_process_admintoolbar(); // This might exit. if ($handler_id = 'view-comments-custom' && count($args) > 1) { midcom::get()->skip_page_style = true; $this->custom_view = $args[1]; } $this->_prepare_request_data(); midcom::get('metadata')->set_request_metadata($this->_get_last_modified(), $this->_objectguid); if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { midcom::get()->skip_page_style = true; } }
/** * Update possible ratings cache as requested in configuration */ private function _cache_ratings() { $config = midcom_baseclasses_components_configuration::get('net.nehmer.comments', 'config'); if ($config->get('ratings_enable') && ($config->get('ratings_cache_to_object') || $config->get('comment_count_cache_to_object'))) { // Handle ratings $comments = net_nehmer_comments_comment::list_by_objectguid($this->objectguid); $ratings_total = 0; $rating_comments = 0; $value = 0; foreach ($comments as $comment) { if (!empty($comment->rating)) { $rating_comments++; $ratings_total += $comment->rating; } } // Get parent object $parent_property = $config->get('ratings_cache_to_object_property'); midcom::get('auth')->request_sudo('net.nehmer.comments'); if ($config->get('ratings_cache_total')) { $value = $ratings_total; } else { if ($rating_comments != 0) { $value = $ratings_total / $rating_comments; } } if ($config->get('ratings_cache_to_object_property_metadata')) { $metadata = midcom_helper_metadata::retrieve($this->objectguid); $metadata->set($parent_property, round($value)); } else { $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid); // TODO: Figure out whether to round if (!$config->get('ratings_cache_to_object_use_rcs')) { $parent_object->_use_rcs = false; } $parent_object->{$parent_property} = $value; $parent_object->update(); if (!$config->get('ratings_cache_to_object_use_rcs')) { $parent_object->_use_rcs = true; } } // Get parent object $parent_property = $config->get('comment_count_cache_to_object_property'); if ($config->get('comment_count_cache_to_object_property_metadata')) { $metadata = midcom_helper_metadata::retrieve($this->objectguid); $metadata->set($parent_property, count($comments)); } else { $parent_object = midcom::get('dbfactory')->get_object_by_guid($this->objectguid); if (!$config->get('comment_count_cache_to_object_use_rcs')) { $parent_object->_use_rcs = false; } $parent_object->{$parent_property} = count($comments); $parent_object->update(); if (!$config->get('comment_count_cache_to_object_use_rcs')) { $parent_object->_use_rcs = true; } } midcom::get('auth')->drop_sudo(); } }