Commit 01ccc12ea88e90208b960b42976605f268fb2ee2

Authored by Megan Watson
1 parent 2e92a208

Updated all docblocks and added new unit tests for the KTAPI_Document class

Committed by: Megan Watson
Reviewed by: Kevin Cyster



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9715 c91229c3-7414-0410-bfa2-8a42b809f60b
ktapi/KTAPIDocument.inc.php
1 1 <?php
2 2 /**
3   - * $Id$
  3 + * Document API for KnowledgeTree
4 4 *
5 5 * KnowledgeTree Community Edition
6 6 * Document Management Made Simple
... ... @@ -32,33 +32,56 @@
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33 33 * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35   - * Contributor( s): ______________________________________
36 35 *
  36 + * @copyright 2008-2009, KnowledgeTree Inc.
  37 + * @license GNU General Public License version 3
  38 + * @author KnowledgeTree Team
  39 + * @package KnowledgeTree API
  40 + * @version Version 0.9
37 41 */
38 42  
39   -//require_once(KT_DIR . '/ktwebservice/KTUploadManager.inc.php');
  43 +require_once(KT_DIR . '/ktwebservice/KTDownloadManager.inc.php');
40 44  
  45 +/**
  46 + * API for the handling document operations within KnowledgeTree
  47 + *
  48 + * @author KnowledgeTree Team
  49 + * @package KnowledgeTree API
  50 + * @version 0.9
  51 + */
