CWIS Developer Documentation
SavedSearch.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: SavedSearch.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2011-2015 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9 
11 {
12 
13  # ---- PUBLIC INTERFACE --------------------------------------------------
14 
15  # search frequency mnemonics
16  const SEARCHFREQ_NEVER = 0;
17  const SEARCHFREQ_HOURLY = 1;
18  const SEARCHFREQ_DAILY = 2;
19  const SEARCHFREQ_WEEKLY = 3;
21  const SEARCHFREQ_MONTHLY = 5;
23  const SEARCHFREQ_YEARLY = 7;
24 
25  # object constructor
26 
34  public function __construct($SearchId, $SearchName = NULL, $UserId = NULL,
35  $Frequency = NULL, $SearchParameters = NULL)
36  {
37  # get our own database handle
38  $this->DB = new Database();
39 
40  # if search ID was provided
41  if ($SearchId !== NULL)
42  {
43  # save search ID
44  $this->SearchId = intval($SearchId);
45 
46  # initialize our local copies of data
47  $this->DB->Query(
48  "SELECT * FROM SavedSearches "
49  ."WHERE SearchId = ".$this->SearchId);
50 
51  if ($this->DB->NumRowsSelected() == 0)
52  {
53  throw new Exception ("Specified SearchId does not exist");
54  }
55 
56  $this->Record = $this->DB->FetchRow();
57 
58  # get our Search Parameters
60  $this->Record["SearchData"]);
61 
62  # remove now redundant 'Data' from our record
63  unset ($this->Record["SearchData"]);
64 
65  # update search details where provided
66  if ($SearchName)
67  {
68  $this->SearchName($SearchName);
69  }
70 
71  if ($UserId)
72  {
73  $this->UserId($UserId);
74  }
75 
76  if ($Frequency)
77  {
78  $this->Frequency($Frequency);
79  }
80  }
81  else
82  {
83  # add new saved search to database
84  $this->DB->Query("INSERT INTO SavedSearches"
85  ." (SearchName, UserId, Frequency) VALUES ("
86  ."'".addslashes($SearchName)."', "
87  .intval($UserId).", "
88  .intval($Frequency).")");
89 
90  # retrieve and save ID of new search locally
91  $this->SearchId = $this->DB->LastInsertId();
92 
93  # populate our local data for this record
94  $this->DB->Query(
95  "SELECT * FROM SavedSearches "
96  ."WHERE SearchId = ".$this->SearchId);
97  $this->Record = $this->DB->FetchRow();
98 
99  if (!is_null($SearchParameters) && is_array($SearchParameters))
100  {
101  $Params = new SearchParameterSet();
102  $Params->SetFromLegacyArray($SearchParameters);
103  $SearchParameters = $Params;
104  }
105 
106  $EndUser = new CWUser($this->UserId());
107 
108  $RFactory = new ResourceFactory();
109 
110  # signal event to allow modification of search parameters
111  $SignalResult = $GLOBALS["AF"]->SignalEvent(
112  "EVENT_FIELDED_SEARCH", array(
113  "SearchParameters" => $SearchParameters,
114  "User" => $EndUser,
115  "SavedSearch" => $this));
116  $this->SearchParameters($SignalResult["SearchParameters"]);
117 
118  # perform search
119  $SearchEngine = new SPTSearchEngine();
120  $SearchResults = $SearchEngine->GroupedSearch(
121  $SearchParameters, 0, PHP_INT_MAX);
122 
123  $NewItemIds = array_keys($SearchResults);
124 
125  #Only allow resources the user can view
126  $NewItemIds = $RFactory->FilterNonViewableResources($NewItemIds, $EndUser);
127 
128  # if search results were found
129  if (count($NewItemIds))
130  {
131  $this->SaveLastMatches($NewItemIds);
132  }
133  }
134  }
135 
144  public function SearchGroups($NewSearchGroups = NULL)
145  {
146  if (!is_null($NewSearchGroups))
147  {
148  $Params = new SearchParameterSet();
149  $Params->SetFromLegacyArray($NewSearchGroups);
150  $this->SearchParameters($Params);
151  }
152 
153  # return search parameters to caller
154  return $this->SearchParameters()->GetAsLegacyArray();
155  }
156 
162  public function SearchParameters($NewParams = NULL)
163  {
164  if (!is_null($NewParams))
165  {
166  if ($NewParams instanceof SearchParameterSet)
167  {
168 
169  $Data = $NewParams->Data();
170 
171  $this->DB->Query(
172  "UPDATE SavedSearches SET SearchData = '". addslashes($Data)."'"
173  ." WHERE SearchId = ".$this->SearchId);
174 
175  $this->SearchParameters = new SearchParameterSet($Data);
176  }
177  else
178  {
179  throw new Exception("NewParams must be a SearchParameterSet");
180  }
181  }
182 
183  return clone $this->SearchParameters;
184  }
185 
191  public function SearchName($NewValue = DB_NOVALUE)
192  {
193  return $this->UpdateValue("SearchName", $NewValue);
194  }
195 
200  public function Id()
201  {
202  return $this->SearchId;
203  }
204 
210  public function UserId($NewValue = DB_NOVALUE)
211  {
212  return $this->UpdateValue("UserId", $NewValue);
213  }
214 
220  public function Frequency($NewValue = DB_NOVALUE)
221  {
222  return $this->UpdateValue("Frequency", $NewValue);
223  }
224 
225 
229  public function UpdateDateLastRun()
230  {
231  $this->DB->Query(
232  "UPDATE SavedSearches SET DateLastRun = NOW() "
233  ."WHERE SearchId = ".$this->SearchId);
234  }
235 
241  public function DateLastRun($NewValue = DB_NOVALUE)
242  {
243  return $this->UpdateValue("DateLastRun", $NewValue);
244  }
245 
250  public function SaveLastMatches($ArrayofMatchingIds)
251  {
252  $NewValue = implode(",", $ArrayofMatchingIds);
253  $this->UpdateValue("LastMatchingIds", $NewValue);
254  }
255 
260  public function LastMatches()
261  {
262  return explode(",", $this->DB->Query(
263  "SELECT LastMatchingIds FROM SavedSearches "
264  ."WHERE SearchId = ".$this->SearchId, "LastMatchingIds"));
265  }
272  {
273  return self::TranslateSearchGroupsToUrlParameters($this->SearchGroups());
274  }
275 
313  public static function TranslateSearchGroupsToUrlParameters($SearchGroups)
314  {
315  # assume that no parameters will be found
316  $UrlPortion = "";
317 
318  # for each group in parameters
319  $Schema = new MetadataSchema();
320  foreach ($SearchGroups as $GroupIndex => $Group)
321  {
322  # if group holds single parameters
323  if ($GroupIndex == "MAIN")
324  {
325  # for each field within group
326  foreach ($Group["SearchStrings"] as $FieldName => $Value)
327  {
328  # add segment to URL for this field
329  if ($FieldName == "XXXKeywordXXX")
330  {
331  $FieldId = "K";
332  }
333  else
334  {
335  $Field = $Schema->GetFieldByName($FieldName);
336  $FieldId = $Field->Id();
337  }
338  if (is_array($Value))
339  {
340  $UrlPortion .= "&F".$FieldId."=";
341  $ValueString = "";
342  foreach ($Value as $SingleValue)
343  {
344  $ValueString .= $SingleValue." ";
345  }
346  $UrlPortion .= urlencode(trim($ValueString));
347  }
348  else
349  {
350  $UrlPortion .= "&F".$FieldId."=".urlencode($Value);
351  }
352  }
353  }
354  else
355  {
356  # convert value based on field type
357  $FieldId = ($GroupIndex[0] == "X")
358  ? substr($GroupIndex, 1)
359  : $GroupIndex;
360  $Field = $Schema->GetField($FieldId);
361  $FieldName = $Field->Name();
362  $Values = self::TranslateValues($Field,
363  $Group["SearchStrings"][$FieldName],
364  "SearchGroup to Database");
365 
366  # add values to URL
367  $FirstValue = TRUE;
368  foreach ($Values as $Value)
369  {
370  if ($FirstValue)
371  {
372  $FirstValue = FALSE;
373  $UrlPortion .= "&G".$FieldId."=".$Value;
374  }
375  else
376  {
377  $UrlPortion .= "-".$Value;
378  }
379  }
380  }
381  }
382 
383  # trim off any leading "&"
384  if (strlen($UrlPortion)) { $UrlPortion = substr($UrlPortion, 1); }
385 
386  # return URL portion to caller
387  return $UrlPortion;
388  }
389 
396  {
397  return self::TranslateSearchGroupsToUrlParameters($this->SearchGroups());
398  }
399 
406  public static function TranslateSearchGroupsToUrlParameterArray($SearchGroups)
407  {
408  # assume that no parameters will be found
409  $UrlPortion = array();
410 
411  # for each group in parameters
412  $Schema = new MetadataSchema();
413  foreach ($SearchGroups as $GroupIndex => $Group)
414  {
415  # if group holds single parameters
416  if ($GroupIndex == "MAIN")
417  {
418  # for each field within group
419  foreach ($Group["SearchStrings"] as $FieldName => $Value)
420  {
421  # add segment to URL for this field
422  if ($FieldName == "XXXKeywordXXX")
423  {
424  $FieldId = "K";
425  }
426  else
427  {
428  $Field = $Schema->GetFieldByName($FieldName);
429  $FieldId = $Field->Id();
430  }
431  if (is_array($Value))
432  {
433  $ValueString = "";
434  foreach ($Value as $SingleValue)
435  {
436  $ValueString .= $SingleValue." ";
437  }
438 
439  $UrlPortion["F".$FieldId] = urlencode(trim($ValueString));
440  }
441  else
442  {
443  $UrlPortion["F".$FieldId] = urlencode($Value);
444  }
445  }
446  }
447  else
448  {
449  # convert value based on field type
450  $FieldId = ($GroupIndex[0] == "X")
451  ? substr($GroupIndex, 1)
452  : $GroupIndex;
453  $Field = $Schema->GetField($FieldId);
454  $FieldName = $Field->Name();
455  $Values = self::TranslateValues($Field,
456  $Group["SearchStrings"][$FieldName],
457  "SearchGroup to Database");
458  $LeadChar = ($Group["Logic"] == SearchEngine::LOGIC_AND)
459  ? "H" : "G";
460 
461  # add values to URL
462  $FirstValue = TRUE;
463  foreach ($Values as $Value)
464  {
465  if ($FirstValue)
466  {
467  $FirstValue = FALSE;
468  $UrlPortion[$LeadChar.$FieldId] = $Value;
469  }
470  else
471  {
472  $UrlPortion[$LeadChar.$FieldId] .= "-".$Value;
473  }
474  }
475  }
476  }
477 
478  # return URL portion to caller
479  return $UrlPortion;
480  }
481 
487  public static function TranslateUrlParametersToSearchGroups($GetVars)
488  {
489  # if URL segment was passed in instead of GET var array
490  if (is_string($GetVars))
491  {
492  $GetVars = ParseQueryString($GetVars);
493  }
494 
495  # start with empty list of parameters
496  $SearchGroups = array();
497 
498  $Schema = new MetadataSchema();
499  $AllFields = $Schema->GetFields(NULL, NULL, TRUE);
500 
501  foreach ($AllFields as $Field)
502  {
503  $FieldId = $Field->Id();
504  $FieldName = $Field->Name();
505 
506  # if URL included literal value for this field
507  if (isset($GetVars["F".$FieldId]))
508  {
509  # retrieve value and add to search parameters
510  $SearchGroups["MAIN"]["SearchStrings"][$FieldName] =
511  $GetVars["F".$FieldId];
512  }
513 
514  # if URL included group value for this field
515  if (isset($GetVars["G".$FieldId]))
516  {
517  # retrieve and parse out values
518  $Values = explode("-", $GetVars["G".$FieldId]);
519 
520  # translate values
521  $Values = self::TranslateValues($Field, $Values,
522  "Database to SearchGroup");
523 
524  # add values to searchgroups
525  $SearchGroups[$FieldId]["SearchStrings"][$FieldName] = $Values;
526  }
527 
528  # if URL included group value for this field
529  if (isset($GetVars["H".$FieldId]))
530  {
531  # retrieve and parse out values
532  $Values = explode("-", $GetVars["H".$FieldId]);
533 
534  # translate values
535  $Values = self::TranslateValues($Field, $Values,
536  "Database to SearchGroup");
537 
538  # add values to searchgroups
539  $SearchGroups["X".$FieldId]["SearchStrings"][$FieldName] = $Values;
540  }
541  }
542 
543  # if keyword pseudo-field was included in URL
544  if (isset($GetVars["FK"]))
545  {
546  # retrieve value and add to search parameters
547  $SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"] = $GetVars["FK"];
548  }
549 
550  # set search logic
551  foreach ($SearchGroups as $GroupIndex => $Group)
552  {
553  $SearchGroups[$GroupIndex]["Logic"] = ($GroupIndex == "MAIN")
555  : (($GroupIndex[0] == "X")
557  }
558 
559  # return parameters to caller
560  return $SearchGroups;
561  }
562 
574  $IncludeHtml = TRUE, $StartWithBreak = TRUE, $TruncateLongWordsTo = 0)
575  {
576  return $this->SearchParameters->TextDescription(
577  $IncludeHtml, $StartWithBreak, $TruncateLongWordsTo);
578  }
579 
591  public static function TranslateSearchGroupsToTextDescription($SearchGroups,
592  $IncludeHtml = TRUE, $StartWithBreak = TRUE, $TruncateLongWordsTo = 0)
593  {
594  $Schema = new MetadataSchema();
595 
596  # start with empty description
597  $Descrip = "";
598 
599  # set characters used to indicate literal strings
600  $LiteralStart = $IncludeHtml ? "<i>" : "\"";
601  $LiteralEnd = $IncludeHtml ? "</i>" : "\"";
602  $LiteralBreak = $IncludeHtml ? "<br>\n" : "\n";
603 
604  # if this is a simple keyword search
605  if (isset($SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"])
606  && (count($SearchGroups) == 1)
607  && (count($SearchGroups["MAIN"]["SearchStrings"]) == 1))
608  {
609  # just use the search string
610  $Descrip .= $LiteralStart;
611  $Descrip .= defaulthtmlentities(
612  $SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"]);
613  $Descrip .= $LiteralEnd . $LiteralBreak;
614  }
615  else
616  {
617  # start description on a new line (if requested)
618  if ($StartWithBreak)
619  {
620  $Descrip .= $LiteralBreak;
621  }
622 
623  # define list of phrases used to represent logical operators
624  $WordsForOperators = array(
625  "=" => "is",
626  ">" => "is greater than",
627  "<" => "is less than",
628  ">=" => "is at least",
629  "<=" => "is no more than",
630  "!" => "is not",
631  );
632 
633  # for each search group
634  foreach ($SearchGroups as $GroupIndex => $Group)
635  {
636  # if group is main
637  if ($GroupIndex == "MAIN")
638  {
639  # for each field in group
640  foreach ($Group["SearchStrings"] as $FieldName => $Value)
641  {
642  # determine wording based on operator
643  preg_match("/^[=><!]+/", $Value, $Matches);
644  if (count($Matches) && isset($WordsForOperators[$Matches[0]]))
645  {
646  $Value = preg_replace("/^[=><!]+/", "", $Value);
647  $Wording = $WordsForOperators[$Matches[0]];
648  }
649  else
650  {
651  $Wording = "contains";
652  }
653 
654  # if field is psuedo-field
655  if ($FieldName == "XXXKeywordXXX")
656  {
657  # add criteria for psuedo-field
658  $Descrip .= "Keyword ".$Wording." "
659  .$LiteralStart.htmlspecialchars($Value)
660  .$LiteralEnd.$LiteralBreak;
661  }
662  else
663  {
664  # if field is valid
665  $Field = $Schema->GetFieldByName($FieldName);
666  if ($Field !== NULL)
667  {
668  # add criteria for field
669  $Descrip .= $Field->GetDisplayName()." ".$Wording." "
670  .$LiteralStart.htmlspecialchars($Value)
671  .$LiteralEnd.$LiteralBreak;
672  }
673  }
674  }
675  }
676  else
677  {
678  # for each field in group
679  $LogicTerm = ($Group["Logic"] == SearchEngine::LOGIC_AND)
680  ? "and " : "or ";
681  foreach ($Group["SearchStrings"] as $FieldName => $Values)
682  {
683  # translate values
684  $Values = self::TranslateValues(
685  $FieldName, $Values, "SearchGroup to Display");
686 
687  # for each value
688  $FirstValue = TRUE;
689  foreach ($Values as $Value)
690  {
691  # determine wording based on operator
692  preg_match("/^[=><!]+/", $Value, $Matches);
693  $Operator = $Matches[0];
694  $Wording = $WordsForOperators[$Operator];
695 
696  # strip off operator
697  $Value = preg_replace("/^[=><!]+/", "", $Value);
698 
699  # add text to description
700  if ($FirstValue)
701  {
702  $Descrip .= $FieldName." ".$Wording." "
703  .$LiteralStart.htmlspecialchars($Value)
704  .$LiteralEnd.$LiteralBreak;
705  $FirstValue = FALSE;
706  }
707  else
708  {
709  $Descrip .= ($IncludeHtml ?
710  "&nbsp;&nbsp;&nbsp;&nbsp;" : " ")
711  .$LogicTerm.$Wording." ".$LiteralStart
712  .htmlspecialchars($Value).$LiteralEnd
713  .$LiteralBreak;
714  }
715  }
716  }
717  }
718  }
719  }
720 
721  # if caller requested that long words be truncated
722  if ($TruncateLongWordsTo > 4)
723  {
724  # break description into words
725  $Words = explode(" ", $Descrip);
726 
727  # for each word
728  $NewDescrip = "";
729  foreach ($Words as $Word)
730  {
731  # if word is longer than specified length
732  if (strlen(strip_tags($Word)) > $TruncateLongWordsTo)
733  {
734  # truncate word and add ellipsis
735  $Word = StdLib::NeatlyTruncateString($Word, $TruncateLongWordsTo - 3);
736  }
737 
738  # add word to new description
739  $NewDescrip .= " ".$Word;
740  }
741 
742  # set description to new description
743  $Descrip = $NewDescrip;
744  }
745 
746  # return description to caller
747  return $Descrip;
748  }
749 
754  public function GetSearchFieldNames()
755  {
756  return $this->SearchParameters->GetFields();
757  }
758 
764  public static function TranslateSearchGroupsToSearchFieldNames($SearchGroups)
765  {
766  # start out assuming no fields are being searched
767  $FieldNames = array();
768 
769  # for each search group defined
770  foreach ($SearchGroups as $GroupIndex => $Group)
771  {
772  # for each field in group
773  foreach ($Group["SearchStrings"] as $FieldName => $Values)
774  {
775  # add field name to list of fields being searched
776  $FieldNames[] = $FieldName;
777  }
778  }
779 
780  # return list of fields being searched to caller
781  return $FieldNames;
782  }
783 
789  public static function GetSearchFrequencyList()
790  {
791  # define list with descriptions
792  $FreqDescr = array(
793  self::SEARCHFREQ_NEVER => "Never",
794  self::SEARCHFREQ_HOURLY => "Hourly",
795  self::SEARCHFREQ_DAILY => "Daily",
796  self::SEARCHFREQ_WEEKLY => "Weekly",
797  self::SEARCHFREQ_BIWEEKLY => "Biweekly",
798  self::SEARCHFREQ_MONTHLY => "Monthly",
799  self::SEARCHFREQ_QUARTERLY => "Quarterly",
800  self::SEARCHFREQ_YEARLY => "Yearly",
801  );
802 
803  # for each argument passed in
804  $Args = func_get_args();
805  foreach ($Args as $Arg)
806  {
807  # remove value from list
808  $FreqDescr = array_diff_key($FreqDescr, array($Arg => ""));
809  }
810 
811  # return list to caller
812  return $FreqDescr;
813  }
814 
818  public function Delete()
819  {
820  $this->DB->Query("DELETE FROM SavedSearches"
821  ." WHERE SearchId = ".intval($this->SearchId));
822  }
823 
824 
825  # ---- PRIVATE INTERFACE -------------------------------------------------
826 
827  private $SearchId;
828  private $Record;
829  private $SearchGroups;
830 
845  private static function TranslateValues($FieldOrFieldName, $Values, $TranslationType)
846  {
847  # start out assuming we won't find any values to translate
848  $ReturnValues = array();
849 
850  # convert field name to field object if necessary
851  if (is_object($FieldOrFieldName))
852  {
853  $Field = $FieldOrFieldName;
854  }
855  else
856  {
857  static $Schema;
858  if (!isset($Schema)) { $Schema = new MetadataSchema(); }
859  $Field = $Schema->GetFieldByName($FieldOrFieldName);
860  }
861 
862  # if incoming value is not an array
863  if (!is_array($Values))
864  {
865  # convert incoming value to an array
866  $Values = array($Values);
867  }
868 
869  # for each incoming value
870  foreach ($Values as $Value)
871  {
872  switch ($TranslationType)
873  {
874  case "SearchGroup to Display":
875  # if field is Flag field
876  if ($Field->Type() == MetadataSchema::MDFTYPE_FLAG)
877  {
878  # translate value to true/false label and add leading operator
879  $ReturnValues[] = ($Value == "=1") ?
880  "=".$Field->FlagOnLabel() : "=".$Field->FlagOffLabel();
881  }
882  elseif ($Field->Name() == "Cumulative Rating")
883  {
884  # translate numeric value to stars
885  $StarStrings = array(
886  "20" => "*",
887  "40" => "**",
888  "60" => "***",
889  "80" => "****",
890  "100" => "*****",
891  );
892  preg_match("/[0-9]+$/", $Value, $Matches);
893  $Number = $Matches[0];
894  preg_match("/^[=><!]+/", $Value, $Matches);
895  $Operator = $Matches[0];
896  $ReturnValues[] = $Operator.$StarStrings[$Number];
897  }
898  else
899  {
900  # use value as is
901  $ReturnValues[] = $Value;
902  }
903  break;
904 
905  case "SearchGroup to Database":
906  # strip off leading operator on value
907  $Value = preg_replace("/^[=><!]+/", "", $Value);
908 
909  # look up index for value
910  if ($Field->Type() & (MetadataSchema::MDFTYPE_FLAG |
912  {
913  # (for flag or number fields the value index is already
914  # what is used in SearchGroups)
915  if ($Value >= 0)
916  {
917  $ReturnValues[] = $Value;
918  }
919  }
920  elseif ($Field->Type() == MetadataSchema::MDFTYPE_USER)
921  {
922  # (for user fields the value index is the user ID)
923  $User = new CWUser(strval($Value));
924  if ($User)
925  {
926  $ReturnValues[] = $User->Id();
927  }
928  }
929  elseif ($Field->Type() == MetadataSchema::MDFTYPE_OPTION)
930  {
931  if (!isset($PossibleFieldValues))
932  {
933  $PossibleFieldValues = $Field->GetPossibleValues();
934  }
935  $NewValue = array_search($Value, $PossibleFieldValues);
936  if ($NewValue !== FALSE)
937  {
938  $ReturnValues[] = $NewValue;
939  }
940  }
941  else
942  {
943  $NewValue = $Field->GetIdForValue($Value);
944  if ($NewValue !== NULL)
945  {
946  $ReturnValues[] = $NewValue;
947  }
948  }
949  break;
950 
951  case "Database to SearchGroup":
952  # look up value for index
953  if ($Field->Type() == MetadataSchema::MDFTYPE_FLAG)
954  {
955  # (for flag fields the value index (0 or 1) is already
956  # what is used in Database)
957  if ($Value >= 0)
958  {
959  $ReturnValues[] = "=".$Value;
960  }
961  }
962  elseif ($Field->Type() == MetadataSchema::MDFTYPE_NUMBER)
963  {
964  # (for flag fields the value index (0 or 1) is already
965  # what is used in Database)
966 
967  if ($Value >= 0)
968  {
969  $ReturnValues[] = ">=".$Value;
970  }
971  }
972  elseif ($Field->Type() == MetadataSchema::MDFTYPE_USER)
973  {
974  $User = new CWUser(intval($Value));
975  if ($User)
976  {
977  $ReturnValues[] = "=".$User->Get("UserName");
978  }
979  }
980  elseif ($Field->Type() == MetadataSchema::MDFTYPE_OPTION)
981  {
982  if (!isset($PossibleFieldValues))
983  {
984  $PossibleFieldValues = $Field->GetPossibleValues();
985  }
986 
987  if (isset($PossibleFieldValues[$Value]))
988  {
989  $ReturnValues[] = "=".$PossibleFieldValues[$Value];
990  }
991  }
992  else
993  {
994  $NewValue = $Field->GetValueForId($Value);
995  if ($NewValue !== NULL)
996  {
997  $ReturnValues[] = "=".$NewValue;
998  }
999  }
1000  break;
1001  }
1002  }
1003 
1004  # return array of translated values to caller
1005  return $ReturnValues;
1006  }
1007 
1010  # utility function for updating values in database
1011 
1017  private function UpdateValue($FieldName, $NewValue)
1018  {
1019  return $this->DB->UpdateValue("SavedSearches", $FieldName, $NewValue,
1020  "SearchId = ".$this->SearchId, $this->Record);
1021  }
1022 
1028  public function GetSearchId()
1029  {
1030  return $this->Id();
1031  }
1032 
1035  private $DB;
1036  private $SearchParameters;
1037 }
const SEARCHFREQ_WEEKLY
Definition: SavedSearch.php:19
const SEARCHFREQ_NEVER
Definition: SavedSearch.php:16
static TranslateUrlParametersToSearchGroups($GetVars)
Translate URL parameters to legacy search group array.
Metadata schema (in effect a Factory class for MetadataField).
const SEARCHFREQ_DAILY
Definition: SavedSearch.php:18
Set of parameters used to perform a search.
UpdateDateLastRun()
Update date this search was last run.
SQL database abstraction object with smart query caching.
Definition: Database.php:22
GetSearchId()
Get search id.
Id()
Get ID of search.
static TranslateSearchGroupsToUrlParameterArray($SearchGroups)
Translate a search group array to an URL parameter array.
const SEARCHFREQ_QUARTERLY
Definition: SavedSearch.php:22
UserId($NewValue=DB_NOVALUE)
Get/set user ID.
Frequency($NewValue=DB_NOVALUE)
Get/set search frequency.
const SEARCHFREQ_YEARLY
Definition: SavedSearch.php:23
const SEARCHFREQ_HOURLY
Definition: SavedSearch.php:17
const SEARCHFREQ_BIWEEKLY
Definition: SavedSearch.php:20
static TranslateSearchGroupsToTextDescription($SearchGroups, $IncludeHtml=TRUE, $StartWithBreak=TRUE, $TruncateLongWordsTo=0)
Translate search group array into multi-line string describing search criteria.
const DB_NOVALUE
Definition: Database.php:1738
DateLastRun($NewValue=DB_NOVALUE)
Get/set the date this search was last run.
const SEARCHFREQ_MONTHLY
Definition: SavedSearch.php:21
static TranslateSearchGroupsToUrlParameters($SearchGroups)
Translate search group array into URL parameters (e.g.
GetSearchGroupsAsTextDescription($IncludeHtml=TRUE, $StartWithBreak=TRUE, $TruncateLongWordsTo=0)
Get multi-line string describing search criteria.
static NeatlyTruncateString($String, $MaxLength, $BreakAnywhere=FALSE)
Attempt to truncate a string as neatly as possible with respect to word breaks, punctuation, and HTML tags.
Definition: StdLib.php:237
SearchGroups($NewSearchGroups=NULL)
Get/set search parameters from legacy array.
GetSearchFieldNames()
Get list of fields to be searched.
__construct($SearchId, $SearchName=NULL, $UserId=NULL, $Frequency=NULL, $SearchParameters=NULL)
Object constructor.
Definition: SavedSearch.php:34
Delete()
Delete saved search.
SearchName($NewValue=DB_NOVALUE)
Get/set name of search.
GetSearchGroupsAsUrlParameterArray()
Get search groups as an URL parameter array.
GetSearchGroupsAsUrlParameters()
Get search groups as URL parameters (e.g.
LastMatches()
Return array of most recently matched ResourceIds for a search.
Factory for Resource objects.
CWIS-specific user class.
Definition: CWUser.php:13
SearchParameters($NewParams=NULL)
Get/set search parameters.
static GetSearchFrequencyList()
Get array of possible search frequency descriptions.
static TranslateSearchGroupsToSearchFieldNames($SearchGroups)
Extract list of fields to be searched from search group array.
SaveLastMatches($ArrayofMatchingIds)
Save array of last matches.