We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

How Does One Hook Into System Actions? | Forum

Drake Moore
Drake Moore May 22 '14
Hello!


I am writing a custom plugin and have the following requirement:


When a user updates their status, posts a picture or makes a comment, a row needs to be inserted into a custom table.  How do you hook into these system actions?


Thanks...

dave Leader
dave May 23 '14
the dao files actually call the sql functions from the main class files in ow_core/base dao


remember that the dao file is specific for the table name, you have one dao for one table and the other dao file for another table in the plugin components folder. 


thats why there is for example  topics.php and topics_dap.php the topics dao only accesses the forum_topic table. 

the plugin bol service.php file calls the dao
your plugin  component  php file sets the common vars
and then your other php files well they do what they do.  
take a look at a plugin and you will see what i mean. 

Drake Moore
Drake Moore May 23 '14
Hi Dave,


thank you for the reply.  I am clear on how the database access works with the dao pattern.  Not sure if you understood my question...  When someone updates their status, posts a picture or makes a comment I want to have my own custom listener invoked that will take some action.  The database part of it was probably unnecessary information for me to have shared...


Any help you can provide is greatly appreciated!


Cheers...

Drake Moore
Drake Moore May 23 '14
Getting closer...


I've created my own event handler class:


<?php
class TICKETER_CLASS_EventHandler{

    public function onPhotoAdd( OW_Event $e )    {

    }
    public function onAddComment( OW_Event $e )    {

        $ticket = new TICKETER_BOL_Ticket();        $ticket->create_datetime = date();        $ticket->event_id = 1;        $ticket->draw_id = 1;        $ticket->created_by_user_id = 1;        $ticket->ip = "127.0.0.1";        $ticket->action_page_link = "http://www.host.com";        TICKETER_BOL_TicketDao::getInstance()->save($ticket);    }
    public function onChangeUserStatus( OW_Event $event )    {

    }
    public function genericInit()    {

        OW::getEventManager()->bind(EVENT_BOL_EventService::EVENT_ON_CHANGE_USER_STATUS, array($this, 'onChangeUserStatus'));        OW::getEventManager()->bind(PHOTO_CLASS_EventHandler::EVENT_PHOTO_ADD, array($this, 'onPhotoAdd'));        OW::getEventManager()->bind('base_add_comment', array($this, 'onAddComment'));    }
    public function init()    {    }}


Then my init.php file does it's thing:


$eventHandler = new TICKETER_CLASS_EventHandler();$eventHandler->genericInit();$eventHandler->init();


When comments are posted a big red "parsererror" message is displayed, but the row is successfully inserted into the database.  I cannot get the methods bound to the EVENT_BOL_EventService::EVENT_ON_CHANGE_USER_STATUS and PHOTO_CLASS_EventHandler::EVENT_PHOTO_ADD to get called (I had the exact same DAO code inserted for these but have omitted it here to keep it simple).  I'm not even sure these are correct.  I am expecting EVENT_BOL_EventService::EVENT_ON_CHANGE_USER_STATUS to be called when a user updates their status and PHOTO_CLASS_EventHandler::EVENT_PHOTO_ADD to be called when a photo is added.  Can someone tell me what I am doing wrong?


Thanks!

The Forum post is edited by Drake Moore May 23 '14