41 52 class KTAPI_Document extends KTAPI_FolderItem
42 53 {
43 54 /**
44 55 * This is a reference to the internal document object.
45 56 *
46   - * @var Document
  57 + * @access protected
  58 + * @var object of Document
47 59 */
48 60 var $document;
  61 +
49 62 /**
50 63 * This is the id of the document.
51 64 *
  65 + * @access protected
52 66 * @var int
53 67 */
54 68 var $documentid;
  69 +
55 70 /**
56 71 * This is a reference to the parent folder.
57 72 *
58   - * @var KTAPI_Folder
  73 + * @access protected
  74 + * @var object of KTAPI_Folder
59 75 */
60 76 var $ktapi_folder;
61 77  
  78 + /**
  79 + * Gets the id of the current document
  80 + *
  81 + * @author KnowledgeTree Team
  82 + * @access public
  83 + * @return string The document id
  84 + */
62 85 function get_documentid()
63 86 {
64 87 return $this->documentid;
... ... @@ -67,11 +90,12 @@ class KTAPI_Document extends KTAPI_FolderItem
67 90 /**
68 91 * This is used to get a document based on document id.
69 92 *
  93 + * @author KnowledgeTree Team
70 94 * @static
71 95 * @access public
72   - * @param KTAPI $ktapi
73   - * @param int $documentid
74   - * @return KTAPI_Document
  96 + * @param KTAPI $ktapi The ktapi object
  97 + * @param int $documentid The document id
  98 + * @return KTAPI_Document The document object
75 99 */
76 100 function &get(&$ktapi, $documentid)
77 101 {
... ... @@ -109,6 +133,13 @@ class KTAPI_Document extends KTAPI_FolderItem
109 133 return new KTAPI_Document($ktapi, $ktapi_folder, $document);
110 134 }
111 135  
  136 + /**
  137 + * Checks if a document has been deleted
  138 + *
  139 + * @author KnowledgeTree Team
  140 + * @access public
  141 + * @return boolean TRUE if deleted | FALSE if in a different state
  142 + */
112 143 function is_deleted()
113 144 {
114 145 return ($this->document->getStatusID() == 3);
... ... @@ -117,7 +148,9 @@ class KTAPI_Document extends KTAPI_FolderItem
117 148 /**
118 149 * Checks if the document is a shortcut
119 150 *
120   - * @return boolean
  151 + * @author KnowledgeTree Team
  152 + * @access public
  153 + * @return boolean TRUE if it is a shortcut | FALSE if not
121 154 */
122 155 function is_shortcut()
123 156 {
... ... @@ -127,6 +160,9 @@ class KTAPI_Document extends KTAPI_FolderItem
127 160 /**
128 161 * Retrieves the shortcuts linking to this document
129 162 *
  163 + * @author KnowledgeTree Team
  164 + * @access public
  165 + * @return array The shortcuts linked to the document
130 166 */
131 167 function get_shortcuts()
132 168 {
... ... @@ -135,17 +171,19 @@ class KTAPI_Document extends KTAPI_FolderItem
135 171  
136 172  
137 173 /**
138   - * This is the constructor for the KTAPI_Folder.
  174 + * This is the constructor for the KTAPI_Document
139 175 *
  176 + * @author KnowledgeTree Team
140 177 * @access private
141   - * @param KTAPI $ktapi
142   - * @param Document $document
  178 + * @param KTAPI $ktapi The KTAPI object
  179 + * @param KTAPI_Folder $ktapi_folder The parent folder object
  180 + * @param Document $document The internal document object
143 181 * @return KTAPI_Document
144 182 */
145 183 function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document)
146 184 {
147   - assert(is_a($ktapi,'KTAPI'));
148   - assert(is_null($ktapi_folder) || is_a($ktapi_folder,'KTAPI_Folder'));
  185 + assert($ktapi instanceof KTAPI); //is_a($ktapi,'KTAPI'));
  186 + assert(is_null($ktapi_folder) || $ktapi_folder instanceof KTAPI_Folder); //is_a($ktapi_folder,'KTAPI_Folder'));
149 187  
150 188 $this->ktapi = &$ktapi;
151 189 $this->ktapi_folder = &$ktapi_folder;
... ... @@ -154,12 +192,23 @@ class KTAPI_Document extends KTAPI_FolderItem
154 192 }
155 193  
156 194 /**
157   - * This checks a document into the repository
  195 + * This checks a document into the repository.
  196 + *
  197 + * <code>
  198 + * $ktapi = new KTAPI();
  199 + * $session = $ktapi->start_system_session();
  200 + * $document = $ktapi->get_document_by_id($documentid);
  201 + * if($document->is_checked_out()){
  202 + * $document->checkin('filename.txt', 'Reason for checkin', '/tmp/filename');
  203 + * }
  204 + * </code>
158 205 *
159   - * @param string $filename
160   - * @param string $reason
161   - * @param string $tempfilename
162   - * @param bool $major_update
  206 + * @author KnowledgeTree Team
  207 + * @access public
  208 + * @param string $filename The name of the file
  209 + * @param string $reason The reason for checking the document in
  210 + * @param string $tempfilename The location of the temporary file
  211 + * @param bool $major_update Determines if the version number should have a major increment (+1) or a minor increment (+0.1)
163 212 */
164 213 function checkin($filename, $reason, $tempfilename, $major_update=false)
165 214 {
... ... @@ -203,6 +252,12 @@ class KTAPI_Document extends KTAPI_FolderItem
203 252 KTUploadManager::temporary_file_imported($tempfilename);
204 253 }
205 254  
  255 + /**
  256 + * Removes the update notification for the document
  257 + *
  258 + * @author KnowledgeTree Team
  259 + * @access public
  260 + */
206 261 function removeUpdateNotification()
207 262 {
208 263 $sql = "DELETE FROM notifications WHERE data_int_1=$this->documentid AND data_str_1='ModifyDocument'";
... ... @@ -210,16 +265,21 @@ class KTAPI_Document extends KTAPI_FolderItem
210 265 }
211 266  
212 267 /**
213   - * Link a document to another
  268 + * Creates a link between two documents
  269 + *
  270 + * @author KnowledgeTree Team
  271 + * @access public
  272 + * @param KTAPI_Document $document The document object
  273 + * @param string $type The link relationship type: depended on|Attachment|Reference|Copy|Default
  274 + * @return PEAR_Error|void Returns nothing on success | a PEAR_Error object on failure
214 275 *
215   - * @param KTAPI_Document $document
216 276 */
217 277 function link_document($document, $type)
218 278 {
219 279 $typeid = $this->ktapi->get_link_type_id($type);
220 280 if (PEAR::isError($typeid))
221 281 {
222   - return $result;
  282 + return $typeid;
223 283 }
224 284  
225 285 $link = new DocumentLink($this->get_documentid(), $document->get_documentid(), $typeid );
... ... @@ -231,9 +291,12 @@ class KTAPI_Document extends KTAPI_FolderItem
231 291 }
232 292  
233 293 /**
234   - * Unlink a document to another
  294 + * Removes the link between two documents
235 295 *
236   - * @param KTAPI_Document $document
  296 + * @author KnowledgeTree Team
  297 + * @access public
  298 + * @param KTAPI_Document $document The document object
  299 + * @return PEAR_Error|void Returns nothing on success | a PEAR_Error object on failure
237 300 */
238 301 function unlink_document($document)
239 302 {
... ... @@ -247,8 +310,22 @@ class KTAPI_Document extends KTAPI_FolderItem
247 310  
248 311  
249 312 /**
  313 + * Checks whether the document has been checked out.
  314 + *
  315 + * <code>
  316 + * $ktapi = new KTAPI();
  317 + * $session = $ktapi->start_system_session();
  318 + * $document = $ktapi->get_document_by_id($documentid);
  319 + * if($document->is_checked_out()){
  320 + * continue;
  321 + * }else{
  322 + * $document->checkout('Reason for document checkout');
  323 + * }
  324 + * </code>
250 325 *
251   - * @return boolean
  326 + * @author KnowledgeTree Team
  327 + * @access public
  328 + * @return boolean TRUE if checked out | FALSE if not
252 329 */
253 330 function is_checked_out()
254 331 {
... ... @@ -256,9 +333,21 @@ class KTAPI_Document extends KTAPI_FolderItem
256 333 }
257 334  
258 335 /**
259   - * This reverses the checkout process.
  336 + * Cancels the checkout on a document
  337 + *
  338 + * <code>
  339 + * $ktapi = new KTAPI();
  340 + * $session = $ktapi->start_system_session();
  341 + * $document = $ktapi->get_document_by_id($documentid);
  342 + * if($document->is_checked_out()){
  343 + * $document->undo_checkout('Reason for cancelling checkout');
  344 + * }
  345 + * </code>
260 346 *
261   - * @param string $reason
  347 + * @author KnowledgeTree Team
  348 + * @access public
  349 + * @param string $reason The reason for cancelling
  350 + * @return PEAR_Error|void Returns nothing on success | a PEAR_Error on failure
262 351 */
263 352 function undo_checkout($reason)
264 353 {
... ... @@ -295,6 +384,14 @@ class KTAPI_Document extends KTAPI_FolderItem
295 384 DBUtil::commit();
296 385 }
297 386  
  387 + /**
  388 + * Gets a list of linked documents
  389 + *
  390 + * @author KnowledgeTree Team
  391 + * @access public
  392 + * @return array|PEAR_Error Returns a list of linked documents on success | a PEAR_Error on failure
  393 + */
  394 +
298 395 function get_linked_documents()
299 396 {
300 397 $sql = "
... ... @@ -361,11 +458,23 @@ class KTAPI_Document extends KTAPI_FolderItem
361 458 return $result;
362 459 }
363 460  
364   -
365 461 /**
366   - * This returns a URL to the file that can be downloaded.
  462 + * Checks out a document
367 463 *
368   - * @param string $reason
  464 + * <code>
  465 + * $ktapi = new KTAPI();
  466 + * $session = $ktapi->start_system_session();
  467 + * $document = $ktapi->get_document_by_id($documentid);
  468 + * $document->checkout('Reason for document checkout');
  469 + * if($document->is_checked_out()){
  470 + * continue;
  471 + * }
  472 + * </code>
  473 + *
  474 + * @author KnowledgeTree Team
  475 + * @access public
  476 + * @param string $reason The reason for checking out the document
  477 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
369 478 */
370 479 function checkout($reason)
371 480 {
... ... @@ -397,9 +506,19 @@ class KTAPI_Document extends KTAPI_FolderItem
397 506 }
398 507  
399 508 /**
400   - * This deletes a document from the folder.
  509 + * Deletes a document from the folder.
401 510 *
402   - * @param string $reason
  511 + * <code>
  512 + * $ktapi = new KTAPI();
  513 + * $session = $ktapi->start_system_session();
  514 + * $document = $ktapi->get_document_by_id($documentid);
  515 + * $document->delete('Reason for deletion');
  516 + * </code>
  517 + *
  518 + * @author KnowledgeTree Team
  519 + * @access public
  520 + * @param string $reason The reason for deleting the document
  521 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
403 522 */
404 523 function delete($reason)
405 524 {
... ... @@ -427,9 +546,13 @@ class KTAPI_Document extends KTAPI_FolderItem
427 546 }
428 547  
429 548 /**
430   - * This changes the owner of the file.
  549 + * Changes the owner of a document and updates its permissions.
431 550 *
432   - * @param string $ktapi_newuser
  551 + * @author KnowledgeTree Team
  552 + * @access public
  553 + * @param string $newusername The username of the new owner
  554 + * @param string $reason The reason for changing the owner
  555 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
433 556 */
434 557 function change_owner($newusername, $reason='Changing of owner.')
435 558 {
... ... @@ -479,18 +602,28 @@ class KTAPI_Document extends KTAPI_FolderItem
479 602 }
480 603  
481 604 /**
482   - * This copies the document to another folder.
  605 + * Copies the document from one folder to another.
483 606 *
484   - * @param KTAPI_Folder $ktapi_target_folder
485   - * @param string $reason
486   - * @param string $newname
487   - * @param string $newfilename
488   - * @return KTAPI_Document
  607 + * <code>
  608 + * $ktapi = new KTAPI();
  609 + * $session = $ktapi->start_system_session();
  610 + * $document = $ktapi->get_document_by_id($documentid);
  611 + * $newFolder = $this->root->add_folder("New folder");
  612 + * $copyOfDoc = $document->copy($newFolder, 'Reason for copying document');
  613 + * </code>
  614 + *
  615 + * @author KnowledgeTree Team
  616 + * @access public
  617 + * @param KTAPI_Folder $ktapi_target_folder The new parent folder where the document is being copied into
  618 + * @param string $reason The reason for the copy
  619 + * @param string $newname Optional. The title of the document to be used in the case of a name clash
  620 + * @param string $newfilename Optional. The filename of the document to be used in the case of a name clash
  621 + * @return KTAPI_Document|PEAR_Error Returns the new KTAPI Document object | a PEAR_Error on failure
489 622 */
490 623 function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null)
491 624 {
492 625 assert(!is_null($ktapi_target_folder));
493   - assert(is_a($ktapi_target_folder,'KTAPI_Folder'));
  626 + assert($ktapi_target_folder instanceof KTAPI_FOLDER); //is_a($ktapi_target_folder,'KTAPI_Folder'));
494 627  
495 628 if (empty($newname))
496 629 {
... ... @@ -510,7 +643,7 @@ class KTAPI_Document extends KTAPI_FolderItem
510 643  
511 644 $target_folder = &$ktapi_target_folder->get_folder();
512 645  
513   - $result = $this->can_user_access_object_requiring_permission( $target_folder, KTAPI_PERMISSION_WRITE);
  646 + $result = $this->can_user_access_object_requiring_permission($target_folder, KTAPI_PERMISSION_WRITE);
514 647  
515 648 if (PEAR::isError($result))
516 649 {
... ... @@ -597,17 +730,28 @@ class KTAPI_Document extends KTAPI_FolderItem
597 730 }
598 731  
599 732 /**
600   - * This moves the document to another folder.
  733 + * Moves the document from one folder to another.
  734 + *
  735 + * <code>
  736 + * $ktapi = new KTAPI();
  737 + * $session = $ktapi->start_system_session();
  738 + * $document = $ktapi->get_document_by_id($documentid);
  739 + * $newFolder = $this->root->add_folder("New folder");
  740 + * $document->move($newFolder, 'Reason for moving the document');
  741 + * </code>
601 742 *
602   - * @param KTAPI_Folder $ktapi_target_folder
603   - * @param string $reason
604   - * @param string $newname
605   - * @param string $newfilename
  743 + * @author KnowledgeTree Team
  744 + * @access public
  745 + * @param KTAPI_Folder $ktapi_target_folder The folder object where the document is being moved into
  746 + * @param string $reason The reason for the move
  747 + * @param string $newname Optional. The title of the document to be used in the case of a name clash
  748 + * @param string $newfilename Optional. The filename of the document to be used in the case of a name clash
  749 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
606 750 */
607 751 function move(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null)
608 752 {
609 753 assert(!is_null($ktapi_target_folder));
610   - assert(is_a($ktapi_target_folder,'KTAPI_Folder'));
  754 + assert($ktapi_target_folder instanceof KTAPI_Folder); // is_a($ktapi_target_folder,'KTAPI_Folder'));
611 755  
612 756 if (empty($newname))
613 757 {
... ... @@ -693,9 +837,13 @@ class KTAPI_Document extends KTAPI_FolderItem
693 837 }
694 838  
695 839 /**
696   - * This changes the filename of the document.
  840 + * Changes the filename of the document.
  841 + * If the filename contains any invalid characters they are replaced with a dash (-). For example: ?, *, %, \, /
697 842 *
698   - * @param string $newname
  843 + * @author KnowledgeTree Team
  844 + * @access public
  845 + * @param string $newname The new filename
  846 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
699 847 */
700 848 function renameFile($newname)
701 849 {
... ... @@ -718,9 +866,12 @@ class KTAPI_Document extends KTAPI_FolderItem
718 866 }
719 867  
720 868 /**
721   - * This changes the document type of the document.
  869 + * Changes the document type of the document.
722 870 *
723   - * @param string $newname
  871 + * @author KnowledgeTree Team
  872 + * @access public
  873 + * @param string $documenttype The new document type
  874 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
724 875 */
725 876 function change_document_type($documenttype)
726 877 {
... ... @@ -743,12 +894,12 @@ class KTAPI_Document extends KTAPI_FolderItem
743 894 $iOldDocTypeID = $this->document->getDocumentTypeID();
744 895 $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->document, $iOldDocTypeID);
745 896 $mdlist = DocumentFieldLink::getByDocument($this->document);
746   -
  897 +
747 898 $field_values = array();
748 899 foreach ($mdlist as $oFieldLink) {
749 900 $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
750 901 }
751   -
  902 +
752 903 DBUtil::startTransaction();
753 904 $this->document->startNewMetadataVersion($user);
754 905 $this->document->setDocumentTypeId($doctypeid);
... ... @@ -763,24 +914,24 @@ class KTAPI_Document extends KTAPI_FolderItem
763 914  
764 915 // Ensure all values for fieldsets common to both document types are retained
765 916 $fs_ids = array();
766   -
  917 +
767 918 $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid);
768 919 foreach($doctype_fieldsets as $fieldset)
769 920 {
770 921 $fs_ids[] = $fieldset->getId();
771 922 }
772   -
  923 +
773 924 $MDPack = array();
774 925 foreach ($fieldsets as $oFieldset)
775 926 {
776 927 if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(), $fs_ids))
777 928 {
778 929 $fields = $oFieldset->getFields();
779   -
  930 +
780 931 foreach ($fields as $oField)
781 932 {
782 933 $val = isset($field_values[$oField->getId()]) ? $field_values[$oField->getId()] : '';
783   -
  934 +
784 935 if (!empty($val))
785 936 {
786 937 $MDPack[] = array($oField, $val);
... ... @@ -788,15 +939,15 @@ class KTAPI_Document extends KTAPI_FolderItem
788 939 }
789 940 }
790 941 }
791   -
  942 +
792 943 $core_res = KTDocumentUtil::saveMetadata($this->document, $MDPack, array('novalidate' => true));
793   -
  944 +
794 945 if (PEAR::isError($core_res)) {
795 946 DBUtil::rollback();
796 947 return $core_res;
797 948 }
798   -
799   -
  949 +
  950 +
800 951  
801 952 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
802 953 $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
... ... @@ -819,9 +970,13 @@ class KTAPI_Document extends KTAPI_FolderItem
819 970 }
820 971  
821 972 /**
822   - * This changes the title of the document.
  973 + * Changes the title of the document.
  974 + * If the title contains any invalid characters they are replaced with a dash (-). For example: ?, *, %, \, /
823 975 *
824   - * @param string $newname
  976 + * @author KnowledgeTree Team
  977 + * @access public
  978 + * @param string $newname The new document title
  979 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
825 980 */
826 981 function rename($newname)
827 982 {
... ... @@ -850,9 +1005,12 @@ class KTAPI_Document extends KTAPI_FolderItem
850 1005 }
851 1006  
852 1007 /**
853   - * This flags the document as 'archived'.
  1008 + * Sets the status of the document to 'archived'.
854 1009 *
855   - * @param string $reason
  1010 + * @author KnowledgeTree Team
  1011 + * @access public
  1012 + * @param string $reason The reason for archiving the document
  1013 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
856 1014 */
857 1015 function archive($reason)
858 1016 {
... ... @@ -893,9 +1051,12 @@ class KTAPI_Document extends KTAPI_FolderItem
893 1051 }
894 1052  
895 1053 /**
896   - * This starts a workflow on a document.
  1054 + * Starts a workflow on a document.
897 1055 *
898   - * @param string $workflow
  1056 + * @author KnowledgeTree Team
  1057 + * @access public
  1058 + * @param string $workflow The workflow being applied
  1059 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
899 1060 */
900 1061 function start_workflow($workflow)
901 1062 {
... ... @@ -932,6 +1093,9 @@ class KTAPI_Document extends KTAPI_FolderItem
932 1093 /**
933 1094 * This deletes the workflow on the document.
934 1095 *
  1096 + * @author KnowledgeTree Team
  1097 + * @access public
  1098 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
935 1099 */
936 1100 function delete_workflow()
937 1101 {
... ... @@ -959,10 +1123,13 @@ class KTAPI_Document extends KTAPI_FolderItem
959 1123 }
960 1124  
961 1125 /**
962   - * This performs a transition on the workflow
  1126 + * This performs a transition to a new state of the workflow on the document
963 1127 *
964   - * @param string $transition
965   - * @param string $reason
  1128 + * @author KnowledgeTree Team
  1129 + * @access public
  1130 + * @param string $transition The transition to perform
  1131 + * @param string $reason The reason for transitioning the document to a new state
  1132 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
966 1133 */
967 1134 function perform_workflow_transition($transition, $reason)
968 1135 {
... ... @@ -995,12 +1162,26 @@ class KTAPI_Document extends KTAPI_FolderItem
995 1162 DBUtil::commit();
996 1163 }
997 1164  
998   -
999   -
1000 1165 /**
1001 1166 * This returns all metadata for the document.
1002 1167 *
1003   - * @return array
  1168 + * <code>
  1169 + * $ktapi = new KTAPI();
  1170 + * $session = $ktapi->start_system_session();
  1171 + * $document = $ktapi->get_document_by_id($documentid);
  1172 + * $metadata = $document->get_metadata();
  1173 + * foreach($metadata as $fieldset){
  1174 + * echo '<br><br>Fieldset: '.$fieldset['fieldset'];
  1175 + *
  1176 + * foreach($fieldset['fields'] as $field){
  1177 + * echo '<br>Field name: '.$field['name'] . ' Value: '. $field['value'];
  1178 + * }
  1179 + * }
  1180 + * </code>
  1181 + *
  1182 + * @author KnowledgeTree Team
  1183 + * @access public
  1184 + * @return array An array of metadata fieldsets and fields
1004 1185 */
1005 1186 function get_metadata()
1006 1187 {
... ... @@ -1060,7 +1241,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1060 1241 'name' => $field->getName(),
1061 1242 'required' => $field->getIsMandatory(),
1062 1243 'value' => $value == '' ? 'n/a' : $value,
1063   - 'blankvalue' => $value=='' ? '1' : '0',
  1244 + 'blankvalue' => $value=='' ? '1' : '0',
1064 1245 'description' => $field->getDescription(),
1065 1246 'control_type' => $controltype,
1066 1247 'selection' => $selection
... ... @@ -1075,6 +1256,26 @@ class KTAPI_Document extends KTAPI_FolderItem
1075 1256 return $results;
1076 1257 }
1077 1258  
  1259 + /**
  1260 + * Gets a simple array of document metadata fields
  1261 + *
  1262 + * <code>
  1263 + * $ktapi = new KTAPI();
  1264 + * $session = $ktapi->start_system_session();
  1265 + * $document = $ktapi->get_document_by_id($documentid);
  1266 + * $metadata = $document->get_packed_metadata();
  1267 + * foreach($metadata as $field){
  1268 + * echo '<br><br>Fieldset: ' . $field[0]->getParentFieldset();
  1269 + * echo '<br>Field name: ' .$field[0]->getName();
  1270 + * echo ' Value: ' . $field[1];
  1271 + * }
  1272 + * </code>
  1273 + *
  1274 + * @author KnowledgeTree Team
  1275 + * @access public
  1276 + * @param array $metadata The full metadata fieldsets and fields
  1277 + * @return array An array of metadata field object and value pairs
  1278 + */
1078 1279 function get_packed_metadata($metadata=null)
1079 1280 {
1080 1281 global $default;
... ... @@ -1093,7 +1294,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1093 1294 $fieldsetname=$fieldset_metadata['fieldset'];
1094 1295 $fields=$fieldset_metadata['fields'];
1095 1296 }
1096   - elseif (is_a($fieldset_metadata, 'stdClass'))
  1297 + elseif ($fieldset_metadata instanceof stdClass) //is_a($fieldset_metadata, 'stdClass'))
1097 1298 {
1098 1299 $fieldsetname=$fieldset_metadata->fieldset;
1099 1300 $fields=$fieldset_metadata->fields;
... ... @@ -1105,7 +1306,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1105 1306 }
1106 1307  
1107 1308 $fieldset = KTFieldset::getByName($fieldsetname);
1108   - if (is_null($fieldset) || PEAR::isError($fieldset) || is_a($fieldset, 'KTEntityNoObjects'))
  1309 + if (is_null($fieldset) || PEAR::isError($fieldset) || $fieldset instanceof KTEntityNoObjects) //is_a($fieldset, 'KTEntityNoObjects'))
1109 1310 {
1110 1311 $default->log->debug("could not resolve fieldset: $fieldsetname for document id: $this->documentid");
1111 1312 // exit graciously
... ... @@ -1119,7 +1320,7 @@ class KTAPI_Document extends KTAPI_FolderItem
1119 1320 $fieldname = $fieldinfo['name'];
1120 1321 $value = $fieldinfo['value'];
1121 1322 }
1122   - elseif (is_a($fieldinfo, 'stdClass'))
  1323 + elseif ($fieldinfo instanceof stdClass) // is_a($fieldinfo, 'stdClass'))
1123 1324 {
1124 1325 $fieldname = $fieldinfo->name;
1125 1326 $value = $fieldinfo->value;
... ... @@ -1146,9 +1347,31 @@ class KTAPI_Document extends KTAPI_FolderItem
1146 1347 }
1147 1348  
1148 1349 /**
1149   - * This updates the metadata on the file. This includes the 'title'.
  1350 + * This updates the metadata on the document. This includes the 'title'.
  1351 + *
  1352 + * <code>
  1353 + * $ktapi = new KTAPI();
  1354 + * $session = $ktapi->start_system_session();
  1355 + * $document = $ktapi->get_document_by_id($documentid);
  1356 + * $metadata = $document->get_metadata();
  1357 + * foreach($metadata as $key => $fieldset){
  1358 + * if($fieldset['fieldset'] == 'XYZ'){
  1359 + *
  1360 + * foreach($fieldset['fields'] as $k => $field){
  1361 + * if($field['name'] == 'ABC'){
  1362 + * $metadata[$key][fields][$k]['value'] = 'new value';
  1363 + * }
  1364 + * }
  1365 + * }
  1366 + * }
1150 1367 *
1151   - * @param array This is an array containing the metadata to be associated with the file.
  1368 + * $res = $document->update_metadata($metadata);
  1369 + * </code>
  1370 + *
  1371 + * @author KnowledgeTree Team
  1372 + * @access public
  1373 + * @param array This is an array containing the metadata to be associated with the document.
  1374 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
1152 1375 */
1153 1376 function update_metadata($metadata)
1154 1377 {
... ... @@ -1215,7 +1438,10 @@ class KTAPI_Document extends KTAPI_FolderItem
1215 1438 /**
1216 1439 * This updates the system metadata on the document.
1217 1440 *
1218   - * @param array $sysdata
  1441 + * @author KnowledgeTree Team
  1442 + * @access public
  1443 + * @param array $sysdata The system metadata to be applied
  1444 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
1219 1445 */
1220 1446 function update_sysdata($sysdata)
1221 1447 {
... ... @@ -1402,6 +1628,12 @@ class KTAPI_Document extends KTAPI_FolderItem
1402 1628 }
1403 1629 }
1404 1630  
  1631 + /**
  1632 + * Clears the cached data on the document and refreshes the document object.
  1633 + *
  1634 + * @author KnowledgeTree Team
  1635 + * @access public
  1636 + */
1405 1637 function clearCache()
1406 1638 {
1407 1639 // TODO: we should only clear the cache for the document we are working on
... ... @@ -1424,6 +1656,13 @@ class KTAPI_Document extends KTAPI_FolderItem
1424 1656 $this->document = &Document::get($this->documentid);
1425 1657 }
1426 1658  
  1659 + /**
  1660 + * Merge new metadata with previous metadata version
  1661 + *
  1662 + * @author KnowledgeTree Team
  1663 + * @access public
  1664 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
  1665 + */
1427 1666 function mergeWithLastMetadataVersion()
1428 1667 {
1429 1668 // keep latest metadata version
... ... @@ -1481,9 +1720,11 @@ class KTAPI_Document extends KTAPI_FolderItem
1481 1720 }
1482 1721  
1483 1722 /**
1484   - * This returns a workflow transition
  1723 + * This returns the workflow transitions available for the user on the document
1485 1724 *
1486   - * @return array
  1725 + * @author KnowledgeTree Team
  1726 + * @access public
  1727 + * @return array|PEAR_Error Array of the workflow transitions | a PEAR_Error on failure
1487 1728 */
1488 1729 function get_workflow_transitions()
1489 1730 {
... ... @@ -1518,11 +1759,13 @@ class KTAPI_Document extends KTAPI_FolderItem
1518 1759 /**
1519 1760 * This returns the current workflow state
1520 1761 *
1521   - * @return string
  1762 + * @author KnowledgeTree Team
  1763 + * @access public
  1764 + * @return string Returns the name of the state | a PEAR_Error on failure
1522 1765 */
1523 1766 function get_workflow_state()
1524 1767 {
1525   - $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW);
  1768 + $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WORKFLOW);
1526 1769  
1527 1770 if (PEAR::isError($user))
1528 1771 {
... ... @@ -1549,6 +1792,16 @@ class KTAPI_Document extends KTAPI_FolderItem
1549 1792  
1550 1793 }
1551 1794  
  1795 + /**
  1796 + * Get the available permissions on the document.
  1797 + * R = read, W = write, E = edit - if the document is checked out by the user.
  1798 + * The method assumes read permissions is available.
  1799 + *
  1800 + * @author KnowledgeTree Team
  1801 + * @access public
  1802 + * @param Document $document The internal document object
  1803 + * @return string The available permissions
  1804 + */
1552 1805 function get_permission_string($document)
1553 1806 {
1554 1807 $perms = 'R';
... ... @@ -1570,7 +1823,9 @@ class KTAPI_Document extends KTAPI_FolderItem
1570 1823 /**
1571 1824 * This returns detailed information on the document.
1572 1825 *
1573   - * @return array
  1826 + * @author KnowledgeTree Team
  1827 + * @access public
  1828 + * @return array The document information
1574 1829 */
1575 1830 function get_detail()
1576 1831 {
... ... @@ -1769,22 +2024,57 @@ class KTAPI_Document extends KTAPI_FolderItem
1769 2024 return $detail;
1770 2025 }
1771 2026  
  2027 + /**
  2028 + * Gets the title of the document
  2029 + *
  2030 + * <code>
  2031 + * $ktapi = new KTAPI();
  2032 + * $session = $ktapi->start_system_session();
  2033 + * $document = $ktapi->get_document_by_id($documentid);
  2034 + * $title = $document->get_title();
  2035 + * </code>
  2036 + *
  2037 + * @author KnowledgeTree Team
  2038 + * @access public
  2039 + * @return string The document title
  2040 + */
1772 2041 function get_title()
1773 2042 {
1774 2043 return $this->document->getDescription();
1775 2044 }
1776 2045  
1777 2046 /**
1778   - * This does a download of a version of the document.
  2047 + * Gets the url which can be used to download the document.
1779 2048 *
1780   - * @param string $version
  2049 + * @param int $version Not implemented. The content version of the document
1781 2050 */
1782   - function download($version=null)
  2051 + function get_download_url($version = null)
  2052 + {
  2053 + $session = $this->ktapi->get_session();
  2054 +
  2055 + // Create the url that can be used to download the document
  2056 + $download_manager = new KTDownloadManager();
  2057 + $download_manager->set_session($session->session);
  2058 + $download_manager->cleanup();
  2059 + $url = $download_manager->allow_download($this);
  2060 +
  2061 + // Log the transaction
  2062 + $this->download();
  2063 +
  2064 + return $url;
  2065 + }
  2066 +
  2067 + /**
  2068 + * Logs the document transaction for a download.
  2069 + *
  2070 + * @author KnowledgeTree Team
  2071 + * @access public
  2072 + */
  2073 + function download()
1783 2074 {
1784 2075 $storage =& KTStorageManagerUtil::getSingleton();
1785 2076 $options = array();
1786 2077  
1787   -
1788 2078 $oDocumentTransaction = new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions);
1789 2079 $oDocumentTransaction->create();
1790 2080 }
... ... @@ -1792,7 +2082,9 @@ class KTAPI_Document extends KTAPI_FolderItem
1792 2082 /**
1793 2083 * This returns the transaction history for the document.
1794 2084 *
1795   - * @return array
  2085 + * @author KnowledgeTree Team
  2086 + * @access public
  2087 + * @return array The list of transactions | a PEAR_Error on failure
1796 2088 */
1797 2089 function get_transaction_history()
1798 2090 {
... ... @@ -1821,7 +2113,9 @@ class KTAPI_Document extends KTAPI_FolderItem
1821 2113 /**
1822 2114 * This returns the version history on the document.
1823 2115 *
1824   - * @return array
  2116 + * @author KnowledgeTree Team
  2117 + * @access public
  2118 + * @return array The version history
1825 2119 */
1826 2120 function get_version_history()
1827 2121 {
... ... @@ -1862,7 +2156,18 @@ class KTAPI_Document extends KTAPI_FolderItem
1862 2156 /**
1863 2157 * This expunges a document from the system.
1864 2158 *
  2159 + * <code>
  2160 + * $ktapi = new KTAPI();
  2161 + * $session = $ktapi->start_system_session();
  2162 + * $document = $ktapi->get_document_by_id($documentid);
  2163 + * if($document->is_deleted()){
  2164 + * $document->expunge();
  2165 + * }
  2166 + * </code>
  2167 + *
  2168 + * @author KnowledgeTree Team
1865 2169 * @access public
  2170 + * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
1866 2171 */
1867 2172 function expunge()
1868 2173 {
... ... @@ -1888,8 +2193,9 @@ class KTAPI_Document extends KTAPI_FolderItem
1888 2193 }
1889 2194  
1890 2195 /**
1891   - * This expunges a document from the system.
  2196 + * Restores a deleted document
1892 2197 *
  2198 + * @author KnowledgeTree Team
1893 2199 * @access public
1894 2200 */
1895 2201 function restore()
... ... @@ -1925,11 +2231,25 @@ class KTAPI_Document extends KTAPI_FolderItem
1925 2231 DBUtil::commit();
1926 2232 }
1927 2233  
  2234 + /**
  2235 + * Returns the internal document object
  2236 + *
  2237 + * @author KnowledgeTree Team
  2238 + * @access public
  2239 + * @return Document The document object
  2240 + */
1928 2241 public function getObject()
1929 2242 {
1930 2243 return $this->document;
1931 2244 }
1932 2245  
  2246 + /**
  2247 + * Checks if the user is subscribed to the document
  2248 + *
  2249 + * @author KnowledgeTree Team
  2250 + * @access public
  2251 + * @return bool TRUE if subscribed | FALSE if not
  2252 + */
1933 2253 public function isSubscribed()
1934 2254 {
1935 2255 $subscriptionType = SubscriptionEvent::subTypes('Document');
... ... @@ -1939,6 +2259,12 @@ class KTAPI_Document extends KTAPI_FolderItem
1939 2259 return Subscription::exists($user->getId(), $document->getId(), $subscriptionType);
1940 2260 }
1941 2261  
  2262 + /**
  2263 + * Removes the users subscription to the document
  2264 + *
  2265 + * @author KnowledgeTree Team
  2266 + * @access public
  2267 + */
1942 2268 public function unsubscribe()
1943 2269 {
1944 2270 if (!$this->isSubscribed())
... ... @@ -1954,6 +2280,12 @@ class KTAPI_Document extends KTAPI_FolderItem
1954 2280 $subscription->delete();
1955 2281 }
1956 2282  
  2283 + /**
  2284 + * Subscribes the user to the document
  2285 + *
  2286 + * @author KnowledgeTree Team
  2287 + * @access public
  2288 + */
1957 2289 public function subscribe()
1958 2290 {
1959 2291 if ($this->isSubscribed())
... ... @@ -1969,25 +2301,54 @@ class KTAPI_Document extends KTAPI_FolderItem
1969 2301 $subscription->create();
1970 2302 }
1971 2303  
1972   -
  2304 + /**
  2305 + * Checks if the document is immutable
  2306 + *
  2307 + * @author KnowledgeTree Team
  2308 + * @access public
  2309 + * @return bool TRUE if it is immutable | FALSE if not
  2310 + */
1973 2311 public function isImmutable()
1974 2312 {
1975 2313 return $this->document->getImmutable();
1976 2314 }
1977 2315  
  2316 + /**
  2317 + * Sets a document to be immutable
  2318 + *
  2319 + * @author KnowledgeTree Team
  2320 + * @access public
  2321 + */
1978 2322 public function immute()
1979 2323 {
1980 2324 $this->document->setImmutable(true);
1981 2325 $this->document->update();
1982 2326 }
1983 2327  
  2328 + /**
  2329 + * Removes the immutability of a document
  2330 + *
  2331 + * @author KnowledgeTree Team
  2332 + * @access public
  2333 + */
1984 2334 public function unimmute()
1985 2335 {
1986 2336 $this->document->setImmutable(false);
1987 2337 $this->document->update();
1988 2338 }
1989 2339  
1990   - public function email($members, $title, $comment, $attachDocument = true)
  2340 + /**
  2341 + * Emails a document as an attachment or hyperlink to a list of users, groups or external email addresses.
  2342 + * In the case of external addresses, if a hyperlink is used then a timed download link (via webservices) is sent allowing the recipient a window period in which to download the document.
  2343 + * The period is set through the webservices config option webservice/downloadExpiry. Defaults to 30 minutes.
  2344 + *
  2345 + * @author KnowledgeTree Team
  2346 + * @access public
  2347 + * @param array $members The email recipients - KTPAI_Users, KTAPI_Groups or email addresses
  2348 + * @param string $comment Content to be appended to the email
  2349 + * @param bool $attachDocument TRUE if document is an attachment | FALSE if using a hyperlink to the document
  2350 + */
  2351 + public function email($members, $comment, $attachDocument = true)
1991 2352 {
1992 2353 if (empty($members))
1993 2354 {
... ... @@ -2020,6 +2381,7 @@ class KTAPI_Document extends KTAPI_FolderItem
2020 2381  
2021 2382 $emailErrors = array();
2022 2383 $userEmails = array();
  2384 + $listEmails = array();
2023 2385  
2024 2386 sendGroupEmails($groupIds, $userEmails, $emailErrors);
2025 2387  
... ... @@ -2034,9 +2396,14 @@ class KTAPI_Document extends KTAPI_FolderItem
2034 2396 sendExternalEmails($aEmailAddresses, $this->document->getID(), $this->document->getName(), $comment, $emailErrors);
2035 2397 }
2036 2398  
2037   - sendEmail($aListEmails, $this->document->getID(), $this->document->getName(), $comment, (boolean)$fAttachDocument, $aEmailErrors);
  2399 + if(empty($userEmails)){
  2400 + return;
  2401 + }
  2402 +
  2403 + $listEmails = array_keys($userEmails);
  2404 + sendEmail($listEmails, $this->document->getID(), $this->document->getName(), $comment, (boolean)$fAttachDocument, $aEmailErrors);
2038 2405  
2039 2406 }
2040 2407 }
2041 2408  
2042 2409 -?>
  2410 +?>
2043 2411 \ No newline at end of file
... ...
tests/api/testDocument.php
1 1 <?php
2   -require_once (dirname(__FILE__) . '/../test.php');
  2 +require_once (KT_DIR . '/tests/test.php');
3 3 require_once (KT_DIR . '/ktapi/ktapi.inc.php');
  4 +
  5 +/**
  6 + * Helper class for the KTAPI_Document unit tests
  7 + *
  8 + * @author KnowledgeTree Team
  9 + * @package KnowledgeTree API
  10 + * @version 0.9
  11 + */
4 12 class APIDocumentHelper {
5 13 function createRandomFile($content = 'this is some text') {
6 14 $temp = tempnam(dirname(__FILE__), 'myfile');
... ... @@ -10,127 +18,318 @@ class APIDocumentHelper {
10 18 return $temp;
11 19 }
12 20 }
  21 +
  22 +/**
  23 + * Unit tests for the KTAPI_Document class
  24 + *
  25 + * @author KnowledgeTree Team
  26 + * @package KnowledgeTree API
  27 + * @version 0.9
  28 + */
13 29 class APIDocumentTestCase extends KTUnitTestCase {
  30 +
14 31 /**
15 32 * @var KTAPI
16 33 */
17 34 var $ktapi;
  35 +
18 36 /**
19 37 * @var KTAPI_Folder
20 38 */
21 39 var $root;
  40 +
  41 + /**
  42 + * @var KTAPI_Session
  43 + */
22 44 var $session;
  45 +
  46 + /**
  47 + * Create a ktapi session
  48 + */
23 49 function setUp() {
24 50 $this->ktapi = new KTAPI();
25 51 $this->session = $this->ktapi->start_system_session();
26 52 $this->root = $this->ktapi->get_root_folder();
27   - $this->assertTrue(is_a($this->root, 'KTAPI_Folder'));
  53 + $this->assertTrue($this->root instanceof KTAPI_Folder);
28 54 }
  55 +
  56 + /**
  57 + * End the ktapi session
  58 + */
29 59 function tearDown() {
30 60 $this->session->logout();
31 61 }
  62 +
  63 + /**
  64 + * Tests the add and delete document functionality
  65 + */
32 66 function testAddDocument() {
33 67 $randomFile = APIDocumentHelper::createRandomFile();
34 68 $this->assertTrue(is_file($randomFile));
  69 +
35 70 $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
36 71 $this->assertNotError($document);
  72 +
37 73 if(PEAR::isError($document)) return;
38   - $this->assertTrue(is_a($document, 'KTAPI_Document'));
  74 + $this->assertTrue($document instanceof KTAPI_Document);
39 75 @unlink($randomFile);
40 76 $documentid = $document->get_documentid();
  77 +
41 78 // get document
42 79 $document = $this->ktapi->get_document_by_id($documentid);
43   - $this->assertTrue(is_a($document, 'KTAPI_Document'));
  80 + $this->assertTrue($document instanceof KTAPI_Document);
44 81 $this->assertEqual($document->get_title(), 'testtitle.txt');
45   - $document->delete('because we can');
  82 + $this->assertFalse($document->is_deleted());
  83 + $document->delete('Testing document add and delete');
  84 +
46 85 // check if document still exists
47 86 $document = $this->ktapi->get_document_by_id($documentid);
48   - $this->assertTrue(is_a($document, 'KTAPI_Document'));
  87 + $this->assertTrue($document instanceof KTAPI_Document);
49 88 $this->assertTrue($document->is_deleted());
50 89 $document->expunge();
  90 +
51 91 // check if document still exists
52 92 $document = $this->ktapi->get_document_by_id($documentid);
53   - $this->assertFalse(is_a($document, 'KTAPI_Document'));
  93 + $this->assertFalse($document instanceof KTAPI_Document);
54 94 }
55   - function testCheckinDocument() {
  95 +
  96 + /**
  97 + * Tests the document download functionality
  98 + */
  99 + function testDownload() {
56 100 $randomFile = APIDocumentHelper::createRandomFile();
57 101 $this->assertTrue(is_file($randomFile));
58   - $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
  102 + $document = $this->root->add_document('testtitle789', 'testname789.txt', 'Default', $randomFile);
59 103 $this->assertNotError($document);
  104 +
60 105 if(PEAR::isError($document)) return;
61   - $this->assertTrue(is_a($document, 'KTAPI_Document'));
  106 + $this->assertTrue($document instanceof KTAPI_Document);
  107 + @unlink($randomFile);
  108 +
  109 + $download_url = $document->get_download_url();
  110 + $this->assertTrue(is_string($download_url));
  111 +
  112 + $doc_id = $document->get_documentid();
  113 + $this->assertFalse(strpos($download_url, 'd='.$doc_id) === false);
  114 +
  115 + // Delete and expunge document
  116 + $document->delete('Testing document download');
  117 + $document->expunge();
  118 + }
  119 +
  120 + /**
  121 + * Tests the get metadata, update metadata and get packed metadata functionality
  122 + */
  123 + function testGetMetadata() {
  124 + // Create a new document
  125 + $randomFile = APIDocumentHelper::createRandomFile();
  126 + $this->assertTrue(is_file($randomFile));
  127 +
  128 + $document = $this->root->add_document('testtitle123', 'testname123.txt', 'Default', $randomFile);
  129 + $this->assertNotError($document);
  130 +
  131 + @unlink($randomFile);
  132 + if(PEAR::isError($document)) return;
  133 +
  134 + // Get the document metadata
  135 + $metadata = $document->get_metadata();
  136 + $this->assertTrue(count($metadata) > 0);
  137 +
  138 + $this->assertTrue($metadata[0]['fieldset'] == 'Tag Cloud');
  139 + $this->assertTrue($metadata[0]['fields'][0]['description'] == 'Tag Words');
  140 +
  141 + // Update the metadata - add a tag
  142 + $metadata[0]['fields'][0]['value'] = 'test';
  143 +
  144 + $res = $document->update_metadata($metadata);
  145 + $this->assertFalse($res instanceof PEAR_Error);
  146 +
  147 + $new_metadata = $document->get_packed_metadata();
  148 +
  149 + $this->assertTrue($new_metadata[0][0]->getDescription() == 'Tag Words');
  150 + $this->assertTrue($new_metadata[0][1] == 'test');
  151 +
  152 + // Delete and expunge document
  153 + $document->delete('Testing document get metadata');
  154 + $document->expunge();
  155 + }
  156 +
  157 + /**
  158 + * Tests the copy functionality. Includes the get_title() functionality.
  159 + */
  160 + function testCopy() {
  161 + // Create a new document
  162 + $randomFile = APIDocumentHelper::createRandomFile();
  163 + $this->assertTrue(is_file($randomFile));
  164 +
  165 + $document = $this->root->add_document('testtitle123', 'testname123.txt', 'Default', $randomFile);
  166 + $this->assertNotError($document);
  167 +
  168 + @unlink($randomFile);
  169 + if(PEAR::isError($document)) return;
  170 +
  171 + // Add a folder to copy into
  172 + $newFolder = $this->root->add_folder("New folder");
  173 + $this->assertNotError($newFolder);
  174 +
  175 + if(PEAR::isError($newFolder)) return;
  176 +
  177 + // Copy document into the new folder
  178 + $copyDoc = $document->copy($newFolder, 'Testing document copy');
  179 + $this->assertTrue($copyDoc instanceof KTAPI_Document);
  180 + $this->assertTrue($copyDoc->get_title() == 'testtitle123');
  181 +
  182 + // Delete and expunge documents
  183 + $document->delete('Testing document copy');
  184 + $document->expunge();
  185 + $copyDoc->delete('Testing document copy');
  186 + $copyDoc->expunge();
  187 +
  188 + // Delete test folder
  189 + $newFolder->delete('Testing document copy');
  190 + }
  191 +
  192 + /**
  193 + * Tests the move functionality. Includes the get_detail() functionality.
  194 + */
  195 + function testMove() {
  196 + // Create a new document
  197 + $randomFile = APIDocumentHelper::createRandomFile();
  198 + $this->assertTrue(is_file($randomFile));
  199 +
  200 + $document = $this->root->add_document('testtitle246', 'testname246.txt', 'Default', $randomFile);
  201 + $this->assertNotError($document);
  202 +
  203 + @unlink($randomFile);
  204 + if(PEAR::isError($document)) return;
  205 +
  206 + // Add a folder to copy into
  207 + $newFolder = $this->root->add_folder("New folder");
  208 + $this->assertNotError($newFolder);
  209 +
  210 + if(PEAR::isError($newFolder)) return;
  211 +
  212 + // Copy document into the new folder
  213 + $document->move($newFolder, 'Testing document move');
  214 + $detail = $document->get_detail();
  215 +
  216 + $this->assertFalse($detail['folder_id'] == $this->root->get_folderid());
  217 + $this->assertTrue($detail['folder_id'] == $newFolder->get_folderid());
  218 +
  219 + // Delete and expunge documents
  220 + $document->delete('Testing document move');
  221 + $document->expunge();
  222 +
  223 + // Delete test folder
  224 + $newFolder->delete('Testing document move');
  225 + }
  226 +
  227 + /**
  228 + * Tests the checkout, checkin, cancel checkout and is_checked_out document functionality
  229 + */
  230 + function testCheckinCheckout() {
  231 + $randomFile = APIDocumentHelper::createRandomFile();
  232 + $this->assertTrue(is_file($randomFile));
  233 + $document = $this->root->add_document('testtitle369', 'testname369.txt', 'Default', $randomFile);
  234 + $this->assertNotError($document);
  235 +
  236 + if(PEAR::isError($document)) return;
  237 + $this->assertTrue($document instanceof KTAPI_Document);
62 238 @unlink($randomFile);
63 239 $documentid = $document->get_documentid();
  240 +
64 241 // document should be checked in
65 242 $document = $this->ktapi->get_document_by_id($documentid);
66 243 $this->assertFalse($document->is_checked_out());
67   - $document->checkout('because');
  244 + $document->checkout('Testing document checkout');
  245 +
68 246 // document should now be checked out
69 247 $document = $this->ktapi->get_document_by_id($documentid);
70 248 $this->assertTrue($document->is_checked_out());
71   - $document->undo_checkout('because we want to undo it');
  249 + $document->undo_checkout('Testing document cancel checkout');
  250 +
72 251 // document should be checked in
73 252 $document = $this->ktapi->get_document_by_id($documentid);
74 253 $this->assertFalse($document->is_checked_out());
75   - $document->checkout('because');
  254 + $document->checkout('Testing document checkout');
  255 +
76 256 // document should now be checked out
77 257 $document = $this->ktapi->get_document_by_id($documentid);
78 258 $this->assertTrue($document->is_checked_out());
  259 +
79 260 // create another random file
80 261 $randomFile = APIDocumentHelper::createRandomFile('updating the previous content');
81 262 $this->assertTrue(is_file($randomFile));
82   - $document->checkin('testname.txt', 'updating', $randomFile);
  263 + $document->checkin('testname369.txt', 'Updating test checkin document', $randomFile);
83 264 @unlink($randomFile);
  265 +
84 266 // document should be checked in
85 267 $document = $this->ktapi->get_document_by_id($documentid);
86 268 $this->assertFalse($document->is_checked_out());
87   - $document->delete('because we can');
  269 + $document->delete('Testing document checkin');
88 270 $document->expunge();
89 271 }
90   - function testAddingDuplicateTitle() {
  272 +
  273 + /**
  274 + * Tests the adding of a duplicate document title
  275 + *
  276 + function testAddingDuplicateTitle()
  277 + {
91 278 $randomFile = APIDocumentHelper::createRandomFile();
92 279 $this->assertTrue(is_file($randomFile));
93 280 $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
94 281 $this->assertNotError($document);
  282 +
95 283 if(PEAR::isError($document)) return;
96 284 $this->assertEntity($document, 'KTAPI_Document');
97 285 $this->assertFalse(is_file($randomFile));
98 286 $documentid = $document->get_documentid();
  287 +
99 288 // file would have been cleaned up because of the add_document
100 289 $randomFile = APIDocumentHelper::createRandomFile();
101 290 $this->assertTrue(is_file($randomFile));
  291 +
102 292 // filenames must be the same as above
103   - $document2 = $this->root->add_document('testtitle.txt', 'testname2.txt', 'Default', $randomFile);
104   - $this->assertFalse(is_a($document2, 'KTAPI_Document'));
  293 + $document2 = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
  294 + $this->assertFalse($document2 instanceof KTAPI_Document);
105 295 @unlink($randomFile);
106 296 $document->delete('because we can');
107 297 $document->expunge();
108   - if (is_a($document2, 'KTAPI_Document')) {
  298 + if ($document2 instanceof KTAPI_Document) {
109 299 $document2->delete('because we can');
110 300 $document2->expunge();
111 301 }
112 302 }
113   - function testAddingDuplicateFile() {
  303 +
  304 + /**
  305 + * Tests the adding of duplicate document file names
  306 + *
  307 + function testAddingDuplicateFile()
  308 + {
114 309 $randomFile = APIDocumentHelper::createRandomFile();
115 310 $this->assertTrue(is_file($randomFile));
116 311 $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
117 312 $this->assertNotError($document);
  313 +
118 314 if(PEAR::isError($document)) return;
119   - $this->assertTrue(is_a($document, 'KTAPI_Document'));
  315 + $this->assertTrue($document instanceof KTAPI_Document);
120 316 $this->assertFalse(is_file($randomFile));
121 317 $documentid = $document->get_documentid();
122 318 $randomFile = APIDocumentHelper::createRandomFile();
123 319 $this->assertTrue(is_file($randomFile));
  320 +
124 321 // filenames must be the same as above
125 322 $document2 = $this->root->add_document('testtitle2.txt', 'testname.txt', 'Default', $randomFile);
126   - $this->assertFalse(is_a($document2, 'KTAPI_Document'));
  323 + $this->assertFalse($document2 instanceof KTAPI_Document);
  324 +
127 325 @unlink($randomFile);
128 326 $document->delete('because we can');
129 327 $document->expunge();
130   - if (is_a($document2, 'KTAPI_Document')) {
  328 + if ($document2 instanceof KTAPI_Document) {
131 329 $document2->delete('because we can');
132 330 $document2->expunge();
133 331 }
134 332 }
  333 + */
135 334 }
136 335 -?>
  336 +?>
137 337 \ No newline at end of file
... ...