Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
395 views
in Plugins by
1. Have an event module registered through qa-plugin.php:

qa_register_plugin_module('event', 'qa-prevent-simultaneous-edits.php', 'qa_prevent_simultaneous_edits', 'Simultaneous Edits Preventer Module');
 

2. Have an event module with:

    class qa_prevent_simultaneous_edits {

        function process_event($event, $userid, $handle, $cookieid, $params) {
            if($event == "q_edit") {
                $userid = qa_get_logged_in_userid();
                qa_db_query_sub('INSERT INTO ^edit_preventer (postid, accessed, userid) VALUES ($, NOW(), $)', $params['postid'], $userid);
            }

        }
    
    }

3. Clicking on edit button of a question is not inserting anything in my db-table, nor do I get an error message!

?
Q2A version: 1.5.3
by
Am I catching the wrong event "q_edit"??

I need the event if a user clicks on "edit" button.

--

Do I need to take qa_clicked() instead, what would be the implementation?

1 Answer

+1 vote
by

The 'q_edit' event is sent when the edit is completed, not when the edit button is clicked.

If you want to prevent an edit from being started, your best bet is probably to override qa_page_q_post_rules(...) to modify the 'editable' field in the function's result. For compatibility with other plugins and future versions of Q2A, be sure to call through to qa_page_q_post_rules_base() and not just copy-paste the code.

by
I am not using it in a layer, but in the event module. Is that not possible? I just want to catch if a user clicks the "edit button", and write the time + userid + postid to the database.
by
edited by
Alright, the event module - as I see no solution - seems not to be powerful (from my recent knowledge). So I go only for the layer.

Qu.: Where do I find the question edit routine, the stuff that displays the edit form and buttons. So I can overwrite that to output a warning message to the user.

Or what element would be best to overwrite? Maybe add something before function main or use something "smaller", e.g. page_title_error? If I go for javascript body_script() would be right?

Sorry for these questions, I am in the process of finding the right way in the dark...
Thanks
by
YES! now it works with the layer! I am using:

class qa_html_theme_layer extends qa_html_theme_base {

    // override body_script to insert our js
    function body_script() {
   
        // check if user comes to edit page
        if (isset($this->content['form_q_edit'])) {
            $this->output('<script type="text/javascript">alert("edit mode");
            </script>');
        }
        // call default method output
        qa_html_theme_base::body_script();
    }

}
by
...