From bf069fd24429db4b5b9062c4df4db52863eb708f Mon Sep 17 00:00:00 2001 From: Mikhail Grebenkin Date: Thu, 20 Aug 2020 16:31:56 +0300 Subject: [PATCH] added some comments --- redmine.php | 54 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/redmine.php b/redmine.php index 429e09b..e4cc990 100644 --- a/redmine.php +++ b/redmine.php @@ -15,7 +15,7 @@ class class_redmine { * Upload $filecontent and return token. * * @param mixed $filecontent - content of file - * @return mixed $token is object, string can be obtained in $token->upload->token + * @return array 0 => http response, 1 => $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; @@ -31,10 +31,10 @@ class class_redmine { * @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 + * @return array 0 => http response, 1 => $issue updated issue */ function upload_attachment(string $issue_id, string $filename, string $filetype, $filecontent){ - $token = $this->get_upload_token($filecontent); + $token = $this->get_upload_token($filecontent)[1]; if (!$token) { return null; } @@ -48,7 +48,7 @@ class class_redmine { * @param string $attachment_id numeric id of attachment * @param bool $thumbnail if true downloading thumbnail - * @return mixed $filecontent - content of file + * @return array 0 => http response, 1 => $filecontent - content of file */ function download_attachment(string $attachment_id, bool $thumbnail=false) { if ($thumbnail) { @@ -71,7 +71,7 @@ class class_redmine { * Create issue * * @param $post_data - string to post to redmine (needs to update) - * @return mixed $issue - new data + * @return array 0 => http response, 1 => $issue - new data */ function create_issue($post_data) { $issue_url = $this->redmine_url.'issues.json?key='.$this->redmine_key; @@ -86,7 +86,7 @@ class class_redmine { * @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 - json data of issue + * @return array 0 => http response, 1 => $issue - json data of issue */ function get_issue(string $issue_id='',string $project_id='', array $inc=array()) { if (count($inc) > 0) { @@ -135,7 +135,7 @@ class class_redmine { * * @param string $issue_id digits only issue id * @param string $comment comment to add to the issue - * @return mixed $issue - new data + * @return mixed array 0 => http response, 1 => $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; @@ -151,23 +151,42 @@ class class_redmine { } - //Projects + //Projects nowadays we don't use it. 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; return $this->curl_redmine($proj_url); } //Contacts + /** + * returns json structure with all contacts + * + * @return mixed array 0 => http response, 1 => $contacts - data + */ function get_contacts() { $cont_url = $this->redmine_url.'contacts.json?key='.$this->redmine_key; return $this->curl_redmine($cont_url); } - + + /** + * search contacts by string. Returns contacts. + * + * @param string $search_str string to search by + * @return mixed array 0 => http response, 1 => $contacts - new data + */ function search_contacts_str(string $search_str) { $cont_url = $this->redmine_url.'contacts.json?key='.$this->redmine_key.'&search='.$search_str; return $this->curl_redmine($cont_url); } + + /** + * search contacts by id. Returns one contact. + * + * @param string $id digits only contact id + * @param bool $issues if true, includes issues, connected to contact + * @return mixed array 0 => http response, 1 => $contact - data + */ function get_contact_id(string $id, bool $issues) { $cont_url = ($issues) ? $this->redmine_url."contacts/$id.json?key=".$this->redmine_key.'&include=issues' @@ -176,6 +195,13 @@ class class_redmine { return $this->curl_redmine($cont_url); } + + /** + * Creates contact from array. + * + * @param array $contact array with all needed contact fields + * @return mixed array 0 => http response, 1 => $contact - data + */ function create_contact(array $contact) { $cont_url = $this->redmine_url.'contacts.json?key='.$this->redmine_key; $request['type'] = 'post'; @@ -189,7 +215,7 @@ class class_redmine { * * @param string $issue_id digits only issue id * @param string $contact_id digits only contact id - * @return mixed $issue - new data + * @return mixed array 0 => http response, 1 => $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; @@ -204,6 +230,14 @@ class class_redmine { return $this->curl_redmine($contact_url, $request , $post_data); } + + /** + * create_ticket creates issue with connected contact. Needs contact email. + * + * @param string $issue_id digits only issue id + * @param string $contact_id digits only contact id + * @return mixed array 0 => http response, 1 => $issue - new data + */ function create_ticket(string $contact_email, string $subject, string $description) { $issue_url = $this->redmine_url."helpdesk/create_ticket.xml?key=".$this->redmine_key; $issue_xml = "