Skip to content

Commit

Permalink
Merge pull request #11 from jonasraoni/bugfix/master/10-fix-folder-cr…
Browse files Browse the repository at this point in the history
…eation

bsobbe/iThenticate/#10 Fixed the creation of folders
  • Loading branch information
bsobbe authored Dec 12, 2021
2 parents 9f19404 + 013a391 commit 8440a85
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 48 deletions.
113 changes: 66 additions & 47 deletions Ithenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace bsobbe\ithenticate;

/*
/**
* Using needed classes from PhpXmlRpc library.
*/
use PhpXmlRpc\Value;
Expand All @@ -11,19 +11,19 @@

class Ithenticate
{
/*
/**
* This property is for ithenticate API Url.
*/
private $url;
/*
/**
* These properties are for storing Ithenticate's API Username and Password.
*/
private $username;
private $password;
//This property will be filled with the login session hash value returned by Ithenticate's API after logging in.
private $sid;

/*
/**
* Construct method initializes Url, Username, and Password in properties.
* It also logs in using login method and puts the login hash session into
* the defined property.
Expand All @@ -36,7 +36,7 @@ public function __construct($username, $password)
$this->setSid($this->login());
}

/*
/**
* This is setter method for Ithenticate's API Url.
*/
public function setUrl($url)
Expand All @@ -46,7 +46,7 @@ public function setUrl($url)
}
}

/*
/**
* This is setter method for Ithenticate's API Username.
*/
public function setUsername($username)
Expand All @@ -56,7 +56,7 @@ public function setUsername($username)
}
}

/*
/**
* This is setter method for Ithenticate's API Password.
*/
public function setPassword($password)
Expand All @@ -66,7 +66,7 @@ public function setPassword($password)
}
}

/*
/**
* This is setter method for Ithenticate's responded hash login session.
*/
public function setSid($sid)
Expand All @@ -76,7 +76,7 @@ public function setSid($sid)
}
}

/*
/**
* This is getter method for Ithenticate's API Url.
*/
public function getUrl()
Expand All @@ -86,7 +86,7 @@ public function getUrl()
}
}

/*
/**
* This is getter method for Ithenticate's API Username.
*/
public function getUsername()
Expand All @@ -96,7 +96,7 @@ public function getUsername()
}
}

/*
/**
* This is getter method for Ithenticate's API Password.
*/
public function getPassword()
Expand All @@ -106,7 +106,7 @@ public function getPassword()
}
}

/*
/**
* This is getter method for Ithenticate's responded hash login session.
*/
public function getSid()
Expand All @@ -116,7 +116,7 @@ public function getSid()
}
}

/*
/**
* This method logs into Ithenticate using Username and Password
* The return value is Ithenticate's login hash session which will
* be used in other methods as the authentication.
Expand All @@ -133,8 +133,8 @@ private function login()
$response = json_decode(json_encode($response), true);

if ($response['val']['me']['struct']['status']['me']['int'] === 401) {
throw new \Exception($response['val']['me']['struct']['messages']['me']['array'][0]['me']['string'], 401);
}
throw new \Exception($response['val']['me']['struct']['messages']['me']['array'][0]['me']['string'], 401);
}

if (isset($response['val']['me']['struct']['sid']['me']['string'])) {
$sid = $response['val']['me']['struct']['sid']['me']['string'];
Expand All @@ -148,7 +148,7 @@ private function login()
}
}

/*
/**
* This method submits new documents into Ithenticate into your prefered folder.
* The return value is the unique number of the submitted document which will be
* used for getting result and other actions which will be performed on document.
Expand Down Expand Up @@ -191,6 +191,9 @@ public function submitDocument($essay_title, $author_firstname, $author_lastname
}
}

/**
* Create a new group
*/
public function createGroup($group_name)
{
$client = new Client($this->getUrl());
Expand All @@ -207,7 +210,10 @@ public function createGroup($group_name)
return false;
}

public function createFolder($folder_name, $folder_description, $group_id, $exclude_quotes)
/**
* Create a new folder
*/
public function createFolder($folder_name, $folder_description, $group_id, $exclude_quotes, $add_to_index)
{
$client = new Client($this->getUrl());
$args = array(
Expand All @@ -216,6 +222,7 @@ public function createFolder($folder_name, $folder_description, $group_id, $excl
'name' => new Value($folder_name),
'description' => new Value($folder_description),
'exclude_quotes' => new Value($exclude_quotes),
'add_to_index' => new Value($add_to_index),
);

$response = $client->send(new Request('folder.add', array(new Value($args, "struct"))));
Expand All @@ -227,18 +234,16 @@ public function createFolder($folder_name, $folder_description, $group_id, $excl
}


/*
/**
* This method fetch all subfolders in a specific folder
*/

*/
public function fetchFolderInGroup($folderId)
{
$client = new Client($this->getUrl());
$args = array(
'sid' => new Value($this->getSid()),
'id' => new Value($folderId),
'r' => new Value('500'),

);
$response = $client->send(new Request('group.folders', array(new Value($args, "struct"))));

Expand All @@ -255,9 +260,11 @@ public function fetchFolderInGroup($folderId)
} else {
return false;
}

}

/**
* Retrieve the group list
*/
public function fetchGroupList()
{
$client = new Client($this->getUrl());
Expand All @@ -281,6 +288,9 @@ public function fetchGroupList()
}
}

