diff --git a/ktapi/KTAPIFolder.inc.php b/ktapi/KTAPIFolder.inc.php index 100667b..a2a2b7e 100644 --- a/ktapi/KTAPIFolder.inc.php +++ b/ktapi/KTAPIFolder.inc.php @@ -121,6 +121,7 @@ class KTAPI_Folder extends KTAPI_FolderItem */ function get_detail() { + $this->clearCache(); $detail = array( 'id'=>(int) $this->folderid, 'folder_name'=>$this->get_folder_name(), @@ -131,6 +132,19 @@ class KTAPI_Folder extends KTAPI_FolderItem return $detail; } + function clearCache() + { + // TODO: we should only clear the cache for the document we are working on + // this is a quick fix but not optimal!! + + $cache = KTCache::getSingleton(); + + $cache->remove('Folder/id', $this->folderid); + + $this->folder = &Folder::get($this->folderid); + } + + function get_parent_folder_id() { return (int) $this->folder->getParentID(); @@ -479,13 +493,16 @@ class KTAPI_Folder extends KTAPI_FolderItem $docTypeId = $document->getDocumentTypeID(); $documentType = DocumentType::get($docTypeId); + $oemDocumentNo = $document->getOemNo(); + if (empty($oemDocumentNo)) $oemDocumentNo = 'n/a'; + $contents[] = array( 'id' => (int) $document->getId(), 'item_type' => 'D', 'custom_document_no'=>'n/a', - 'oem_document_no'=>'n/a', + 'oem_document_no'=>$oemDocumentNo, 'title' => $document->getName(), 'document_type'=>$documentType->getName(), diff --git a/ktapi/ktapi.inc.php b/ktapi/ktapi.inc.php index a7fbb3a..abe5caf 100644 --- a/ktapi/ktapi.inc.php +++ b/ktapi/ktapi.inc.php @@ -179,6 +179,36 @@ class KTAPI return $user; } + /** + * Search for documents matching the oem_no. + * + * Note that oem_no is associated with a document and not with version of file (document content). + * oem_no is set on a document using document::update_sysdata(). + * + * @param string $oem_no + * @param boolean idsOnly Defaults to true + * @return array + */ + function get_documents_by_oem_no($oem_no, $idsOnly=true) + { + $sql = array("SELECT id FROM documents WHERE oem_no=?",$oem_no); + $rows = DBUtil::getResultArray($sql); + if (is_null($rows) || PEAR::isError($rows)) + { + return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $rows); + } + + $result = array(); + foreach($rows as $row) + { + $documentid = $row['id']; + + $result[] = $idsOnly?$documentid:KTAPI_Document::get($this, $documentid); + } + + return $result; + } + /** * This returns a session object based on a session string. *