Skip to content

Commit

Permalink
Merge pull request #89 from wiwi-nl/master
Browse files Browse the repository at this point in the history
UPDATE: added functionality to create tickets with content description
  • Loading branch information
Sander authored Mar 2, 2023
2 parents ba37ae4 + e4aea64 commit 5d1866d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Invoices/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class Invoice
const COMPANY = 'company';

/**
* @var int
* @var int
*/
private $id;

/**
* @var string
* @var string
*/
private $name;

Expand Down
4 changes: 2 additions & 2 deletions Products/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class Product
{
/**
* @var int
* @var int
*/
private $id;

/**
* @var string
* @var string
*/
private $name;

Expand Down
17 changes: 17 additions & 0 deletions Teamleader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use SumoCoders\Teamleader\Notes\Note;
use SumoCoders\Teamleader\Products\Product;
use \SumoCoders\Teamleader\CustomFields\CustomField;
use SumoCoders\Teamleader\Tickets\Ticket;

/**
* Teamleader class
Expand Down Expand Up @@ -1306,6 +1307,22 @@ public function notesGetNotes($objectType, $objectId, $pageNumber = 0)
return $notes;
}

// methods for tickets

/**
* Add a ticket
*
* @param Ticket $ticket
* @return Ticket
*/
public function addTicket(Ticket $ticket)
{
$fields = $ticket->toArrayForApi();
$id = $this->doCall('addTicket.php', $fields);
$ticket->setId($id);
return $ticket;
}

// methods for products

/**
Expand Down
116 changes: 116 additions & 0 deletions Tickets/Ticket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace SumoCoders\Teamleader\Tickets;

use SumoCoders\Teamleader\Exception;
use SumoCoders\Teamleader\Teamleader;
use SumoCoders\Teamleader\Crm\Contact;
use SumoCoders\Teamleader\Crm\Company;

class Ticket
{
/**
* @var integer
*/
private $id;

/**
* @var string
* client_name
*/
private $clientName;

/**
* @var string
* client_email
*/
private $clientEmail;

/**
* @var string
* subject
*/
private $subject;

/**
* @var string
* description_html
*/
private $content;


public function setId($id) {
$this->id = $id;
}

public function getId() {
return $this->id;
}

public function getClientName() {
return $this->clientName;
}

public function setClientName($clientName) {
$this->clientName = $clientName;
}

public function getClientEmail() {
return $this->clientEmail;
}

public function setClientEmail($clientEmail) {
$this->clientEmail = $clientEmail;
}

public function getSubject() {
return $this->subject;
}

public function setSubject($subject) {
$this->subject = $subject;
}

public function getContent() {
return $this->content;
}

public function setContent($content) {
$this->content = $content;
}

/**
* Prepares the ticket for an API request
* API-request
*
* @return array
*/
public function toArrayForApi()
{
$return = array(
'client_name' => $this->getClientName(),
'client_email' => $this->getclientEmail(),
'subject' => $this->getSubject(),
'description_html' => $this->getContent(),
);

return $return;
}

/**
* Initialize an Ticket with raw data we got from the API
*
* @return Ticket
*/
public static function initializeWithRawData($data)
{
$ticket = new Ticket();

$ticket->setClientName($data['client_name']);
$ticket->setClientEmail($data['client_email']);
$ticket->setSubject($data['subject']);
$ticket->setContent($data['content']);

return $ticket;
}
}

0 comments on commit 5d1866d

Please sign in to comment.