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
6 minutes ago, 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 .

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

Posted
27 minutes ago, naja7host said:

Thanks mate ....

You got the small plugin ever created for blesta  , just 2 files !!!!

Lol mate I still can't even edit that to grab services and there's not much to edit lol. Need more time I think :D

Posted
14 minutes ago, 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

 

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
7 hours ago, 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 ?

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...