Commit ed1661a1accd8d0df310911a7d2056c8bda7a2ed

Authored by nbm
1 parent 1c623fdf

Criteria now know how to generate the WHERE part of statements when

they're being searched on in HTML form submissions.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3085 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 32 additions and 7 deletions
lib/browse/Criteria.inc
... ... @@ -38,6 +38,8 @@ class BrowseCriterion {
38 38 var $bFolderCriterion = false;
39 39 var $aOptions = array();
40 40 var $iID;
  41 + var $bString = false;
  42 + var $sSearchTable = "D";
41 43  
42 44 function BrowseCriterion ($sDisplay, $sDocumentField, $sSortField, $iID) {
43 45 $this->sDisplay =& $sDisplay;
... ... @@ -124,10 +126,15 @@ class BrowseCriterion {
124 126 return $this->sSortField;
125 127 }
126 128  
  129 + function getSearchField () {
  130 + return $this->sDocumentField;
  131 + }
  132 +
127 133 function getLookup () {
128 134 return $this->aLookup;
129 135 }
130 136  
  137 +
131 138 function getName() {
132 139 return $this->sDocumentField;
133 140 }
... ... @@ -147,10 +154,23 @@ class BrowseCriterion {
147 154 function searchWidget ($aRequest) {
148 155 return "<input type=\"text\" size=\"50\" name=\"bmd" . $this->getID() . "\" />";
149 156 }
  157 +
  158 + function getSearchTable() {
  159 + return $this->sSearchTable;
  160 + }
  161 +
  162 + function searchSQL ($aRequest) {
  163 + if ($this->bString) {
  164 + return array($this->getSearchTable() . "." . $this->getSearchField() . " LIKE '%" . DBUtil::escapeSimple($aRequest['bmd' . $this->getID()]) . "%'", array());
  165 + } else {
  166 + return array($this->getSearchTable() . "." . $this->getSearchField() . " = ?", array($aRequest['bmd' . $this->getID()]));
  167 + }
  168 + }
150 169 }
151 170  
152 171 class NameCriterion extends BrowseCriterion {
153 172 var $bFolderCriterion = true;
  173 + var $bString = true;
154 174 function documentDisplay ($oDocument) {
155 175 $aOptions = $this->aOptions;
156 176 if (array_key_exists('displayFullPath', $aOptions)) {
... ... @@ -192,6 +212,7 @@ class IDCriterion extends BrowseCriterion {
192 212  
193 213 class TitleCriterion extends BrowseCriterion {
194 214 var $bFolderCriterion = true;
  215 + var $bString = true;
195 216 function documentDisplay ($oDocument) {
196 217 return $oDocument->getName();
197 218 }
... ... @@ -280,12 +301,12 @@ class GenericMetadataCriterion extends BrowseCriterion {
280 301 "field" => "value",
281 302 "joinColumn" => "document_id",
282 303 );
283   - var $iFieldID;
  304 + var $bString = true;
  305 + var $sSearchTable = "DFL";
284 306  
285   - function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, $iFieldID) {
286   - $this->iFieldID = $iFieldID;
287   - $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField, $iFieldID);
288   - $this->aLookup['whereClause'] = 'document_field_id = ' . $iFieldID;
  307 + function GenericMetadataCriterion ($sDisplay, $sDocumentField, $sSortField, $iID) {
  308 + $this->BrowseCriterion($sDisplay, $sDocumentField, $sSortField, $iID);
  309 + $this->aLookup['whereClause'] = 'document_field_id = ' . $iID;
289 310 }
290 311  
291 312 function documentDisplay ($oDocument) {
... ... @@ -294,7 +315,7 @@ class GenericMetadataCriterion extends BrowseCriterion {
294 315 "FROM $default->document_fields_link_table AS DFL " .
295 316 "WHERE DFL.document_id = ? " .
296 317 "AND DFL.document_field_id = ?";
297   - $aParams = array($oDocument->getID(), $this->iFieldID);
  318 + $aParams = array($oDocument->getID(), $this->getID());
298 319  
299 320 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'value');
300 321 if (PEAR::isError($res)) {
... ... @@ -306,9 +327,13 @@ class GenericMetadataCriterion extends BrowseCriterion {
306 327  
307 328 function getName() {
308 329 global $default;
309   - $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($this->iFieldID)); /*ok*/
  330 + $aQuery = array("SELECT name FROM $default->document_fields_table WHERE id = ?", array($this->getID())); /*ok*/
310 331 return "gmd_" . DBUtil::getOneResultKey($aQuery, 'name');
311 332 }
  333 +
  334 + function getSearchField () {
  335 + return $this->aLookup['field'];
  336 + }
312 337 }
313 338  
314 339 class Criteria {
... ...