Commit af4e69cc3704d33be0b6a7cb4ff5d3429b010150

Authored by Conrad Vermeulen
1 parent 53796d03

KTS-2512

"Search result object must return more fields to be used in templating and web services"
Updated. added more fields to the result object

Reviewed By: Kevin Fourie
Committed By: Conrad Vermeulen

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7400 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/indexerCore.inc.php
... ... @@ -3,7 +3,7 @@
3 3 require_once('indexing/extractorCore.inc.php');
4 4  
5 5  
6   -class MatchResult
  6 +class QueryResultItem
7 7 {
8 8 protected $document_id;
9 9 protected $title;
... ... @@ -13,15 +13,27 @@ class MatchResult
13 13 protected $fullpath;
14 14 protected $live;
15 15 protected $version;
  16 + protected $mimeType;
16 17 protected $filename;
17 18 protected $thumbnail; // TODO: if not null, gui can display a thumbnail
18 19 protected $viewer; // TODO: if not null, a viewer can be used to view the document
19 20 protected $document;
20   - protected $checkoutuser;
21   - protected $workflowstate;
  21 + protected $checkedOutUser;
  22 + protected $dateCheckedout;
  23 + protected $workflowState;
22 24 protected $workflow;
23   -
24   - public function __construct($document_id, $rank, $title, $text)
  25 + protected $modifiedBy;
  26 + protected $dateModified;
  27 + protected $createdBy;
  28 + protected $dateCreated;
  29 + protected $owner;
  30 + protected $immutable;
  31 + protected $deleted;
  32 + protected $status;
  33 + protected $folderId;
  34 +
  35 +
  36 + public function __construct($document_id, $rank=null, $title=null, $text=null)
25 37 {
26 38 $this->document_id=$document_id;
27 39 $this->rank= $rank;
... ... @@ -48,17 +60,25 @@ class MatchResult
48 60 private function loadDocumentInfo()
49 61 {
50 62 $sql = "SELECT
51   - f.full_path, f.name, dcv.size as filesize, dcv.major_version,
52   - dcv.minor_version, dcv.filename, cou.name as checkoutuser, w.human_name as workflow, ws.human_name as workflowstate
  63 + f.folder_id, f.full_path, f.name, dcv.size as filesize, dcv.major_version,
  64 + dcv.minor_version, dcv.filename, cou.name as checkoutuser, w.human_name as workflow, ws.human_name as workflowstate,
  65 + mt.mimetypes as mimetype, md.mime_doc as mimedoc, d.checkedout, mbu.name as modifiedbyuser, d.modified,
  66 + cbu.name as createdbyuser, ou.name as owneruser, d.immutable, d.status_id, d.created
53 67  
54 68 FROM
55 69 documents d
56 70 INNER JOIN document_metadata_version dmv ON d.metadata_version_id = dmv.id
57 71 INNER JOIN document_content_version dcv ON dmv.content_version_id = dcv.id
  72 + INNER JOIN mime_types mt ON dcv.mime_id=mt.id
58 73 LEFT JOIN folders f ON f.id=d.folder_id
59 74 LEFT JOIN users cou ON d.checked_out_user_id=cou.id
60 75 LEFT JOIN workflows w ON dmv.workflow_id=w.id
61 76 LEFT JOIN workflow_states ws ON dmv.workflow_state_id = ws.id
  77 + LEFT JOIN mime_documents md ON mt.mime_document_id = md.id
  78 + LEFT JOIN users mbu ON d.modified_user_id=mbu.id
  79 + LEFT JOIN users cbu ON d.creator_id=cbu.id
  80 + LEFT JOIN users ou ON d.owner_id=ou.id
  81 +
62 82 WHERE
63 83 d.id=$this->document_id";
64 84  
... ... @@ -81,65 +101,86 @@ class MatchResult
81 101 if (substr($this->fullpath,0,1) == '/') $this->fullpath = substr($this->fullpath,1);
82 102 }
83 103  
84   -
85   - $this->filesize = $result['filesize'] + 0;
86   -
87   - if ($this->filesize > 1024 * 1024 * 1024)
88   - {
89   - $this->filesize = floor($this->filesize / (1024 * 1024 * 1024)) . 'g';
90   - }
91   - elseif ($this->filesize > 1024 * 1024)
92   - {
93   - $this->filesize = floor($this->filesize / (1024 * 1024)) . 'm';
94   - }
95   - elseif ($this->filesize > 1024)
96   - {
97   - $this->filesize = floor($this->filesize / (1024)) . 'k';
98   - }
99   - else
100   - {
101   - $this->filesize .= 'b';
102   - }
  104 + $this->filesize = KTUtil::filesizeToString($result['filesize']);
103 105  
104 106 $this->version = $result['major_version'] . '.' . $result['minor_version'];
105 107 $this->filename=$result['filename'];
106   - $this->checkoutuser = $result['checkoutuser'];
  108 + $this->checkedOutUser = $result['checkoutuser'];
107 109 $this->workflow = $result['workflow'];
108   - $this->workflowstate = $result['workflowstate'];
  110 + $this->workflowState = $result['workflowstate'];
109 111  
110   - }
111 112  
  113 + $this->mimeType = $result['mimetype'];
  114 + $this->dateCheckedout = $result['checkedout'];
112 115  
  116 + $this->modifiedBy = $result['modifiedbyuser'];
  117 + $this->dateModified = $result['modified'];
  118 + $this->createdBy = $result['createdbyuser'];
  119 + $this->dateCreated = $result['created'];
  120 +
  121 + $this->owner = $result['owneruser'];
  122 + $this->immutable = ($result['immutable'] + 0)?_kt('Immutable'):'';
  123 + $this->status = Document::getStatusString($result['status_id']);
  124 + $this->folderId = $result['folder_id'];
  125 +
  126 + }
