Commit c560e9501c0664af62c24da7b88914092fd2612d

Authored by Conrad Vermeulen
1 parent b97be9c6

KTS-3766

"Search results must return the permissions similar to KTAPI for use by client tools"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9448 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/indexerCore.inc.php
... ... @@ -40,6 +40,7 @@
40 40 define('SEARCH2_INDEXER_DIR',realpath(dirname(__FILE__)) . '/');
41 41 require_once('indexing/extractorCore.inc.php');
42 42 require_once(KT_DIR . '/plugins/ktcore/scheduler/schedulerUtil.php');
  43 +require_once(KT_DIR . '/ktapi/ktapi.inc.php');
43 44  
44 45 class IndexerInconsistencyException extends Exception {};
45 46  
... ... @@ -211,21 +212,6 @@ class DocumentResultItem extends QueryResultItem
211 212 $this->loadDocumentInfo();
212 213 }
213 214  
214   - /*protected function __isset($property)
215   - {
216   - switch($property)
217   - {
218   - case 'DocumentID': return isset($this->document_id);
219   - case 'Rank': return isset($this->rank);
220   - case 'Text': return isset($this->text);
221   - case 'Title': return isset($this->title);
222   - case null: break;
223   - default:
224   - throw new Exception("Unknown property '$property' to get on QueryResultItem");
225   - }
226   - return true; // should not be reached
227   - }*/
228   -
229 215 // TODO: this is bad. must refactor to do the query on the group of documents.
230 216 public function loadDocumentInfo()
231 217 {
... ... @@ -327,11 +313,7 @@ class DocumentResultItem extends QueryResultItem
327 313 public function getFilename() { return (string)$this->filename; }
328 314 public function getFolderId() { return (int)$this->folderId; }
329 315 public function getOemDocumentNo() { return (string) $this->oemDocumentNo; }
330   - public function getDocument() { if (is_null($this->document))
331   - {
332   - $this->document = Document::get($this->id);
333   - }
334   - return $this->document; }
  316 + public function getDocument() { return Document::get($this->id); }
335 317 public function getIsAvailable() { return $this->Document->isLive(); }
336 318 public function getCheckedOutUser() { return (string) $this->checkedOutUser; }
337 319 public function getCheckedOutByr() { return $this->getCheckedOutUser(); }
... ... @@ -339,11 +321,13 @@ class DocumentResultItem extends QueryResultItem
339 321 public function getWorkflow() { return $this->getWorkflow(); }
340 322 public function getWorkflowStateOnly() { return (string)$this->workflowState; }
341 323 public function getWorkflowState() { return $this->getWorkflowStateOnly(); }
342   - public function getWorkflowAndState() { if (is_null($this->workflow))
343   - {
344   - return '';
345   - }
346   - return "$this->workflow - $this->workflowState"; }
  324 + public function getWorkflowAndState() {
  325 + if (is_null($this->workflow))
  326 + {
  327 + return '';
  328 + }
  329 + return "$this->workflow - $this->workflowState";
  330 + }
347 331 public function getMimeType() { return (string) $this->mimeType; }
348 332 public function getMimeIconPath() { return (string) $this->mimeIconPath; }
349 333 public function getMimeDisplay() { return (string) $this->mimeDisplay; }
... ... @@ -359,16 +343,16 @@ class DocumentResultItem extends QueryResultItem
359 343 public function getStatus() { return $this->status; }
360 344 public function getStoragePath() { return $this->storagePath; }
361 345 public function getDocumentType() { return $this->documentType; }
362   - public function getPermissions() { return 'not available'; }
363   - public function getCanBeReadByUser() { if (!$this->live)
364   - return false;
365   - if (Permission::userHasDocumentReadPermission($this->Document))
366   - return true;
367   - if (Permission::adminIsInAdminMode())
368   - return true;
369   - return false; }
370   -
371   -
  346 + public function getPermissions() { return KTAPI_Document::get_permission_string($this->Document); }
  347 + public function getCanBeReadByUser() {
  348 + if (!$this->live)
  349 + return false;
  350 + if (Permission::userHasDocumentReadPermission($this->Document))
  351 + return true;
  352 + if (Permission::adminIsInAdminMode())
  353 + return true;
  354 + return false;
  355 + }
372 356 }
373 357  
374 358 class FolderResultItem extends QueryResultItem
... ... @@ -380,20 +364,20 @@ class FolderResultItem extends QueryResultItem
380 364 public function __construct($folder_id, $rank=null, $title=null, $text=null, $fullpath = null)
381 365 {
382 366 parent::__construct($folder_id, $title, $rank, $text, $fullpath);
383   - $this->loadDocumentInfo();
  367 + $this->loadFolderInfo();
384 368 }
385 369  
386 370 public function getFolderID() { return $this->getId(); }
387 371 public function getParentID() { return $this->parentId; }
388 372 public function getCreatedBy() { return $this->createdBy; }
389 373 public function getMimeIconPath() { return 'folder'; }
390   - public function getFolder() {
391   - return $this->folder; }
  374 + public function getFolder() { return Folder::get($this->getFolderID()); }
  375 + public function getPermissions() { return KTAPI_Folder::get_permission_string($this->Folder); }
392 376  
393   - public function loadDocumentInfo()
  377 + public function loadFolderInfo()
394 378 {
395 379 global $default;
396   - $this->folder = $folder = Folder::get($this->getFolderID());
  380 + $folder = $this->getFolder();
397 381 if (PEAR::isError($folder))
398 382 {
399 383 throw new Exception('Database exception! There appears to be an error in the system: ' .$result->getMessage());
... ...