Michael Posted September 26, 2016 Report Posted September 26, 2016 Is there a way to grab things from the database for use on the structure using something like: $client_ticket_id = $client->id; $status_opened = "open"; $ticket_numbers = $this->Record->select()->from("support_tickets")->where('client_id', $client_ticket_id)->where('status', $status_opened)->fetch(); $ticket_open = count($ticket_numbers); Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 The simple way is to create a simple plugin that fetch the request and show the result as json, then in your template just add a blestarequest ajax to fetch the data and show it in DIV . something like the balance credit of client in his profile . Michael and INUMIO-Rob 2 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 25 minutes ago, naja7host said: The simple way is to create a simple plugin that fetch the request and show the result as json, then in your template just add a blestarequest ajax to fetch the data and show it in DIV . something like the balance credit of client in his profile . Merci mate Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 6 minutes ago, Licensecart said: Merci mate If you want help in coding it i'm ready .... Paul 1 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 5 minutes ago, naja7host said: If you want help in coding it i'm ready .... I would need to learn how to do a basic plugin but if it's simple and you're up for it it would help the community and maybe expand what can be done and I'll donate a bit towards it mate. Quote
Paul Posted September 26, 2016 Report Posted September 26, 2016 What are you trying to do exactly Mike? Show like ticket stats on the portal or someplace for public view? I'd like to update the ticket system to show stats in the admin UI, and also have an optional javascript feed to embed on your website. Michael 1 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 13 minutes ago, Paul said: What are you trying to do exactly Mike? Show like ticket stats on the portal or someplace for public view? I'd like to update the ticket system to show stats in the admin UI, and also have an optional javascript feed to embed on your website. yeah mate so we can show the tickets open on the structure page like client overview and maybe if we can get that sorted maybe be able to pull other content from the database like "How many active services" a client has active etc :). ariq01 and INUMIO-Rob 2 Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 @Licensecart relax, take a pen and paper . cup of coffee ... i will teach you in 5 min !!!!!. create the fallowing directory files structure . count_tickets Lــــــــــ count_tickets_controller.php Lــــــــــ count_tickets_model.php Lــــــــــ controllers Lــــــــــ main.php Lــــــــــ models Lــــــــــ count_tickets.php next step is the content of each file . INUMIO-Rob and Paul 2 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 11 minutes ago, naja7host said: @Licensecart relax, take a pen and paper . cup of coffee ... i will teach you in 5 min !!!!!. create the fallowing directory files structure . count_tickets Lــــــــــ count_tickets_controller.php Lــــــــــ count_tickets_model.php Lــــــــــ controllers Lــــــــــ main.php Lــــــــــ models Lــــــــــ count_tickets.php next step is the content of each file . Done merci mate Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 count_tickets_controller.php <?php class MyTestController extends AppController { public function preAction() { $this->structure->setDefaultView(APPDIR); parent::preAction(); // Override default view directory $this->view->view = "default"; $this->orig_structure_view = $this->structure->view; $this->structure->view = "default"; } } count_tickets_model.php <?php class CountTicketsModel extends AppModel { } Next is coming Paul and INUMIO-Rob 2 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 Done mate changed the top one to <?php class CountTicketsController extends AppController Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 models/count_tickets_model.php <?php class CountTicketsModel extends AppModel { /** * Constructor */ public function __construct() { parent::__construct(); // You Can Load Language here } /** * Retrieves ticket count * * @return string */ public function getCountTickets( $client_ticket_id, $status_opened ) { $ticket_numbers = $this->Record->select()-> from("support_tickets")-> where('client_id', $client_ticket_id)-> where('status', $status_opened)-> fetch(); return count($ticket_numbers); } } Paul and INUMIO-Rob 2 Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 controllers/main.php <?php /** */ class Main extends CountTicketsController { /** * Pre-action */ public function preAction() { parent::preAction(); $this->uses(["CountTickets.CountTicketsModel")); $this->client_id = $this->Session->read("blesta_client_id"); } /** * Portal Newe index */ public function index() { if ($this->isAjax()) { $response = $this->CountTicketsModel ->getCountTickets($this->client_id, "open"); // JSON encode the AJAX response $this->outputAsJson($response); return false; } return false; } } INUMIO-Rob and Paul 2 Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 Just to note the model file is count_tickets_model.php and not count_tickets.php . now you can access the plugin via a url and see what it show you . http://your_domain.com/blesta/plugin/count_tickets/main Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 now the template side, add a jquery request to fetch the numbers and add the response to a div class that has the id count_ticket . <div id="count_ticket">0</div> <?php $this->Javascript->setInline(' $(document).ready(function() { fetchCountTickets(); }); function fetchCountTickets() { $(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/count_tickets/main") . '", null, function(data) { if (data) $("#count_ticket").html(data); }, null, {dataType:"json"}); } '); ?> INUMIO-Rob and Paul 2 Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 Lol mate trust me to duck up as you told me what to do, got a white page. Do you have Skype mate? Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 13 minutes ago, Licensecart said: Lol mate trust me to duck up as you told me what to do, got a white page. Do you have Skype mate? error reporting is enabled ? i suspect it the model name maybe . can you PM the url ? Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 8 minutes ago, naja7host said: error reporting is enabled ? i suspect it the model name maybe . can you PM the url ? I don't get anything with the errors on lol it's like I'm missing a page or cocked up: https://licensecart.com/plugin/count_tickets/main Zip: https://licensecart.com/remote/plugins.zip Quote
Blesta Addons Posted September 26, 2016 Report Posted September 26, 2016 Uff how stupid 'im , is normal to see a blank page , because it will show response only in ajax request ; in controller main change this if ($this->isAjax()) { by if (!$this->isAjax()) { and revert back when you call it from Jquery request . Quote
Michael Posted September 26, 2016 Author Report Posted September 26, 2016 6 minutes ago, naja7host said: Uff how stupid 'im , is normal to see a blank page , because it will show response only in ajax request ; in controller main change this if ($this->isAjax()) { by if (!$this->isAjax()) { and revert back when you call it from Jquery request . Still the same mate: https://licensecart.com/plugin/count_tickets/main Maybe I'm being stupid too lol. Quote
Michael Posted September 27, 2016 Author Report Posted September 27, 2016 Thanks mate let's make a thread and upload it free to download now we've got a working one INUMIO-Rob 1 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.