113 127  
114 128 protected function __get($property)
115 129 {
116 130 switch($property)
117 131 {
118   - case 'DocumentID': return $this->document_id;
119   - case 'Rank': return $this->rank;
120   - case 'Text': return $this->text;
121   - case 'Title': return $this->title;
122   - case 'FullPath': return $this->fullpath;
123   - case 'IsLive': return $this->live;
124   - case 'Filesize': return $this->filesize;
125   - case 'Version': return $this->version;
126   - case 'Filename': return $this->filename;
  132 + case null: return '';
  133 + case 'DocumentID': return (int) $this->document_id;
  134 + case 'Relevance':
  135 + case 'Rank': return (float) $this->rank;
  136 + case 'Text': return (string) $this->text;
  137 + case 'Title': return (string) $this->title;
  138 + case 'FullPath': return (string) $this->fullpath;
  139 + case 'IsLive': return (bool) $this->live;
  140 + case 'Filesize': return (int) $this->filesize;
  141 + case 'Version': return (string) $this->version;
  142 + case 'Filename': return (int)$this->filename;
  143 + case 'FolderId': return (int)$this->folderId;
127 144 case 'Document':
128 145 if (is_null($this->document))
  146 + {
129 147 $this->document = Document::get($this->document_id);
  148 + }
130 149 return $this->document;
131 150 case 'IsAvailable':
132 151 return $this->Document->isLive();
133   -
134 152 case 'CheckedOutUser':
135   - return $this->checkoutuser;
  153 + return (string) $this->checkedOutUser;
  154 + case 'WorkflowOnly':
  155 + return (string)$this->workflow;
  156 + case 'WorkflowStateOnly':
  157 + return (string)$this->workflowState;
136 158 case 'Workflow':
137 159 if (is_null($this->workflow))
138 160 {
139 161 return '';
140 162 }
141   - return "$this->workflow - $this->workflowstate";
142   - case null: break;
  163 + return "$this->workflow - $this->workflowState";
  164 + case 'MimeType':
  165 + return (string) $this->mimeType;
  166 + case 'DateCheckedOut':
  167 + return (string) $this->dateCheckedout;
  168 + case 'ModifiedBy':
  169 + return (string) $this->modifiedBy;
  170 + case 'DateModified':
  171 + return (string) $this->dateModified;
  172 + case 'CreatedBy':
  173 + return (string) $this->createdBy;
  174 + case 'DateCreated':
  175 + return (string) $this->dateCreated;
  176 + case 'Owner':
  177 + return (string) $this->owner;
  178 + case 'Immutable':
  179 + return (bool) $this->immutable;
  180 + case 'Status':
  181 + return $this->status;
  182 + case 'CanBeReadByUser':
  183 + return (bool) $this->live && (Permission::userHasDocumentReadPermission($this->Document) || Permission::adminIsInAdminMode());
143 184 default:
144 185 throw new Exception("Unknown property '$property' to get on MatchResult");
145 186 }
... ... @@ -151,6 +192,7 @@ class MatchResult
151 192 switch($property)
152 193 {
153 194 case 'Rank': $this->rank = number_format($value,2,'.',','); break;
  195 + case 'Title': $this->title = $value; break;
154 196 case 'Text': $this->text = $value; break;
155 197 default:
156 198 throw new Exception("Unknown property '$property' to set on MatchResult");
... ... @@ -166,35 +208,6 @@ function MatchResultCompare($a, $b)
166 208 return ($a->Rank < $b->Rank) ? -1 : 1;
167 209 }
168 210  
169   -class QueryResultItem extends MatchResult
170   -{
171   - protected $discussion;
172   -
173   - public function __construct($document_id, $rank, $title, $text, $discussion)
174   - {
175   - parent::__construct($document_id, $rank, $title, $text);
176   - $this->discussion=$discussion;
177   - }
178   -
179   - protected function __isset($property)
180   - {
181   - switch($property)
182   - {
183   - case 'Discussion': return isset($this->discussion);
184   - default: return parent::__isset($property);
185   - }
186   - }
187   -
188   - protected function __get($property)
189   - {
190   - switch($property)
191   - {
192   - case 'Discussion': return $this->discussion;
193   - default: return parent::__get($property);
194   - }
195   - }
196   -}
197   -
198 211 abstract class Indexer
199 212 {
200 213 /**
... ...