Michael Posted February 21, 2019 Report Posted February 21, 2019 Is there a way to extend the support manager to create a ticket or will it be best to use the API and if it's the API how is the best way to do it? I saw @Blesta Addons did this and I edited it but I'm trying to start a ticket? $reply_data = array( 'ticket_id'=> NULL, 'vars' => array( 'ticket_id'=>null, 'staff_id' => null, 'client_id' => $data['client_id'], 'contact_id' => null, 'type' => "reply", 'details' => $data['content'], 'status' => "open", 'staff_id' => null, ), 'files' => null, 'new_ticket' => true ); $response = $api->post("support_manager.support_manager_tickets", "addReply", $reply_data); Because I would like to set these up somehow: - Subject - Department - priority Thank you for your help. Quote
Jono Posted February 21, 2019 Report Posted February 21, 2019 Well I kinds depends. If you are looking to do it through the API then you should first call SupportManagerTickets::add() like this $ticket_data = [ 'vars' => [ 'department_id' => 1, 'staff_id' => 1, // This field is optional 'service_id' => 1, // This field is optional 'client_id' => 1, // This field is optional 'email' => 'firsttes@mailinator.com', // This field is optional 'summary' => 'Something is terribly wrong', 'priority' => 'critical', 'status' => 'open' ] ] $ticket = $api->post("support_manager.support_manager_tickets", "add", $ticket_data); On the other hand, if you are within Blesta you should be able to use the loader to access the model even though it's from a plugin. In a controller that would look like this $ticket_data = [ 'department_id' => 1, 'staff_id' => 1, // This field is optional 'service_id' => 1, // This field is optional 'client_id' => 1, // This field is optional 'email' => 'firsttes@mailinator.com', // This field is optional 'summary' => 'Something is terribly wrong', 'priority' => 'critical', 'status' => 'open' ]; $this->uses(['SupportManager.SupportManagerTickets']); $ticket = $this->SupportManagerTickets->add($ticket_data); Blesta Addons and Michael 1 1 Quote
Michael Posted February 21, 2019 Author Report Posted February 21, 2019 Thank you Jonathan mate Paul 1 Quote
Michael Posted February 24, 2019 Author Report Posted February 24, 2019 @Jono sorry mate how do we add the ticket content because we can't add 'details' to the ticket? Quote
Tyson Posted February 25, 2019 Report Posted February 25, 2019 There are two separate calls you need to make: Create a ticket (as @Jono mentioned above) Create a reply for the ticket (as you did in your OP). FYI the first question from a customer that opens the ticket represents the first reply Michael 1 Quote
Michael Posted February 25, 2019 Author Report Posted February 25, 2019 6 minutes ago, Tyson said: There are two separate calls you need to make: Create a ticket (as @Jono mentioned above) Create a reply for the ticket (as you did in your OP). FYI the first question from a customer that opens the ticket represents the first reply Thanks mate. Is there a way to redirect to another function in Blesta for example: <?php public function index(){ if($success == true){ return self::success(); } } public function success(){ //run this function? } ?> Quote
Tyson Posted February 25, 2019 Report Posted February 25, 2019 56 minutes ago, Blesta.Store said: Thanks mate. Is there a way to redirect to another function in Blesta for example: <?php public function index(){ if($success == true){ return self::success(); } } public function success(){ //run this function? } ?> Your example mixes procedural and class syntax, so I'm not sure if you're running individual functions or if those are methods in a class. If you are writing procedural functions, simply: return success(); otherwise for one class method to call another non-statically: return $this->success(); Michael 1 Quote
Michael Posted February 25, 2019 Author Report Posted February 25, 2019 Thanks Tyson mate I'll try both Quote
Michael Posted February 25, 2019 Author Report Posted February 25, 2019 Thanks @Tyson mate that return $this->valid($client_info); worked as I found I had to pass the variable through to the function to show the information on the views. However submitting another form it tries to run the first form post in the index function and not the post in the success function do I need to set something up on the forms to call each one? <?php class Validate extends SupportController { public function index(){ if (!empty($this->post)) { $data2 = (isset($this->post) ? $this->post : ''); if($data2){ return $this->valid($data2); } } } public function valid($data2){ if (!empty($this->post)) { $data = (isset($this->post) ? $this->post : ''); if($data){ return true; } } } } both of the forms have this in the views: <?php $this->Form->create(null, ['id' => 'validate', 'enctype' => 'multipart/form-data']); ?> <?php $this->Form->create(null, ['id' => 'support_ticket', 'enctype' => 'multipart/form-data']); ?> Quote
Tyson Posted February 25, 2019 Report Posted February 25, 2019 It sounds like you want to POST each form to a separate location. <?php // POST to the valid method $this->Form->create('/validate/valid/', [...]); ... $this->Form->end(); // POST to the index method $this->Form->create(null, [...]); ... $this->Form->end(); Your Validate::valid() method really shouldn't require an argument if you want to POST to it Michael 1 Quote
Richzendy Posted June 10, 2020 Report Posted June 10, 2020 Hi all, How this: $this->uses(['SupportManager.SupportManagerTickets']); Can be used from a module? i can make a button on a client tab just to create a ticket with a format to require something with a pre-defined data. Quote
Abdy Posted June 10, 2020 Report Posted June 10, 2020 26 minutes ago, Richzendy said: Hi all, How this: $this->uses(['SupportManager.SupportManagerTickets']); Can be used from a module? i can make a button on a client tab just to create a ticket with a format to require something with a pre-defined data. Try using Loader::loadModels($this, ['SupportManager.SupportManagerTickets']); This is due to $this->uses() is not accessible from a module. Quote
Richzendy Posted June 10, 2020 Report Posted June 10, 2020 3 hours ago, Abdy said: Try using Loader::loadModels($this, ['SupportManager.SupportManagerTickets']); This is due to $this->uses() is not accessible from a module. Hi! thank you, is working now, but to create a new ticket a details is needed, this can be all code to create a new ticket: $ticket_data = [ 'department_id' => 1, 'staff_id' => 1, // This field is optional 'service_id' => 38, // This field is optional 'client_id' => 1, // This field is optional 'summary' => 'This a new Requirement', 'priority' => 'high', 'status' => 'open', ]; $ticket_repply = [ 'details' => 'Hi, I need a new Requirement' ]; Loader::loadModels($this, ['SupportManager.SupportManagerTickets']); $ticket = $this->SupportManagerTickets->add($ticket_data); if (!is_null($ticket)) { $this->SupportManagerTickets->addReply($ticket,$ticket_repply); } Quote
Manuel Posted December 8, 2022 Report Posted December 8, 2022 Hello, A idea below... it works. <?php require_once "blesta_api.php"; $user = "apiuser"; $key = "apipw"; $url = "https://domain.tld/api/"; $clientmail = "test@demo.tld"; $ticketsummary = "This is a test."; $ticketmsg = "Hello, I am unable to login. Please help!!"; $ticket_data = [ 'vars' => [ 'department_id' => 1, 'staff_id' => 1, // optional, set staffID 'service_id' => null, // optional 'client_id' => null, // optional 'email' => $clientmail, // optional 'summary' => $ticketsummary, 'priority' => 'critical', 'status' => 'open' ] ]; $api = new BlestaApi($url, $user, $key); $ticket = $api->post("support_manager.support_manager_tickets", "add", $ticket_data); $zzid = $ticket->response(); $reply_data = array( 'ticket_id'=> $zzid, 'vars' => array( 'ticket_id'=> $zzid, 'staff_id' => null, 'client_id' => null, 'contact_id' => null, 'type' => "reply", 'details' => $ticketmsg, 'status' => "open", 'staff_id' => null, ), 'files' => null, 'new_ticket' => false ); $response = $api->post("support_manager.support_manager_tickets", "addReply", $reply_data); ?> 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.