phpelgg

Whenever comment on any issue, last comment username not update in issues


Whenever comment on any one of the issues, comment save successfully.

Comment saving code in given below:

$user = elgg_get_logged_in_user_entity();
$p_url = parse_url($_SERVER['HTTP_REFERER']);

if($p_url['path'] == '/issues/view' || $p_url['path'] == '/issues/respond')
    $tracker_comment = TRUE;
else
    $tracker_comment = FALSE;

if($tracker_comment)
{
    action_gatekeeper();

    // Get input
    $entity_guid = (int) get_input('entity_guid');

    $comment_text = get_input('generic_comment');

    // Let's see if we can get an entity with the specified GUID
    if ($entity = get_entity($entity_guid)) {

        $comment = new ElggComment();
        $comment->description = $comment_text;
        $comment->owner_guid = $user->getGUID();
        $comment->container_guid = $entity->getGUID();
        $comment->access_id = $entity->access_id;
        $guid = $comment->save();

        // If posting the comment was successful, say so
        if ($guid) {
            system_message(elgg_echo("generic_comment:posted"));

        } else {
            register_error(elgg_echo("generic_comment:failure"));
        }

    } else {

        register_error(elgg_echo("generic_comment:notfound"));

    }

    // Forward to the
    forward($entity->getURL());
}

else

    RETURN TRUE;

I am unable to retrieve the last comment username not updated in list of issues. I am using elgg_get_annotation() to retrieve the last comment details.
But not retrieving the details. Last comment code in given bellow.

if ($table_rows) {
foreach ( $table_rows as $entity ) {

    if ($entity->unread == 1) {
        $unread = "Yes";
    } else {
        $unread = "No";
    }

    if ($entity->assigned_to == 0) {
        $assigned = "No";
    } else {
        $assigned = "Yes";
    }

    $last_options = array ();

    $comments = elgg_get_annotations(array(
            'annotation_names' => 'issue_tracker_changes',
            'guid' =>  $entity->guid,
            'limit' => 1,
            'order_by' => 'n_table.id DESC',

    ));

    foreach ( $comments as $comment ) {
        $last_comment = get_entity ( $comment->owner_guid );
    }

Solution

  • Comments are no longer annotations since Elgg 1.9 but entities. You are creating comment using ElggComment class that represents entity so you're using Elgg 1.9 or newer. You just need to use elgg_get_entities instead of elgg_get_annotations. Use type object and subtype comment.