PauloV Posted August 29, 2014 Report Posted August 29, 2014 Hello Can anyone help me to see what Im doing rong? I want to call the controller "AdminLiveChatCount" wen the event "Appcontroller.structure" triggers on "body_end" in "admin" side public function getEvents() { return array( array( 'event' => "Appcontroller.structure", 'callback' => array("this", "addCode") ) ); } public function addCode($event) { //$params = $event->getParams(); $params['controller'] = array("AdminLiveChatCount"); $params['action'] = "body_end"; $params['portal'] = "admin"; $event->setParams($params); } Quote
Tyson Posted August 29, 2014 Report Posted August 29, 2014 I don't much use the events, but it looks like your reference to "this" should be an object, not a string. Quote
PauloV Posted August 29, 2014 Author Report Posted August 29, 2014 I don't much use the events, but it looks like your reference to "this" should be an object, not a string. Thanks I also see this post now, that can help me http://www.blesta.com/forums/index.php?/topic/2979-more-events/?p=23298 Quote
Blesta Addons Posted August 29, 2014 Report Posted August 29, 2014 i'm also in this case ... if you or me arrive to a worked code , on share it . Quote
PauloV Posted August 29, 2014 Author Report Posted August 29, 2014 Im trying to add the event "Appcontroller.structure" to a plugin "plugins/my_name/my_name_plugin.php" but still cannot run I have trie almost everithing but no luck My latest try was: public function getEvents() { return array( array( 'event' => "Appcontroller.structure", 'callback' => array("this", "addCode") ) ); } public function addCode($event) { //$params = $event->getParams(); $params['controller'] .= array("AdminLiveChatCount"); $params['action'] .= "body_end"; $params['portal'] .= "admin"; $event->setParams($params); if (!array_key_exists("body_end", $return)) $return['body_end'] = null; $return['body_end'] .= "<p>Hello World!</p>"; $event->setReturnVal($return); } Any help? Thanks in advance PV Quote
Blesta Addons Posted August 29, 2014 Report Posted August 29, 2014 i'm now in the ofice so can't try anything , i need to return to home to make some test . i hope you can arrive to w worked solution before i lose some hours in test also PauloV 1 Quote
PauloV Posted August 29, 2014 Author Report Posted August 29, 2014 i'm now in the ofice so can't try anything , i need to return to home to make some test . i hope you can arrive to w worked solution before i lose some hours in test also lol I will trie eheh Quote
Blesta Addons Posted August 29, 2014 Report Posted August 29, 2014 i'm now in home , i will try now some test . Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 Hello Paulov , have you got it working for you ? Quote
PauloV Posted September 1, 2014 Author Report Posted September 1, 2014 Hello Paulov , have you got it working for you ? no still no luck, but I think Im close to discover the soltuion (I hope) Quote
PauloV Posted September 1, 2014 Author Report Posted September 1, 2014 OK now Im finally getting something in /[my-blesta-folder]/plugins/[myplugin]/myplugin_plugin.php added this in "class MyPlugin extends Plugin {" /** * Execute evet on Appcontroller.structure */ public function getEvents() { $this->Events->register("Appcontroller.structure", array($this,'addCode')); $event = new EventObject("Appcontroller.structure", array('controller' => 'AdminLiveChatCount', 'action' => 'body_end', 'portal' => 'admin')); $this->Events->trigger($event); } /** * On Appcontroller.structure run this */ public function addCode($event) { $params = $event->getParams(); // get current values $params['portal'] = "admin"; // only show on admin $params['body_end'] = "<p>Hello World!</p>"; // add code in the body_end $event->setReturnVal($params); // set values //print_r ($params); //output array } Now it outputs correctly the "Hello World!" on body_end but there is a bug, (I think) because I have specify to only show in "admin" but it output in both "client" and "admin" Any help? thanks in advance, PV Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 hello Paul yesterday night i have arrived to a working soltion solution .. when i return to home this night i will post it . but in general , my solutuon was based in : $params = i used it to just check wich controller or class was loaded (like identifcating the location . then i have made a condition to that url , if the $params match my condition then i use $return['head'] to pass my code to header . so the $params has no effect to sent data , is used just to identificating the controller/class admin/client side wich is loaded . Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 i have checked the client/admin side , and i found the same result as you, the return is sent to both admin and client side , even if the condition exist in my code . so all possibilities i have tried , and i'm now 99% sur the output is not controlled in wich side should returned (admin-client) . @Cody any explication about this ? or our result is true , then no way now to controle wich side should the output show . from docs this code should make output to client side only . $params = $event->getParams(); // get any set data previoslly , to not overide other plugin data $params['portal'] = "client"; // injest the markup in client side structure $event->setParams($params); // send array of new params with old and new data . so is a v3.3 bug the solution is $return['admin_head'] $return['admin_body_start'] $return['admin_body_end'] $return['client_head'] $return['client_body_start'] $return['client_body_end'] Quote
Cody Posted September 1, 2014 Report Posted September 1, 2014 Didn't I post how to use this event in another thread? <?php class MyPluginPlugin extends Plugin { ... public function getEvents() { return array( array( 'event' => "Appcontroller.structure", 'callback' => array("this", "run") ) // Add multiple events here ); } public function run($event) { // Fetch current return val $result = $event->getReturnVal(); $params = $event->getParams(); // Set return val if not set if (!isset($result['body_start'])) $result['body_start'] = null; // Update return val -- ONLY set if client portal if ($params['portal'] == "client") $result['body_start'] .= "<p>your HTML goes here</p>"; // Update return val $event->setReturnVal($result); } } ?> See Plugin Events. Creating Events. PauloV 1 Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 Didn't I post how to use this event in another thread? <?php class MyPluginPlugin extends Plugin { ... public function getEvents() { return array( array( 'event' => "Appcontroller.structure", 'callback' => array("this", "run") ) // Add multiple events here ); } public function run($event) { // Fetch current return val $result = $event->getReturnVal(); // Set return val if not set if (!isset($result['body_start'])) $result['body_start'] = null; // Update return val $result['body_start'] .= "<p>your HTML goes here</p>"; // Update return val $event->setReturnVal($result); } } ?> See Plugin Events. Hello Cody yes, but the probleme is what i have and PauloV also . we can't specify wich side the output shoud returned (client/admin) now all returned data shown in client/admin side both . theQuestion now is howto display just in client or admin side PauloV 1 Quote
Cody Posted September 1, 2014 Report Posted September 1, 2014 i have checked the client/admin side , and i found the same result as you, the return is sent to both admin and client side , even if the condition exist in my code . so all possibilities i have tried , and i'm now 99% sur the output is not controlled in wich side should returned (admin-client) . @Cody any explication about this ? or our result is true , then no way now to controle wich side should the output show . from docs this code should make output to client side only . $params = $event->getParams(); // get any set data previoslly , to not overide other plugin data $params['portal'] = "client"; // injest the markup in client side structure $event->setParams($params); // send array of new params with old and new data . You're using the params wrong for this event. PauloV 1 Quote
Cody Posted September 1, 2014 Report Posted September 1, 2014 Hello Cody yes, but the probleme is what i have and PauloV also . we can't specify wich side the output shoud returned (client/admin) now all returned data shown in client/admin side both . theQuestion now is howto display just in client or admin side See my updated post. PauloV 1 Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 don't go , stay 2 min i test and back , i remmeber i have already made this condition Quote
Blesta Addons Posted September 1, 2014 Report Posted September 1, 2014 back again , yes is working now , i get it working for me yesterday withthe same condition , and ihave already told this toPAulov in my post #12 , but i don't know how i have chende this and it stop working . Another Question if possible ; how we can make $this->Base_Uri , $this->view_dir inside the myplugin_plugin.php ? answer this and go to sleep PauloV 1 Quote
PauloV Posted September 2, 2014 Author Report Posted September 2, 2014 Just to say Thanks to naja7host and cody for all the help We have since this morning optimise all our plugins for Blesta 3.3 now with the new Events is more easier Here is a working sample of what we did in our Blesta Live Chat Plugin: /** * Execute evet on Appcontroller.structure */ public function getEvents() { return array( array( 'event' => "Appcontroller.structure", 'callback' => array("this", "addCode") ) // Add multiple events here ); } /** * On Appcontroller.structure run this */ public function addCode($event) { // Fetch current return val $result = $event->getReturnVal(); $params = $event->getParams(); // Set return val if not set if (!isset($result['body_end'])) $result['body_end'] = null; // Set return val if not set if (!isset($result['head'])) $result['head'] = null; // Update return val -- ONLY set if client portal if ($params['portal'] == "admin") $result['body_end'] .= $this->liveChatAdminInclude(); $result['head'] .= ' <style type="text/css"> <!-- .bchat_badge { top: -8px; font-size: 10px; font-weight: 700; float: none !important; position: relative; padding: 2px 5px 3px 5px;color: #fff; background-image: linear-gradient(#fa3c45, #dc0d17); background-image: -webkit-gradient(linear, center top, center bottom, from(#fa3c45), to(#dc0d17)); background-image: -webkit-linear-gradient(#fa3c45, #dc0d17); -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .7); box-shadow: 0px 1px 1px rgba(0,0,0,0.7); text-shadow: 0px -1px 0px rgba(0,0,0,0.4); -webkit-border-radius: 10px; -moz-border-radius: 10px;border-radius: 10px; } --> </style> '; if ($params['portal'] == "client") $result['body_end'] .= $this->liveChatClientInclude(); // Update return val $event->setReturnVal($result); } /** * On Appcontroller.structure add the code to Admin Side */ public function liveChatAdminInclude() { //print_r($GLOBALS); $nick = new Record(); $nick = $nick->select(array("first_name","last_name"))->from("staff")->where("user_id", "=", $GLOBALS['_SESSION']['blesta_staff_id'])->fetch(); $nick = $nick->{"first_name"}." ".$nick->{"last_name"}; $blc_include = file_get_contents(PLUGINDIR . DS . "live_chat" . DS . "views" . DS . "default" . DS . "admin_live_chat_include.pdt"); $blc_include = str_replace("{{base_web}}", WEBDIR.Configure::get("Route.admin")."/", $blc_include); $blc_include = str_replace("{{nick}}", $nick, $blc_include); return $blc_include; } /** * On Appcontroller.structure add the code to Client Side */ public function liveChatClientInclude() { $blc_include = file_get_contents(PLUGINDIR . DS . "live_chat" . DS . "views" . DS . "default" . DS . "client_live_chat_include.pdt"); $blc_include = str_replace("{{base_uri}}", WEBDIR, $blc_include); return $blc_include; } Blesta Addons 1 Quote
Cody Posted September 11, 2014 Report Posted September 11, 2014 Please note that the AppController.structure event has been updated to use arrays instead of strings for head, body_start, body_end in 3.3.0-b2. This is a backwards incompatible change (with 3.3.0-b1). Please be prepared to update your plugins if your plugins use the AppController.structure event. See CORE-1421 for more info. Blesta Addons and PauloV 2 Quote
Blesta Addons Posted September 11, 2014 Report Posted September 11, 2014 Please note that the AppController.structure event has been updated to use arrays instead of strings for head, body_start, body_end in 3.3.0-b2. This is a backwards incompatible change (with 3.3.0-b1). Please be prepared to update your plugins if your plugins use the AppController.structure event. See CORE-1421 for more info. Will Noted , is thier any possibility to make it inject php function ? something like $return_val['body_start'][] = my_own_phpfunction($vars); Note , i mean leave the function intact and run it inside the caller section (head/body_start/body_end) ? PauloV 1 Quote
Cody Posted September 12, 2014 Report Posted September 12, 2014 Will Noted , is thier any possibility to make it inject php function ? something like $return_val['body_start'][] = my_own_phpfunction($vars); Note , i mean leave the function intact and run it inside the caller section (head/body_start/body_end) ? Why would you need that? You can just call your function inside of your plugin. PauloV 1 Quote
Blesta Addons Posted September 13, 2014 Report Posted September 13, 2014 i need this to override some varaible in the body , or to set other that are not set in some pages . also i need it to run my own function in the header , i use it for seo analisys ( the preaction event is not given me some info i need , like the title page and some other vars . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.