/**
* Retrieve the folder list
*/
public function fetchFolderList()
{
$client = new Client($this->getUrl());
Expand Down Expand Up @@ -328,31 +338,31 @@ public function documentGetRequest(int $document_id)
$return = [];
if (isset($response['val']['me']['struct']['documents']['me']['array'])) {
foreach ($response['val']['me']['struct']['documents']['me']['array'] as $index => $document_array) {
$document_data = $document_array['me']['struct'];
if (isset($document_data['author_first']['me']['string'])) {
$return['documents'][$index]['author_first'] = $document_data['author_first']['me']['string'];
}
if (isset($document_data['author_last']['me']['string'])) {
$return['documents'][$index]['author_last'] = $document_data['author_last']['me']['string'];
}
$return['documents'][$index]['is_pending'] = $document_data['is_pending']['me']['int'];
$return['documents'][$index]['id'] = $document_data['id']['me']['int'];
$return['documents'][$index]['processed_time'] = $document_data['processed_time']['me']['dateTime.iso8601'];
$return['documents'][$index]['percent_match'] = $document_data['percent_match']['me']['int'];
$return['documents'][$index]['title'] = $document_data['title']['me']['string'];
$return['documents'][$index]['uploaded_time'] = $document_data['uploaded_time']['me']['dateTime.iso8601'];

if (isset($document_data['parts']['me']['array'])) {
foreach ($document_data['parts']['me']['array'] as $part_index => $parts_array) {
$part_data = $parts_array['me']['struct'];
$return['documents'][$index]['parts'][$part_index]['max_percent_match'] = $part_data['max_percent_match']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['processed_time'] = $part_data['processed_time']['me']['string'];
$return['documents'][$index]['parts'][$part_index]['score'] = $part_data['score']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['words'] = $part_data['words']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['id'] = $part_data['id']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['doc_id'] = $part_data['doc_id']['me']['int'];
$document_data = $document_array['me']['struct'];
if (isset($document_data['author_first']['me']['string'])) {
$return['documents'][$index]['author_first'] = $document_data['author_first']['me']['string'];
}
if (isset($document_data['author_last']['me']['string'])) {
$return['documents'][$index]['author_last'] = $document_data['author_last']['me']['string'];
}
$return['documents'][$index]['is_pending'] = $document_data['is_pending']['me']['int'];
$return['documents'][$index]['id'] = $document_data['id']['me']['int'];
$return['documents'][$index]['processed_time'] = $document_data['processed_time']['me']['dateTime.iso8601'];
$return['documents'][$index]['percent_match'] = $document_data['percent_match']['me']['int'];
$return['documents'][$index]['title'] = $document_data['title']['me']['string'];
$return['documents'][$index]['uploaded_time'] = $document_data['uploaded_time']['me']['dateTime.iso8601'];

if (isset($document_data['parts']['me']['array'])) {
foreach ($document_data['parts']['me']['array'] as $part_index => $parts_array) {
$part_data = $parts_array['me']['struct'];
$return['documents'][$index]['parts'][$part_index]['max_percent_match'] = $part_data['max_percent_match']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['processed_time'] = $part_data['processed_time']['me']['string'];
$return['documents'][$index]['parts'][$part_index]['score'] = $part_data['score']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['words'] = $part_data['words']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['id'] = $part_data['id']['me']['int'];
$return['documents'][$index]['parts'][$part_index]['doc_id'] = $part_data['doc_id']['me']['int'];
}
}
}
}
$return['sid'] = $response['val']['me']['struct']['sid']['me']['string'];
$return['api_status'] = $response['val']['me']['struct']['api_status']['me']['int'];
Expand Down Expand Up @@ -412,6 +422,9 @@ public function reportGetRequest(int $report_id, $exclude_biblio = 1, $exclude_q
return $return;
}

/**
* Fetch the document report state
*/
public function fetchDocumentReportState($document_id)
{
$client = new Client($this->getUrl());
Expand All @@ -436,6 +449,9 @@ public function fetchDocumentReportState($document_id)

}

/**
* Fetch the document report ID
*/
public function fetchDocumentReportId($document_id)
{
$client = new Client($this->getUrl());
Expand All @@ -458,6 +474,9 @@ public function fetchDocumentReportId($document_id)
}
}

/**
* Fetch the document report URL
*/
public function fetchDocumentReportUrl($report_id, $exclude_biblio = 1, $exclude_quotes = 1, $exclude_small_matches = 1)
{
$client = new Client($this->getUrl());
Expand Down Expand Up @@ -528,7 +547,7 @@ protected function readErrors($response_array) {
*/
protected function readFolder($response_array) {
if (!isset($response_array['val']['me']['struct']['folder']['me']['struct'])) {
return [];
return [];
}

$return = [];
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ $report_url = $result['report_url'];
```

### Contribute
Feel free to **contribute** and add new methods based on ithenticate's [API Guide](http://www.ithenticate.com/hs-fs/hub/92785/file-1383985272-pdf/iTh_documentation/iThenticate_API_Manual.pdf?t=1488585417195)
Feel free to **contribute** and add new methods based on ithenticate's [API Guide](https://help.turnitin.com/ithenticate/ithenticate-developer/api/api-guide.htm#APImethodreference)

Add method usage instructions in ReadMe.md

0 comments on commit 8440a85

Please sign in to comment.