Jump to content

Grab the number of open tickets / Tutorial on how to make a plugin.


Recommended Posts

Posted

@Naja7Host helped show me how to get this working and this is what he did to achieve it:

Folder structure:

- plugins
---  count_tickets
--------- count_tickets_controller.php
------- controllers
----------- client_main.php
------- models
----------- client_tickets_model.php
----------- count_tickets_model.php


If you just want to download the files and not do it manually you can grab them from: https://licensecart.com/public/count_tickets.zip

Posted

Next make the files:

/plugins/count_tickets/count_tickets_controller.php

<?php
/**
 * News plugin handler
 */
class CountTicketsController 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";
	}
}

/plugins/count_tickets/controllers/client_main.php

<?php
/**
 */
class CLientMain extends CountTicketsController
{

	/**
	 * Pre-action save and upload
	 */
	public function preAction()
	{
		parent::preAction();
		$this->uses(["SupportManager.SupportManagerTickets"]);
		$this->client_id = $this->Session->read("blesta_client_id");
	}

	/**
	 * Portal Newe index
	 */
	public function index()
	{
		if ($this->isAjax()) {
			$response = $this->SupportManagerTickets->getStatusCount("open", null, $this->client_id);

			// JSON encode the AJAX response
			$this->outputAsJson($response);
			return false;
		}

		return false;
	}
}

/plugins/count_tickets/models/client_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);
    }
 } 

/plugins/count_tickets/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);
    }
 } 

 

Posted

Next on the /app/views/client/bootstrap/structure.pdt add this:

<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/client_main") . '", null, function(data) {
					if (data)
						$("#count_ticket").html(data);
				},
				null,
				{dataType:"json"});
			}
		');
		?>

 

Posted
  On 9/27/2016 at 12:49 AM, naja7host said:

Just to note the model is no longer used as we use the support manager model . Is safe to delete the model directory .

Expand  

Magic haha :P Just to let people know donated to you mate for your help and time :D

Posted
  On 9/27/2016 at 1:57 PM, naja7host said:

Maybe we will make a plugin that return some usefull info for the client like

Tickets open closed

Services active suspend

Invoices closed open

Pending orders

 

Expand  

That would be awesome mate :P so you can expand by seeing how you did what for each one and then hopefully more can expand as needed?

  • 2 months later...
Posted

@Licensecart and @Blesta Addons

I uploaded the files for "Count tickets"   to   /plugins/count_tickets

And then went to   /admin/settings/company/plugins/available/

I did not see anything.

I even deleted the "model" directory folder.

==========

 

Why am I not able to see the plugin to activate it ?

OR...

Is it automatically activated when uploaded ?

 

Posted
  On 11/28/2016 at 3:52 AM, turner2f said:

@Licensecart and @Blesta Addons

I uploaded the files for "Count tickets"   to   /plugins/count_tickets

And then went to   /admin/settings/company/plugins/available/

I did not see anything.

I even deleted the "model" directory folder.

==========

 

Why am I not able to see the plugin to activate it ?

OR...

Is it automatically activated when uploaded ?

 

Expand  

Ignore this thread go to the contribute thread with the proper script / plugin by Naja7Host.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...