diff --git a/redmine.php b/redmine.php index 0b33e01..f6e3b0f 100644 --- a/redmine.php +++ b/redmine.php @@ -1,11 +1,22 @@ - + */ class class_redmine { protected $redmine_key = ''; protected $redmine_url = ''; - - //files + /** + * Upload $filecontent and return token. + * + * @param mixed $filecontent - content of file + * @return mixed $token is object, string can be obtained in $token->upload->token + */ function get_upload_token($filecontent) { $upload_url = $this->redmine_url.'uploads.json?key='.$this->redmine_key; $request['type'] = 'post'; @@ -13,7 +24,16 @@ class class_redmine { return $token = $this->curl_redmine($upload_url,$request,$filecontent); } - function uploadd_attachment(string $issue_id, string $filename, string $filetype, $filecontent){ + /** + * Uploads an attachment, attaches it to an issue and returns updated issue + * + * @param string $issue_id numeric id of issue to attach file + * @param string $filename name of file + * @param string $filetype type of content i.e. "image/png" + * @param mixed $filecontent content of file. + * @return mixed $issue updated issue + */ + function upload_attachment(string $issue_id, string $filename, string $filetype, $filecontent){ $token = $this->get_upload_token($filecontent); if (!$token) { return null; @@ -22,6 +42,14 @@ class class_redmine { return $this->attach_to_issue($issue_id,$upload_token, $filename, $filetype); } + /** + * Download an attachment or thumbnail + * + * @param string $attachment_id numeric id of attachment + * @param bool $thumbnail if true downloading thumbnail + + * @return mixed $filecontent - content of file + */ function download_attachment(string $attachment_id, bool $thumbnail=false) { if ($thumbnail) { $file_url = $this->redmine_url.'attachments/thumbnail/'.$attachment_id.'?key='.$this->redmine_key; @@ -39,7 +67,12 @@ class class_redmine { } } - //Issue + /** + * Create issue + * + * @param $post_data - string to post to redmine (need to update) + * @return mixed $issue - new data + */ function create_issue($post_data) { $issue_url = $this->redmine_url.'issues.json?key='.$this->redmine_key; $request['type'] = 'post'; @@ -47,6 +80,14 @@ class class_redmine { return $this->curl_redmine($issue_url,$request,$post_data); } + /** + * get issue + * + * @param string $issue_id numeric issue id + * @param string $project_id numeric project id + * @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); + * @return mixed $issue - new data + */ function get_issue(string $issue_id='',string $project_id='', array $inc=array()) { if (count($inc) > 0) { $inc = implode(",", $inc); @@ -64,6 +105,15 @@ class class_redmine { return $this->curl_redmine($issue_url); } + /** + * get issue + * + * @param string $issue_id digits only issue id + * @param string $upload_token digits only project id + * @param string $upload_token + * @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); + * @return mixed $issue - new data + */ function attach_to_issue(string $issue_id,string $upload_token, string $filename, string $filetype) { $issue_url = $this->redmine_url.'issues/'.$issue_id.'.json?key='.$this->redmine_key; $update = array( "issue" => array( @@ -80,6 +130,13 @@ class class_redmine { return $this->curl_redmine($issue_url, $request , $post_data); } + /** + * add comment to issue + * + * @param string $issue_id digits only issue id + * @param string $comment comment to add to the issue + * @return mixed $issue - new data + */ function post_issue_comment(string $issue_id,string $comment) { $issue_url = $this->redmine_url.'issues/'.$issue_id.'.json?key='.$this->redmine_key; $update = array( "issue" => array( @@ -93,6 +150,7 @@ class class_redmine { return $this->curl_redmine($issue_url, $request , $post_data); } + //Projects function get_projects($project_id='') { $proj_url = ($project_id=='')?$this->redmine_url.'projects.json?key='.$this->redmine_key : $this->redmine_url.'projects/'.$project_id.'.json?key='.$this->redmine_key; @@ -110,11 +168,12 @@ class class_redmine { return $this->curl_redmine($cont_url); } - function get_contact_id(int $id, bool $issues) { + function get_contact_id(string $id, bool $issues) { $cont_url = ($issues) ? $this->redmine_url."contacts/$id.json?key=".$this->redmine_key.'&include=issues' : $this->redmine_url."contacts/$id.json?key=".$this->redmine_key; - return $this->curl_redmine($cont_url, array(),''); + echo($cont_url); + return $this->curl_redmine($cont_url); } function create_contact(array $contact) { @@ -125,6 +184,54 @@ class class_redmine { return $this->curl_redmine($cont_url,$request,$post_data); } + /** + * attach contact to issue + * + * @param string $issue_id digits only issue id + * @param string $contact_id digits only contact id + * @return mixed $issue - new data + */ + function attach_issue_to_contact(string $issue_id,string $contact_id) { + $contact_url = $this->redmine_url."contacts/".$contact_id."?key=".$this->redmine_key; + $update = array( "contact" => array( + "issues"=> array( 0=> array("id" => $issue_id)) + ) + ); + $request['type'] = 'put'; + $request['content_type'] = 'application/json'; + + $post_data = json_encode($update); + return $this->curl_redmine($contact_url, $request , $post_data); + } + + function create_ticket(string $contact_id, string $subject, string $description) { + $issue_url = $this->redmine_url."helpdesk/create_ticket.xml?key=".$this->redmine_key; + $issue = array( "ticket" => array ( + "issue" => array( + "project_id" => "xtesx", + "tracker_id" => "3", + "subject" => $subject, + "description"=> $description, + ), + "contact" => array ("id" => $contact_id), + )); + $issue_xml = " + + + + 3 + $subject + $description + + + $contact_id + + "; + $request['type'] = 'post'; + $request['content_type'] = 'application/xml'; + return $this->curl_redmine($issue_url, $request, $issue_xml ); + } + //Curl function curl_redmine(string $redmine_url,array $request=array(),string $post_data='') { if(!isset($request['type'])){ $request['type']=null; } diff --git a/$screenshot_download.png b/screenshot_download.png similarity index 100% rename from $screenshot_download.png rename to screenshot_download.png diff --git a/screenshot_eskiz.png b/screenshot_eskiz.png new file mode 100644 index 0000000..1351219 Binary files /dev/null and b/screenshot_eskiz.png differ diff --git a/tester.php b/tester.php index c0e0b27..432d75a 100644 --- a/tester.php +++ b/tester.php @@ -46,7 +46,15 @@ $test_contact = array("contact" => array("first_name" => "Test testing", // $res = $obj_redmine->send_contact($data); -// $res = $obj_redmine->get_contact_id(2906, true); +//$res = $obj_redmine->get_contact_id("3373", true); +//var_dump($res); + +$inc=array(0 => "contacts"); +$res = $obj_redmine->get_issue($issue_id="10442", '', $inc); +//var_dump($res); +$res = $obj_redmine->create_ticket("3373", "One more test", "test test one more"); + +var_dump($res); //$filecontent = file_get_contents("screenshot.png"); //$token = $obj_redmine->get_upload_token($filecontent); @@ -57,16 +65,16 @@ $test_contact = array("contact" => array("first_name" => "Test testing", //$filecontent = file_get_contents("screenshot.png"); -//echo($obj_redmine->uploadd_attachment('10314', 'screenshot.png', 'image/png', $filecontent)); +// echo($obj_redmine->upload_attachment('10314', 'screenshot.png', 'image/png', $filecontent)); -$inc = array( 0 => "journals", - 1 => "attachments" - ); +//$inc = array( 0 => "journals", +// 1 => "attachments" +// ); -$res = $obj_redmine->get_issue('10314', '', $inc); -var_dump($res); +//$res = $obj_redmine->get_issue('10314', '', $inc); +//var_dump($res); -$res = $obj_redmine->download_attachment('5152'); -file_put_contents('$screenshot_download.png', $res); +//$res = $obj_redmine->download_attachment('5152', true); +//file_put_contents('screenshot_eskiz.png', $res); ?> \ No newline at end of file