creating a simple delete button

Hi Guys,

I have a page that details some information on an object then also returns comments. I'm using a comments hook and not the default comments system.

within the foreach routine that grabs the comments - I'd like either the user that posted the comment or the admin to be able to delete the comment.

within each comment i have saved

$compost->owner_guid as well as a whole bunch of relevant info.

at the very end of the foreach routine as the particular $compost->info is grabbed - I'm not sure if I keep it as simple as something like;

                    if ( $vars['entity']->canEdit() ) {
                    $info .= elgg_view('input/button', array('commentGUID' => $compost->owner_guid, 'action'=>$compost->delete()));
                    }

OR

if i need to call an action in which the deletion happens...(and be more specific with the IF routine prior:

if $compost->owner_GUID == $_SESSION['user']->getGUID(); {

// and then an OR if is admin

$info .= elgg_view('input/button', array('commentGUID' => $compost->getGUID(), 'action'=> "{$CONFIG->url}mod/myplugin/actions/comments/delete.php"));

}

Any thoughts or suggestions - any help greatly appreciated.... :D

Regards,

Jimbo

 

  • <?php

    echo elgg_view("output/confirmlink",

      array( 'href' => $vars['url'] . "action/thewire/delete?comment_guid=" . $vars['entity']->getGUID(),

     

          'text' => elgg_echo('delete'),

     

          'confirm' => elgg_echo('deleteconfirm'),

     

    ));

    ?>

  • ese código no funciona me muestra mal el riverdashboard 

  • *bump*

    any idea's as to why my plugin would return the error:

    Fatal error: Call to a member function delete() on a non-object in .../actions/comments/delete.php

    and still actually delete the comment?

    my delete.php now looks like this;

    <?php
    $guid = get_input('comment_guid');
    $comment = get_entity($guid);
    $comment->delete();
    system_message(elgg_echo("generic_comment:deleted"));
    $returnurl = full_url();
    forward($returnurl);
    ?>

    (english, and this is in no relation to riverdashboard, please).

    Thanks,

     

  • **bump**

    anyone have any ideas what might be causing the fatal error, above?

     

  • a comment is not an object, it's an annotation. Although I might be way off base. What I'm confused about is that comments have a standard delete link in them anyway. Go to:

    elgg-root/views/default/comments and have a poke around (guessing at the folder name but it's in views/default somewhere)

  • Thanks Trajan - I am basically doing a comment work-around to allow for more input by users. I know the default comment system works as an annotation - but I can't see where in my:

                    $comment = new ElggObject();   
                    $comment->subtype = "comment";   
                    $comment->owner_guid = $_SESSION['user']->getGUID();   
                    $comment->container_guid = $_SESSION['user']->getGUID();
                    $comment->access_id = 1; // logged in users   
                    $comment->parent_guid = $entity_guid;

                    $comment->save();

    ...the $comment is saved as as annotation vs. an object.
    I will try calling delete_annotation() etc.
    (the funny thing is it when using the delete button it returns the fatal error, but then deletes the comment as desired anyway?!)
  • Yes, I've come across similar peculiarities with fatal errors as well. For me it calls a fatal error but still displays the correct content.

  • 1. You are definitely saving the comment as an object according to the code that you posted.

    2. Your delete action looks like it should work. It should have a check after getting the entity to make sure that you actually got something.

    3. An object is not going to be deleted if there is no object to delete. There has to be something else going on here. Basically - we need more information to help.

  • Hi Guys,

    I've created a topic to help cover all the basics of what I'm trying to achieve with the comments system. Hopefully its useful for everyone. And can help resolve the delete functionality.

    http://community.elgg.org/mod/groups/topicposts.php?topic=698389&group_guid=7

    Look forward to hearing from you.